ROSE 0.11.145.147
Architecture/Base.h
1#ifndef ROSE_BinaryAnalysis_Architecture_Base_H
2#define ROSE_BinaryAnalysis_Architecture_Base_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/Alignment.h>
7#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
8#include <Rose/BinaryAnalysis/ByteOrder.h>
9#include <Rose/BinaryAnalysis/CallingConvention/BasicTypes.h>
10#include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
11#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
12#include <Rose/BinaryAnalysis/Unparser/Base.h>
13
14#include <Sawyer/Interval.h>
15#include <Sawyer/Optional.h>
16
17namespace Rose {
18namespace BinaryAnalysis {
19namespace Architecture {
20
22class Base: public std::enable_shared_from_this<Base> {
23public:
25 using Ptr = BasePtr;
26
29
30private:
31 std::string name_; // name of architecture
32 Sawyer::Optional<size_t> registrationId_; // registration identification number
33 size_t bytesPerWord_ = 0;
35
36protected:
37 Sawyer::Cached<RegisterDictionaryPtr> registerDictionary_;
38 Sawyer::Cached<RegisterDictionaryPtr> interruptDictionary_;
40 Sawyer::Cached<Unparser::Base::Ptr> insnToString_, insnToStringNoAddr_;
41
42protected:
43 Base(const std::string &name, size_t bytesPerWord, ByteOrder::Endianness byteOrder);
44 virtual ~Base();
45
47 // Properties
49public:
62 const std::string& name() const;
63
81 size_t bytesPerWord() const;
82 size_t bitsPerWord() const;
93
104
117
128
130 // Lookup functions
132public:
138 virtual bool matchesName(const std::string&) const;
139
145 virtual bool matchesHeader(SgAsmGenericHeader*) const;
146
148 // Factories
150public:
157
163 virtual Unparser::BasePtr newUnparser() const = 0;
164
176
178 // Instruction characteristics
180public:
186
188 virtual Alignment instructionAlignment() const = 0;
189
195
204 virtual std::string toString(const SgAsmInstruction*) const;
205 virtual std::string toStringNoAddr(const SgAsmInstruction*) const;
213 virtual std::string instructionMnemonic(const SgAsmInstruction*) const = 0;
214
225 virtual std::string instructionDescription(const SgAsmInstruction*) const;
226
234 virtual bool isUnknown(const SgAsmInstruction*) const = 0;
235
243 virtual bool terminatesBasicBlock(SgAsmInstruction*) const = 0;
244
261 virtual bool isFunctionCallFast(const std::vector<SgAsmInstruction*>&, rose_addr_t *target, rose_addr_t *ret) const;
262 virtual bool isFunctionCallSlow(const std::vector<SgAsmInstruction*>&, rose_addr_t *target, rose_addr_t *ret) const;
276 virtual bool isFunctionReturnFast(const std::vector<SgAsmInstruction*>&) const;
277 virtual bool isFunctionReturnSlow(const std::vector<SgAsmInstruction*>&) const;
289
299 virtual AddressSet getSuccessors(SgAsmInstruction*, bool &complete) const;
300
315 AddressSet getSuccessors(const std::vector<SgAsmInstruction*> &basicBlock, bool &complete) const;
316 virtual AddressSet getSuccessors(const std::vector<SgAsmInstruction*> &basicBlock, bool &complete,
317 const MemoryMapPtr &initial_memory) const;
321 // Architecture-specific stuff for a partitioning engine.
323public:
330 virtual std::vector<Partitioner2::FunctionPrologueMatcherPtr>
332
338 virtual std::vector<Partitioner2::BasicBlockCallbackPtr>
340
342 // Miscellaneous
344protected:
345 Ptr ptr();
346 ConstPtr constPtr() const;
347};
348
349} // namespace
350} // namespace
351} // namespace
352
353#endif
354#endif
Information about alignments.
Definition Alignment.h:16
Base class for architecture definitions.
virtual const CallingConvention::Dictionary & callingConventions() const
Property: Calling convention definitions.
ByteOrder::Endianness byteOrder() const
Property: Byte order for memory.
virtual RegisterDictionaryPtr registerDictionary() const =0
Property: Register dictionary.
virtual std::string instructionDescription(const SgAsmInstruction *) const
Description for an instruction.
virtual bool matchesName(const std::string &) const
Tests whether this architecture matches a name.
AddressSet getSuccessors(const std::vector< SgAsmInstruction * > &basicBlock, bool &complete) const
Control flow successors for a basic block.
size_t bitsPerWord() const
Property: Word size.
virtual bool terminatesBasicBlock(SgAsmInstruction *) const =0
Determines whether the specified instruction normally terminates a basic block.
virtual std::vector< Partitioner2::BasicBlockCallbackPtr > basicBlockCreationHooks(const Partitioner2::EnginePtr &) const
Architecture-specific basic block callbacks for partitioning.
virtual std::string instructionMnemonic(const SgAsmInstruction *) const =0
Mnemonic for an instruction.
virtual Disassembler::BasePtr newInstructionDecoder() const =0
Construct and return a new instruction decoder.
virtual bool isFunctionCallSlow(const std::vector< SgAsmInstruction * > &, rose_addr_t *target, rose_addr_t *ret) const
Returns true if the specified basic block looks like a function call.
virtual AddressSet getSuccessors(const std::vector< SgAsmInstruction * > &basicBlock, bool &complete, const MemoryMapPtr &initial_memory) const
Control flow successors for a basic block.
virtual Unparser::BasePtr newUnparser() const =0
Construct and return a new instruction unparser.
BaseConstPtr ConstPtr
Reference counting pointer to const object.
const Sawyer::Optional< size_t > & registrationId() const
Property: Registration identification number.
virtual Sawyer::Container::Interval< size_t > bytesPerInstruction() const =0
Valid sizes for encoded machine instructions.
size_t bytesPerWord() const
Property: Word size.
virtual Sawyer::Optional< rose_addr_t > branchTarget(SgAsmInstruction *) const
Obtains the virtual address for a branching instruction.
virtual bool isUnknown(const SgAsmInstruction *) const =0
Returns true if the instruction is the special "unknown" instruction.
const std::string & name() const
Property: Architecture definition name.
virtual bool isFunctionReturnSlow(const std::vector< SgAsmInstruction * > &) const
Returns true if the specified basic block looks like a function return.
virtual Alignment instructionAlignment() const =0
Alignment for encoded machine instructions.
virtual std::string toString(const SgAsmInstruction *) const
Unparse an instruction to a string.
virtual std::vector< Partitioner2::FunctionPrologueMatcherPtr > functionPrologueMatchers(const Partitioner2::EnginePtr &) const
Instruction patterns matching function prologues.
virtual AddressSet getSuccessors(SgAsmInstruction *, bool &complete) const
Control flow successors for a single instruction.
virtual std::string toStringNoAddr(const SgAsmInstruction *) const
Unparse an instruction to a string.
virtual RegisterDictionaryPtr interruptDictionary() const
Property: Interrupt dictionary.
virtual bool isFunctionCallFast(const std::vector< SgAsmInstruction * > &, rose_addr_t *target, rose_addr_t *ret) const
Returns true if the specified basic block looks like a function call.
void registrationId(const Sawyer::Optional< size_t > &)
Property: Registration identification number.
virtual bool isFunctionReturnFast(const std::vector< SgAsmInstruction * > &) const
Returns true if the specified basic block looks like a function return.
BasePtr Ptr
Reference counting pointer.
virtual InstructionSemantics::BaseSemantics::DispatcherPtr newInstructionDispatcher(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &) const
Construct and return a new instruction dispatcher.
bool instructionsCanOverlap() const
Whether instructions can overlap in memory.
virtual bool matchesHeader(SgAsmGenericHeader *) const
Tests whether this architecture matches a file header.
Implements cache data members.
Definition Cached.h:40
Range of values delimited by endpoints.
Definition Interval.h:31
Holds a value or nothing.
Definition Optional.h:56
Base class for container file headers.
Base class for machine instructions.
std::shared_ptr< Base > BasePtr
Reference counted pointer for Architecture::Base.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
@ ORDER_UNSPECIFIED
Endianness is unspecified and unknown.
Definition ByteOrder.h:21
std::vector< DefinitionPtr > Dictionary
An ordered collection of calling convention definitions.
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.
The ROSE library.
const char * Architecture(int64_t)
Convert Rose::BinaryAnalysis::Disassembler::Mips::Decoder::Architecture enum constant to a string.