1 #ifndef ROSE_BinaryAnalysis_Partitioner2_InstructionProvider_H
2 #define ROSE_BinaryAnalysis_Partitioner2_InstructionProvider_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include "Disassembler.h"
8 #include "BaseSemantics2.h"
9 #include "AstSerialization.h"
11 #include <boost/serialization/access.hpp>
12 #include <Sawyer/Assert.h>
13 #include <Sawyer/HashMap.h>
14 #include <Sawyer/SharedPointer.h>
42 mutable InsnMap insnMap_;
43 bool useDisassembler_;
45 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
47 friend class boost::serialization::access;
50 void save(S &s,
const unsigned )
const {
51 roseAstSerializationRegistration(s);
52 bool hasDisassembler = disassembler_ != NULL;
53 s <<BOOST_SERIALIZATION_NVP(hasDisassembler);
54 s <<BOOST_SERIALIZATION_NVP(useDisassembler_);
55 s <<BOOST_SERIALIZATION_NVP(memMap_);
56 s <<BOOST_SERIALIZATION_NVP(insnMap_);
57 if (hasDisassembler) {
58 std::string disName = disassembler_->
name();
59 s <<BOOST_SERIALIZATION_NVP(disName);
64 void load(S &s,
const unsigned ) {
65 roseAstSerializationRegistration(s);
66 bool hasDisassembler =
false;
67 s >>BOOST_SERIALIZATION_NVP(hasDisassembler);
68 s >>BOOST_SERIALIZATION_NVP(useDisassembler_);
69 s >>BOOST_SERIALIZATION_NVP(memMap_);
70 s >>BOOST_SERIALIZATION_NVP(insnMap_);
71 if (hasDisassembler) {
73 s >>BOOST_SERIALIZATION_NVP(disName);
75 ASSERT_not_null2(disassembler_,
"disassembler name=" + disName);
79 BOOST_SERIALIZATION_SPLIT_MEMBER();
84 : disassembler_(NULL), useDisassembler_(false) {
89 InstructionProvider(Disassembler *
disassembler,
const MemoryMap::Ptr &map)
90 : disassembler_(disassembler), memMap_(map), useDisassembler_(true) {
91 ASSERT_not_null(disassembler);
118 return useDisassembler_;
121 ASSERT_require(!enable || disassembler_);
122 useDisassembler_ = enable;
125 useDisassembler_ =
false;
void registerDictionary(const RegisterDictionary *rdict)
Properties: Register dictionary.
RegisterDescriptor instructionPointerRegister() const
Register used as the instruction pointer.
Sawyer::Container::HashMap< rose_addr_t, SgAsmInstruction * > InsnMap
Mapping from address to instruction.
size_t wordSizeBytes() const
Property: Basic word size in bytes.
const CallingConvention::Dictionary & callingConventions() const
Returns the calling convention dictionary.
void disableDisassembler()
Enable or disable the disassembler.
Disassembler * disassembler() const
Returns the disassembler.
RegisterDescriptor stackSegmentRegister() const
Register used as a segment to access stack memory.
size_t wordSize() const
Word size in bits.
void showStatistics() const
Print some partitioner performance statistics.
Base class for machine instructions.
Provides and caches instructions.
RegisterDescriptor stackPointerRegister() const
Register used as a user-mode stack pointer.
const std::string & name() const
Property: Name by which disassembler is registered.
InstructionSemantics2::BaseSemantics::DispatcherPtr dispatcher() const
Instruction dispatcher.
virtual RegisterDescriptor stackFrameRegister() const
Returns the register that ponts to the stack frame.
Main namespace for the ROSE library.
RegisterDescriptor stackFrameRegister() const
Register used for function call frames.
virtual RegisterDescriptor stackSegmentRegister() const
Returns the segment register for accessing the stack.
ByteOrder::Endianness defaultByteOrder() const
Default memory byte order.
ByteOrder::Endianness byteOrder() const
Property: Byte order of instructions in memory.
size_t size() const
Number of nodes, keys, or values in this container.
RegisterDescriptor callReturnRegister() const
Register holding a function call's return address.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
size_t instructionAlignment() const
Property: Instruction alignment requirement.
virtual RegisterDescriptor instructionPointerRegister() const
Returns the register that points to instructions.
virtual RegisterDescriptor callReturnRegister() const
Returns the register that holds the return address for a function.
std::vector< Definition::Ptr > Dictionary
A ordered collection of calling convention definitions.
Describes (part of) a physical CPU register.
bool isDisassemblerEnabled() const
Enable or disable the disassembler.
static Disassembler * lookup(SgAsmGenericHeader *)
Finds a suitable disassembler.
Sawyer::SharedPointer< InstructionProvider > Ptr
Shared-ownership pointer to an InstructionProvider.
void insert(SgAsmInstruction *)
Insert an instruction into the cache.
const RegisterDictionary * registerDictionary() const
Returns the register dictionary.
void rehash(size_t nBuckets)
Change number of buckets.
const CallingConvention::Dictionary & callingConventions() const
Property: Calling convention dictionary.
Base class for reference counted objects.
const Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::DispatcherPtr & dispatcher() const
Return an instruction semantics dispatcher if possible.
static Ptr instance(Disassembler *disassembler, const MemoryMap::Ptr &map)
Static allocating Constructor.
void enableDisassembler(bool enable=true)
Enable or disable the disassembler.
Defines registers available for a particular architecture.
virtual RegisterDescriptor stackPointerRegister() const
Returns the register that points to the stack.
SgAsmInstruction * operator[](rose_addr_t va) const
Returns the instruction at the specified virtual address, or null.
Virtual base class for instruction disassemblers.
size_t instructionAlignment() const
Alignment requirement for instructions.
size_t nCached() const
Returns number of cached starting addresses.