ROSE 0.11.145.192
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
184 virtual Unparser::BasePtr newUnparser() const = 0;
199
201 // Instruction characteristics
203public:
209
211 virtual Alignment instructionAlignment() const = 0;
212
218
227 virtual std::string toString(const SgAsmInstruction*) const;
228 virtual std::string toStringNoAddr(const SgAsmInstruction*) const;
237 virtual std::string toString(const SgAsmExpression*) const;
238
244 virtual std::string instructionMnemonic(const SgAsmInstruction*) const = 0;
245
256 virtual std::string instructionDescription(const SgAsmInstruction*) const;
257
265 virtual bool isUnknown(const SgAsmInstruction*) const = 0;
266
273 virtual bool isControlTransfer(const SgAsmInstruction*) const;
274
282 virtual bool terminatesBasicBlock(SgAsmInstruction*) const = 0;
283
300 virtual bool isFunctionCallFast(const std::vector<SgAsmInstruction*>&, rose_addr_t *target, rose_addr_t *ret) const;
301 virtual bool isFunctionCallSlow(const std::vector<SgAsmInstruction*>&, rose_addr_t *target, rose_addr_t *ret) const;
315 virtual bool isFunctionReturnFast(const std::vector<SgAsmInstruction*>&) const;
316 virtual bool isFunctionReturnSlow(const std::vector<SgAsmInstruction*>&) const;
328
338 virtual AddressSet getSuccessors(SgAsmInstruction*, bool &complete) const;
339
354 AddressSet getSuccessors(const std::vector<SgAsmInstruction*> &basicBlock, bool &complete) const;
355 virtual AddressSet getSuccessors(const std::vector<SgAsmInstruction*> &basicBlock, bool &complete,
356 const MemoryMapPtr &initial_memory) const;
360 // Architecture-specific stuff for a partitioning engine.
362public:
369 virtual std::vector<Partitioner2::FunctionPrologueMatcherPtr>
371
377 virtual std::vector<Partitioner2::BasicBlockCallbackPtr>
379
381 // Miscellaneous
383protected:
384 Ptr ptr();
385 ConstPtr constPtr() const;
386
387 // Safely obtain a pointer to an unparser that's suitable for unparsing an instruction or expression.
388 virtual Unparser::BasePtr insnUnparser() const;
389};
390
391} // namespace
392} // namespace
393} // namespace
394
395#endif
396#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 std::string toString(const SgAsmExpression *) const
Unparse an expression to a string.
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 Unparser::BasePtr newInstructionUnparser() const
Construct and return a new instruction unparser.
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.
virtual bool isControlTransfer(const SgAsmInstruction *) const
Returns true if the specified instruction is a control transfer instruction.
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 expressions.
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.