void visit(SgNode *node) { SgAsmRegisterReferenceExpression *rre = isSgAsmRegisterReferenceExpression(node); if (rre) { size_t nbits = rre->get_descriptor().get_nbits(); double v = log(nbits) / M_LN2; sum += do_variance ? (v-mean)*(v-mean) : v; ++n; } }
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"; } } }
// see base class bool SgAsmMipsInstruction::is_function_return(const std::vector<SgAsmInstruction*> &insns) { if (insns.empty()) return false; SgAsmMipsInstruction *last = isSgAsmMipsInstruction(insns.back()); if (!last) return false; if (last->get_kind()!=mips_jr) return false; const SgAsmExpressionPtrList &args = last->get_operandList()->get_operands(); if (args.size()<1) return false; SgAsmRegisterReferenceExpression *rre = isSgAsmRegisterReferenceExpression(args[0]); if (!rre) return false; if (rre->get_descriptor().get_major()!=mips_regclass_gpr || rre->get_descriptor().get_minor()!=31) return false; return true; // this is a "JR ra" instruction. }
/** 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; } } }