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