|
OpenADFortTk (basic)
|
00001 // -*-Mode: C++;-*- 00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/whirl2xaif/wn2xaif.h,v 1.34 2006/07/19 19:48:19 utke Exp $ 00003 00004 #ifndef wn2xaif_h 00005 #define wn2xaif_h 00006 00007 #include <vector> // STL 00008 #include <list> // STL 00009 00010 00011 #include "Open64IRInterface/Open64BasicTypes.h" 00012 00013 00014 #include <OpenAnalysis/CFG/CFG.hpp> // for DGraphStandard, CFG::Edge 00015 #include <OpenAnalysis/Utils/DGraph/DGraphInterface.hpp> 00016 00017 #include "whirl2xaif.h" 00018 #include "PUXlationContext.h" 00019 #include <xmlostream.h> 00020 #include <XAIFStrings.h> 00021 00022 00023 namespace whirl2xaif { 00024 00025 // TranslateWN: Given a translation context, translates the given 00026 // WHIRL node, emitting output to 'xos'. 00027 extern void 00028 TranslateWN(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00029 00030 // xlate_PregRef: (essentially a special version of xlate_SymRef for PREGs) 00031 void 00032 xlate_PregRef(xml::ostream& xos, ST* st, TY_IDX preg_ty, 00033 PREG_IDX preg_idx, PUXlationContext& ctxt); 00034 00035 // xlate_SymRef: Given a base symbol 'base_st' and an offset 'offset' 00036 // within it, generate an XAIF expression to reference an object of 00037 // 'ref_ty' at this location. The base symbol 'base_st' has an 00038 // address of type 'baseptr_ty'. 00039 extern void 00040 xlate_SymRef(xml::ostream& xos, ST* base_st, TY_IDX baseptr_ty, 00041 TY_IDX ref_ty, STAB_OFFSET offset, PUXlationContext& ctxt); 00042 00043 // xlate_MemRef: 00044 extern void 00045 xlate_MemRef(xml::ostream& xos, WN* addr, TY_IDX addr_ty, TY_IDX object_ty, 00046 STAB_OFFSET addr_offset, PUXlationContext& ctxt); 00047 00048 00049 00050 00051 // REMOVE/FIXME 00052 // WN2F_Sum_Offsets: Sums any ADD nodes encountered in an address tree 00053 // WN2F_Address_Of: Generates an expression to explicitly take the 00054 // address of the lvalue constituted by the tokens in the given 00055 // token-buffer. 00056 extern void WN2F_Address_Of(xml::ostream& xos); 00057 extern WN_OFFSET WN2F_Sum_Offsets(WN *addr); 00058 00059 00060 // *************************************************************************** 00061 // Graph utilities 00062 // *************************************************************************** 00063 00064 //typedef std::vector<OA::DGraph::DGraphStandard::Node*> DGraphNodeVec; 00065 //typedef std::vector<OA::DGraph::DGraphStandard::Edge*> DGraphEdgeVec; 00066 //typedef std::vector<OA::CFG::CFGStandard::Edge*> CFGEdgeVec; 00067 //typedef std::vector<OA::DGraph::DGraphStandard::Node> DGraphNodeVec; 00068 //typedef std::vector<OA::DGraph::DGraphStandard::Edge> DGraphEdgeVec; 00069 typedef std::vector<OA::OA_ptr<OA::DGraph::NodeInterface> > DGraphNodeVec; 00070 typedef std::vector<OA::OA_ptr<OA::DGraph::EdgeInterface> > DGraphEdgeVec; 00071 //typedef std::vector<OA::CFG::CFGStandard::Edge> CFGEdgeVec; 00072 typedef std::vector<OA::OA_ptr<OA::CFG::EdgeInterface> > CFGEdgeVec; 00073 00074 00075 // SortDGraphNodes: Sorts DGraph nodes. User must deallocate returned 00076 // object. 00077 extern DGraphNodeVec* 00078 SortDGraphNodes(OA::OA_ptr<OA::DGraph::DGraphInterface> g); 00079 //SortDGraphNodes(OA::OA_ptr<OA::DGraph::DGraphStandard> g); 00080 00081 // SortDGraphEdges: Sorts DGraph edges. User must deallocate returned 00082 // object. 00083 extern DGraphEdgeVec* 00084 SortDGraphEdges(OA::OA_ptr<OA::DGraph::DGraphInterface> g); 00085 //SortDGraphEdges(OA::OA_ptr<OA::DGraph::DGraphStandard> g); 00086 00087 // SortCFGEdges: Sorts CFG edges. User must deallocate returned 00088 // object. 00089 extern CFGEdgeVec* 00090 SortCFGEdges(OA::OA_ptr<OA::CFG::CFGInterface> g); 00091 //SortCFGEdges(OA::OA_ptr<OA::CFG::CFGStandard> g); 00092 00093 00094 // *************************************************************************** 00095 // XAIF xml::ostream utilities 00096 // *************************************************************************** 00097 00098 // DumpGraphEdge: Generic edge dumper. Given an edge name 'nm', id, 00099 // source id, target id and position, dumps the edge in XAIF. If 00100 // 'pos' is 0 it will not be output. 00101 void 00102 DumpGraphEdge(xml::ostream& xos, const char* nm, 00103 UINT eid, UINT srcid, UINT targid, UINT pos); 00104 00105 // DumpScopeGraphEdge: Dumps a xaif:ScopeEdge 00106 inline void 00107 DumpScopeGraphEdge(xml::ostream& xos, UINT eid, UINT srcid, UINT targid) 00108 { 00109 DumpGraphEdge(xos, "xaif:ScopeEdge", eid, srcid, targid, 0); 00110 } 00111 00112 // DumpCallGraphEdge: Dumps a xaif:CallGraphEdge 00113 inline void 00114 DumpCallGraphEdge(xml::ostream& xos, UINT eid, UINT srcid, UINT targid) 00115 { 00116 DumpGraphEdge(xos, "xaif:CallGraphEdge", eid, srcid, targid, 0); 00117 } 00118 00119 // DumpCFGraphEdge: Dumps a xaif:ControlFlowEdge (special requirements) 00120 00121 // DumpExprGraphEdge: Dumps a xaif:ExpressionEdge 00122 inline void 00123 DumpExprGraphEdge(xml::ostream& xos, UINT eid, UINT srcid, UINT targid, 00124 UINT pos) 00125 { 00126 DumpGraphEdge(xos, "xaif:ExpressionEdge", eid, srcid, targid, pos); 00127 } 00128 00129 00130 // *************************************************************************** 00131 // XAIF xml::ostream operators 00132 // *************************************************************************** 00133 00134 // --------------------------------------------------------- 00135 // AttrSymId: Generate an XAIF symbol id attribute 00136 // --------------------------------------------------------- 00137 00138 struct AttrSymId_ { 00139 const ST* st; 00140 }; 00141 00142 inline ostream& 00143 operator<<(std::ostream& os, const AttrSymId_& x) 00144 { 00145 xml::ostream& xos = dynamic_cast<xml::ostream&>(os); // FIXME 00146 00147 const ST* st = x.st; 00148 00149 // We cannot generate symbol_id references for CONSTs because they 00150 // are not in the symbol table. (Also, a ST_name(st) on a CONST is 00151 // not valid.) 00152 FORTTK_ASSERT(ST_class(st) != CLASS_CONST, 00153 "Attempting to generate a symbol_id for a CONST. ST level/index = " << (fortTkSupport::SymTabId)ST_level(st) << ", " << (fortTkSupport::SymId)ST_index(st)); 00154 00155 const char* st_name = ST_name(st); 00156 fortTkSupport::SymId st_id = (fortTkSupport::SymId)ST_index(st); 00157 00158 xos << xml::BegAttr(XAIFStrings.attr_symId()) 00159 << st_name << "_" << st_id 00160 << xml::EndAttr; 00161 00162 return xos; 00163 } 00164 00165 // AttrSymId: Given a symtab symbol (ST*), generate a symbol id attribute 00166 inline AttrSymId_ 00167 AttrSymId(ST* st_) 00168 { 00169 AttrSymId_ x; 00170 x.st = st_; 00171 return x; 00172 } 00173 00174 00175 // --------------------------------------------------------- 00176 // AttrAnnot, AttrAnnotVal: Generate an XAIF annotation attribute 00177 // --------------------------------------------------------- 00178 template<class T> 00179 struct AttrAnnotInfo_ { 00180 bool completeAttr; 00181 const char* tag; 00182 const T* val; 00183 }; 00184 00185 template<class T> 00186 ostream& 00187 operator<<(std::ostream& os, const AttrAnnotInfo_<T>& x) 00188 { 00189 xml::ostream& xos = dynamic_cast<xml::ostream&>(os); // FIXME 00190 00191 if (x.completeAttr) { 00192 xos << xml::BegAttr(XAIFStrings.attr_annot()); 00193 } 00194 00195 xos << x.tag << *x.val << XAIFStrings.tag_End(); 00196 00197 if (x.completeAttr) { 00198 xos << xml::EndAttr; 00199 } 00200 00201 return xos; 00202 } 00203 00204 // AttrAnnot: Given a tag and a value, generate a complete annotiation 00205 // attribute 00206 template<class T> 00207 AttrAnnotInfo_<T> 00208 AttrAnnot(const char* tag_, const T& val_) 00209 { 00210 AttrAnnotInfo_<T> x; 00211 x.completeAttr = true; 00212 x.tag = tag_; 00213 x.val = &val_; 00214 return x; 00215 } 00216 00217 // AttrAnnotVal: Given a tag and a value, generate only the 00218 // annotiation attribute value 00219 template<class T> 00220 AttrAnnotInfo_<T> 00221 AttrAnnotVal(const char* tag_, const T& val_) 00222 { 00223 AttrAnnotInfo_<T> x; 00224 x.completeAttr = false; 00225 x.val = &val_; 00226 x.tag = tag_; 00227 return x; 00228 } 00229 00230 // *AttrAnnot: Given a value, generate a complete annotiation 00231 // attribute with appropriate tag 00232 template<class T> 00233 AttrAnnotInfo_<T> 00234 SymTabIdAnnot(const T& val_) 00235 { 00236 return AttrAnnot(XAIFStrings.tag_SymTabId(), val_); 00237 } 00238 00239 template<class T> 00240 AttrAnnotInfo_<T> 00241 SymIdAnnot(const T& val_) 00242 { 00243 return AttrAnnot(XAIFStrings.tag_SymId(), val_); 00244 } 00245 00246 template<class T> 00247 AttrAnnotInfo_<T> 00248 PUIdAnnot(const T& val_) 00249 { 00250 return AttrAnnot(XAIFStrings.tag_PUId(), val_); 00251 } 00252 00253 template<class T> 00254 AttrAnnotInfo_<T> 00255 WhirlIdAnnot(const T& val_) 00256 { 00257 return AttrAnnot(XAIFStrings.tag_WHIRLId(), val_); 00258 } 00259 00260 inline AttrAnnotInfo_<const char*> 00261 IntrinsicKeyAnnot(const char* const & val_) 00262 { 00263 return AttrAnnot(XAIFStrings.tag_IntrinsicKey(), val_); 00264 } 00265 00266 template<class T> 00267 AttrAnnotInfo_<T> 00268 PregIdAnnot(const T& val_) 00269 { 00270 return AttrAnnot(XAIFStrings.tag_PregId(), val_); 00271 } 00272 00273 00274 // *AttrAnnotVal: Given a tag and a value, generate only the 00275 // annotiation attribute value with the appropriate tag 00276 template<class T> 00277 AttrAnnotInfo_<T> 00278 SymTabIdAnnotVal(const T& val_) 00279 { 00280 return AttrAnnotVal(XAIFStrings.tag_SymTabId(), val_); 00281 } 00282 00283 template<class T> 00284 AttrAnnotInfo_<T> 00285 SymIdAnnotVal(const T& val_) 00286 { 00287 return AttrAnnotVal(XAIFStrings.tag_SymId(), val_); 00288 } 00289 00290 template<class T> 00291 AttrAnnotInfo_<T> 00292 PUIdAnnotVal(const T& val_) 00293 { 00294 return AttrAnnotVal(XAIFStrings.tag_PUId(), val_); 00295 } 00296 00297 template<class T> 00298 AttrAnnotInfo_<T> 00299 WhirlIdAnnotVal(const T& val_) 00300 { 00301 return AttrAnnotVal(XAIFStrings.tag_WHIRLId(), val_); 00302 } 00303 00304 template<class T> 00305 AttrAnnotInfo_<T> 00306 StmtGotoAnnotVal(const T& val_) 00307 { 00308 return AttrAnnotVal(XAIFStrings.tag_StmtGoto(), val_); 00309 } 00310 00311 template<class T> 00312 AttrAnnotInfo_<T> 00313 StmtLabelAnnotVal(const T& val_) 00314 { 00315 return AttrAnnotVal(XAIFStrings.tag_StmtLabel(), val_); 00316 } 00317 00318 template<class T> 00319 AttrAnnotInfo_<T> 00320 StmtReturnAnnotVal(const T& val_) 00321 { 00322 return AttrAnnotVal(XAIFStrings.tag_StmtReturn(), val_); 00323 } 00324 00325 } /* namespace whirl2xaif */ 00326 00327 #endif