00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 static const char *source_file = __FILE__;
00067
00068 #ifdef _KEEP_RCS_ID
00069
00070 static char *rcs_id = "$Source: crayf90/sgi/SCCS/s.cwh_pdgcs.cxx $ $Revision: 1.9 $";
00071 #endif
00072
00073
00074
00075
00076 #include "defs.h"
00077 #include "config.h"
00078 #include "config_opt.h"
00079 #include "glob.h"
00080 #include "stab.h"
00081 #include "strtab.h"
00082 #include "wn.h"
00083 #if defined(BUILD_OS_DARWIN)
00084 #include "darwin_elf.h"
00085 #else
00086 #include "elf.h"
00087 #endif
00088 #include "pu_info.h"
00089 #include <sys/types.h>
00090 #include "ir_reader.h"
00091 #include "ir_bwrite.h"
00092 #include "file_util.h"
00093 #include "tracing.h"
00094
00095
00096
00097 #include "i_cvrt.h"
00098
00099
00100
00101 #include "cwh_defines.h"
00102 #include "cwh_addr.h"
00103 #include "cwh_dst.h"
00104 #include "cwh_data.h"
00105 #include "cwh_mkdepend.h"
00106 #include "cwh_stmt.h"
00107 #include "cwh_preg.h"
00108 #include "cwh_stab.h"
00109 #include "cwh_auxst.h"
00110 #include "cwh_stk.h"
00111 #include "cwh_block.h"
00112
00113 #include "sgi_cmd_line.h"
00114
00115
00116 #include <sys/stat.h>
00117 #include <errno.h>
00118 #include <unistd.h>
00119
00120 INT32 cwh_assign_label_id;
00121 static BOOL Generate_IR = TRUE;
00122 static BOOL FE_Write_Binary = TRUE;
00123 static PU_Info *PU_Tree_Root ;
00124 static PU_Info *PU_Current ;
00125 static PU_Info *PU_Parent ;
00126
00127 #define IRB_FILE_EXTENSION ".B"
00128 #define DSTDUMP_FILE_EXTENSION ".fe.dst"
00129
00130 static PU_Info * cwh_pdgcs_pu_mem(void) ;
00131 static void update_rii_file ( void ) ;
00132 static void delete_rii_file ( void ) ;
00133
00134
00135 static MEM_POOL map_mem_pool_s;
00136 static MEM_POOL *map_mem_pool = &map_mem_pool_s;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 extern void
00154 PDGCS_initialize(LANG language_code,
00155 INT32 flags,
00156 char *cmplr_name,
00157 char *cmplr_rel,
00158 char *code_file_name,
00159 char *list_file_name,
00160 INT32 trunc_bits,
00161 INT32 debug_opts,
00162 char *src_path_name,
00163 char *cif_file_name,
00164 char *debug_file_name,
00165 FILE *debug_file,
00166 FILE *cif_file,
00167 char *src_fname,
00168 char *cwd,
00169 INT32 n_pes,
00170 INT32 meta_test)
00171
00172 {
00173
00174 Output_File *Irb_File1;
00175
00176 Set_Error_Line ( ERROR_LINE_UNKNOWN );
00177
00178 WHIRL_Keep_Cvt_On = TRUE;
00179
00180 if ( Generate_IR ) {
00181
00182 Initialize_Symbol_Tables (TRUE);
00183 cwh_auxst_alloc_container_table();
00184 cwh_auxst_register_table();
00185
00186 if ( FE_Write_Binary ) {
00187 if (!Irb_File_Name) {
00188 Irb_File_Name = New_Extension(code_file_name,
00189 IRB_FILE_EXTENSION);
00190 }
00191 Irb_File1 = Open_Output_Info ( Irb_File_Name );
00192 #ifdef KEY
00193 cwh_dst_init_file(src_fname) ;
00194 #else
00195 cwh_dst_init_file(src_path_name) ;
00196 #endif
00197 cwh_stmt_init_file(test_flag(flags,PDGCS_INITIALIZE_MP));
00198 fe_preg_init() ;
00199
00200 }
00201 }
00202
00203 if (Get_Trace (TKIND_IR,TP_IRB) ||
00204 Get_Trace (TKIND_SYMTAB,TP_IRB) ||
00205 Get_Trace (TP_IRB,TINFO_STATS)) {
00206
00207
00208 if (debug_file) {
00209 Set_Trace_File_internal(debug_file);
00210 } else if (debug_file_name) {
00211 Set_Trace_File_internal(init_debug_file());
00212 } else {
00213 if (!Trc_File_Name) {
00214
00215 Trc_File_Name = New_Extension(code_file_name,".t");
00216 }
00217 Set_Trace_File_internal(fopen(Trc_File_Name,"w"));
00218 }
00219 if (TFile == NULL) {
00220 fprintf(stderr,"Error opening trace file %s, using stdout\n",Trc_File_Name);
00221 Set_Trace_File_internal(stdout);
00222 }
00223 }
00224
00225 if (Get_Trace(TP_IRB, 0x2000))
00226 DSTdump_File_Name = New_Extension(code_file_name, DSTDUMP_FILE_EXTENSION);
00227
00228 #ifndef KEY
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 #ifdef TARG_MIPS
00239 if ( ! FE_Full_Split_Set )
00240 FE_Full_Split = OPT_Reorg_Common || OPT_Pad_Common;
00241 #endif
00242 #endif
00243
00244
00245
00246 if ( rii_file_name ) {
00247
00248 if ( enable_dsm_processing ) {
00249 if ( enable_dsm_recompile == FALSE )
00250 update_rii_file ();
00251 }
00252
00253 else
00254 delete_rii_file ();
00255 }
00256
00257
00258
00259
00260 MEM_POOL_Initialize(map_mem_pool,"map_mem_pool",FALSE);
00261 MEM_POOL_Push(map_mem_pool);
00262 Current_Map_Tab = WN_MAP_TAB_Create(map_mem_pool);
00263
00264 Set_Error_Phase ( "Front End Parse/Semantic");
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 extern void
00278 PDGCS_comp_unit(char *comp_unit_name,
00279 INT32 module_node)
00280
00281
00282 {
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 extern void
00305 PDGCS_new_proc(INT32 ir_count,
00306 INTPTR func_st_idx,
00307 INT32 alt_entry_count,
00308 INT32 scalar_opt_level,
00309 INT32 vector_opt_level,
00310 INT32 task_opt_level,
00311 INT32 opt_flags,
00312 INT32 user_mobes,
00313 INT32 user_sades,
00314 INT32 lineno,
00315 INT32 meta_opt_level)
00316 {
00317
00318 PU_Info *pu;
00319 PU_Info *pp;
00320 STB_pkt *p ;
00321 ST *fn;
00322
00323
00324 p = cast_to_STB(func_st_idx);
00325 fn = cast_to_ST(p->item);
00326
00327 cwh_stab_set_symtab(fn);
00328
00329
00330 if ( IN_NESTED_PU ) {
00331
00332
00333
00334 pu = cwh_pdgcs_pu_mem();
00335
00336 if (PU_Parent == NULL) {
00337
00338 pp = cwh_pdgcs_pu_mem();
00339 PU_Info_child(pp) = pu ;
00340
00341 if (PU_Tree_Root == NULL)
00342 PU_Tree_Root = pp;
00343 else
00344 PU_Info_next(PU_Current) = pp ;
00345
00346 PU_Parent = pp ;
00347 Set_PU_Info_flags(pp,PU_HAS_NESTED_PU);
00348
00349 } else
00350 PU_Info_next(PU_Current) = pu ;
00351
00352 } else if (PU_Tree_Root == NULL) {
00353
00354
00355
00356 pu = cwh_pdgcs_pu_mem();
00357 PU_Tree_Root = pu;
00358 PU_Parent = NULL;
00359
00360 } else if (PU_Parent == NULL) {
00361
00362
00363
00364 pu = cwh_pdgcs_pu_mem();
00365 PU_Info_next(PU_Current) = pu ;
00366
00367 } else {
00368
00369
00370
00371 pu = PU_Parent;
00372 PU_Parent = NULL;
00373 }
00374
00375 PU_Info_proc_sym(pu) = ST_st_idx(fn) ;
00376 PU_Info_maptab(pu) = Current_Map_Tab;
00377 PU_Current = pu ;
00378
00379
00380
00381 cwh_assign_label_id=0;
00382
00383
00384
00385 array_name_map = WN_MAP_Create(map_mem_pool);
00386
00387 Set_Error_Phase ( "IR->WHIRL Conversion" );
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 extern void
00400 fei_proc_body( INT32 lineno )
00401 {
00402
00403 ST *st;
00404
00405 st = &St_Table[PU_Info_proc_sym(PU_Current)];
00406 cwh_stab_set_tylist_for_entries(st);
00407 cwh_stab_emit_commons_and_equivalences(CURRENT_SYMTAB);
00408 cwh_stmt_init_pu(st,lineno);
00409
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 extern void
00431 #ifdef KEY
00432 PDGCS_do_proc(int is_module)
00433 #else
00434 PDGCS_do_proc(void)
00435 #endif
00436 {
00437
00438 WN *wn;
00439 PU_Info *pu;
00440 #ifndef KEY
00441 TYPE tt;
00442 #endif
00443 ST *st;
00444
00445 DST_IDX d ;
00446
00447 pu = PU_Current ;
00448
00449 st = &St_Table[PU_Info_proc_sym(pu)];
00450 PU& p = Pu_Table[ST_pu(st)];
00451 if (PU_is_mainpu (p)) {
00452 #ifdef KEY
00453 TYPE tt;
00454 memset(&tt, 0, sizeof(tt));
00455 #endif
00456 fei_return(2,tt);
00457 }
00458
00459 if (cwh_stab_pu_has_globals) {
00460 Set_PU_Info_flags(pu,PU_HAS_GLOBALS);
00461 }
00462
00463 cwh_stmt_postprocess_pu();
00464 wn = cwh_stmt_end_pu();
00465 #ifdef KEY
00466
00467
00468 if (is_module) {
00469 cwh_dst_module_vars(st);
00470
00471 Set_PU_Info_tree_ptr(pu, wn);
00472 }
00473 else {
00474 d = cwh_dst_enter_pu(st);
00475
00476 Set_PU_Info_tree_ptr(pu, wn);
00477 Set_PU_Info_pu_dst(pu,d);
00478 Set_PU_Info_cu_dst(pu,d);
00479 }
00480 #else
00481 d = cwh_dst_enter_pu(st);
00482 Set_PU_Info_pu_dst(pu,d);
00483 Set_PU_Info_cu_dst(pu,d);
00484 #endif
00485
00486 Set_PU_Info_state(pu, WT_SYMTAB, Subsect_InMem);
00487 Set_PU_Info_state(pu, WT_TREE, Subsect_InMem);
00488 Set_PU_Info_state(pu, WT_PROC_SYM, Subsect_InMem);
00489
00490
00491 cwh_data_emit_symbol_inits(CURRENT_SYMTAB);
00492
00493 if (Get_Trace (TKIND_IR,TP_IRB))
00494 fdump_tree(TFile,wn);
00495
00496 if (Get_Trace (TKIND_SYMTAB,TP_IRB)) {
00497
00498 fprintf(TFile,"PU info: %s (0x%08x)\n",
00499 ST_name(PU_Info_proc_sym(pu)),
00500 PU_Info_flags(pu));
00501
00502 Print_local_symtab (TFile, Scope_tab [CURRENT_SYMTAB]);
00503 }
00504
00505 cwh_stk_verify_empty();
00506 Verify_SYMTAB (CURRENT_SYMTAB);
00507 Write_PU_Info (pu);
00508
00509 #if 0
00510 if (Get_Trace (TP_IRB,TINFO_STATS))
00511 cwh_stats_print(PU_Info_proc_sym(pu));
00512 #endif
00513
00514 WN_MAP_Delete(array_name_map);
00515 WN_Mem_Pop();
00516
00517 Set_Error_Phase ( "IR->WHIRL Conversion" );
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 extern void
00530 PDGCS_end_procs(INT32 *code_size,
00531 INT32 *data_size )
00532 {
00533 cwh_stab_end_procs();
00534 Set_Error_Phase ( "Front End Parse/Semantic");
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 extern void
00549 PDGCS_terminate ( void)
00550 {
00551
00552
00553 cwh_stab_emit_commons_and_equivalences(GLOBAL_SYMTAB);
00554
00555
00556 cwh_data_emit_symbol_inits(GLOBAL_SYMTAB);
00557
00558 if (Get_Trace (TKIND_SYMTAB,TP_IRB)) {
00559 Print_global_symtab ( TFile );
00560 }
00561
00562 cwh_dst_write();
00563
00564
00565 Verify_SYMTAB (GLOBAL_SYMTAB);
00566 Write_Global_Info (PU_Tree_Root);
00567 Close_Output_Info ();
00568
00569 cwh_write_makedepend();
00570
00571 Set_Error_Phase ( "Front End Parse/Semantic");
00572 }
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 static PU_Info *
00586 cwh_pdgcs_pu_mem(void)
00587 {
00588
00589 PU_Info *p;
00590
00591 p = TYPE_MEM_POOL_ALLOC(PU_Info, FE_Mempool);
00592 PU_Info_init(p);
00593
00594 WN_Mem_Push();
00595
00596 return p ;
00597
00598 }
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 #if 0
00610 static char *
00611 basename ( char * const s )
00612 {
00613 char * p;
00614 char * last;
00615 char * name;
00616 int size;
00617
00618 if ( s == NULL || *s == '\0' )
00619 return ".";
00620
00621 else {
00622
00623 p = s + strlen ( s );
00624
00625
00626
00627 while ( p != s && *p == '/' )
00628 --p;
00629
00630 last = p;
00631
00632 while ( p != s ) {
00633
00634 if ( *--p == '/' ) {
00635
00636 ++p;
00637 break;
00638 }
00639 }
00640
00641 size = last - p;
00642 name = (char *) malloc ( size + 1);
00643 strncpy ( name, p, size );
00644 name [size] = '\0';
00645
00646 return name;
00647 }
00648 }
00649 #endif
00650
00651 static const char *
00652 dirname ( char * const s )
00653 {
00654 char * p;
00655 char * name;
00656 int size;
00657
00658 if ( s == NULL || *s == '\0' )
00659 return ".";
00660
00661 else {
00662
00663 p = s + strlen ( s );
00664
00665
00666
00667 while ( p != s && *p == '/' )
00668 --p;
00669
00670 while ( p != s ) {
00671
00672 if ( *--p == '/' ) {
00673
00674 if ( p == s )
00675 return "/";
00676
00677 while ( *p == '/' )
00678 --p;
00679
00680 size = p - s + 1;
00681 name = (char *) malloc ( size + 1 );
00682 strncpy ( name, s, size );
00683 name [size] = '\0';
00684 return name;
00685 }
00686 }
00687
00688 return ".";
00689 }
00690 }
00691
00692
00693
00694
00695
00696 static void
00697 skip_old_rii_controls ( FILE * f )
00698 {
00699 int c;
00700 int terminator_found = 0;
00701
00702 c = getc ( f );
00703
00704 while ( c != EOF ) {
00705
00706 if ( c == '-'
00707 && ( c = getc ( f ) ) == '-'
00708 && ( c = getc ( f ) ) == '-'
00709 && ( c = getc ( f ) ) == '-' )
00710 terminator_found = 1;
00711
00712 while ( c != '\n' && c != EOF )
00713 c = getc ( f );
00714
00715 if ( terminator_found )
00716 break;
00717
00718 if (c == '\n')
00719 c = getc ( f );
00720 }
00721
00722 if ( c == EOF )
00723 rewind(f);
00724 }
00725
00726
00727 static void
00728 delete_rii_file ( void )
00729 {
00730 FILE * f_rii_file;
00731
00732 f_rii_file = fopen ( rii_file_name, "r" );
00733
00734 if ( f_rii_file ) {
00735
00736 fclose ( f_rii_file );
00737 unlink ( rii_file_name );
00738 }
00739 }
00740
00741
00742 static void
00743 update_rii_file ( void )
00744 {
00745 FILE * f_rii_file;
00746 FILE * f_old_rii_file;
00747 FILE * f_cmd_file;
00748 const char * rii_dir_name;
00749 char * new_rii_file_name;
00750 int ch;
00751
00752 rii_dir_name = dirname ( rii_file_name );
00753 f_old_rii_file = fopen ( rii_file_name, "r" );
00754
00755 if ( f_old_rii_file == NULL ) {
00756
00757 if ( mkdir ( rii_dir_name, 0777 ) < 0 && errno != EEXIST ) {
00758
00759
00760
00761
00762 fprintf ( stderr, "could not create rii directory %s\n", rii_dir_name );
00763 return;
00764
00765 }
00766
00767 else
00768 new_rii_file_name = rii_file_name;
00769 }
00770
00771 else {
00772
00773 skip_old_rii_controls ( f_old_rii_file );
00774
00775 new_rii_file_name = (char *) malloc ( strlen ( rii_file_name ) + 5 );
00776 sprintf ( new_rii_file_name, "%s.NEW", rii_file_name );
00777 }
00778
00779 if ( access ( rii_dir_name, W_OK ) < 0 ) {
00780
00781
00782
00783
00784 fprintf ( stderr, "no write permissions in rii directory %s\n",
00785 rii_dir_name );
00786 return;
00787 }
00788
00789 f_rii_file = fopen ( new_rii_file_name, "w" );
00790
00791 if ( f_rii_file == NULL ) {
00792
00793
00794 fprintf ( stderr, "unable to open rii file for writing %s\n", rii_file_name );
00795 return;
00796 }
00797
00798 f_cmd_file = fopen ( FE_command_line, "r" );
00799
00800 if ( f_cmd_file == NULL ) {
00801
00802
00803 fprintf ( stderr, "unable to open cmd file for reading %s\n",
00804 FE_command_line );
00805 return;
00806 }
00807
00808 fputs ( "CMDLINE=", f_rii_file );
00809
00810 while ( ( ch = getc ( f_cmd_file ) ) != '\n' )
00811 putc ( ch, f_rii_file );
00812
00813 fputs ( "\nPWD=", f_rii_file );
00814
00815 while ( ( ch = getc ( f_cmd_file ) ) != '\n' )
00816 putc ( ch, f_rii_file );
00817
00818 fclose ( f_cmd_file );
00819
00820 fputs ( "\n----\n", f_rii_file );
00821
00822 if ( f_old_rii_file ) {
00823
00824 while ( ( ch = getc ( f_old_rii_file ) ) != EOF )
00825 putc ( ch, f_rii_file );
00826
00827
00828
00829 fclose ( f_old_rii_file );
00830 fclose ( f_rii_file );
00831
00832 if ( rename ( new_rii_file_name, rii_file_name ) < 0 ) {
00833
00834 fprintf (stderr, "error in renaming %s %s\n",
00835 new_rii_file_name, rii_file_name );
00836 }
00837
00838 free ( new_rii_file_name );
00839 }
00840
00841 else
00842 fclose ( f_rii_file );
00843 }