1 #include <featureTests.h>
2 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
3 #include "sage3basic.h"
4 #include "AsmUnparser.h"
7 #include <boost/lexical_cast.hpp>
8 #include "integerOps.h"
10 #include "Diagnostics.h"
22 registers = RegisterDictionary::dictionary_powerpc32();
23 std::string name = registers->lookup(rdesc);
25 name = AsmUnparser::invalid_register(insn, rdesc, registers);
32 std::string result =
"";
33 if (expr == NULL)
return "BOGUS:NULL";
35 case V_SgAsmBinaryAdd:
36 result = unparsePowerpcExpression(isSgAsmBinaryExpression(expr)->get_lhs(), labels, registers,
false) +
" + " +
37 unparsePowerpcExpression(isSgAsmBinaryExpression(expr)->get_rhs(), labels, registers,
false);
39 case V_SgAsmMemoryReferenceExpression: {
43 case V_SgAsmBinaryAdd: {
45 std::string lhs = unparsePowerpcExpression(a->
get_lhs(), labels, registers,
false);
46 if (isSgAsmValueExpression(a->
get_rhs())) {
50 result = boost::lexical_cast<std::string>(
51 (int64_t)IntegerOps::signExtend<16, 64>(SageInterface::getAsmConstant(ve)));
52 result +=
"(" + lhs +
")";
54 result = lhs +
", " + unparsePowerpcExpression(a->
get_rhs(), labels, registers,
false);
59 result =
"(" + unparsePowerpcExpression(addr, labels, registers,
false) +
")";
64 case V_SgAsmDirectRegisterExpression: {
65 SgAsmInstruction *insn = SageInterface::getEnclosingNode<SgAsmInstruction>(expr);
67 result = unparsePowerpcRegister(insn, rr->get_descriptor(), registers);
70 case V_SgAsmIntegerValueExpression: {
78 AsmUnparser::LabelMap::const_iterator li = labels->find(v);
79 if (li!=labels->end())
85 ASSERT_not_reachable(
"invalid PowerPC expression: " + expr->
class_name());
94 ASSERT_not_null(insn);
104 insn = isSgAsmPowerpcInstruction(node);
106 ASSERT_not_null(insn);
109 bool isBranchTarget = (((kind ==
powerpc_b ||
114 ((kind == powerpc_bc ||
115 kind == powerpc_bcl ||
116 kind == powerpc_bca ||
117 kind == powerpc_bcla) &&
120 return unparsePowerpcExpression(expr, labels, registers, isBranchTarget);
ROSE_UTIL_API std::string intToHex(uint64_t)
Convert an integer to a hexadecimal string.
Expression that adds two operands.
ROSE_UTIL_API std::string numberToString(long long)
Convert an integer to a string.
SgAsmExpression * get_lhs() const
Property: Left-hand side operand.
Base class for machine instructions.
const std::string & get_comment() const
Property: Comment.
SgAsmExpression * get_address() const
Property: Memory address expression.
Main namespace for the ROSE library.
virtual VariantT variantT() const
returns new style SageIII enum values
PowerpcInstructionKind
PowerPC instruction types.
const std::string & get_mnemonic() const
Property: Instruction mnemonic string.
SgAsmExpression * get_rhs() const
Property: Right-hand side operand.
Reference to memory locations.
ROSE_UTIL_API std::string appendAsmComment(const std::string &s, const std::string &comment)
Append an assembly comment to a string.
Expression representing a machine register.
Describes (part of) a physical CPU register.
This class represents the base class for all IR nodes within Sage III.
Represents one PowerPC machine instruction.
Rose::BinaryAnalysis::PowerpcInstructionKind get_kind() const
Property: Instruction kind.
Base class for expressions.
virtual std::string class_name() const
returns a string representing the class name
std::map< uint64_t, std::string > LabelMap
Maps integers to labels.
SgNode * get_parent() const
Access function for parent node.
size_t nOperands() const
Number of operands.
Defines registers available for a particular architecture.
uint64_t get_absoluteValue(size_t nbits=0) const
Returns the current absolute value zero filled to 64 bits.
Controls diagnostic messages from ROSE.
SgAsmExpression * operand(size_t) const
Nth operand.