ROSE 0.11.145.147
Assembler.h
1#ifndef ROSE_BinaryAnalysis_Assembler_H
2#define ROSE_BinaryAnalysis_Assembler_H
3
4#include <featureTests.h>
5#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6
7#include <Rose/Exception.h>
8
9namespace Rose {
10namespace BinaryAnalysis {
11
58class Assembler {
59public:
61 class Exception: public Rose::Exception {
62 public:
64 Exception(const std::string &reason, SgAsmInstruction *insn)
65 : Rose::Exception(reason), insn(insn)
66 {}
68 Exception(const std::string &reason)
69 : Rose::Exception(reason), insn(NULL)
70 {}
71 void print(std::ostream&) const;
72 friend std::ostream& operator<<(std::ostream&, const Exception&);
73
75 };
76
88
89 Assembler()
91 {}
92
93 virtual ~Assembler() {}
94
97
100
101 /*==========================================================================================================================
102 * Main public assembly methods
103 *========================================================================================================================== */
104public:
108 virtual SgUnsignedCharList assembleOne(SgAsmInstruction *insn) = 0;
109
113 SgUnsignedCharList assembleBlock(SgAsmBlock*);
114
118 SgUnsignedCharList assembleBlock(const std::vector<SgAsmInstruction*> &insns, rose_addr_t starting_rva);
119
121 virtual SgUnsignedCharList assembleProgram(const std::string &source) = 0;
122
123 /*==========================================================================================================================
124 * Assembler properties and settings
125 *========================================================================================================================== */
126public:
131
134 return p_encoding_type;
135 }
136
138 void set_debug(FILE *f) {
139 p_debug = f;
140 }
141
143 FILE *get_debug() const {
144 return p_debug;
145 }
146
147 /*==========================================================================================================================
148 * Data members
149 *========================================================================================================================== */
150protected:
151 FILE *p_debug;
153};
154
155} // namespace
156} // namespace
157
158#endif
159#endif
Exception thrown by the assemblers.
Definition Assembler.h:61
Exception(const std::string &reason, SgAsmInstruction *insn)
An exception bound to a particular instruction being assembled.
Definition Assembler.h:64
Exception(const std::string &reason)
An exception not bound to a particular instruction.
Definition Assembler.h:68
SgAsmInstruction * insn
Instruction associated with an assembly error.
Definition Assembler.h:74
Virtual base class for instruction assemblers.
Definition Assembler.h:58
SgUnsignedCharList assembleBlock(const std::vector< SgAsmInstruction * > &insns, rose_addr_t starting_rva)
Assembles a single basic block of instructions like the version that takes an SgAsmBlock pointer.
EncodingType p_encoding_type
Which encoding should be returned by assembleOne.
Definition Assembler.h:152
EncodingType
Assemblers can often assemble a single instruction various ways.
Definition Assembler.h:81
@ ET_SHORTEST
Returns the shortest possible encoding.
Definition Assembler.h:82
@ ET_LONGEST
Returns the longest encoding.
Definition Assembler.h:83
@ ET_MATCHES
Returns an encoding that matches the SgAsmInstruction::p_raw_bytes.
Definition Assembler.h:84
static Assembler * create(SgAsmInterpretation *interp)
Creates an assembler that is appropriate for assembling instructions in the specified interpretation.
FILE * get_debug() const
Returns the file currently used for debugging; null implies no debugging.
Definition Assembler.h:143
void set_encoding_type(EncodingType et)
Controls how the assembleOne() method determines which encoding to return.
Definition Assembler.h:128
SgUnsignedCharList assembleBlock(SgAsmBlock *)
Assembles a single basic block of instructions, packing them together and adjusting their virtual add...
static Assembler * create(SgAsmGenericHeader *)
Creates an assembler that is appropriate for assembling instructions in the specified header.
FILE * p_debug
Set to non-null to get debugging info.
Definition Assembler.h:151
virtual SgUnsignedCharList assembleOne(SgAsmInstruction *insn)=0
This is the lowest level architecture-independent assembly function and is implemented in the archite...
virtual SgUnsignedCharList assembleProgram(const std::string &source)=0
Assembles a program from an assembly listing.
void set_debug(FILE *f)
Sends assembler diagnostics to the specified output stream.
Definition Assembler.h:138
EncodingType get_encoding_type() const
Returns the encoding type employed by this assembler.
Definition Assembler.h:133
Base class for all ROSE exceptions.
Instruction basic block.
Base class for container file headers.
Base class for machine instructions.
Represents an interpretation of a binary container.
The ROSE library.