1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_Dispatcher_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_Dispatcher_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/BasicTypes.h>
7#include <Rose/BinaryAnalysis/ByteCode/Analysis.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RiscOperators.h>
10#include <boost/enable_shared_from_this.hpp>
12#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
13#include <boost/serialization/access.hpp>
14#include <boost/serialization/export.hpp>
15#include <boost/serialization/nvp.hpp>
16#include <boost/serialization/shared_ptr.hpp>
20namespace BinaryAnalysis {
21namespace InstructionSemantics {
48class Dispatcher:
public boost::enable_shared_from_this<Dispatcher> {
56 uint32_t nextObjectId_ = 1;
66 typedef std::vector<InsnProcessor*> InsnProcessors;
67 InsnProcessors iproc_table;
79#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
81 friend class boost::serialization::access;
84 void serializeCommon(S &s,
const unsigned version) {
85 ASSERT_always_require(version >= 2);
86 s & boost::serialization::make_nvp(
"operators", operators_);
87 s & BOOST_SERIALIZATION_NVP(nextObjectId_);
94 void save(S &s,
const unsigned version)
const {
95 const_cast<Dispatcher*
>(
this)->serializeCommon(s, version);
96 ASSERT_not_null(architecture_);
102 void load(S &s,
const unsigned version) {
103 serializeCommon(s, version);
109 BOOST_SERIALIZATION_SPLIT_MEMBER();
123 virtual ~Dispatcher();
152 virtual void processCommon();
355#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
Dispatches instructions through the RISC layer.
virtual void operators(const RiscOperatorsPtr &)
Property: RISC operators.
virtual void initializeState(const StatePtr &)
Initialize the state.
Architecture::BaseConstPtr architecture() const
Property: Architecture.
virtual InsnProcessor * iprocLookup(SgAsmInstruction *insn)
Lookup the processor for an instruction.
virtual RegisterDescriptor stackPointerRegister() const
Returns the stack pointer register.
virtual void postUpdate(SgAsmExpression *, const BaseSemantics::SValuePtr &enabled)
Update registers for post-add expressions.
virtual SValuePtr protoval() const
Return the prototypical value.
const ByteCode::ClassRepository::Ptr & classRepository() const
Returns the ByteCode::Class repository.
bool autoResetInstructionPointer_
Reset instruction pointer register for each instruction.
virtual void preUpdate(SgAsmExpression *, const BaseSemantics::SValuePtr &enabled)
Update registers for pre-add expressions.
virtual SValuePtr unspecified_(size_t nbits) const
Return a new undefined semantic value.
virtual SValuePtr read(SgAsmExpression *, size_t value_nbits=0, size_t addr_nbits=0)
Reads an R-value expression.
virtual StatePtr currentState() const
Get a pointer to the state object.
virtual RegisterDescriptor stackFrameRegister() const
Returns the stack call frame register.
virtual int iprocKey(SgAsmInstruction *) const =0
Given an instruction, return the InsnProcessor key that can be used as an index into the iproc_table.
virtual SValuePtr number_(size_t nbits, uint64_t number) const
Return a semantic value representing a number.
void completeReturn(BaseSemantics::RiscOperators *, const BaseSemantics::SValuePtr result=BaseSemantics::SValuePtr())
Completes a return from the current method.
virtual RegisterDescriptor callReturnRegister() const
Returns the function call return address register.
virtual void incrementRegisters(SgAsmExpression *)
Increment all auto-increment registers in the expression.
virtual SValuePtr undefined_(size_t nbits) const
Return a new undefined semantic value.
uint32_t allocateObjectId()
Allocates a new unique object identifier.
virtual void decrementRegisters(SgAsmExpression *)
Decrement all auto-decrement registers in the expression.
virtual InsnProcessor * iprocGet(int key)
Obtain an iproc table entry for the specified key.
virtual RegisterDescriptor findRegister(const std::string ®name, size_t nbits=0, bool allowMissing=false) const
Lookup a register by name.
void classes(const ByteCode::ClassRepository *classes)
Sets non-owning pointer to the ByteCode class repository maintained by the Engine.
virtual SValuePtr effectiveAddress(SgAsmExpression *, size_t nbits=0)
Returns a memory address by evaluating the address expression.
void classRepository(const ByteCode::ClassRepository::Ptr &repo)
Sets the ByteCode::Class repository.
bool autoResetInstructionPointer() const
Property: Reset instruction pointer register for each instruction.
virtual void iprocReplace(SgAsmInstruction *insn, InsnProcessor *iproc)
Replace an instruction processor with another.
virtual void processInstruction(SgAsmInstruction *insn)
Process a single instruction.
size_t addressWidth() const
Property: Width of memory addresses in bits.
DispatcherPtr Ptr
Shared-ownership pointer.
virtual SgAsmInstruction * currentInstruction() const
Returns the instruction that is being processed.
virtual void write(SgAsmExpression *, const SValuePtr &value, size_t addr_nbits=0)
Writes to an L-value expression.
ByteCode::ClassRepository::Ptr classes_
The ByteCode class repository maintained by the Engine.
virtual void advanceInstructionPointer(SgAsmInstruction *)
Update the instruction pointer register.
virtual DispatcherPtr create(const RiscOperatorsPtr &ops) const =0
Virtual constructor.
void autoResetInstructionPointer(bool b)
Property: Reset instruction pointer register for each instruction.
virtual RegisterDescriptor segmentRegister(SgAsmMemoryReferenceExpression *)
Returns a register descriptor for the segment part of a memory reference expression.
virtual void iprocSet(int key, InsnProcessor *iproc)
Set an iproc table entry to the specified value.
RegisterDictionaryPtr registerDictionary() const
Property: Register dictionary.
virtual RegisterDescriptor instructionPointerRegister() const
Returns the instruction pointer register.
virtual RiscOperatorsPtr operators() const
Property: RISC operators.
virtual void processDelaySlot(SgAsmInstruction *delayInsn)
Process a delay slot.
Functor that knows how to dispatch a single kind of instruction.
Base class for most instruction semantics RISC operators.
Describes (part of) a physical CPU register.
Base class for expressions.
Base class for machine instructions.
Reference to memory locations.
const std::string & name(const BaseConstPtr &)
Architecture name free function.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
Sawyer::Result< BasePtr, NotFound > findByName(const std::string &)
Look up a new architecture by name.
Base classes for instruction semantics.
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.
ValueKind
Kind of an SValue for emulating JVM and CIL instructions.