Rose2xaif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sage2XAIFGraph.hpp
Go to the documentation of this file.
1 
14 #ifndef SAGE2GRAPH_HPP
15 #define SAGE2GRAPH_HPP
16 
17 #include <sstream>
18 
19 #include <Rose2OA/common.h>
20 #include <Rose2OA/Sage2OA.h>
21 #include <Rose2OA/SageOACallGraph.h>
22 #include <Rose2OA/MemSage2OA.h>
23 #include <OpenAnalysis/XAIF/UDDUChainsXAIF.hpp>
24 #include <OpenAnalysis/XAIF/ManagerUDDUChainsXAIF.hpp>
25 #include <OpenAnalysis/XAIF/ManagerReachDefsOverwriteXAIF.hpp>
26 #include <OpenAnalysis/UDDUChains/ManagerUDDUChainsStandard.hpp>
27 #include "xaif/XAIFGraphImpl.hpp"
28 
29 // to build this test: g++ -I.. -o testGraph.exe XAIFGraphImpl.cpp XAIFGraphTest.cpp
30 
31 
32 #include "canon/SageCanon.hpp"
33 #include "util/Messages.hpp"
34 
35 
36 //#include "BasicBlockVertex.hpp"
37 //#include "BasicBlock.hpp"
38 //#include "CallGraph.hpp"
39 //#include "ControlFlowGraph.hpp"
40 //#include "ControlFlowGraphVertex.hpp"
41 
42 #define NO_VERTEX 99999
43 
44 namespace rose2xaif {
45  namespace SgXAIF {
46 
51  void populateScopes(std::list<SgScopeStatement *> & lst, CallGraph& cg);
52 
58  void writeToFile(const std::string& fileBaseName, CallGraph& theCallGraph);
59 
63  std::string getSymbolKind(SgSymbol *anSgSymbol_p);
64 
65  bool isMathIntrinsic(SgFunctionSymbol& funcSymbol);
66 
67  bool isMemoryIntrinsic(SgFunctionSymbol& funcSymbol);
68 
72  void setXAIFtypeInfoFromSgType(SgType* anSgType_p,std::string &xaifType, std::string& xaifFeType);
73 
75  private:
77  int myIndex;
80  public:
81  DimensionHelper() : myIndexFlag(false), myIndex(0), myLboundFlag(false), myUboundFlag(false),myLbound(0), myUbound(0) {};
82  void setIndex(int index) {
84  THROW_LOGICEXCEPTION_MACRO("DimensionHelper::setIndex: already has lbound or ubound or was set before");
85  }
86  myIndexFlag=true;
87  myIndex=index;
88  }
89  bool hasIndex() const { return myIndexFlag; }
90  int getIndex() const {
91  if (not myIndexFlag) {
92  THROW_LOGICEXCEPTION_MACRO("DimensionHelper::getIndex: not set");
93  }
94  return myIndex;
95  }
96  void setLbound(int anLbound) {
97  if (myLboundFlag || myIndexFlag) {
98  THROW_LOGICEXCEPTION_MACRO("DimensionHelper::setLbound: already has index or was set before");
99  }
100  myLboundFlag=true;
101  myLbound=anLbound;
102  }
103  bool hasLbound() const { return myLboundFlag; }
104  int getLbound() const {
105  if (not myLboundFlag) {
106  THROW_LOGICEXCEPTION_MACRO("DimensionHelper::getLbound: not set");
107  }
108  return myLbound;
109  }
110  void setUbound(int aUbound) {
111  if (myUboundFlag || myIndexFlag) {
112  THROW_LOGICEXCEPTION_MACRO("DimensionHelper::setUbound: already has index or was set before");
113  }
114  myUboundFlag=true;
115  myUbound=aUbound;
116  }
117  bool hasUbound() const { return myUboundFlag; }
118  int getUbound() const {
119  if (not myUboundFlag) {
120  THROW_LOGICEXCEPTION_MACRO("DimensionHelper::getUbound: not set");
121  }
122  return myUbound;
123  }
124  };
125 
126  class DimensionHelperList : public std::list<DimensionHelper> {
127  public:
130  };
131 
135  int getSymbolRank(SgNode * node, DimensionHelperList& );
136 
140  int getPointerSymbolRank(SgNode * theSgNode_p);
141 
145  class InheritedXAIFContext : SgInheritedAttribute {
146  public:
153  SgScopeStatement * scope;
193 
199 
205 
211 
212 
220  bbPtr(NULL), asPtr(NULL), scope(NULL),
222  myVariableReference_p(NULL),
223  myMadeNewVarRefFlag(false),
224  myExpression_p(NULL),
226  myIndexTriplet_p(NULL),
227  myFieldReference_p(NULL),
229  myNestingLevel(0) {}
233  std::string dump() const {
234  std::ostringstream oss;
235  oss << "IC: vr:" << myVariableReference_p << " nv:" << myMadeNewVarRefFlag << " ex:" << myExpression_p << " ae:" << myArrayElementReference_p << " it:" << myIndexTriplet_p << " fr:" << myFieldReference_p << std::ends;
236  return oss.str();
237  }
241  unsigned short myNestingLevel;
242  };
243 
244  class SynthesizedXAIFInfo : SgSynthesizedAttribute {
245  public:
254  typedef std::list<DefaultVertex*> VertexPList;
268  std::string dump() const {
269  std::ostringstream oss;
270  oss << "SA: v:" << ((myVertex_p)?myVertex_p->getAttribute("ElementName").c_str():"") << ":" << ((myVertex_p)?myVertex_p->getId().c_str():"") << " av:" << myActiveVariableReferenceFlag << " vl:[";
271  for (VertexPList::const_iterator it=myVertexPList.begin(); it!=myVertexPList.end(); ++it) {
272  oss << *it << " ";
273  }
274  oss << "]" << std::ends;
275  return oss.str();
276  }
277  };
278 
285  class XAIFExpressionTraverse : public SgTopDownBottomUpProcessing<InheritedXAIFContext, SynthesizedXAIFInfo> {
286  public:
287  XAIFExpressionTraverse(OA::OA_ptr<SageIRInterface> argirInterface, OA::OA_ptr<OA::XAIF::UDDUChainsXAIF> argudduchainsXAIF): irInterface(argirInterface), udduchainsXAIF(argudduchainsXAIF) { }
289  SynthesizedXAIFInfo evaluateSynthesizedAttribute(SgNode*, InheritedXAIFContext inh, SynthesizedAttributesList st);
290  private:
291  // helper methods for top down
293  InheritedXAIFContext changeInheritedContext(SgDeclarationStatement* n, InheritedXAIFContext inh);
302  // helper methods for bottom up
303  SynthesizedXAIFInfo sageToGraph(SgVarRefExp *, InheritedXAIFContext, SynthesizedAttributesList);
304  SynthesizedXAIFInfo sageToGraph(SgBinaryOp *, InheritedXAIFContext, SynthesizedAttributesList);
305  SynthesizedXAIFInfo sageToGraph(SgValueExp *, InheritedXAIFContext, SynthesizedAttributesList); // for constants
306  SynthesizedXAIFInfo sageToGraph(SgSizeOfOp *node, InheritedXAIFContext inh, SynthesizedAttributesList st);
307  SynthesizedXAIFInfo sageToGraph(SgFunctionCallExp *, InheritedXAIFContext, SynthesizedAttributesList);
308  SynthesizedXAIFInfo sageToGraph(SgExprListExp *, InheritedXAIFContext, SynthesizedAttributesList);
309  SynthesizedXAIFInfo sageToGraph(SgExprStatement *, InheritedXAIFContext, SynthesizedAttributesList);
310  SynthesizedXAIFInfo sageToGraph(SgPointerDerefExp *, InheritedXAIFContext, SynthesizedAttributesList);
311  SynthesizedXAIFInfo sageToGraph(SgAddressOfOp *, InheritedXAIFContext,SynthesizedAttributesList);
312  SynthesizedXAIFInfo sageToGraph(SgArrowExp *, InheritedXAIFContext, SynthesizedAttributesList);
313  SynthesizedXAIFInfo sageToGraph(SgPntrArrRefExp *, InheritedXAIFContext, SynthesizedAttributesList);
314  SynthesizedXAIFInfo sageToGraph(SgDotExp *, InheritedXAIFContext, SynthesizedAttributesList);
315  SynthesizedXAIFInfo sageToGraph(SgUnaryOp *, InheritedXAIFContext, SynthesizedAttributesList);
316 
323  void handleGraphContainers(SgNode* node, InheritedXAIFContext &inh);
324 
330  void collectContainerInfo(SgNode* node, const InheritedXAIFContext &inh, SynthesizedXAIFInfo & synInfo);
331 
332  //Stores the DUUD information for later use in the creation of VariableReferences
333  OA::OA_ptr<OA::XAIF::UDDUChainsXAIF> udduchainsXAIF;
334 
335  OA::OA_ptr<SageIRInterface> irInterface;
336  };
337 
338  }
339 } // namespace rose2xaif::SgXAIF
340 #endif