Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /* 00037 * Dynamically set up the right LD_LIBRARY_PATH before exec'ing the backend 00038 * proper. 00039 */ 00040 00041 #include <stdio.h> /* for fprintf () */ 00042 #include <stdlib.h> /* for getenv() */ 00043 #include <unistd.h> /* for execv() */ 00044 #include <string.h> /* for strcpy(), strerror(), etc. */ 00045 #include <limits.h> /* for PATH_MAX */ 00046 #include <errno.h> /* for errno */ 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, /* The filename to check */ 00062 char *ext) /* The extension to look for */ 00063 { 00064 INT16 nlen = strlen(name); 00065 INT16 elen = strlen(ext); 00066 00067 /* If ext is longer than name, no chance: */ 00068 if ( elen > nlen ) return FALSE; 00069 00070 /* Otherwise compare the tail of name to ext: */ 00071 return ( strcmp ( &name[nlen-elen], ext ) == 0 ); 00072 } /* Has_Extension */ 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 } /* Usage */ 00153 00154 00155 int 00156 main (INT argc, /* Number of command line arguments */ 00157 char *argv[], /* Array of command line arguments */ 00158 char *envp[]) /* Array of environment poINTers */ 00159 { 00160 /* Take the current value for the environment variable LD_LIBRARY_PATH, 00161 * then add in the path where this executable was found, assuming any 00162 * necessary DSOs (be.so and whirl2f.so) are found in the same 00163 * directory. Then execute "whirl2f_be", also assumed to be 00164 * in the directory where this executable resides. 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; /* Any -fB option? */ 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; /* env. variable name plus '=' */ 00190 00191 env = getenv (libpath[i]); 00192 00193 if (env) { 00194 len += strlen (env) + 1; /* old path plus ':' */ 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 } /* For each libpath kind */ 00213 00214 /* Copy the argument list into a new list of strings, with a spare 00215 * element for a missing -fB option. 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 /* Create a "-fB" option, provided the file-argument (only argument 00231 * not preceded by a '-') represents the WHIRL file if suffixed by 00232 * ".B", ".I", ".N" or ".o". 00233 */ 00234 argidx = argc-1; 00235 while (argidx > 0) 00236 { 00237 if (new_argv[argidx][0] != '-' && /* A file argument */ 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 /* A file argument representing the WHIRL input file. We need 00244 * to change this around a little bit. Put this filename under 00245 * a "-fB,filename" option and add a new filename with the 00246 * suffix substituted by ".f". 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; /* We are done! */ 00256 } 00257 argidx--; 00258 } /*while*/ 00259 } /*if (!dash_fB_option)*/ 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 } /* main */ 00273 00274 00275