OpenADFortTk (basic)
src/whirl2sexp/whirl2sexp.cxx
Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /m_home/m_utkej/Argonne/cvs2svn/cvs/OpenADFortTk/src/whirl2sexp/whirl2sexp.cxx,v 1.9 2007-10-08 18:28:34 utke Exp $
00003 #include <fstream>
00004 
00005 #include "Open64IRInterface/Open64BasicTypes.h"
00006 
00007 #include "whirl2sexp.h"
00008 #include "wn2sexp.h"
00009 #include "symtab2sexp.h"
00010 
00011 #include "Open64IRInterface/WhirlGlobalStateUtils.h"
00012 #include "SexpTags.h"
00013 
00014 static void
00015 GenHeader(sexp::ostream& sos);
00016 
00017 static void
00018 xlate_IR(sexp::ostream& os, PU_Info* pu_forest, int flags);
00019 
00020 static void
00021 xlate_PUForest(sexp::ostream& sos, PU_Info* pu_forest, int flags);
00022 
00023 static void 
00024 xlate_PUTree(sexp::ostream& os, PU_Info* pu_tree, int flags);
00025 
00026 static void 
00027 xlate_PU(sexp::ostream& os, PU_Info* pu, int flags);
00028 
00029 static void 
00030 xlate_WN(sexp::ostream& xos, WN* wn, int flags);
00031 
00032 //***************************************************************************
00033 // Implementation of interface routines
00034 //***************************************************************************
00035 
00036 void
00037 whirl2sexp::TranslateIR(std::ostream& os, PU_Info* pu_forest, int flags)
00038 {
00039   sexp::ostream sos(os.rdbuf());
00040   GenHeader(sos);
00041   xlate_IR(sos, pu_forest, flags);
00042   sos.flush();
00043 }
00044 
00045 void 
00046 whirl2sexp::TranslatePUTree(std::ostream& os, PU_Info* pu_tree, int flags)
00047 {
00048   sexp::ostream sos(os.rdbuf());
00049   GenHeader(sos);
00050   xlate_PUTree(sos, pu_tree, flags);
00051   sos.flush();
00052 }
00053 
00054 void 
00055 whirl2sexp::TranslatePU(std::ostream& os, PU_Info* pu, int flags)
00056 {
00057   sexp::ostream sos(os.rdbuf());
00058   GenHeader(sos);
00059   xlate_PU(sos, pu, flags);
00060   sos.flush();
00061 }
00062 
00063 void 
00064 whirl2sexp::TranslateWN(std::ostream& os, WN* wn, int flags)
00065 {
00066   sexp::ostream sos(os.rdbuf());
00067   GenHeader(sos);
00068   xlate_WN(sos, wn, flags);
00069   sos.flush();
00070 }
00071 
00072 
00073 void 
00074 whirl2sexp::DumpIR(PU_Info* pu_forest, int flags)
00075 {
00076   TranslateIR(std::cout, pu_forest, flags);
00077 }
00078 
00079 void 
00080 whirl2sexp::DumpPUTree(PU_Info* pu_tree, int flags)
00081 {
00082   TranslatePUTree(std::cout, pu_tree, flags);
00083 }
00084 
00085 void 
00086 whirl2sexp::DumpPU(PU_Info* pu, int flags)
00087 {
00088   TranslatePU(std::cout, pu, flags);
00089 }
00090 
00091 void 
00092 whirl2sexp::DumpWN(WN* wn, int flags)
00093 {
00094   TranslateWN(std::cout, wn, flags);
00095 }
00096 
00097 
00098 //***************************************************************************
00099 // Helper routines
00100 //***************************************************************************
00101 
00102 void
00103 GenHeader(sexp::ostream& sos)
00104 {
00105   sos << SexpTags::get_grammar();
00106 }
00107 
00108 
00109 void
00110 xlate_IR(sexp::ostream& sos, PU_Info* pu_forest, int flags)
00111 {
00112   sos << sexp::BegList << sexp::Atom(SexpTags::WHIRL) << sexp::EndLine;
00113   
00114   whirl2sexp::TranslateGlobalSymbolTables(sos, flags);
00115   sos << sexp::EndLine; // end the line 
00116 
00117   xlate_PUForest(sos, pu_forest, flags);
00118   
00119   sos << sexp::EndList << sexp::EndLine;
00120 }
00121 
00122 
00123 void
00124 xlate_PUForest(sexp::ostream& sos, PU_Info* pu_forest, int flags)
00125 {
00126   sos << sexp::BegList << sexp::Atom(SexpTags::PU_FOREST) << sexp::EndLine;
00127   
00128   // Translate each PU_TREE
00129   for (PU_Info* pu_tree = pu_forest; 
00130        pu_tree != NULL; pu_tree = PU_Info_next(pu_tree)) {
00131     xlate_PUTree(sos, pu_tree, flags);
00132   }
00133   
00134   sos << sexp::EndList << sexp::EndLine;
00135 }
00136 
00137 
00138 void 
00139 xlate_PUTree(sexp::ostream& sos, PU_Info* pu_tree, int flags)
00140 {
00141   sos << sexp::BegList << sexp::Atom(SexpTags::PU_TREE) << sexp::EndLine;
00142   
00143   // Translate the parent PU
00144   xlate_PU(sos, pu_tree, flags);
00145 
00146   // Translate each child PU
00147   if (pu_tree) { 
00148     for (PU_Info* child = PU_Info_child(pu_tree); 
00149          child != NULL; child = PU_Info_next(child)) {
00150       xlate_PU(sos, child, flags);
00151     }
00152   }
00153   
00154   sos << sexp::EndList << sexp::EndLine;
00155 }
00156 
00157 
00158 void 
00159 xlate_PU(sexp::ostream& sos, PU_Info* pu, int flags)
00160 {  
00161   if (!pu) { return; }
00162   
00163   PU_SetGlobalState(pu);
00164   
00165   //PU& real_pu = PU_Info_pu(pu); 
00166   //bool isProgram = PU_is_mainpu(real_pu);
00167   
00168   ST_IDX st_idx = PU_Info_proc_sym(pu);
00169   WN* wn_pu = PU_Info_tree_ptr(pu);
00170   const SCOPE& scope = Scope_tab[CURRENT_SYMTAB];
00171   
00172   sos << sexp::BegList << sexp::Atom(SexpTags::PU) << GenSexpSymRef(st_idx)
00173       << sexp::EndLine;
00174   whirl2sexp::TranslateLocalSymbolTables(sos, CURRENT_SYMTAB, flags);
00175   sos << sexp::EndLine;
00176   
00177   xlate_WN(sos, wn_pu, flags);
00178   sos << sexp::EndList << sexp::EndLine;
00179   
00180   sos.flush();
00181 }
00182 
00183 
00184 void 
00185 xlate_WN(sexp::ostream& sos, WN* wn, int flags)
00186 {
00187   whirl2sexp::TranslateWN(sos, wn);
00188 }
00189 
00190 //***************************************************************************
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines