-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCfg.cpp
71 lines (63 loc) · 1.7 KB
/
Cfg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stack>
#include"Cfg.h"
/*Insert a basic block according to its rank*/
void Cfg::insertBB(int rank,string lab){
PBB cBB = new BasicBlock(rank);
cBB->set_Str_Insts(lab);
m_listBB.push_back(cBB);
}
/*Insert an edge*/
void Cfg::insertEdge(unsigned int srcBB,unsigned int dstBB){
//1. Find the basic block with the specified basic block number
list<PBB>::iterator it = m_listBB.begin();
PBB fBB, tBB;
for(;it!=m_listBB.end();it++){
if(srcBB == (*it)->getRank()){
fBB = (*it);
}
if(dstBB == (*it)->getRank()){
tBB = (*it);
}
}
//2. Add the bidirected edge
fBB->appendOutEdge(tBB);
tBB->appendInEdge(fBB);
}
/*Analysis the string of the instruction list*/
void Cfg::label2AsmList(){
list<PBB>::iterator it = m_listBB.begin();
ADDRESS instNum = 0;
for(;it != m_listBB.end();it++){
(*it)->getAsmInst(&instNum);
}
}
/*Set the type of instructions*/
void Cfg::setInstructionType(){
list<PBB>::iterator it = m_listBB.begin();
for(;it != m_listBB.end();it++){
(*it)->setInstructionType();
}
}
/*TEST::Print the assembly program into file*/
void Cfg::printCFG(FILE* f){
list<PBB>::iterator it = m_listBB.begin();
for(;it != m_listBB.end();it++){
(*it)->printBB(f);
}
}
/*TEST::Stat undefined opcodes*/
void Cfg::undefOpcodes(FILE* f,char* fName){
list<PBB>::iterator it = m_listBB.begin();
for(;it != m_listBB.end();it++){
(*it)->undefOpcodes(f,fName);
}
}
/*TEST::Print the vector of instruction type*/
void Cfg::printInstVector(FILE* f, char* fName){
fprintf(f, "Func:: %s\n",fName);
list<PBB>::iterator it = m_listBB.begin();
for(;it != m_listBB.end();it++){
(*it)->printInstVector(f);
}
fprintf(f,"----------\n");
}