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 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <sys/stat.h>
00031 #include <cmplrs/rcodes.h>
00032 #include "gspin-wgen-interface.h"
00033 #include "defs.h"
00034 #include "glob.h"
00035 #include "erglob.h"
00036 #include "err_host.tab"
00037 #include "config.h"
00038 #include "file_util.h"
00039 #include "wgen_misc.h"
00040
00041 extern BOOL List_Enabled;
00042 extern INT Opt_Level;
00043 extern BOOL Enable_WFE_DFE;
00044
00045 #ifndef TARG_MIPS
00046 BOOL TARGET_64BIT = TRUE;
00047 #else
00048 BOOL TARGET_64BIT = FALSE;
00049 #endif
00050
00051 BOOL wgen_invoke_inliner = FALSE;
00052 int lineno = 0;
00053 char *Spin_File_Name = NULL;
00054 FILE *Spin_File = NULL;
00055 BOOL flag_no_common = FALSE;
00056 int pstatic_as_global = 0;
00057 int key_exceptions = 0;
00058 BOOL opt_regions = 0;
00059 BOOL lang_cplus = FALSE;
00060 BOOL c_omit_external = TRUE;
00061 #ifdef FE_GNU_4_2_0
00062 BOOL enable_cxx_openmp = TRUE;
00063 #endif
00064 gs_t program;
00065
00066 # define DEF_DEBUG_LEVEL 0
00067 INT Debug_Level = DEF_DEBUG_LEVEL;
00068
00069 extern void WGEN_Weak_Finish(void);
00070 extern void WGEN_Expand_Top_Level_Decl(gs_t);
00071 extern void WGEN_Expand_Defers(void);
00072 extern void WGEN_Expand_Decl(gs_t, BOOL);
00073 #ifdef KEY
00074 extern void WGEN_Alias_Finish(void);
00075 #endif
00076
00077
00078
00079
00080 void
00081 Process_Command_Line(INT argc, char **argv)
00082 {
00083 INT i;
00084 char *cp;
00085
00086 for (i = 1; i < argc; i++) {
00087 if ( argv[i] != NULL && *(argv[i]) == '-' ) {
00088 cp = argv[i]+1;
00089
00090 switch ( *cp++ ) {
00091
00092 case 'f':
00093 if (*cp == 0)
00094 ;
00095 else if (*(cp+1) != ',' && *(cp+1) != ':')
00096 ;
00097 else {
00098 switch (*cp) {
00099 case 'f':
00100 Feedback_File_Name = cp + 2;
00101 break;
00102 case 'l':
00103 List_Enabled = TRUE;
00104 Lst_File_Name = cp + 2;
00105 break;
00106
00107 case 't':
00108 Trc_File_Name = cp + 2;
00109 break;
00110
00111 case 'B':
00112 Irb_File_Name = cp + 2;
00113 break;
00114
00115 case 'S':
00116 Spin_File_Name = cp + 2;
00117 break;
00118
00119 default:
00120 break;
00121 }
00122 }
00123 break;
00124
00125 case 'O':
00126 if (strncmp(cp, "PT:", 3) == 0)
00127 Process_Command_Line_Group (cp-1, Common_Option_Groups);
00128 break;
00129
00130 case 't':
00131 Process_Trace_Option(cp-2);
00132 break;
00133 case 'v':
00134 Show_Progress = TRUE;
00135 break;
00136
00137
00138 default:
00139 break;
00140 }
00141 }
00142 }
00143 }
00144
00145
00146
00147
00148 void
00149 Process_Cc1_Command_Line(gs_t arg_list)
00150 {
00151 INT i, j;
00152 char *cp;
00153 INT Src_Count = 0;
00154 BOOL opt_set = FALSE;
00155 INT argc = gs_length(arg_list);
00156 char *argv;
00157
00158
00159 argv = gs_s(gs_index(arg_list, 0));
00160 char *command = Last_Pathname_Component(argv);
00161
00162 #ifdef FE_GNU_4_2_0
00163 lang_cplus = !strcmp(command, "cc1plus42");
00164 #else
00165 lang_cplus = !strcmp(command, "cc1plus");
00166 #endif
00167
00168 if (lang_cplus)
00169 key_exceptions = 1;
00170
00171 for (i = 1; i < argc; i++) {
00172 argv = gs_s(gs_index(arg_list, i));
00173
00174 if ( *argv == '-' ) {
00175 cp = argv+1;
00176
00177 switch ( *cp++ ) {
00178
00179 case 'a':
00180 if (!strcmp( cp, "uxbase" ))
00181 i++;
00182 break;
00183
00184 case 'd':
00185 if (!strcmp( cp, "umpbase" ))
00186 {
00187 i++;
00188 Orig_Src_File_Name = gs_s(gs_index(arg_list, i));
00189 }
00190 break;
00191
00192 case 'e':
00193 if (lang_cplus && !strcmp( cp, "xceptions" ))
00194 key_exceptions = TRUE;
00195 break;
00196
00197 case 'f':
00198 if (!strcmp( cp, "no-exceptions" )) {
00199 key_exceptions = FALSE;
00200 }
00201 else if (lang_cplus && !strcmp( cp, "exceptions" )) {
00202 key_exceptions = TRUE;
00203 }
00204 else if (!strcmp( cp, "no-gnu-exceptions")) {
00205
00206 key_exceptions = FALSE;
00207 }
00208 else if (!lang_cplus && !strcmp( cp, "no-c-omit-external")) {
00209 c_omit_external = FALSE;
00210 }
00211 else if (!lang_cplus && !strcmp( cp, "c-omit-external")) {
00212 c_omit_external = TRUE;
00213 }
00214 #ifdef FE_GNU_4_2_0
00215 else if (!strcmp( cp, "no-cxx-openmp")) {
00216 enable_cxx_openmp = FALSE;
00217 }
00218 else if (lang_cplus && !strcmp( cp, "cxx-openmp")) {
00219 enable_cxx_openmp = TRUE;
00220 }
00221 #endif
00222 break;
00223
00224 case 'g':
00225 Debug_Level = Get_Numeric_Flag (&cp, 0, MAX_DEBUG_LEVEL, 2,
00226 argv);
00227 if (Debug_Level > 1 && !opt_set)
00228 Opt_Level = 0;
00229 break;
00230
00231 case 'i':
00232 if (!strcmp( cp, "prefix" ))
00233 i++;
00234 break;
00235
00236 case 'm':
00237 #ifndef TARG_MIPS
00238 if (!strcmp( cp, "32" )) {
00239 TARGET_64BIT = FALSE;
00240 }
00241 else if (!strcmp( cp, "64" )) {
00242 TARGET_64BIT = TRUE;
00243 }
00244 #ifdef TARG_X8664
00245 else if (!strncmp( cp, "regparm=", 8 )) {
00246 cp += 8;
00247 Reg_Parm_Count = Get_Numeric_Flag (&cp, 0, 3, 0, argv );
00248 }
00249 else if (!strcmp( cp, "sseregparm" )) {
00250 SSE_Reg_Parm = TRUE;
00251 }
00252 #endif
00253 #else
00254
00255 if (!strcmp( cp, "abi=n32" )) {
00256 TARGET_64BIT = FALSE;
00257 }
00258 else if (!strcmp( cp, "abi=64" )) {
00259 TARGET_64BIT = TRUE;
00260 }
00261 #endif
00262 break;
00263
00264 case 'o':
00265 if (*cp == 0)
00266 i++;
00267 break;
00268
00269 case 'p':
00270 if (!strcmp( cp, "static_as_global" )) {
00271 pstatic_as_global = TRUE;
00272 }
00273 break;
00274
00275 case 'O':
00276 Opt_Level = Get_Numeric_Flag (&cp, 0, MAX_OPT_LEVEL,
00277 DEF_O_LEVEL, argv );
00278 opt_set = TRUE;
00279 break;
00280
00281 case 's':
00282 if (!strcmp( cp, "pinfile" ))
00283 i++;
00284 break;
00285
00286 case 'v':
00287 Show_Progress = TRUE;
00288 break;
00289
00290 default:
00291 break;
00292 }
00293 } else if (argv != NULL) {
00294 Src_Count++;
00295 FmtAssert(Src_Count == 1,
00296 ("wgen passed more than one source file in command line"));
00297 Src_File_Name = argv;
00298 if (Orig_Src_File_Name == NULL)
00299 Orig_Src_File_Name = argv;
00300 }
00301 }
00302 }
00303
00304
00305
00306
00307
00308 int
00309 main ( INT argc, char **argv, char **envp)
00310 {
00311 INT error_count, sorry_count;
00312 BOOL need_inliner;
00313 struct stat sbuf;
00314 int st;
00315
00316 Disable_Simplification_For_FE = TRUE;
00317 Set_Error_Tables ( Phases, host_errlist );
00318 Process_Command_Line(argc, argv);
00319
00320 st = stat(Spin_File_Name, &sbuf);
00321 if (st == -1 && (errno == ENOENT || errno == ENOTDIR))
00322 printf ("wgen: file %s does not exist\n", Spin_File_Name);
00323 else if ((program = gs_read_file (Spin_File_Name)) != (gs_t) NULL) {
00324
00325
00326 Process_Cc1_Command_Line(gs_cc1_command_line_args(program));
00327
00328 WGEN_Init(argc, argv, envp);
00329
00330 WGEN_File_Init(argc, argv);
00331
00332 gs_t list = gs_operand(program, GS_PROGRAM_DECLARATIONS);
00333
00334 if (gs_code(list) != EMPTY)
00335 list = gs_operand(list, 1);
00336 for (; gs_code(list) != EMPTY; list = gs_operand(list, 1)) {
00337 gs_t decl = gs_operand(list, 0);
00338 if (lang_cplus)
00339 WGEN_Expand_Top_Level_Decl(decl);
00340 else WGEN_Expand_Decl(decl, TRUE);
00341 #ifdef KEY
00342 WGEN_Expand_Defers();
00343 #endif
00344 }
00345
00346
00347 WGEN_Expand_Top_Level_Decl(list);
00348
00349 #ifdef KEY
00350 if (!lang_cplus)
00351 WGEN_Alias_Finish();
00352 #endif
00353 WGEN_Weak_Finish();
00354 WGEN_File_Finish ();
00355 WGEN_Finish ();
00356 }
00357 else
00358 printf ("wgen: libspin returned (gs_t) NULL.\n");
00359
00360 WGEN_Check_Errors (&error_count, &sorry_count, &need_inliner);
00361 if (error_count)
00362 Terminate (RC_INTERNAL_ERROR) ;
00363 if (need_inliner &&
00364 ((!Enable_WFE_DFE) || (Opt_Level > 1)))
00365 exit ( RC_NEED_INLINER );
00366 exit (RC_OKAY);
00367 }