bool SgAsmBlock::has_instructions() const { const SgAsmStatementPtrList &stmts = get_statementList(); for (SgAsmStatementPtrList::const_iterator si=stmts.begin(); si!=stmts.end(); ++si) { if (isSgAsmInstruction(*si)) return true; } return false; }
SgUnsignedCharList Assembler::assembleBlock(SgAsmBlock *bb) { std::vector<SgAsmInstruction*> ivec; std::vector<SgNode*> nvec = NodeQuery::querySubTree(bb, V_SgAsmInstruction); for (std::vector<SgNode*>::iterator i=nvec.begin(); i!=nvec.end(); ++i) { SgAsmInstruction *insn = isSgAsmInstruction(*i); ROSE_ASSERT(insn!=NULL); ivec.push_back(insn); } if (0==ivec.size()) return SgUnsignedCharList(); return assembleBlock(ivec, ivec.front()->get_address()); }
void AST_BIN_Traversal::visit(SgNode* n) { if (n) { nrOfInstructions++; std::string name = ""; if (isSgAsmInstruction(n)) name = unparseInstruction(isSgAsmInstruction(n)); SgNode* parent = n->get_parent(); // node std::string add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=yellow,fontname=\"7x13bold\",fontcolor=black,style=filled"; if (isSgAsmFunction(n)) { add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=purple,fontname=\"7x13bold\",fontcolor=black,style=filled"; name = isSgAsmFunction(n)->get_name(); } if (isSgAsmX86Instruction(n) && isSgAsmX86Instruction(n)->get_kind() == x86_call) add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=red,fontname=\"7x13bold\",fontcolor=black,style=filled"; if (isSgAsmValueExpression(n)) add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=lightgreen,fontname=\"7x13bold\",fontcolor=black,style=filled"; if (isSgAsmMemoryReferenceExpression(n)) add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=lightblue,fontname=\"7x13bold\",fontcolor=black,style=filled"; if (isSgAsmBinaryExpression(n)) add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=orange,fontname=\"7x13bold\",fontcolor=black,style=filled"; if (isSgAsmRegisterReferenceExpression(n)) { SgAsmRegisterReferenceExpression* rr = isSgAsmRegisterReferenceExpression(n); std::string exprName = unparseX86Register(rr->get_descriptor(), NULL); name += " "+exprName; add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=green,fontname=\"7x13bold\",fontcolor=black,style=filled"; } if (isSgAsmOperandList(n)) add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=white,fontname=\"7x13bold\",fontcolor=black,style=filled"; myfile << "\"" << n << "\"[label=\"" << name << "\\n" << n->class_name() << "\"" << add << " ];\n"; if (parent) { // edge myfile << "\"" << parent << "\" -> \"" << n << "\" [label=\"" << n->class_name() << "\" ];\n"; } } }
virtual void visit(SgNode* n) { SgAsmInstruction* insn = isSgAsmInstruction(n); if (!insn) return; #ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT #if 1 ASSERT_not_reachable("no longer supported"); #else vector<CFGEdge> outEdgesSoFar = insn->cfgBinOutEdges(info); for (size_t i = 0; i < outEdgesSoFar.size(); ++i) { info->incomingEdges[outEdgesSoFar[i].target().getNode()].insert(insn->get_address()); } #endif #else printf ("This function is not supported in the ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT mode.\n"); ROSE_ASSERT(false); #endif }
/** HashAST::visit * * Called by traverse. Gets the whatever data is of interest and puts * it in the hash. * * @param[in] node to submit to hash **/ void AstHash::visit(SgNode* node) { //Always include the type of each node in the hash VariantT vType = node->variantT(); hasher_.insert(vType); //If it's an instruction, include the mnemonic, and maybe the address SgAsmInstruction* asmInstruction = isSgAsmInstruction(node); if(asmInstruction != NULL) { std::string mnemonic = asmInstruction->get_mnemonic(); hasher_.insert(mnemonic); if(includeAddresses) { rose_addr_t addr = asmInstruction->get_address(); hasher_.insert(addr); } return; } //Always include register references SgAsmRegisterReferenceExpression* regRef = isSgAsmRegisterReferenceExpression(node); if(regRef != NULL) { unsigned regHash = regRef->get_descriptor().hash(); hasher_.insert(regHash); return; } //Maybe inlcude constants (integers, floats, pointers) if(includeConstants) { SgAsmConstantExpression* constExpr = isSgAsmConstantExpression(node); if(constExpr != NULL) { std::string mnemonic = constExpr->get_bitVector().toHex(); hasher_.insert(mnemonic); return; } } }
virtual void visit(SgNode* n) { SgAsmInstruction* insn = isSgAsmInstruction(n); if (!insn) return; info->addressToInstructionMap[insn->get_address()] = insn; }
void visit(SgNode *node) { if (SgAsmInstruction *insn = isSgAsmInstruction(node)) imap.erase(insn->get_address()); }
void visit(SgNode *node) { if (SgAsmInstruction *insn = isSgAsmInstruction(node)) imap[insn->get_address()] = insn; }