OpenADFortTk (basic)
src/testers/main.cxx
Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/testers/main.cxx,v 1.10 2005/03/19 22:54:51 eraxxon Exp $
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 
00008 #include <OpenAnalysis/Utils/Exception.hpp>
00009 
00010 #include "Open64IRInterface/Open64BasicTypes.h"
00011 #include "cmplrs/rcodes.h"  // return codes
00012 #include "tracing.h"        // trace routines
00013 #include "ir_reader.h"      // fdump_tree
00014 #include "Open64IRInterface/WhirlIO.h"
00015 #include "Open64IRInterface/IFDiagnostics.h"
00016 
00017 #include "Exception.h"
00018 
00019 #include "Args.h"
00020 #include "tester.h"
00021 
00022 static int 
00023 real_main(int argc, char **argv);
00024 
00025 static void 
00026 OpenFile(std::ofstream& fs, const char* filename);
00027 
00028 static void 
00029 CloseFile(std::ofstream& fs);
00030 
00031 //***************************************************************************
00032 
00033 int
00034 main(int argc, char **argv)
00035 {
00036   try {
00037     return real_main(argc, argv);
00038   }
00039   catch (CmdLineParser::Exception& e) {
00040     e.Report(cerr); // fatal error
00041     exit(1);
00042   }
00043   catch (fortTkSupport::BaseException& e) {
00044     e.Report(cerr);
00045     exit(1);
00046   }
00047   catch (OA::Exception& e) {
00048     e.report(cerr);
00049     exit(1);
00050   }
00051   catch (...) {
00052     cerr << "Unknown exception caught\n";
00053     exit(1);
00054   }
00055 }
00056 
00057 static int
00058 real_main(int argc, char* argv[])
00059 {
00060   // -------------------------------------------------------
00061   // 1. Open64 Initialization
00062   // -------------------------------------------------------
00063   Handle_Signals();
00064   MEM_Initialize();
00065   Init_Error_Handler( 100 );
00066   Set_Error_Line( ERROR_LINE_UNKNOWN );
00067   Set_Error_File( NULL );
00068   Set_Error_Phase("whirltester");
00069   IR_set_dump_order(TRUE /*pre*/); // pre-order trees when debugging, please!
00070   
00071 #ifdef Is_True_On
00072   if (Get_Trace(TKIND_ALLOC, TP_MISC)) {
00073     MEM_Tracing_Enable();
00074   }
00075 #endif
00076   
00077   Preconfigure();         // from config.cxx...
00078   Configure();            // needed for WN_lower!
00079   Configure_Source(NULL); // Most config variables set here
00080 
00081   Init_Operator_To_Opcode_Table(); // FIXME
00082     
00083   // -------------------------------------------------------
00084   // 2. Local initialization (options, etc.)
00085   // -------------------------------------------------------
00086   Diag_Init();
00087   Diag_Set_Max_Diags(100); // Maximum 100 warnings by default
00088   Diag_Set_Phase("WHIRL Harness");
00089 
00090   Args args(argc, argv);
00091   
00092   // -------------------------------------------------------
00093   // 3. Read WHIRL IR
00094   // -------------------------------------------------------
00095   PU_Info* pu_forest = ReadIR(args.whirlFileNm.c_str());
00096   PrepareIR(pu_forest); // used in whirl2xaif, xaif2whirl
00097 
00098   // -------------------------------------------------------
00099   // 4. Do something
00100   // -------------------------------------------------------  
00101   
00102   if (args.dumpIR) { 
00103     DumpIR(pu_forest); 
00104   }
00105   
00106   if (args.runMode == 1) {
00107     whirltester::TestIR(std::cout, pu_forest);
00108   } else if (args.runMode == 2) {
00109     whirltester::TestIR_OA(std::cout, pu_forest);
00110   } else if (args.runMode == 3) {
00111     whirltester::TestIR_whirl2f(std::cout, pu_forest);
00112   }
00113   
00114   FreeIR(pu_forest); // N.B. cannot use with WriteIR
00115 
00116   // -------------------------------------------------------
00117   // 5. Finalization
00118   // -------------------------------------------------------
00119 
00120   // If we've seen errors, note them and terminate
00121   INT local_ecount, local_wcount;
00122   if ( Get_Error_Count ( &local_ecount, &local_wcount ) ) {
00123     Terminate(Had_Internal_Error() ? RC_INTERNAL_ERROR : 
00124               RC_NORECOVER_USER_ERROR);
00125   }
00126 
00127   Diag_Exit();
00128   Cleanup_Files(TRUE, FALSE); // Open64
00129 
00130   return RC_OKAY;
00131 }
00132 
00133 
00134 //***************************************************************************
00135 // 
00136 //***************************************************************************
00137 
00138 #include "file_util.h" // New_Extension, Last_Pathname_Component
00139 
00140 #if 0
00141   // progname = Last_Pathname_Component(argv[0]);
00142   // new_name = New_Extension(Src_File_Name, IRB_FILE_EXTENSION);
00143   
00144   // We want the output files to be created in the current directory,
00145   // so strip off any directory path, and substitute the suffix 
00146   // appropriately.
00147   // new_file = New_Extension(Last_Pathname_Component(whirlfn), ".xaif");
00148   
00149   // Src_File_Name, Irb_File_Name, Obj_File_Name are from Open64 "glob.h"
00150   // Src_File_Name = Irb_File_Name = (char*)WHIRL_filename.c_str();
00151 #endif
00152 
00153 //***************************************************************************
00154 
00155 static void 
00156 OpenFile(std::ofstream& fs, const char* filename)
00157 {
00158   using namespace std;
00159 
00160   fs.open(filename, ios::out | ios::trunc);
00161   if (!fs.is_open() || fs.fail()) {
00162     ErrMsg(EC_IR_Open, filename, 0/*FIXME*/);
00163   } 
00164   
00165 #if 0//FIXME
00166   fs.open(filename, ios::out | ios::app);
00167   fs = Open_Append_File(W2F_File_Name[kind]);
00168 #endif
00169 
00170 }
00171 
00172 static void
00173 CloseFile(std::ofstream& fs)
00174 {
00175   fs.close();
00176 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines