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