|
OpenADFortTk (basic)
|
00001 // -*-Mode: C++;-*- 00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/xaif2whirl/xaif2whirl.h,v 1.24 2006/05/12 16:12:24 utke Exp $ 00003 #ifndef xaif2whirl_INCLUDED_h 00004 #define xaif2whirl_INCLUDED_h 00005 00006 00007 #include <iostream> 00008 #include <vector> 00009 00010 #include "xercesc/dom/DOMDocument.hpp" 00011 00012 #include "OpenAnalysis/CFG/CFG.hpp" // for DGraphStandard, CFG::Edge 00013 //#include "OpenAnalysis/Utils/DGraph/DGraphInterfaceIterators.hpp" 00014 #include "OpenAnalysis/Utils/DGraph/DGraphInterface.hpp" 00015 00016 #include "Open64IRInterface/Open64BasicTypes.h" 00017 00018 #include "WhirlIDMaps.h" 00019 #include "IntrinsicXlationTable.h" 00020 00021 #include "PUXlationContext.h" 00022 00023 namespace xaif2whirl { 00024 00025 enum AlgorithmType { 00026 ALG_NULL, 00027 ALG_BB_PATCHING // temporary 00028 }; 00029 00030 extern fortTkSupport::IntrinsicXlationTable IntrinsicTable; 00031 extern fortTkSupport::WNIdToWNTabMap WNIdToWNTableMap; 00032 00033 void 00034 TranslateIR(PU_Info* pu_forest, const xercesc::DOMDocument* doc); 00035 00036 // **************************************************************************** 00037 // Functions that were static, but now aren't anymore (so that the SAX2 parser can call them) 00038 00039 void 00040 xlate_Scope(const xercesc::DOMElement* elem, 00041 PUXlationContext& ctxt); 00042 00046 void 00047 TranslateCFG(PU_Info* pu_forest, 00048 const xercesc::DOMElement* cfgElem, 00049 PUXlationContext& ctxt); 00050 00051 void DeclareActiveTypes(); 00052 00053 // **************************************************************************** 00054 00055 // FIXME: relocate... 00056 fortTkSupport::Symbol* 00057 GetSymbol(const xercesc::DOMElement* elem, PUXlationContext& ctxt); 00058 00059 void 00060 DDumpDotGraph(OA::OA_ptr<OA::DGraph::DGraphInterface> graph); 00061 00062 void 00063 DumpDotGraph(std::ostream& os, OA::OA_ptr<OA::DGraph::DGraphInterface> graph); 00064 00065 TYPE_ID 00066 XAIFFETypeToWHIRLMTy(const char* anFETypeName); 00067 00068 fortTkSupport::Symbol* 00069 GetOrCreateSymbol(const char* sname, PUXlationContext& ctxt); 00070 00071 fortTkSupport::Symbol* 00072 GetOrCreateBogusTmpSymbol(PUXlationContext& ctxt); 00073 00074 // **************************************************************************** 00075 00076 // ------------------------------------------------------- 00077 // Generic attribute retrieval funtions 00078 // ------------------------------------------------------- 00079 00080 bool 00081 GetBoolAttr(const xercesc::DOMElement* elem, XMLCh* attr, bool default_val); 00082 00083 int 00084 GetIntAttr(const xercesc::DOMElement* elem, XMLCh* attr, int default_val); 00085 00086 // Return the value of the respective attribute. The default values 00087 // are given below if the attribute is not present. 00088 00089 // Default: false. 00090 bool 00091 GetHasConditionAttr(const xercesc::DOMElement* elem); 00092 00093 // Default: 0. 00094 unsigned int 00095 GetCondAttr(const xercesc::DOMElement* elem); 00096 00097 // Default: true. 00098 bool 00099 GetActiveAttr(const xercesc::DOMElement* elem); 00100 00101 // Default: false. 00102 bool 00103 GetDerivAttr(const xercesc::DOMElement* elem); 00104 00105 // Default: 0. A valid position value is non-zero. 00106 unsigned int 00107 GetPositionAttr(const xercesc::DOMElement* elem); 00108 00109 00110 // ------------------------------------------------------- 00111 // Get information within XAIF 'annotation' attribute 00112 // ------------------------------------------------------- 00113 00114 // Given an element or annotation string and a tag, returns whether 00115 // the tag is present in teh annotation attribute. 00116 bool 00117 IsTagPresent(const xercesc::DOMElement* elem, const char* tag); 00118 00119 bool 00120 IsTagPresent(const char* annotstr, const char* tag); 00121 00122 // Get the appropriate persistant id from the element 'elem'. See 00123 // detailed descriptions for generic functions below. 00124 fortTkSupport::SymTabId GetSymTabId(const xercesc::DOMElement* elem); 00125 00126 fortTkSupport::SymId GetSymId(const xercesc::DOMElement* elem); 00127 00128 fortTkSupport::PUId GetPUId(const xercesc::DOMElement* elem); 00129 00130 fortTkSupport::WNId GetWNId(const xercesc::DOMElement* elem); 00131 00132 fortTkSupport::IdList<fortTkSupport::WNId>* GetWNIdList(const xercesc::DOMElement* elem); 00133 00134 // Get the value of the tag IntrinsicKey 00135 std::string GetIntrinsicKey(const xercesc::DOMElement* elem); 00136 00137 // Get the value of the tag PregId 00138 PREG_IDX GetPregId(const xercesc::DOMElement* elem); 00139 00140 // GetId, GetIdList: Returns an id or list of ids from the given tag 00141 // within the annotation attribute. For the non-list version, 0 is 00142 // returned if no id is found. For the list version, the returned list 00143 // may be empty; the caller is responsible for freeing returned 00144 // memory. 00145 template <class T> 00146 T GetId(const xercesc::DOMElement* elem, const char* tag); 00147 00148 template <class T> 00149 fortTkSupport::IdList<T>* GetIdList(const xercesc::DOMElement* elem, const char* tag); 00150 00151 00152 // GetId, GetIdList: Returns an id or the list of ids from the given 00153 // tag within the string 'idstr'. For the non-list version, 0 is 00154 // returned if no id is found. For the list version, the returned 00155 // list may be empty; the caller is responsible for freeing returned 00156 // memory. 00157 template <class T> 00158 T GetId(const char* idstr, const char* tag); 00159 00160 template <class T> 00161 fortTkSupport::IdList<T>* GetIdList(const char* idstr, const char* tag); 00162 00163 00164 // *************************************************************************** 00165 00166 // FIXME: move to another file 00167 00168 WN* CreateCallToIntrin(TYPE_ID rtype, const char* fname, unsigned int argc); 00169 00170 WN* CreateCallToIntrin(TYPE_ID rtype, const char* fname, std::vector<WN*>& args); 00171 00172 WN* CreateIntrinsicCall(OPERATOR opr, INTRINSIC intrn, 00173 TYPE_ID rtype, TYPE_ID dtype, std::vector<WN*>& args); 00174 00175 inline WN* CreateParm(WN *arg, UINT32 flag) 00176 { 00177 TYPE_ID rtype = WN_rtype(arg); 00178 return WN_CreateParm(rtype, arg, MTYPE_To_TY(rtype), flag); 00179 } 00180 00181 WN* CreateBoolConst(unsigned int val); 00182 00183 // *************************************************************************** 00184 00185 class MyDGNode; 00186 00187 typedef std::map<std::string, OA::OA_ptr<MyDGNode> > VertexIdToMyDGNodeMap; 00188 00189 // --------------------------------------------------------- 00190 // MyDGNode, MyDGEdge: Used to create graph structures from XAIF 00191 // graphs (lists of nodes and edges) 00192 // --------------------------------------------------------- 00193 class MyDGNode : public OA::DGraph::NodeImplement { 00194 public: 00195 MyDGNode(const xercesc::DOMElement* e_) : e(e_) { Ctor(); } 00196 virtual ~MyDGNode() { } 00197 00198 xercesc::DOMElement* GetElem() const { return const_cast<xercesc::DOMElement*>(e); } 00199 00200 // getId: An id unique within instances of this class 00201 virtual unsigned int getId() const { return id; } 00202 // resetIds: reset id numbering 00203 static void resetIds() { nextId = 1; } 00204 00205 private: 00206 void Ctor() { id = nextId++; } 00207 static unsigned int nextId; 00208 00209 const xercesc::DOMElement* e; 00210 unsigned int id; // 0 is reserved; first instance is 1 00211 }; 00212 00213 class MyDGEdge : public OA::DGraph::EdgeImplement { 00214 public: 00215 MyDGEdge(OA::OA_ptr<OA::DGraph::NodeImplement> source_, 00216 OA::OA_ptr<OA::DGraph::NodeImplement> sink_, 00217 const xercesc::DOMElement* e_) 00218 : OA::DGraph::EdgeImplement(source_, sink_), e(e_) { } 00219 virtual ~MyDGEdge() { } 00220 00221 xercesc::DOMElement* GetElem() const { return const_cast<xercesc::DOMElement*>(e); } 00222 00223 private: 00224 const xercesc::DOMElement* e; 00225 }; 00226 00227 00228 // GetSuccessor: Assuming node has 0 or 1 outgoing edges, return the 00229 // successor node. In most graphs the successor will be along the 00230 // outgoing edge, and this parameter defaults to true. 00231 extern OA::OA_ptr<MyDGNode> 00232 GetSuccessor(OA::OA_ptr<MyDGNode> node, bool succIsOutEdge = true); 00233 00234 extern OA::OA_ptr<MyDGNode> 00235 GetSuccessorAlongEdge(OA::OA_ptr<MyDGNode> node, unsigned int condition, 00236 bool succIsOutEdge = true); 00237 00238 } 00239 00240 #endif