Go to the documentation of this file.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
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifdef _KEEP_RCS_ID
00076 #endif
00077
00078 #include <elf.h>
00079 #include "whirl2c_common.h"
00080 #include "glob.h"
00081 #include "flags.h"
00082 #include "pu_info.h"
00083 #include "ir_bread.h"
00084 #include "err_host.tab"
00085
00086 #include "pu_info.h"
00087 #include "file_util.h"
00088 #include "wn_lower.h"
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #define C_FILE_EXTENSION ".c"
00100 #define IRB_FILE_EXTENSION ".B"
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 static void
00114 Usage (char *progname)
00115 {
00116 fprintf(stderr,
00117 "USAGE: in EBNF notation, where '|' indicates choice and '['\n"
00118 "indicates an optional item:\n"
00119 "\n"
00120 "\t%s [-CLIST:<opts>] [-TARG:<t>] [-TENV:<e>] <Whirl_File_Name>\n"
00121 "\n"
00122 "\t<opts> ::= <single_opt>[:<opts>]\n"
00123 "\n"
00124 "The <Whirl_File_Name> is a mandatory command-line argument.\n"
00125 "We recommend always using the common option -TARG:abi=[32|64].\n"
00126 "\n",
00127 progname);
00128
00129 fprintf(stderr,
00130 "Each -CLIST:<single_opt> is described below:\n"
00131 "\n"
00132 "-CLIST:show\n"
00133 "\tIndicate the input/output file-names to stderr.\n"
00134 "-CLIST:no_pragmas\n"
00135 "\tTurn off emission of pragmas into the C output file.\n"
00136 "-CLIST:emit_adims\n"
00137 "\tComment multi-dimensional array indexing expressions to\n"
00138 "\tindicate which subexpression denotes which dimension.\n"
00139 "-CLIST:emit_pfetch\n"
00140 "\tEmit comments to indicate prefetch instructions.\n"
00141 "-CLIST:emit_linedir\n"
00142 "\tEmit #line directives to map the generated statements back to\n"
00143 "\tthe corresponding original source statements.\n"
00144 "-CLIST:ftn\n"
00145 "\tThe intermediate is for a Fortran source program; intrinsics\n"
00146 "\tand IO-statements must be lowered for translation to C.\n"
00147 "-CLIST:src_file=<Src_File_Name>\n"
00148 "\tThe name of the original source program. When not given,\n"
00149 "\tthe <Src_File_Name> is derived from the <Whirl_File_Name>.\n"
00150 "-CLIST:doth_file=<H_File_Name>\n"
00151 "\tThe file into which file-level declarations will be emitted.\n"
00152 "\tWhen not given, <H_File_Name> is derived from <Src_File_Name>.\n"
00153 "-CLIST:dotc_file=<C_File_Name>\n"
00154 "\tThe file into which program units will be emitted. When\n"
00155 "\tnot given, <C_File_Name> is derived from <Src_File_Name>.\n"
00156 "-CLIST:loc_file=<Loc_File_Name>\n"
00157 "\tThe file for emission of a mapping from positions in the\n"
00158 "\tsource to corresponding positions in the original source\n"
00159 "\tfile. Without this option, no such file is created.\n"
00160 "\n");
00161 fprintf(stderr,
00162 "Compile the generated <C_File_Name> with \"-dollar -lm\". When\n"
00163 "-CLIST:ftn, then compile the generated <C_File_Name> with\n"
00164 "\"-D_FORTRAN2C -dollar -lftn\" and possibly other \"-l\" options\n"
00165 "to account for libraries referenced in the source.\n"
00166 "\n");
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 static void
00180 Process_Common_Options(INT argc,
00181 char *argv[],
00182 char *envp[])
00183 {
00184 INT argidx;
00185
00186 for (argidx = 1; argidx < argc; argidx++ )
00187 {
00188 if (argv[argidx] != NULL)
00189 {
00190 if (argv[argidx][0] == '-' )
00191 {
00192 (void)Process_Command_Line_Group(&argv[argidx][1],
00193 Common_Option_Groups);
00194 }
00195 }
00196 }
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 void
00210 Local_Terminate ( void )
00211 {
00212
00213 W2C_Fini();
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 static INT32
00230 Get_Irb_File_Name(INT argc, char *argv[])
00231 {
00232
00233 #define MAX_FNAME_LENGTH 256-7
00234 static char filename[MAX_FNAME_LENGTH+7];
00235 const char *fname;
00236 INT32 argidx;
00237 INT32 src_count = 0;
00238
00239 for (argidx = 1; argidx < argc; argidx++)
00240 {
00241
00242 if (argv[argidx][0] == '-' )
00243 {
00244
00245 }
00246 else if (src_count > 0)
00247 src_count += 1;
00248 else if (src_count == 0)
00249 {
00250
00251 Irb_File_Name = argv[argidx];
00252 if (strlen(Irb_File_Name) > MAX_FNAME_LENGTH)
00253 {
00254 Irb_File_Name = strncpy(filename, Irb_File_Name, MAX_FNAME_LENGTH);
00255 filename[MAX_FNAME_LENGTH] = '\0';
00256 fprintf(stderr,
00257 "WARNING: input file-name truncated to "
00258 "(max=%d chars): \"%s\"\n",
00259 MAX_FNAME_LENGTH, Irb_File_Name);
00260 }
00261 else
00262 Irb_File_Name = strcpy(filename, Irb_File_Name);
00263
00264 src_count = 1;
00265 }
00266 }
00267 return src_count;
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 INT
00281 main (INT argc,
00282 char *argv[],
00283 char *envp[])
00284 {
00285 WN *pu;
00286 INT32 ecount = 0, wcount = 0, local_ecount = 0, local_wcount = 0;
00287 INT32 inp_file_count;
00288 PU_Info *pu_tree, *current_pu;
00289
00290
00291
00292
00293 MEM_Initialize();
00294 Init_Error_Handler(10);
00295 Set_Error_Line(ERROR_LINE_UNKNOWN);
00296 Set_Error_Phase("Whirl2c");
00297 Set_Error_File(NULL);
00298
00299 Preconfigure();
00300 Process_Common_Options(argc, argv, envp);
00301 Configure();
00302
00303 Init_Operator_To_Opcode_Table();
00304
00305
00306 inp_file_count = Get_Irb_File_Name(argc, argv);
00307 if (inp_file_count == 0)
00308 {
00309 Usage(argv[0]);
00310 fprintf(stderr, "ERROR: missing input file on command-line\n");
00311 }
00312 else if (inp_file_count > 1)
00313 {
00314 Usage(argv[0]);
00315 fprintf(stderr, "ERROR: too many input files on command-line\n");
00316 }
00317 else
00318 {
00319
00320
00321
00322
00323 (void)Open_Input_Info(Irb_File_Name);
00324
00325 Initialize_Symbol_Tables (FALSE);
00326 New_Scope (GLOBAL_SYMTAB, Malloc_Mem_Pool, FALSE);
00327
00328
00329
00330 pu_tree = Read_Global_Info(NULL);
00331 Initialize_Special_Global_Symbols ();
00332
00333 W2C_Process_Command_Line(argc, argv, argc, argv);
00334
00335 W2C_Outfile_Init(TRUE);
00336
00337 for (current_pu = pu_tree;
00338 current_pu != NULL;
00339 current_pu = PU_Info_next (current_pu)) {
00340
00341 Current_PU_Info = current_pu;
00342 MEM_POOL_Push (MEM_pu_nz_pool_ptr);
00343 Read_Local_Info (MEM_pu_nz_pool_ptr, current_pu);
00344 pu = PU_Info_tree_ptr(current_pu);
00345
00346 W2C_Outfile_Translate_Pu(pu, TRUE);
00347
00348 if (PU_Info_child(current_pu)) {
00349 fprintf(stderr, "WARNING: ignoring nested procedures in \"%s\"\n",
00350 ST_name(PU_Info_proc_sym(current_pu)));
00351 }
00352
00353 Free_Local_Info (current_pu);
00354 MEM_POOL_Pop (MEM_pu_nz_pool_ptr);
00355 }
00356
00357 W2C_Outfile_Fini(TRUE);
00358 Cleanup_Files(TRUE, FALSE);
00359 }
00360
00361
00362 if (Get_Error_Count(&local_ecount, &local_wcount))
00363 {
00364 ecount += local_ecount;
00365 wcount += local_wcount;
00366 }
00367 if ( ecount > 0 )
00368 {
00369 Local_Terminate();
00370 Terminate(1);
00371 }
00372
00373 exit(0);
00374 }