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 #include <stdio.h>
00042 #include <stdlib.h>
00043 #include <unistd.h>
00044 #include <string.h>
00045 #include <limits.h>
00046 #include <errno.h>
00047 #include <cmplrs/rcodes.h>
00048 #include "defs.h"
00049
00050 char path[PATH_MAX];
00051 static char *libpath[3] =
00052 {"LD_LIBRARY_PATH",
00053 "LD_LIBRARYN32_PATH",
00054 "LD_LIBRARY64_PATH"
00055 };
00056
00057 static const char * const errstring = "%s: can't allocate memory\n";
00058
00059
00060 static BOOL
00061 Has_Extension (char *name,
00062 char *ext)
00063 {
00064 INT16 nlen = strlen(name);
00065 INT16 elen = strlen(ext);
00066
00067
00068 if ( elen > nlen ) return FALSE;
00069
00070
00071 return ( strcmp ( &name[nlen-elen], ext ) == 0 );
00072 }
00073
00074
00075 static void
00076 Usage (char *progname)
00077 {
00078 fprintf(stderr,
00079 "USAGE: in EBNF notation, where '|' indicates choice and '['\n"
00080 "indicates an optional item:\n"
00081 "\n"
00082 "\t%s [-FLIST:<opts>] [-TARG:<t>] [-TENV:<e>] [-openad] [-openadType <name>] <inp_files>\n"
00083 "\n"
00084 "\t<inp_files> ::= [-fB,<Whirl_File_Name>] <File_Name>\n"
00085 "\t<opts> ::= <single_opt>[:<opts>]\n"
00086 "\n"
00087 "We recommend always using the common option -TARG:abi=[32|64].\n"
00088 "\n"
00089 "The <File_Name> is a mandatory command-line argument, which may\n"
00090 "denote either a (Fortran) source filename or a WHIRL file.\n"
00091 "In the abscense of a -fB option, the <Whirl_File_Name> will be\n"
00092 "derived from the <File_Name>\n"
00093 "-openad required within the OpenAD tool, see \n"
00094 " http://www.mcs.anl.gov/OpenAD .\n"
00095 "-openadType <name> unparses a specially named active type <name>; default is \'oadactive\'\n"
00096 "\t<name> cannot be longer than 26 characters; requires the -openad flag\n"
00097 "\n",
00098 progname);
00099
00100 fprintf(stderr,
00101 "Each -FLIST:<single_opt> is described below:\n"
00102 "\n"
00103 "-FLIST:show\n"
00104 "\tIndicate the input/output file-names to stderr.\n"
00105 "-FLIST:linelength=<n>\n"
00106 "\tSpecifies an upper limit on the number of characters we allow\n"
00107 "\ton each line in the output file. For tab-formatting, a tab\n"
00108 "\tis counted as one character\n"
00109 "-FLIST:old_f77\n"
00110 "\tPrevents emission of calls to intrinsic functions that are not\n"
00111 "\tin compilers earlier than version v7.00. The generated source\n"
00112 "\twill include <whirl2f.h>\n"
00113 "-FLIST:ansi_format\n"
00114 "\tFormat the output according to Fortran 77 rules, with at most\n"
00115 "\t72 columns per line. Without this option, tab formatting is\n"
00116 "\temployed without any limit on the line-length.\n"
00117 "-FLIST:emit_pfetch\n"
00118 "\tEmit comments to indicate prefetch instructions.\n"
00119 "-FLIST:emit_regions\n"
00120 "\tEmit all regions, whether user defined or compiler generated.\n"
00121 "\tThe default is to only emit user-defined regions.\n"
00122 "-FLIST:emit_linedirs\n"
00123 "\tEmit #line directives to map the generated statements back to\n"
00124 "\tthe corresponding original source statements.\n"
00125 "-FLIST:emit_nested_pu\n"
00126 "\tEmit code for PUs nested within other PUs. Currently, the\n"
00127 "\tsymbol-table context will not be correctly set up for this and\n"
00128 "\tthe nested PU will be emitted immediately after the parent PU.\n"
00129 "\tNote that this will also lower MP constructs.\n"
00130 "-FLIST:emit_frequency\n"
00131 "\tEmit feedback frequency numbers for each statement. The\n"
00132 "\tfrequency information will be emitted using the bang (!)\n"
00133 "\tcomment notation, and will apply to statement up till the\n"
00134 "\tprevious frequency information seen.\n"
00135 "-FLIST:src_file=<Src_File_Name>\n"
00136 "\tThe name of the original source program. When not given,\n"
00137 "\tthe <Src_File_Name> is derived from the <Whirl_File_Name>.\n"
00138 "-FLIST:ftn_file=<Ftn_OutFile_Name>\n"
00139 "\tThe file into which program units will be emitted. When not\n"
00140 "\tgiven, <Ftn_OutFile_Name> is derived from <Src_File_Name>.\n"
00141 "-FLIST:loc_file=<Loc_OutFile_Name>\n"
00142 "\tThe file for emission of a mapping from positions in the\n"
00143 "\tsource to corresponding positions in the original source\n"
00144 "\tfile. Without this option, no such file is created.\n"
00145 "\n");
00146
00147 fprintf(stderr,
00148 "The generated source will employ \"tab\" formatting, and\n"
00149 "identifiers may have the \'$\' character in their names,\n"
00150 "so always compile with the \"-dollar\" option.\n"
00151 "\n");
00152 }
00153
00154
00155 int
00156 main (INT argc,
00157 char *argv[],
00158 char *envp[])
00159 {
00160
00161
00162
00163
00164
00165
00166 register char **new_argv;
00167 register char *p;
00168 register char *env;
00169 register INT i, len;
00170 register INT argidx;
00171 register BOOL dash_fB_option = FALSE;
00172 char *newlibpath[3];
00173
00174 if (argc == 1)
00175 {
00176 Usage(argv[0]);
00177 exit(RC_NORECOVER_USER_ERROR);
00178 }
00179
00180 strcpy (path, argv[0]);
00181 if (p = strrchr(path, '/'))
00182 p[0] = 0;
00183 else
00184 strcpy (path, ".");
00185
00186 for (i = 0; i<3; i++)
00187 {
00188 len = strlen (path) + 1;
00189 len += strlen (libpath[i]) + 1;
00190
00191 env = getenv (libpath[i]);
00192
00193 if (env) {
00194 len += strlen (env) + 1;
00195
00196 newlibpath[i] = (char *) malloc (len);
00197 if (newlibpath[i] == 0) {
00198 fprintf (stderr, errstring, argv[0]);
00199 exit(RC_NORECOVER_USER_ERROR);
00200 }
00201
00202 sprintf (newlibpath[i], "%s=%s:%s", libpath[i], env, path);
00203 } else {
00204 newlibpath[i] = (char *) malloc (len);
00205 if (newlibpath[i] == 0) {
00206 fprintf (stderr, errstring, argv[0]);
00207 exit(RC_NORECOVER_USER_ERROR);
00208 }
00209
00210 sprintf (newlibpath[i], "%s=%s", libpath[i], path);
00211 }
00212 }
00213
00214
00215
00216
00217 new_argv = (char **) malloc((argc+2)*sizeof(char *));
00218 for (argidx = 0; argidx < argc; argidx++)
00219 {
00220 new_argv[argidx] = (char *) malloc(strlen(argv[argidx]) + 1);
00221 new_argv[argidx] = strcpy(new_argv[argidx], argv[argidx]);
00222 if (new_argv[argidx][0] == '-' &&
00223 new_argv[argidx][1] == 'f' &&
00224 new_argv[argidx][2] == 'B')
00225 dash_fB_option = TRUE;
00226 }
00227
00228 if (!dash_fB_option)
00229 {
00230
00231
00232
00233
00234 argidx = argc-1;
00235 while (argidx > 0)
00236 {
00237 if (new_argv[argidx][0] != '-' &&
00238 (Has_Extension(new_argv[argidx], ".B") ||
00239 Has_Extension(new_argv[argidx], ".I") ||
00240 Has_Extension(new_argv[argidx], ".N") ||
00241 Has_Extension(new_argv[argidx], ".o")))
00242 {
00243
00244
00245
00246
00247
00248 dash_fB_option = TRUE;
00249 new_argv[argc] = (char *) malloc(strlen(new_argv[argidx]) + 5);
00250 (void)strcpy(new_argv[argc], "-fB,");
00251 (void)strcpy(&new_argv[argc][4], new_argv[argidx]);
00252 argc++;
00253
00254 new_argv[argidx][strlen(new_argv[argidx])-1] = 'f';
00255 argidx = 1;
00256 }
00257 argidx--;
00258 }
00259 }
00260 new_argv[argc] = NULL;
00261
00262 for (i = 0; i<3; i++)
00263 putenv (newlibpath[i]);
00264 strcat (path, "/whirl2f_be");
00265
00266 execv (path, new_argv);
00267 fprintf (stderr, "%s: fail to execute %s: %s.\n", argv[0], path,
00268 strerror(errno));
00269 exit(RC_SYSTEM_ERROR);
00270
00271 return 0;
00272 }
00273
00274
00275