ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cfgUtils.h
Go to the documentation of this file.
1 #ifndef CFGUTILS_H
2 #define CFGUTILS_H
3 
4 #include "genericDataflowCommon.h" // for quad typedefs
5 #include "variables.h"
6 #include "VirtualCFGIterator.h"
7 #include "DataflowCFG.h"
8 //#include "DataflowCFG.cfgToDot.h"
9 
10 #include <set>
11 #include <string>
12 
13 namespace cfgUtils
14 {
15  extern SgProject* project;
16 
17  // initializes the cfgUtils module
18  void initCFGUtils(SgProject* project_arg);
19 
21 
22  // parses a logical condition, determines whether it is in the form (x <= y + c) and
23  // if it is, sets x, y, c to be the unique ids of the relevant variables
24  // If the condition is in a similar form (ex: x<y, x>c), x, y and c are normalized to the form x<=y+c
25  // negX=true if x is supposed to be negated and false otherwise
26  // negY=true if y is supposed to be negated and false otherwise
27  bool computeTermsOfIfCondition_LTEQ(SgExpression *expr, varID &x, bool& negX, varID &y, bool& negY, long &c);
28 
29  // parses a logical condition, determines whether it is in the form (x == y + c) and
30  // if it is, sets x, y, c to be the unique ids of the relevant variables
31  // negX=true if x is supposed to be negated and false otherwise
32  // negY=true if y is supposed to be negated and false otherwise
33  bool computeTermsOfIfCondition_EQ(SgExpression *expr, varID &x, bool& negX, varID &y, bool& negY, long &c);
34 
35  // returns true if SgNode contains an array access to any variable in arrays
36  // wrIndex - map of i+c pairs that containsfor each variable in arrays all the indexes
37  // used to access the array variable for a Write operation
38  // rdIndex - map of i+c pairs that containsfor each variable in arrays all the indexes
39  // used to access the array variable for a Read operation
40  // rdFromExp - map of flags indicating for each variable in arrays whether ast_node
41  // contains an array Read expression of this array with its index in the wrong format:
42  // something other than i or i+c
43  // wrFromExp - map of flags indicating for each variable in arrays whether ast_node
44  // contains an array Write expression with its index in the wrong format: something
45  // other than i or i+c
46  bool
47  findArrayAccesses(SgNode* ast_node,
48  m_varID2varID2quad &wrIndex, m_varID2varID2quad &rdIndex,
49  m_varID2bool &rdFromExp, m_varID2bool &wrFromExp,
50  varIDSet arrays, m_varID2str vars2Name);
51 
52  // examines the given expression.
53  // If it is an array access, fills wrIndex with the ids of variables on the left-hand-side
54  // of the assignment, fills rdIndex with the ids of variables on the right-hand-side
55  // of the assignment and returns true.
56  // Otherwise, returns false.
57  // wrIndexSimp, rdIndexSimp - maps of array variables to variable/constant pairs. Each pair
58  // contains i,c that represent the fact that the given array variable was accessed (for
59  // writing or reading, respectively using the index expression [i+c], where i is a variable
60  // and c is a constant
61  // wrIndexCpx, rdIndexCpx - lists of array variables that were accessed (for writing or
62  // reading, respectively) using a complex index expression
63  bool parseArrayAccess(SgNode* ast_node,
64  m_varID2varID2quad& wrIndexSimp, varIDlist& wrIndexCpx,
65  m_varID2varID2quad& rdIndexSimp, varIDlist& rdIndexCpx,
66  m_varID2str vars2Name);
67 
68  // if the given SgNode is an assignment operation, returns true, otherwise false
71  /*SgExpression**/ bool isAssignment(SgNode* n);
72 
73  // if the given SgNode is an assignment operation, returns an SgNode that is the left-hand
74  // side of this assignment and NULL otherwise
76 
77  // if the given SgNode is an assignment operation, adds to rhs the set of SgNodes that comprise the right-hand
78  // side of this assignment
79  void getAssignmentRHS(SgNode* n, std::set<SgNode*>& rhs);
80 
81  const short none=0;
82  const short add=1;
83  const short subtract=2;
84  const short mult=3;
85  const short divide=4;
86 
87  // Returns true if the expression is of the permitted type
88  // and sets i, j, k and c appropriately to represent an expression of the form
89  // i = j op k op c
90  // where op may be either + (add), * (mult) or / (divide)
91  // This function parses expressions such as i = j op k, i = j op c, i op= j, i++)
92  bool parseAssignment(/*SgExpression*/SgNode* expr, short& op, varID &i, varID &j, bool& negJ, varID &k, bool& negK, long &c);
93 
94  // Returns true if the expression is of the permitted type
95  // and sets op, i, j and c appropriately to represent an expression of the form
96  // i op j op c
97  // where op may be either + (add), * (mult) or / (divide)
98  // op may be = none if the rhs has only one term
99  // This function parses non-assignment expressions such as i op j or c but not i = j op c, i op= j or i++
100  bool parseExpr(const SgExpression* expr, short& op, varID &i, bool &negI, varID& j, bool &negJ, long &c);
101 
102  // returns true if parsing was successful
103  // (expressions accepted: c, -c, j, c +/- j, j +/- c, j +/- k
104  // and sets *j and *c appropriately
105  // negJ=true if j is supposed to be negated and false otherwise
106  // negK=true if k is supposed to be negated and false otherwise
107  bool parseAddition(const SgExpression* expr, varID &j, bool &negJ, varID& k, bool &negK, long &c);
108 
109  // returns true if parsing was successful
110  // (expressions accepted: c, -c, j, c * j, j * c, j * k)
111  // and sets *j, *k and *c appropriately
112  bool parseMultiplication(const SgExpression* expr, varID &j, varID& k, long &c);
113 
114  // returns true if parsing was successful
115  // (expressions accepted: c, -c, j, c / j, j / c, j / k
116  // and sets *j, *k and *c appropriately
117  bool parseDivision(const SgExpression* expr, varID &j, varID& k, long &c);
118 
119  /*// returns true if the given SgValueExp is some type of integral value, rather than a string or something more complex
120  bool isIntegralVal(SgValueExp* exp);
121 
122  // if the given SgValueExp contains an integral value, returns that integer
123  // no error return value, since caller supposed to check with isIntegralVal()
124  int getIntegralVal(SgValueExp* exp);
125  */
126  // returns whether a given AST node that represents a constant is an integer and
127  // sets *val to be the numeric value of that integer (all integer types are included
128  // but not floating point, characters, etc.)
129  bool IsConstInt (const SgExpression* rhs, long &val);
130 
131  // pulls off all the SgCastExps that may be wrapping the given expression, returning the expression that is being wrapped
132  const SgExpression* unwrapCasts(const SgExpression* e);
133 
134  // returns the DataflowNode that represents that start of the CFG of the given function's body
136 
137  // returns the DataflowNode that represents that end of the CFG of the given function's body
139 
140  // returns a string containing a unique name that is not otherwise used inside this project
141  std::string genUniqueName();
142 
143  // returns the SgFunctionDeclaration for the function with the given name
144  SgFunctionDeclaration* getFuncDecl(std::string name);
145 
146  // given a function's declaration, returns the function's definition.
147  // handles the case where decl->get_definition()==NULL
149 
150 }
151 
152 #endif