00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __RoseBin_DataFlowAnalysis__
00009 #define __RoseBin_DataFlowAnalysis__
00010
00011 #include <queue>
00012
00013
00014 #include "RoseBin_FlowAnalysis.h"
00015 #include "RoseBin_DefUseAnalysis.h"
00016 #include "RoseBin_Emulate.h"
00017 #include "RoseBin_VariableAnalysis.h"
00018 #include "RoseBin_DataFlowAbstract.h"
00019 #include "RoseBin_abstract.h"
00020
00021
00022
00023
00024
00025 class RoseBin_DataFlowAnalysis : public RoseBin_FlowAnalysis {
00026 private:
00027 bool writeFile;
00028 int nrOfNodesVisited;
00029 bool interprocedural;
00030 RoseBin_DataFlowAbstract* variableAnalysis;
00031
00032
00033 std::map < SgGraphNode*,int> visitedCounter;
00034
00035
00036
00037 #if 0
00038
00039 typedef rose_hash::unordered_map <SgGraphNode*, SgGraphNode*> BeforeMapType;
00040 #else
00041 typedef rose_hash::unordered_map <SgGraphNode*, SgGraphNode*,rose_hash::hash_graph_node,rose_hash::eqstr_graph_node> BeforeMapType;
00042 #endif
00043
00044 BeforeMapType nodeBeforeMap;
00045
00046
00047 #if 0
00048
00049 typedef rose_hash::unordered_set < SgGraphNode*> nodeHashSetType;
00050 #else
00051 typedef rose_hash::unordered_set < SgGraphNode*,rose_hash::hash_graph_node,rose_hash::eqstr_graph_node> nodeHashSetType;
00052 #endif
00053
00054 nodeHashSetType visited;
00055
00056 void traverseEdges(RoseBin_DataFlowAbstract* analysis);
00057
00058
00059
00060
00061 bool existsPath(SgGraphNode* start, SgGraphNode* end);
00062
00063
00064 bool containsHash( nodeHashSetType& vec,
00065 SgGraphNode* node);
00066
00067
00068 RoseBin_DefUseAnalysis* defuse;
00069 bool printEdges;
00070
00071
00072
00073 bool exceptionCall(SgAsmx86Instruction* call);
00074
00075
00076 public:
00077
00078 RoseBin_DataFlowAnalysis(SgAsmNode* global, bool forward, RoseBin_abstract*
00079 ,GraphAlgorithms* algo):RoseBin_FlowAnalysis(global,algo) {
00080 #ifdef _MSC_VER
00081
00082 #endif
00083 ROSE_ASSERT(algo);
00084 typeNode="DFG";
00085 typeEdge="DFG-E";
00086 interprocedural = false;
00087 writeFile=true;
00088 printEdges = false;
00089 analysisName = "dfa";
00090 forward_analysis=forward;
00091 defuse = new RoseBin_DefUseAnalysis(algo);
00092 ROSE_ASSERT(defuse);
00093 }
00094 ~RoseBin_DataFlowAnalysis() {
00095 delete globalBin;
00096
00097 delete vizzGraph;
00098
00099 std::map <std::string, SgAsmFunction* >::iterator it;
00100 for (it = bin_funcs.begin();
00101 it!= bin_funcs.end(); it++) {
00102 delete it->second;
00103 }
00104 }
00105
00106 void writeToFile(bool w);
00107
00108 void traverseNodes(RoseBin_DataFlowAbstract* analysis);
00109
00110 void init();
00111
00112 void traverseGraph(std::vector <SgGraphNode*>& rootNodes,
00113 RoseBin_DataFlowAbstract* defuse,
00114 bool interprocedural);
00115
00116
00117 void init(bool interp, bool pedges) {
00118 interprocedural = interp;
00119 printEdges = pedges;
00120 }
00121
00122 void init(bool interp, bool pedges, RoseBin_Graph* g) {
00123 interprocedural = interp;
00124 printEdges = pedges;
00125 vizzGraph = g;
00126
00127
00128
00129 }
00130
00131 int nrOfMemoryWrites() {
00132 return dynamic_cast<RoseBin_DefUseAnalysis*>(defuse)->getNrOfMemoryWrites();
00133 }
00134
00135 int nrOfRegisterWrites() {
00136 return dynamic_cast<RoseBin_DefUseAnalysis*>(defuse)->getNrOfRegisterWrites() ;
00137 }
00138
00139 int nrOfDefinitions() {
00140 return defuse->getDefinitionSize();
00141 }
00142
00143 int nrOfUses() {
00144 return defuse->getUsageSize();
00145 }
00146
00147
00148 RoseBin_DefUseAnalysis* getDefUseAnalysis() { return defuse;}
00149
00150 void run(RoseBin_Graph* vg, std::string fileN, bool multiedge) ;
00151
00152 std::set < SgGraphNode* >
00153 getDefFor(SgGraphNode* node, std::pair<X86RegisterClass, int> initName);
00154 std::set < SgGraphNode* >
00155 getDefFor( uint64_t inst, std::pair<X86RegisterClass, int> initName);
00156
00157 std::set < uint64_t >
00158 getDefForInst( uint64_t inst, std::pair<X86RegisterClass, int> initName);
00159
00160 RoseBin_DataFlowAbstract* getVariableAnalysis() {return variableAnalysis;}
00161 };
00162
00163 #endif
00164