本文整理汇总了C++中PBB类的典型用法代码示例。如果您正苦于以下问题:C++ PBB类的具体用法?C++ PBB怎么用?C++ PBB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PBB类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeDF
void DataFlow::computeDF(int n) {
std::set<int> S;
/* THis loop computes DF_local[n] */
// for each node y in succ(n)
PBB bb = BBs[n];
std::vector<PBB>& outEdges = bb->getOutEdges();
std::vector<PBB>::iterator it;
for (it = outEdges.begin(); it != outEdges.end(); it++) {
int y = indices[*it];
if (idom[y] != n)
S.insert(y);
}
// for each child c of n in the dominator tree
// Note: this is a linear search!
int sz = idom.size(); // ? Was ancestor.size()
for (int c = 0; c < sz; ++c) {
if (idom[c] != n) continue;
computeDF(c);
/* This loop computes DF_up[c] */
// for each element w of DF[c]
std::set<int>& s = DF[c];
std::set<int>::iterator ww;
for (ww = s.begin(); ww != s.end(); ww++) {
int w = *ww;
// if n does not dominate w, or if n = w
if (n == w || !doesDominate(n, w)) {
S.insert(w);
}
}
}
DF[n] = S;
} // end computeDF
示例2: ReturnStatement
// Add a synthetic return instruction (or branch to the existing return instruction).
// NOTE: the call BB should be created with one out edge (the return or branch BB)
void FrontEnd::appendSyntheticReturn(PBB pCallBB, UserProc* pProc, RTL* pRtl) {
ReturnStatement *ret = new ReturnStatement();
std::list<RTL*> *ret_rtls = new std::list<RTL*>();
std::list<Statement*>* stmt_list = new std::list<Statement*>;
stmt_list->push_back(ret);
PBB pret = createReturnBlock(pProc, ret_rtls, new RTL(pRtl->getAddress()+1, stmt_list));
pret->addInEdge(pCallBB);
pCallBB->setOutEdge(0, pret);
}
示例3: findLiveAtDomPhi
// Helper function for UserProc::propagateStatements()
// Works on basic block n; call from UserProc with n=0 (entry BB)
// If an SSA location is in usedByDomPhi it means it is used in a phi that dominates its assignment
// However, it could turn out that the phi is dead, in which case we don't want to keep the associated entries in
// usedByDomPhi. So we maintain the map defdByPhi which maps locations defined at a phi to the phi statements. Every
// time we see a use of a location in defdByPhi, we remove that map entry. At the end of the procedure we therefore have
// only dead phi statements in the map, so we can delete the associated entries in defdByPhi and also remove the dead
// phi statements.
// We add to the set usedByDomPhi0 whenever we see a location referenced by a phi parameter. When we see a definition
// for such a location, we remove it from the usedByDomPhi0 set (to save memory) and add it to the usedByDomPhi set.
// For locations defined before they are used in a phi parameter, there will be no entry in usedByDomPhi, so we ignore
// it. Remember that each location is defined only once, so that's the time to decide if it is dominated by a phi use or
// not.
void DataFlow::findLiveAtDomPhi(int n, LocationSet& usedByDomPhi, LocationSet& usedByDomPhi0,
std::map<Exp*, PhiAssign*, lessExpStar>& defdByPhi) {
// For each statement this BB
BasicBlock::rtlit rit; StatementList::iterator sit;
PBB bb = BBs[n];
Statement* S;
for (S = bb->getFirstStmt(rit, sit); S; S = bb->getNextStmt(rit, sit)) {
if (S->isPhi()) {
// For each phi parameter, insert an entry into usedByDomPhi0
PhiAssign* pa = (PhiAssign*)S;
PhiAssign::iterator it;
for (it = pa->begin(); it != pa->end(); ++it) {
if (it->e) {
RefExp* re = new RefExp(it->e, it->def);
usedByDomPhi0.insert(re);
}
}
// Insert an entry into the defdByPhi map
RefExp* wrappedLhs = new RefExp(pa->getLeft(), pa);
defdByPhi[wrappedLhs] = pa;
// Fall through to the below, because phi uses are also legitimate uses
}
LocationSet ls;
S->addUsedLocs(ls);
// Consider uses of this statement
LocationSet::iterator it;
for (it = ls.begin(); it != ls.end(); ++it) {
// Remove this entry from the map, since it is not unused
defdByPhi.erase(*it);
}
// Now process any definitions
ls.clear();
S->getDefinitions(ls);
for (it = ls.begin(); it != ls.end(); ++it) {
RefExp* wrappedDef = new RefExp(*it, S);
// If this definition is in the usedByDomPhi0 set, then it is in fact dominated by a phi use, so move it to
// the final usedByDomPhi set
if (usedByDomPhi0.find(wrappedDef) != usedByDomPhi0.end()) {
usedByDomPhi0.remove(wrappedDef);
usedByDomPhi.insert(wrappedDef);
}
}
}
// Visit each child in the dominator graph
// Note: this is a linear search!
// Note also that usedByDomPhi0 may have some irrelevant entries, but this will do no harm, and attempting to erase
// the irrelevant ones would probably cost more than leaving them alone
int sz = idom.size();
for (int c = 0; c < sz; ++c) {
if (idom[c] != n) continue;
// Recurse to the child
findLiveAtDomPhi(c, usedByDomPhi, usedByDomPhi0, defdByPhi);
}
}
示例4: setDominanceNums
void DataFlow::setDominanceNums(int n, int& currNum) {
BasicBlock::rtlit rit; StatementList::iterator sit;
PBB bb = BBs[n];
Statement* S;
for (S = bb->getFirstStmt(rit, sit); S; S = bb->getNextStmt(rit, sit))
S->setDomNumber(currNum++);
int sz = idom.size();
for (int c = 0; c < sz; ++c) {
if (idom[c] != n) continue;
// Recurse to the child
setDominanceNums(c, currNum);
}
}
示例5: DFS
void DataFlow::DFS(int p, int n) {
if (dfnum[n] == 0) {
dfnum[n] = N; vertex[N] = n; parent[n] = p;
N++;
// For each successor w of n
PBB bb = BBs[n];
std::vector<PBB>& outEdges = bb->getOutEdges();
std::vector<PBB>::iterator oo;
for (oo = outEdges.begin(); oo != outEdges.end(); oo++) {
DFS(n, indices[*oo]);
}
}
}
示例6: CPPUNIT_ASSERT
void CfgTest::testSemiDominators ()
{
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(SEMI_PENTIUM);
CPPUNIT_ASSERT(pBF != 0);
Prog* prog = new Prog;
FrontEnd* pFE = new PentiumFrontEnd(pBF, prog, &bff);
Type::clearNamedTypes();
prog->setFrontEnd(pFE);
pFE->decode(prog);
bool gotMain;
ADDRESS addr = pFE->getMainEntryPoint(gotMain);
CPPUNIT_ASSERT (addr != NO_ADDRESS);
UserProc* pProc = (UserProc*) prog->getProc(0);
Cfg* cfg = pProc->getCFG();
DataFlow* df = pProc->getDataFlow();
df->dominators(cfg);
// Find BB "L (6)" (as per Appel, Figure 19.8).
BB_IT it;
PBB bb = cfg->getFirstBB(it);
while (bb && bb->getLowAddr() != SEMI_L)
{
bb = cfg->getNextBB(it);
}
CPPUNIT_ASSERT(bb);
int nL = df->pbbToNode(bb);
// The dominator for L should be B, where the semi dominator is D
// (book says F)
unsigned actual_dom = (unsigned)df->nodeToBB(df->getIdom(nL))->getLowAddr();
unsigned actual_semi = (unsigned)df->nodeToBB(df->getSemi(nL))->getLowAddr();
CPPUNIT_ASSERT_EQUAL((unsigned)SEMI_B, actual_dom);
CPPUNIT_ASSERT_EQUAL((unsigned)SEMI_D, actual_semi);
// Check the final dominator frontier as well; should be M and B
std::ostringstream expected, actual;
//expected << std::hex << SEMI_M << " " << SEMI_B << " ";
expected << std::hex << SEMI_B << " " << SEMI_M << " ";
std::set<int>::iterator ii;
std::set<int>& DFset = df->getDF(nL);
for (ii=DFset.begin(); ii != DFset.end(); ii++)
actual << std::hex << (unsigned)df->nodeToBB(*ii)->getLowAddr() << " ";
CPPUNIT_ASSERT_EQUAL(expected.str(), actual.str());
delete pFE;
}
示例7: createReturnBlock
/*==============================================================================
* FUNCTION: createReturnBlock
* OVERVIEW: Create a Return or a Oneway BB if a return statement already exists
* PARAMETERS: pProc: pointer to enclosing UserProc
* BB_rtls: list of RTLs for the current BB (not including pRtl)
* pRtl: pointer to the current RTL with the semantics for the return statement (including a
* ReturnStatement as the last statement)
* RETURNS: Pointer to the newly created BB
*============================================================================*/
PBB FrontEnd::createReturnBlock(UserProc* pProc, std::list<RTL*>* BB_rtls, RTL* pRtl) {
Cfg* pCfg = pProc->getCFG();
PBB pBB;
// Add the RTL to the list; this has the semantics for the return instruction as well as the ReturnStatement
// The last Statement may get replaced with a GotoStatement
if (BB_rtls == NULL) BB_rtls = new std::list<RTL*>; // In case no other semantics
BB_rtls->push_back(pRtl);
ADDRESS retAddr = pProc->getTheReturnAddr();
std::cout << "retAddr = " << std::hex << retAddr << " rtl = " <<std::hex<< pRtl->getAddress() << "\n";
// LOG << "retAddr = " << retAddr << " rtl = " << pRtl->getAddress() << "\n";
if (retAddr == NO_ADDRESS) {
// Create the basic block
pBB = pCfg->newBB(BB_rtls, RET, 0);
Statement* s = pRtl->getList().back(); // The last statement should be the ReturnStatement
pProc->setTheReturnAddr((ReturnStatement*)s, pRtl->getAddress());
} else {
// We want to replace the *whole* RTL with a branch to THE first return's RTL. There can sometimes be extra
// semantics associated with a return (e.g. Pentium return adds to the stack pointer before setting %pc and
// branching). Other semantics (e.g. SPARC returning a value as part of the restore instruction) are assumed to
// appear in a previous RTL. It is assumed that THE return statement will have the same semantics (NOTE: may
// not always be valid). To avoid this assumption, we need branches to statements, not just to native addresses
// (RTLs).
PBB retBB = pProc->getCFG()->findRetNode();
assert(retBB);
if (retBB->getFirstStmt()->isReturn()) {
// ret node has no semantics, clearly we need to keep ours
pRtl->deleteLastStmt();
} else
pRtl->clear();
pRtl->appendStmt(new GotoStatement(retAddr));
try {
pBB = pCfg->newBB(BB_rtls, ONEWAY, 1);
// if BB already exists but is incomplete, exception is thrown
pCfg->addOutEdge(pBB, retAddr, true);
// Visit the return instruction. This will be needed in most cases to split the return BB (if it has other
// instructions before the return instruction).
targetQueue.visit(pCfg, retAddr, pBB);
} catch(Cfg::BBAlreadyExistsError &) {
if (VERBOSE)
LOG << "not visiting " << retAddr << " due to exception\n";
}
}
return pBB;
}
示例8: BinaryFileStub
void FrontSparcTest::testDelaySlot() {
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(BRANCH_SPARC);
if (pBF == NULL)
pBF = new BinaryFileStub(); // fallback on stub
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
Prog* prog = new Prog;
FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// decode calls readLibraryCatalog(), which needs to have definitions for non-sparc architectures cleared
Type::clearNamedTypes();
pFE->decode(prog);
bool gotMain;
ADDRESS addr = pFE->getMainEntryPoint(gotMain);
CPPUNIT_ASSERT (addr != NO_ADDRESS);
std::string name("testDelaySlot");
UserProc* pProc = new UserProc(prog, name, addr);
std::ofstream dummy;
bool res = pFE->processProc(addr, pProc, dummy, false);
CPPUNIT_ASSERT(res == 1);
Cfg* cfg = pProc->getCFG();
BB_IT it;
PBB bb = cfg->getFirstBB(it);
std::ostringstream o1;
bb->print(o1);
std::string expected("Call BB:\n"
"in edges: \n"
"out edges: 10a98 \n"
"00010a80 0 *32* tmp := r14 - 120\n"
" 0 *32* m[r14] := r16\n"
" 0 *32* m[r14 + 4] := r17\n"
" 0 *32* m[r14 + 8] := r18\n"
" 0 *32* m[r14 + 12] := r19\n"
" 0 *32* m[r14 + 16] := r20\n"
" 0 *32* m[r14 + 20] := r21\n"
" 0 *32* m[r14 + 24] := r22\n"
" 0 *32* m[r14 + 28] := r23\n"
" 0 *32* m[r14 + 32] := r24\n"
" 0 *32* m[r14 + 36] := r25\n"
" 0 *32* m[r14 + 40] := r26\n"
" 0 *32* m[r14 + 44] := r27\n"
" 0 *32* m[r14 + 48] := r28\n"
" 0 *32* m[r14 + 52] := r29\n"
" 0 *32* m[r14 + 56] := r30\n"
" 0 *32* m[r14 + 60] := r31\n"
" 0 *32* r24 := r8\n"
" 0 *32* r25 := r9\n"
" 0 *32* r26 := r10\n"
" 0 *32* r27 := r11\n"
" 0 *32* r28 := r12\n"
" 0 *32* r29 := r13\n"
" 0 *32* r30 := r14\n"
" 0 *32* r31 := r15\n"
" 0 *32* r14 := tmp\n"
"00010a84 0 *32* r16 := 0x11400\n"
"00010a88 0 *32* r16 := r16 | 808\n"
"00010a8c 0 *32* r8 := r16\n"
"00010a90 0 *32* tmp := r30\n"
" 0 *32* r9 := r30 - 20\n"
"00010a90 0 CALL scanf(\n"
" )\n"
" Reaching definitions: \n"
" Live variables: \n");
std::string actual(o1.str());
CPPUNIT_ASSERT_EQUAL(expected, actual);
bb = cfg->getNextBB(it);
CPPUNIT_ASSERT(bb);
std::ostringstream o2;
bb->print(o2);
expected = std::string("Call BB:\n"
"in edges: 10a90 \n"
"out edges: 10aa4 \n"
"00010a98 0 *32* r8 := r16\n"
"00010a9c 0 *32* tmp := r30\n"
" 0 *32* r9 := r30 - 24\n"
"00010a9c 0 CALL scanf(\n"
" )\n"
" Reaching definitions: \n"
" Live variables: \n");
actual = std::string(o2.str());
CPPUNIT_ASSERT_EQUAL(expected, actual);
bb = cfg->getNextBB(it);
CPPUNIT_ASSERT(bb);
std::ostringstream o3;
bb->print(o3);
expected = std::string("Twoway BB:\n"
"in edges: 10a9c \n"
"out edges: 10ac8 10ab8 \n"
"00010aa4 0 *32* r8 := m[r30 - 20]\n"
"00010aa8 0 *32* r16 := 5\n"
"00010aac 0 *32* tmp := r16\n"
//.........这里部分代码省略.........
示例9: canRename
bool DataFlow::renameBlockVars(UserProc* proc, int n, bool clearStacks /* = false */ ) {
if (++progress > 200) {
std::cerr << 'r' << std::flush;
progress = 0;
}
bool changed = false;
// Need to clear the Stacks of old, renamed locations like m[esp-4] (these will be deleted, and will cause compare
// failures in the Stacks, so it can't be correctly ordered and hence balanced etc, and will lead to segfaults)
if (clearStacks) Stacks.clear();
// For each statement S in block n
BasicBlock::rtlit rit; StatementList::iterator sit;
PBB bb = BBs[n];
Statement* S;
for (S = bb->getFirstStmt(rit, sit); S; S = bb->getNextStmt(rit, sit)) {
// if S is not a phi function (per Appel)
/* if (!S->isPhi()) */ {
// For each use of some variable x in S (not just assignments)
LocationSet locs;
if (S->isPhi()) {
PhiAssign* pa = (PhiAssign*)S;
Exp* phiLeft = pa->getLeft();
if (phiLeft->isMemOf() || phiLeft->isRegOf())
phiLeft->getSubExp1()->addUsedLocs(locs);
// A phi statement may use a location defined in a childless call, in which case its use collector
// needs updating
PhiAssign::iterator pp;
for (pp = pa->begin(); pp != pa->end(); ++pp) {
Statement* def = pp->def;
if (def && def->isCall())
((CallStatement*)def)->useBeforeDefine(phiLeft->clone());
}
}
else { // Not a phi assignment
S->addUsedLocs(locs);
}
LocationSet::iterator xx;
for (xx = locs.begin(); xx != locs.end(); xx++) {
Exp* x = *xx;
// Don't rename memOfs that are not renamable according to the current policy
if (!canRename(x, proc)) continue;
Statement* def = NULL;
if (x->isSubscript()) { // Already subscripted?
// No renaming required, but redo the usage analysis, in case this is a new return, and also because
// we may have just removed all call livenesses
// Update use information in calls, and in the proc (for parameters)
Exp* base = ((RefExp*)x)->getSubExp1();
def = ((RefExp*)x)->getDef();
if (def && def->isCall()) {
// Calls have UseCollectors for locations that are used before definition at the call
((CallStatement*)def)->useBeforeDefine(base->clone());
continue;
}
// Update use collector in the proc (for parameters)
if (def == NULL)
proc->useBeforeDefine(base->clone());
continue; // Don't re-rename the renamed variable
}
// Else x is not subscripted yet
if (STACKS_EMPTY(x)) {
if (!Stacks[defineAll].empty())
def = Stacks[defineAll].top();
else {
// If the both stacks are empty, use a NULL definition. This will be changed into a pointer
// to an implicit definition at the start of type analysis, but not until all the m[...]
// have stopped changing their expressions (complicates implicit assignments considerably).
def = NULL;
// Update the collector at the start of the UserProc
proc->useBeforeDefine(x->clone());
}
}
else
def = Stacks[x].top();
if (def && def->isCall())
// Calls have UseCollectors for locations that are used before definition at the call
((CallStatement*)def)->useBeforeDefine(x->clone());
// Replace the use of x with x{def} in S
changed = true;
if (S->isPhi()) {
Exp* phiLeft = ((PhiAssign*)S)->getLeft();
phiLeft->setSubExp1(phiLeft->getSubExp1()->expSubscriptVar(x, def /*, this*/));
} else {
S->subscriptVar(x, def /*, this */);
}
}
}
// MVE: Check for Call and Return Statements; these have DefCollector objects that need to be updated
// Do before the below, so CallStatements have not yet processed their defines
if (S->isCall() || S->isReturn()) {
DefCollector* col;
if (S->isCall())
col = ((CallStatement*)S)->getDefCollector();
else
col = ((ReturnStatement*)S)->getCollector();
col->updateDefs(Stacks, proc);
}
// For each definition of some variable a in S
//.........这里部分代码省略.........
示例10: assert
bool DataFlow::placePhiFunctions(UserProc* proc) {
// First free some memory no longer needed
dfnum.resize(0);
semi.resize(0);
ancestor.resize(0);
samedom.resize(0);
vertex.resize(0);
parent.resize(0);
best.resize(0);
bucket.resize(0);
defsites.clear(); // Clear defsites map,
defallsites.clear();
A_orig.clear(); // and A_orig,
defStmts.clear(); // and the map from variable to defining Stmt
bool change = false;
// Set the sizes of needed vectors
unsigned numBB = indices.size();
Cfg* cfg = proc->getCFG();
assert(numBB == cfg->getNumBBs());
A_orig.resize(numBB);
// We need to create A_orig[n] for all n, the array of sets of locations defined at BB n
// Recreate each call because propagation and other changes make old data invalid
unsigned n;
for (n=0; n < numBB; n++) {
BasicBlock::rtlit rit; StatementList::iterator sit;
PBB bb = BBs[n];
for (Statement* s = bb->getFirstStmt(rit, sit); s; s = bb->getNextStmt(rit, sit)) {
LocationSet ls;
LocationSet::iterator it;
s->getDefinitions(ls);
if (s->isCall() && ((CallStatement*)s)->isChildless()) // If this is a childless call
defallsites.insert(n); // then this block defines every variable
for (it = ls.begin(); it != ls.end(); it++) {
if (canRename(*it, proc)) {
A_orig[n].insert((*it)->clone());
defStmts[*it] = s;
}
}
}
}
// For each node n
for (n=0; n < numBB; n++) {
// For each variable a in A_orig[n]
std::set<Exp*, lessExpStar>& s = A_orig[n];
std::set<Exp*, lessExpStar>::iterator aa;
for (aa = s.begin(); aa != s.end(); aa++) {
Exp* a = *aa;
defsites[a].insert(n);
}
}
// For each variable a (in defsites, i.e. defined anywhere)
std::map<Exp*, std::set<int>, lessExpStar>::iterator mm;
for (mm = defsites.begin(); mm != defsites.end(); mm++) {
Exp* a = (*mm).first; // *mm is pair<Exp*, set<int>>
// Special processing for define-alls
// for each n in defallsites
std::set<int>::iterator da;
for (da = defallsites.begin(); da != defallsites.end(); ++da)
defsites[a].insert(*da);
// W <- defsites[a];
std::set<int> W = defsites[a]; // set copy
// While W not empty
while (W.size()) {
// Remove some node n from W
int n = *W.begin(); // Copy first element
W.erase(W.begin()); // Remove first element
// for each y in DF[n]
std::set<int>::iterator yy;
std::set<int>& DFn = DF[n];
for (yy = DFn.begin(); yy != DFn.end(); yy++) {
int y = *yy;
// if y not element of A_phi[a]
std::set<int>& s = A_phi[a];
if (s.find(y) == s.end()) {
// Insert trivial phi function for a at top of block y: a := phi()
change = true;
Statement* as = new PhiAssign(a->clone());
PBB Ybb = BBs[y];
Ybb->prependStmt(as, proc);
// A_phi[a] <- A_phi[a] U {y}
s.insert(y);
// if a !elementof A_orig[y]
if (A_orig[y].find(a) == A_orig[y].end()) {
// W <- W U {y}
W.insert(y);
}
}
}
}
}
return change;
} // end placePhiFunctions
示例11: assert
/*==============================================================================
* FUNCTION: FrontEnd::processProc
* OVERVIEW: Process a procedure, given a native (source machine) address.
* PARAMETERS: address - the address at which the procedure starts
* pProc - the procedure object
* frag - if true, this is just a fragment of a procedure
* spec - if true, this is a speculative decode
* os - the output stream for .rtl output
* NOTE: This is a sort of generic front end. For many processors, this will be overridden
* in the FrontEnd derived class, sometimes calling this function to do most of the work
* RETURNS: true for a good decode (no illegal instructions)
*============================================================================*/
bool FrontEnd::processProc(ADDRESS uAddr, UserProc* pProc, std::ofstream &os, bool frag /* = false */,
bool spec /* = false */) {
PBB pBB; // Pointer to the current basic block
std::cout<<"Entering Processing Proc\n";
// just in case you missed it
first_line = true;
if (AssProgram)
std::cout <<"Name Of Program : " << AssProgram->name << std::endl;
Boomerang::get()->alert_new(pProc);
// We have a set of CallStatement pointers. These may be disregarded if this is a speculative decode
// that fails (i.e. an illegal instruction is found). If not, this set will be used to add to the set of calls
// to be analysed in the cfg, and also to call newProc()
std::list<CallStatement*> callList;
// Indicates whether or not the next instruction to be decoded is the lexical successor of the current one.
// Will be true for all NCTs and for CTIs with a fall through branch.
bool sequentialDecode = true;
Cfg* pCfg = pProc->getCFG();
// If this is a speculative decode, the second time we decode the same address, we get no cfg. Else an error.
if (spec && (pCfg == 0))
return false;
assert(pCfg);
// Initialise the queue of control flow targets that have yet to be decoded.
targetQueue.initial(uAddr);
// Clear the pointer used by the caller prologue code to access the last call rtl of this procedure
//decoder.resetLastCall();
// ADDRESS initAddr = uAddr;
int nTotalBytes = 0;
ADDRESS startAddr = uAddr;
ADDRESS lastAddr = uAddr;
ADDRESS address = uAddr;
std::cout << "Start at address = " << uAddr << std::endl;
//------IMPORTANT------------------------------------------------------------------------
list<AssemblyLabel*>::iterator lbi;
list<AssemblyLine*>* temp_lines = new list<AssemblyLine*>();
if (AssProgram){
for(lbi = AssProgram->labelList->begin(); lbi != AssProgram->labelList->end(); ++lbi ){
if((*lbi)->address == uAddr){
temp_lines = (*lbi)->lineList;
std::cout << "***DECODE LABEL: " << (*lbi)->name << std::endl;
std::cout << "***AT ADDRESS: " << (*lbi)->address << std::endl;
std::cout << "***NUMBER OF INSTRUCTION: " << (*lbi)->lineList->size() << std::endl;
break;
}
}
}
list<AssemblyLine*>::iterator li;
if (temp_lines->size()>0)
li = temp_lines->begin();
//---------------------------------------------------------------------------------------
while ((uAddr = targetQueue.nextAddress(pCfg)) != NO_ADDRESS) {
// The list of RTLs for the current basic block
std::list<RTL*>* BB_rtls = new std::list<RTL*>();
// Keep decoding sequentially until a CTI without a fall through branch is decoded
//ADDRESS start = uAddr;
DecodeResult inst;
while (sequentialDecode) {
// Decode and classify the current source instruction
if (Boomerang::get()->traceDecoder)
LOG << "*" << uAddr << "\t";
// Decode the inst at uAddr.
if(ASS_FILE){
if(li != temp_lines->end()){
inst = decodeAssemblyInstruction(uAddr,"assemblySets.at(line)", (*li));
}
}
else
inst = decodeInstruction(uAddr);
// If invalid and we are speculating, just exit
if (spec && !inst.valid)
return false;
// Need to construct a new list of RTLs if a basic block has just been finished but decoding is
//.........这里部分代码省略.........
示例12: processProc
/*==============================================================================
* FUNCTION: processProc
* OVERVIEW: Process a procedure, given a native (source machine) address.
* PARAMETERS: address - the address at which the procedure starts
* delta - the offset of the above address from the logical
* address at which the procedure starts (i.e. the one
* given by dis)
* uUpper - the highest address of the text segment
* pProc - the procedure object
* decoder - NJMCDecoder object
* RETURNS: <nothing>
*============================================================================*/
void processProc(ADDRESS uAddr, ptrdiff_t delta, ADDRESS uUpper, UserProc* pProc,
NJMCDecoder& decoder)
{
PBB pBB; // Pointer to the current basic block
INSTTYPE type; // Cfg type of instruction (e.g. IRET)
// Declare a queue of targets not yet processed yet. This has to be
// individual to the procedure!
TARGETS targets;
// Indicates whether or not the next instruction to be decoded is the
// lexical successor of the current one. Will be true for all NCTs and for
// CTIs with a fall through branch.
bool sequentialDecode = true;
Cfg* pCfg = pProc->getCFG();
// Initialise the queue of control flow targets that have yet to be decoded.
targets.push(uAddr);
// Clear the pointer used by the caller prologue code to access the last
// call rtl of this procedure
//decoder.resetLastCall();
while ((uAddr = nextAddress(targets, pCfg)) != 0)
{
// The list of RTLs for the current basic block
list<HRTL*>* BB_rtls = new list<HRTL*>();
// Keep decoding sequentially until a CTI without a fall through branch
// is decoded
ADDRESS start = uAddr;
DecodeResult inst;
while (sequentialDecode)
{
// Decode and classify the current instruction
if (progOptions.trace)
cout << "*" << hex << uAddr << "\t" << flush;
// Decode the inst at uAddr.
inst = decoder.decodeInstruction(uAddr, delta, pProc);
// Need to construct a new list of RTLs if a basic block has just
// been finished but decoding is continuing from its lexical
// successor
if (BB_rtls == NULL)
BB_rtls = new list<HRTL*>();
HRTL* pRtl = inst.rtl;
if (inst.numBytes == 0)
{
// An invalid instruction. Most likely because a call did
// not return (e.g. call _exit()), etc. Best thing is to
// emit a INVALID BB, and continue with valid instructions
ostrstream ost;
ost << "invalid instruction at " << hex << uAddr;
warning(str(ost));
// Emit the RTL anyway, so we have the address and maybe
// some other clues
BB_rtls->push_back(new RTL(uAddr));
pBB = pCfg->newBB(BB_rtls, INVALID, 0);
sequentialDecode = false;
BB_rtls = NULL;
continue;
}
HLJump* rtl_jump = static_cast<HLJump*>(pRtl);
// Display RTL representation if asked
if (progOptions.rtl) pRtl->print();
ADDRESS uDest;
switch (pRtl->getKind())
{
case JUMP_HRTL:
{
uDest = rtl_jump->getFixedDest();
// Handle one way jumps and computed jumps separately
if (uDest != NO_ADDRESS)
{
BB_rtls->push_back(pRtl);
sequentialDecode = false;
//.........这里部分代码省略.........