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