Download ROSE Compiler Framework

Transcript
Generic Dataflow Framework
• it provides static functions to initialize all FunctionState And retrieve FunctionState
class FunctionState
{
friend class CollectFunctions;
public:
Function func;
NodeState state;
// The lattices that describe the value of the function's
return variables
NodeState retState;
private:
static std::set<FunctionState*> allDefinedFuncs;
static std::set<FunctionState*> allFuncs;
static bool allFuncsComputed;
public:
FunctionState(Function &func):
func(func),
state(/*func.get_declaration()->cfgForBeginning()*/)
{}
// We should use this interface -------------// 1. returns a set of all the functions whose bodies are in the
project
static std::set<FunctionState*>& getAllDefinedFuncs();
}
// 2. returns the FunctionState associated with the given function
// func may be any declared function
static FunctionState* getFuncState(const Function& func);
...
FunctionState* fs = new FunctionState(func); // empty From FuntionState to NodeState
/*************************************
*** UnstructuredPassInterAnalysis ***
*************************************/
void UnstructuredPassInterAnalysis::runAnalysis()
{
set<FunctionState*> allFuncs =
FunctionState::getAllDefinedFuncs(); // call a static function to get
all function state s
}
// Go through functions one by one, call an intra-procedural
analysis on each of them
// iterate over all functions with bodies
for(set<FunctionState*>::iterator it=allFuncs.begin();
it!=allFuncs.end(); it++)
{
FunctionState* fState = *it;
intraAnalysis->runAnalysis(fState->func,
&(fState->state));
}
// runs the intra-procedural analysis on the given function, returns
true if
// the function's NodeState gets modified as a result and false
otherwise
// state - the function's NodeState
bool UnstructuredPassIntraAnalysis::runAnalysis(const Function& func,
52