1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_LlvmSemantics_H 
    2#define ROSE_BinaryAnalysis_InstructionSemantics_LlvmSemantics_H 
    3#include <featureTests.h> 
    4#ifdef ROSE_ENABLE_BINARY_ANALYSIS 
    6#include <Rose/BinaryAnalysis/BasicTypes.h> 
    7#include <Rose/BinaryAnalysis/InstructionSemantics/SymbolicSemantics.h> 
    8#include <Rose/BinaryAnalysis/InstructionSemantics/DispatcherX86.h> 
    9#include <Rose/CommandLine.h> 
   12namespace BinaryAnalysis {
 
   13namespace InstructionSemantics {
 
   16namespace LlvmSemantics {
 
   18typedef std::vector<RegisterDescriptor> RegisterDescriptors;
 
   25typedef SymbolicExpression::Nodes TreeNodes;
 
   33typedef SymbolicSemantics::MemoryStatePtr MemoryStatePtr;
 
   56    RegisterStatePtr prev_regstate;                     
 
   57    RegisterDescriptors important_registers;            
 
   60    std::string indent_string;                          
 
  131    int indent(
int nlevels=1) { indent_level += nlevels; 
return nlevels; }
 
  143            ops->indent(nlevels);
 
  146            ops->indent(nlevels);
 
  149            ops->indent(-nlevels);
 
 
 
 
Extends std::map with methods that return optional values.
 
A RegisterState for any architecture.
 
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
 
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
 
Base class for semantics machine states.
 
virtual const RegisterDescriptors & get_important_registers()
Return the list of registers that needs to be emitted to LLVM.
 
virtual LeafPtr emit_expression(std::ostream &, const SValuePtr &)
Emit LLVM statements for an expression.
 
virtual ExpressionPtr emit_truncate(std::ostream &, const ExpressionPtr &value, size_t nbits)
Emit an operation as LLVM instructions.
 
virtual void emit_register_definitions(std::ostream &, const RegisterDescriptors &)
Output LLVM global register definitions for the specified registers.
 
virtual std::string next_label()
Obtain the name for an LLVM label, excluding the "%" sigil.
 
virtual void make_current()
Mark the current state as having been emitted.
 
virtual ExpressionPtr emit_global_read(std::ostream &, const std::string &varname, size_t nbits)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_left_shift(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
static RiscOperatorsPtr instanceFromProtoval(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified prototypical values.
 
virtual ExpressionPtr emit_left_associative(std::ostream &, const std::string &llvm_op, const TreeNodes &operands)
Emit an operation as LLVM instructions.
 
virtual SValuePtr get_instruction_pointer()
Return the value of the instruction pointer.
 
virtual ExpressionPtr emit_memory_read(std::ostream &, const ExpressionPtr &address, size_t nbits)
Emit an operation as LLVM instructions.
 
virtual std::string llvm_integer_type(size_t nbits)
Obtain the LLVM type name for an integer.
 
virtual ExpressionPtr emit_zero_extend(std::ostream &, const ExpressionPtr &value, size_t nbits)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_signed_multiply(std::ostream &, const TreeNodes &operands)
Emit an operation as LLVM instructions.
 
void llvmVersion(int v)
Property: LLVM version.
 
virtual void emit_next_eip(std::ostream &, SgAsmInstruction *latest_insn)
Output an LLVM branch instruction.
 
virtual ExpressionPtr emit_compare(std::ostream &, const std::string &llvm_op, const ExpressionPtr &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_extract(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &from, size_t result_nbits)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_logical_right_shift(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
virtual RegisterDescriptor get_insn_pointer_register()
Return the descriptor for the instruction pointer register.
 
virtual void emit_memory_writes(std::ostream &)
Output changed memory state.
 
int llvmVersion() const
Property: LLVM version.
 
virtual ExpressionPtr emit_sign_extend(std::ostream &, const ExpressionPtr &value, size_t nbits)
Emit an operation as LLVM instructions.
 
virtual LeafPtr emit_expression(std::ostream &, const ExpressionPtr &)
Emit LLVM statements for an expression.
 
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
 
virtual std::string function_label(SgAsmFunction *)
Obtain a label for a function.
 
static RiscOperatorsPtr instanceFromState(const BaseSemantics::StatePtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified state.
 
RiscOperatorsPtr Ptr
Shared-ownership pointer.
 
virtual void reset()
Reset to initial state.
 
int indent(int nlevels=1)
Increase indentation by nlevels levels.
 
virtual std::string llvm_term(const ExpressionPtr &)
Convert a ROSE variable or integer to an LLVM term.
 
virtual void emit_changed_state(std::ostream &)
Output LLVM to bring the LLVM state up to date with respect to the ROSE state.
 
virtual void add_rewrite(const ExpressionPtr &from, const LeafPtr &to)
Register a rewrite.
 
virtual LeafPtr emit_assignment(std::ostream &, const ExpressionPtr &rhs)
Emit an assignment and add a rewrite rule.
 
virtual void emit_prerequisites(std::ostream &, const RegisterDescriptors &, const RegisterDictionaryPtr &)
Output LLVM global variable reads that are needed to define the specified registers and pending memor...
 
virtual const TreeNodes & get_memory_writes()
Return the list of memory writes that have occured since the last call to make_current().
 
virtual ExpressionPtr emit_arithmetic_right_shift(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
virtual std::string add_variable(const LeafPtr &)
Register an LLVM variable.
 
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
 
virtual RegisterDescriptors get_stored_registers()
Return the list of important registers that are stored.
 
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to Llvm operators.
 
virtual ExpressionPtr emit_signed_divide(std::ostream &, const ExpressionPtr &numerator, const ExpressionPtr &denominator)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_unsigned_multiply(std::ostream &, const TreeNodes &operands)
Emit an operation as LLVM instructions.
 
virtual std::string addr_label(Address)
Obtain a label for a virtual address.
 
virtual std::string get_variable(const LeafPtr &)
Returns the LLVM name for a variable, including the sigil.
 
virtual ExpressionPtr emit_lssb(std::ostream &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
virtual std::string llvm_lvalue(const LeafPtr &)
Convert a ROSE variable to an LLVM lvalue.
 
virtual LeafPtr next_temporary(size_t nbits)
Create a temporary variable.
 
virtual ExpressionPtr emit_signed_modulo(std::ostream &, const ExpressionPtr &numerator, const ExpressionPtr &denominator)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_rotate_left(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_ite(std::ostream &, const ExpressionPtr &cond, const ExpressionPtr &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
static RiscOperatorsPtr instanceFromRegisters(const RegisterDictionaryPtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object and configures it to use semantic values and states that are ...
 
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
 
virtual void emit_memory_write(std::ostream &, const ExpressionPtr &address, const ExpressionPtr &value)
Emit an operation as LLVM instructions.
 
std::string prefix() const
Return indentation string.
 
virtual ExpressionPtr emit_signed_binary(std::ostream &, const std::string &llvm_op, const ExpressionPtr &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
virtual void emit_register_declarations(std::ostream &, const RegisterDescriptors &)
Output LLVM global register declarations for the specified registers.
 
virtual ExpressionPtr emit_unsigned_modulo(std::ostream &, const ExpressionPtr &numerator, const ExpressionPtr &denominator)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_logical_right_shift_ones(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_invert(std::ostream &, const ExpressionPtr &value)
Emit an operation as LLVM instructions.
 
virtual RegisterDescriptors get_modified_registers()
Return the list of important registers that have been modified since the last call to make_current().
 
virtual ExpressionPtr emit_concat(std::ostream &, TreeNodes operands)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_unsigned_binary(std::ostream &, const std::string &llvm_op, const ExpressionPtr &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_rotate_right(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_mssb(std::ostream &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_left_shift_ones(std::ostream &, const ExpressionPtr &value, const ExpressionPtr &amount)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_unsigned_resize(std::ostream &, const ExpressionPtr &value, size_t nbits)
Emit an operation as LLVM instructions.
 
virtual ExpressionPtr emit_binary(std::ostream &, const std::string &llvm_op, const ExpressionPtr &, const ExpressionPtr &)
Emit an operation as LLVM instructions.
 
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
 
virtual ExpressionPtr emit_unsigned_divide(std::ostream &, const ExpressionPtr &numerator, const ExpressionPtr &denominator)
Emit an operation as LLVM instructions.
 
virtual LeafPtr emit_expression(std::ostream &, const LeafPtr &)
Emit LLVM statements for an expression.
 
Translates machine instructions to LLVM.
 
int llvmVersion() const
Property: LLVM version number.
 
std::string transcodeInterpretation(SgAsmInterpretation *)
Transcode an entire binary interpretation.
 
std::string transcodeInstruction(SgAsmInstruction *)
Translate a single machine instruction to LLVM instructions.
 
void quietErrors(bool b)
Property to control what happens when a translation exception occurs.
 
std::string transcodeFunction(SgAsmFunction *)
Transcode an entire function to LLVM instructions.
 
std::string emitFunctionDeclarations(SgNode *ast)
Emit function declarations.
 
void emitFilePrologue(std::ostream &)
Emit LLVM file prologue.
 
bool emitFunctionFragements() const
Property to determine whether function fragments should be emitted.
 
std::string transcodeBasicBlock(SgAsmBlock *)
Transcode a basic block of machine instructions to LLVM instructions.
 
static TranscoderPtr instance(const BaseSemantics::DispatcherPtr &)
Factory method to create a new transcoder for an arbitrary machine architecture.
 
bool quietErrors() const
Property to control what happens when a translation exception occurs.
 
static TranscoderPtr instanceX86()
Factory method to create a new transcoder for 32-bit X86 instructions.
 
void llvmVersion(int version)
Property: LLVM version number.
 
void transcodeInterpretation(SgAsmInterpretation *, std::ostream &)
Transcode an entire binary interpretation.
 
size_t transcodeFunction(SgAsmFunction *, std::ostream &)
Transcode an entire function to LLVM instructions.
 
void transcodeInstruction(SgAsmInstruction *, std::ostream &)
Translate a single machine instruction to LLVM instructions.
 
void emitFunctionFragements(bool b)
Property to determine whether function fragments should be emitted.
 
size_t transcodeBasicBlock(SgAsmBlock *, std::ostream &)
Transcode a basic block of machine instructions to LLVM instructions.
 
TranscoderPtr Ptr
Reference counting pointer.
 
std::string emitFilePrologue()
Emit LLVM file prologue.
 
void emitFunctionDeclarations(SgNode *ast, std::ostream &)
Emit function declarations.
 
Defines RISC operators for the SymbolicSemantics domain.
 
Type of values manipulated by the SymbolicSemantics domain.
 
Describes (part of) a physical CPU register.
 
Interior node of an expression tree for instruction semantics.
 
Leaf node of an expression tree for instruction semantics.
 
Reference-counting intrusive smart pointer.
 
Represents a synthesized function.
 
Base class for machine instructions.
 
Represents an interpretation of a binary container.
 
This class represents the base class for all IR nodes within Sage III.
 
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
 
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
 
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
 
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
 
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to LLVM RISC operations.
 
boost::shared_ptr< class Transcoder > TranscoderPtr
Shared-ownership pointer to an LLVM transcoder.
 
std::uint64_t Address
Address.
 
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
 
Cause indentation until this object is destroyed.