ROSE  0.9.11.56
Assembler.h
1 #ifndef ROSE_BinaryAnalysis_Assembler_H
2 #define ROSE_BinaryAnalysis_Assembler_H
3 
4 #include <RoseException.h>
5 
6 namespace Rose {
7 namespace BinaryAnalysis {
8 
54 class Assembler {
55 public:
57  class Exception: public Rose::Exception {
58  public:
60  Exception(const std::string &reason, SgAsmInstruction *insn)
61  : Rose::Exception(reason), insn(insn)
62  {}
64  Exception(const std::string &reason)
65  : Rose::Exception(reason), insn(NULL)
66  {}
67  void print(std::ostream&) const;
68  friend std::ostream& operator<<(std::ostream&, const Exception&);
69 
71  };
72 
77  {
83  };
84 
85  Assembler()
87  {}
88 
89  virtual ~Assembler() {}
90 
92  static Assembler *create(SgAsmInterpretation *interp);
93 
95  static Assembler *create(SgAsmGenericHeader*);
96 
97  /*==========================================================================================================================
98  * Main public assembly methods
99  *========================================================================================================================== */
100 public:
104  virtual SgUnsignedCharList assembleOne(SgAsmInstruction *insn) = 0;
105 
109  SgUnsignedCharList assembleBlock(SgAsmBlock*);
110 
114  SgUnsignedCharList assembleBlock(const std::vector<SgAsmInstruction*> &insns, rose_addr_t starting_rva);
115 
117  virtual SgUnsignedCharList assembleProgram(const std::string &source) = 0;
118 
119  /*==========================================================================================================================
120  * Assembler properties and settings
121  *========================================================================================================================== */
122 public:
125  p_encoding_type = et;
126  }
127 
130  return p_encoding_type;
131  }
132 
134  void set_debug(FILE *f) {
135  p_debug = f;
136  }
137 
139  FILE *get_debug() const {
140  return p_debug;
141  }
142 
143  /*==========================================================================================================================
144  * Data members
145  *========================================================================================================================== */
146 protected:
147  FILE *p_debug;
149 };
150 
151 } // namespace
152 } // namespace
153 
154 #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:139
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:78
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:60
Base class for machine instructions.
EncodingType p_encoding_type
Which encoding should be returned by assembleOne.
Definition: Assembler.h:148
Main namespace for the ROSE library.
EncodingType get_encoding_type() const
Returns the encoding type employed by this assembler.
Definition: Assembler.h:129
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:80
Base class for container file headers.
Returns the longest encoding.
Definition: Assembler.h:79
FILE * p_debug
Set to non-null to get debugging info.
Definition: Assembler.h:147
void set_debug(FILE *f)
Sends assembler diagnostics to the specified output stream.
Definition: Assembler.h:134
EncodingType
Assemblers can often assemble a single instruction various ways.
Definition: Assembler.h:76
SgAsmInstruction * insn
Instruction associated with an assembly error.
Definition: Assembler.h:70
Exception thrown by the assemblers.
Definition: Assembler.h:57
Exception(const std::string &reason)
An exception not bound to a particular instruction.
Definition: Assembler.h:64
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:124
Virtual base class for instruction assemblers.
Definition: Assembler.h:54