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 #define __STDC_LIMIT_MACROS
00053 #include <stdint.h>
00054 #include <unistd.h>
00055 #if defined(BUILD_OS_DARWIN)
00056 #include <darwin_elf.h>
00057 #else
00058 #include <elf.h>
00059 #endif
00060 #include <cmplrs/rcodes.h>
00061 #ifdef __MINGW32__
00062 #include <WINDOWS.h>
00063 void CG_force_link(void);
00064
00065 #endif
00066
00067 #include "defs.h"
00068 #include "config.h"
00069 #include "config_ipa.h"
00070 #include "flags.h"
00071 #include "file_util.h"
00072 #include "glob.h"
00073 #include "err_host.tab"
00074 #include "erglob.h"
00075 #include "mempool.h"
00076 #include "wn.h"
00077 #include "pu_info.h"
00078 #include "ir_bwrite.h"
00079 #include "strtab.h"
00080 #include "ipc_option.h"
00081 #include "timing.h"
00082 #include "tracing.h"
00083 #include "inline.h"
00084
00085
00086 #define IRB_FILE_EXTENSION ".B"
00087 #define TRC_FILE_EXTENSION ".t"
00088 char* Irb_Output_Name = NULL;
00089
00090
00091 #define MAX_OLIMIT INT32_MAX
00092
00093 BOOL Verbose = FALSE;
00094
00095
00096
00097
00098
00099 SKIPLIST *IPA_Skip_List = NULL;
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 static void
00114 Process_Command_Line (INT argc, char **argv)
00115 {
00116 INT i;
00117 INT Src_Count = 0;
00118 BOOL dashdash_flag = FALSE;
00119
00120
00121 for ( i = 1; i < argc; i++ ) {
00122 if (argv[i] != NULL && (strcmp(argv[i],"--")==0)) {
00123 dashdash_flag = TRUE;
00124 continue;
00125 }
00126 if ( !dashdash_flag && argv[i] != NULL && *(argv[i]) == '-' ) {
00127
00128 if (Process_Command_Line_Group (argv[i]+1, Common_Option_Groups))
00129 continue;
00130
00131 switch (argv[i][1]) {
00132
00133 case 'c':
00134 i = argc;
00135 break;
00136
00137 case 'g':
00138 switch (argv[i][2]) {
00139 case '0':
00140 case '1':
00141 case '2':
00142 case '3':
00143 if (argv[i][3] != 0)
00144 break;
00145
00146 #if ! (defined(linux) || defined(BUILD_OS_DARWIN))
00147 case 0:
00148 if (!IPA_Enable_DFE_Set)
00149 IPA_Enable_DFE = FALSE;
00150 #endif
00151 }
00152 break;
00153
00154 case 'f':
00155 if (argv[i][2] == 0)
00156 ErrMsg (EC_File_Name, '?', argv[i]);
00157 else if (argv[i][3] != ',' && argv[i][3] != ':')
00158 ErrMsg (EC_File_Name, argv[i][2], argv[i]);
00159 else {
00160 switch (argv[i][2]) {
00161 case 'B':
00162 Irb_File_Name = argv[i] + 4;
00163 break;
00164 case 'I':
00165 Irb_Output_Name = argv[i] + 4;
00166 break;
00167
00168 default:
00169 ErrMsg ( EC_File_Flag, argv[i][2], argv[i] );
00170 break;
00171 }
00172 }
00173 break;
00174
00175 case 'm':
00176 break;
00177
00178 case 's':
00179 if (strcmp (argv[i]+1, "show") == 0)
00180 Verbose = TRUE;
00181 else
00182 ErrMsg ( EC_Unknown_Flag, argv[i][0], argv[i] );
00183 break;
00184
00185 case 't':
00186 Process_Trace_Option ( argv[i] );
00187 break;
00188
00189 case 'O':
00190 switch (argv[i][2])
00191 {
00192 case '3':
00193 Opt_Level = 3;
00194 INLINE_Enable_Split_Common = TRUE;
00195 break;
00196 case '2':
00197 Opt_Level = 2;
00198 INLINE_Enable_Split_Common = FALSE;
00199 break;
00200 default:
00201 Opt_Level = 1;
00202 INLINE_Enable_Split_Common = FALSE;
00203 break;
00204 }
00205 break;
00206
00207 case 'P':
00208 break;
00209
00210 case 'd':
00211 if (strncmp (argv[i]+1, "dsm", 3) != 0)
00212 ErrMsg ( EC_Unknown_Flag, argv[i][0], argv[i] );
00213 break;
00214
00215 default:
00216 ErrMsg ( EC_Unknown_Flag, argv[i][0], argv[i] );
00217 break;
00218 }
00219 } else if (argv[i] != NULL) {
00220 dashdash_flag = FALSE;
00221 Src_Count++;
00222 Src_File_Name = argv[i];
00223 }
00224 }
00225
00226
00227 if ( Olimit == 0 ) Olimit = MAX_OLIMIT;
00228
00229
00230 Process_Inline_Options ();
00231
00232 IPA_Enable_BarrierFarg = FALSE;
00233
00234 #if 0
00235
00236 if ( Tracing_Enabled ) {
00237 Initialize_Timing (TRUE);
00238 }
00239 #endif
00240
00241 if ( Get_Trace ( TKIND_ALLOC, TP_INLINE ) ) {
00242 MEM_Tracing_Enable ();
00243 }
00244
00245 if (Src_Count == 0) {
00246 ErrMsg ( EC_No_Sources );
00247 exit (RC_USER_ERROR);
00248 }
00249
00250 if (Irb_File_Name == NULL)
00251 Irb_File_Name = New_Extension (Src_File_Name, IRB_FILE_EXTENSION);
00252
00253 if (Irb_Output_Name == NULL)
00254 Irb_Output_Name = New_Extension (Src_File_Name, ".I");
00255
00256 if (Trc_File_Name == NULL) {
00257 if (Tracing_Enabled)
00258 Trc_File_Name = New_Extension (Irb_Output_Name, TRC_FILE_EXTENSION);
00259 } else if ( *Trc_File_Name == '-')
00260 Trc_File_Name = NULL;
00261
00262 Set_Trace_File (Trc_File_Name);
00263
00264
00265 if ( Get_Trace ( TP_PTRACE1, 1 ) ) {
00266 Set_Trace ( TP_PTRACE1, 0xffffffff );
00267 Set_Trace ( TP_PTRACE2, 0xffffffff );
00268 }
00269
00270
00271 if (Get_Trace ( TP_PTRACE1, TP_PTRACE1_INL )) {
00272 if ( Tlog_File_Name == NULL ) {
00273
00274 Tlog_File_Name = New_Extension (Irb_Output_Name , ".tlog" );
00275 }
00276 if ( (Tlog_File = fopen ( Tlog_File_Name, "w" ) ) == NULL ) {
00277 ErrMsg ( EC_Tlog_Open, Tlog_File_Name, errno );
00278 Tlog_File_Name = NULL;
00279 Tlog_File = stdout;
00280 }
00281 }
00282
00283
00284
00285 if ( Get_Trace ( TKIND_INFO, TINFO_TFLAGS ) ) {
00286 List_Phase_Numbers ();
00287 }
00288
00289 #if 0
00290 if (Get_Trace (TKIND_INFO, TINFO_TIME))
00291 Tim_File = TFile;
00292 #endif
00293
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 main (INT argc, char **argv)
00306 {
00307 INT32 ecount, local_ecount, local_wcount;
00308
00309 ecount = 0;
00310
00311
00312
00313 Handle_Signals();
00314 MEM_Initialize();
00315 Dont_Use_WN_Free_List ();
00316
00317
00318 Cur_PU_Name = NULL;
00319 Init_Error_Handler (100);
00320 #if !defined(SHARED_BUILD)
00321 Set_Error_Tables ( Phases, host_errlist );
00322 #endif
00323 Set_Error_Line ( ERROR_LINE_UNKNOWN );
00324 Set_Error_File (NULL);
00325
00326 #ifdef _LIGHTWEIGHT_INLINER
00327 Set_Error_Phase ( "Lightweight Inliner" );
00328 #else // _LIGHTWEIGHT_INLINER
00329 Set_Error_Phase ( "Inliner" );
00330 #endif // _LIGHTWEIGHT_INLINER
00331
00332 Preconfigure ();
00333 Process_Command_Line (argc, argv);
00334 if ( ! INLINE_Enable ) {
00335 INT rc;
00336
00337
00338
00339
00340 unlink(Irb_Output_Name);
00341 #ifndef __MINGW32__
00342 rc = symlink(Irb_File_Name, Irb_Output_Name);
00343 if (rc != 0)
00344 #else
00345 rc = CopyFile(Irb_File_Name, Irb_Output_Name, TRUE);
00346 if (rc == 0)
00347 #endif
00348 ErrMsg ( EC_IR_Create, Irb_Output_Name, errno);
00349 }
00350 else {
00351 Configure ();
00352 Set_Error_Source (Src_File_Name);
00353 Init_Operator_To_Opcode_Table();
00354 BOOL close_output = Inliner(Irb_File_Name, Irb_Output_Name);
00355
00356 #if 0
00357 Finish_Compilation_Timing ( Tim_File, Src_File_Name );
00358 #endif
00359
00360 if ( Get_Trace ( TKIND_ALLOC, TP_IPA ) ) {
00361 fprintf ( TFile,
00362 "\n%s%s\tMemory allocation information after Inliner\n%s%s\n",
00363 DBar, DBar, DBar, DBar );
00364 MEM_Trace ();
00365 }
00366
00367 Cleanup_Files ( TRUE, FALSE );
00368 if (close_output)
00369 Close_Output_Info();
00370 }
00371
00372
00373 if ( Get_Error_Count ( &local_ecount, &local_wcount ) ) {
00374 ecount += local_ecount;
00375 }
00376
00377 if ( ecount > 0 ) {
00378 Terminate (RC_USER_ERROR) ;
00379 }
00380
00381 exit (RC_OKAY);
00382 }