|
OpenADFortTk (basic)
|
00001 // -*-Mode: C++;-*- 00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/sexp2whirl/main.cxx,v 1.4 2005/01/12 20:01:01 eraxxon Exp $ 00003 00004 #include <fcntl.h> // for use in ReadWhirlSexp() 00005 #include <errno.h> // for use in ReadWhirlSexp() 00006 00007 #include <sexp.h> 00008 00009 #include "Open64IRInterface/Open64BasicTypes.h" 00010 #include "cmplrs/rcodes.h" // return codes 00011 #include "tracing.h" // trace routines 00012 #include "ir_reader.h" // fdump_tree 00013 #include "Open64IRInterface/WhirlIO.h" 00014 #include "Open64IRInterface/IFDiagnostics.h" 00015 00016 #include "Diagnostics.h" 00017 #include "Exception.h" 00018 00019 #include "Args.h" 00020 #include "sexp2whirl.h" 00021 00022 static int real_main(int argc, char **argv); 00023 00024 static sexp_t* ReadWhirlSexp(const char* filename); 00025 00026 00027 int 00028 main(int argc, char **argv) 00029 { 00030 try { 00031 return real_main(argc, argv); 00032 } 00033 catch (CmdLineParser::Exception& e) { 00034 e.Report(cerr); // fatal error 00035 exit(1); 00036 } 00037 catch (fortTkSupport::BaseException& e) { 00038 e.Report(cerr); 00039 exit(1); 00040 } 00041 catch (...) { 00042 cerr << "Unknown exception caught\n"; 00043 exit(1); 00044 } 00045 // FIXME: catch badalloc? 00046 } 00047 00048 static int 00049 real_main(int argc, char **argv) 00050 { 00051 // ------------------------------------------------------- 00052 // 1. Open64 Initialization 00053 // ------------------------------------------------------- 00054 Handle_Signals(); 00055 MEM_Initialize(); 00056 Init_Error_Handler( 100 ); 00057 Set_Error_Line( ERROR_LINE_UNKNOWN ); 00058 Set_Error_File( NULL ); 00059 Set_Error_Phase("sexp2whirl"); 00060 IR_set_dump_order(TRUE /*pre*/); // pre-order trees when debugging, please! 00061 00062 #ifdef Is_True_On 00063 if (Get_Trace(TKIND_ALLOC, TP_MISC)) { 00064 MEM_Tracing_Enable(); 00065 } 00066 #endif 00067 00068 Preconfigure(); // from config.cxx... 00069 Configure(); // needed for WN_lower! 00070 Configure_Source(NULL); // Most config variables set here 00071 00072 Init_Operator_To_Opcode_Table(); // FIXME 00073 00074 // ------------------------------------------------------- 00075 // 2. Local initialization (options, etc.) 00076 // ------------------------------------------------------- 00077 Diag_Init(); 00078 Diag_Set_Max_Diags(100); // Maximum 100 warnings by default 00079 Diag_Set_Phase("WHIRL to sexp: driver"); 00080 00081 Args args(argc, argv); 00082 fortTkSupport::Diagnostics::setDiagnosticFilterLevel(args.debug); 00083 00084 // ------------------------------------------------------- 00085 // 3. Read S-expressions and Translate into WHIRL 00086 // ------------------------------------------------------- 00087 00088 sexp_t* ir_sexp = ReadWhirlSexp(args.sexpFileNm.c_str()); 00089 00090 PU_Info* ir_whirl = sexp2whirl::TranslateIR(ir_sexp); 00091 //sexp2whirl::DumpIR(ir_sexp, sexp2whirl::XlateFlags::NONE); 00092 00093 WriteIR(args.whirlFileNm.c_str(), ir_whirl); 00094 00095 destroy_sexp(ir_sexp); 00096 sexp_cleanup(); 00097 00098 // ------------------------------------------------------- 00099 // 4. Finalization 00100 // ------------------------------------------------------- 00101 00102 // If we've seen errors, note them and terminate 00103 INT local_ecount, local_wcount; 00104 if ( Get_Error_Count ( &local_ecount, &local_wcount ) ) { 00105 Terminate(Had_Internal_Error() ? RC_INTERNAL_ERROR : 00106 RC_NORECOVER_USER_ERROR); 00107 } 00108 00109 Diag_Exit(); 00110 Cleanup_Files(TRUE, FALSE); // Open64 00111 00112 return RC_OKAY; 00113 } 00114 00115 00116 //*************************************************************************** 00117 // 00118 //*************************************************************************** 00119 00120 static sexp_t* 00121 ReadWhirlSexp(const char* filename) 00122 { 00123 // see readtests.c (FIXME) 00124 int fd = open(filename, O_RDONLY); 00125 if (fd < 0) { 00126 FORTTK_DIE("Error opening " << filename << ": " << strerror(errno)); 00127 } 00128 00129 sexp_iowrap_t* iow = init_iowrap(fd); 00130 sexp_t* sexp = read_one_sexp(iow); 00131 return sexp; 00132 } 00133 00134