//******************************************************* // WGEN driver //******************************************************* int main ( INT argc, char **argv, char **envp) { INT error_count, sorry_count; BOOL need_inliner; struct stat sbuf; int st; Set_Error_Tables ( Phases, host_errlist ); Process_Command_Line(argc, argv); st = stat(Spin_File_Name, &sbuf); if (st == -1 && (errno == ENOENT || errno == ENOTDIR)) printf ("wgen: file %s does not exist\n", Spin_File_Name); else if ((program = gs_read_file (Spin_File_Name)) != (gs_t) NULL) { // gs_dump(program); Process_Cc1_Command_Line(gs_cc1_command_line_args(program)); WGEN_Init(argc, argv, envp); WGEN_File_Init(argc, argv); gs_t list = gs_operand(program, GS_PROGRAM_DECLARATIONS); // in bug 10185, first list node is NULL, so skip first node if (gs_code(list) != EMPTY) list = gs_operand(list, 1); for (; gs_code(list) != EMPTY; list = gs_operand(list, 1)) { gs_t decl = gs_operand(list, 0); WGEN_Expand_Top_Level_Decl(decl); #ifdef KEY WGEN_Expand_Defers(); #endif } #ifdef KEY if (!lang_cplus) WGEN_Alias_Finish(); #endif WGEN_Weak_Finish(); WGEN_File_Finish (); WGEN_Finish (); } else printf ("wgen: libspin returned (gs_t) NULL.\n"); WGEN_Check_Errors (&error_count, &sorry_count, &need_inliner); if (error_count) Terminate (RC_INTERNAL_ERROR) ; if (need_inliner && ((!Enable_WFE_DFE) || (Opt_Level > 1))) exit ( RC_NEED_INLINER ); exit (RC_OKAY); }
INT main (INT argc, /* Number of command line arguments */ char *argv[], /* Array of command line arguments */ char *envp[]) /* Array of environment pointers */ { WN *pu; INT32 ecount = 0, wcount = 0, local_ecount = 0, local_wcount = 0; INT32 inp_file_count; PU_Info *pu_tree, *current_pu; /* Here are things that every process driver should do as soon as * possible upon start-up. */ MEM_Initialize(); Set_Error_Tables(PHASES_NAME, ERRLIST_NAME); Init_Error_Handler(10); Set_Error_Line(ERROR_LINE_UNKNOWN); Set_Error_Phase("Whirl2c"); Set_Error_File(NULL); /* Use stderr */ Preconfigure(); /* Setup target and host specific info before flags */ Process_Common_Options(argc, argv, envp); /* Common options */ Configure(); /* Setup target and host specific info after flags */ Init_Operator_To_Opcode_Table(); /* Process the source files */ inp_file_count = Get_Irb_File_Name(argc, argv); if (inp_file_count == 0) { Usage(argv[0]); fprintf(stderr, "ERROR: missing input file on command-line\n"); } else if (inp_file_count > 1) { Usage(argv[0]); fprintf(stderr, "ERROR: too many input files on command-line\n"); } else { /* Get the global symbol table, the string table, the constant table, * and the initialization table, before initializing the translation * to C. */ (void)Open_Input_Info(Irb_File_Name); pu_tree = Read_Global_Info(NULL); W2C_Process_Command_Line(argc, argv, argc, argv); W2C_Init(TRUE/*emit_global_decls*/); /* Loop thru all the PUs */ for (current_pu = pu_tree; current_pu != NULL; current_pu = PU_Info_next (current_pu)) { Current_PU_Info = current_pu; MEM_POOL_Push (MEM_pu_nz_pool_ptr); Read_Local_Info (MEM_pu_nz_pool_ptr, current_pu); pu = PU_Info_tree_ptr(current_pu); W2C_Translate_Pu(pu, TRUE/*emit_global_decls*/); if (PU_Info_child(current_pu)) { fprintf(stderr, "WARNING: ignoring nested procedures in \"%s\"\n", ST_name(PU_Info_proc_sym(current_pu))); } Free_Local_Info (current_pu); MEM_POOL_Pop (MEM_pu_nz_pool_ptr); } /* for each PU */ W2C_Fini(TRUE/*emit_global_decls*/); Cleanup_Files(TRUE, FALSE); } /* If we've seen errors, note them and terminate: */ if (Get_Error_Count(&local_ecount, &local_wcount)) { ecount += local_ecount; wcount += local_wcount; } if ( ecount > 0 ) { Local_Terminate(); Terminate(1); } exit(0); } /* main */