ROSE  0.9.9.109
Assembler.h
1 #ifndef ROSE_ASSEMBLER_H
2 #define ROSE_ASSEMBLER_H
3 
49 class Assembler {
50 public:
52  class Exception: public std::runtime_error {
53  public:
55  Exception(const std::string &reason, SgAsmInstruction *insn)
56  : std::runtime_error(reason), insn(insn)
57  {}
59  Exception(const std::string &reason)
60  : std::runtime_error(reason), insn(NULL)
61  {}
62  void print(std::ostream&) const;
63  friend std::ostream& operator<<(std::ostream&, const Exception&);
64 
66  };
67 
72  {
78  };
79 
80  Assembler()
82  {}
83 
84  virtual ~Assembler() {}
85 
87  static Assembler *create(SgAsmInterpretation *interp);
88 
91 
92  /*==========================================================================================================================
93  * Main public assembly methods
94  *========================================================================================================================== */
95 public:
99  virtual SgUnsignedCharList assembleOne(SgAsmInstruction *insn) = 0;
100 
104  SgUnsignedCharList assembleBlock(SgAsmBlock*);
105 
109  SgUnsignedCharList assembleBlock(const std::vector<SgAsmInstruction*> &insns, rose_addr_t starting_rva);
110 
112  virtual SgUnsignedCharList assembleProgram(const std::string &source) = 0;
113 
114 
115 
116  /*==========================================================================================================================
117  * Assembler properties and settings
118  *========================================================================================================================== */
119 public:
122  p_encoding_type = et;
123  }
124 
127  return p_encoding_type;
128  }
129 
131  void set_debug(FILE *f) {
132  p_debug = f;
133  }
134 
136  FILE *get_debug() const {
137  return p_debug;
138  }
139 
140  /*==========================================================================================================================
141  * Data members
142  *========================================================================================================================== */
143 protected:
144  FILE *p_debug;
146 };
147 
148 #endif
Exception(const std::string &reason)
An exception not bound to a particular instruction.
Definition: Assembler.h:59
Instruction basic block.
virtual SgUnsignedCharList assembleProgram(const std::string &source)=0
Assembles a program from an assembly listing.
Base class for machine instructions.
STL namespace.
SgAsmInstruction * insn
Instruction associated with an assembly error.
Definition: Assembler.h:65
SgUnsignedCharList assembleBlock(SgAsmBlock *)
Assembles a single basic block of instructions, packing them together and adjusting their virtual add...
FILE * get_debug() const
Returns the file currently used for debugging; null implies no debugging.
Definition: Assembler.h:136
EncodingType get_encoding_type() const
Returns the encoding type employed by this assembler.
Definition: Assembler.h:126
Base class for container file headers.
FILE * p_debug
Set to non-null to get debugging info.
Definition: Assembler.h:144
void set_encoding_type(EncodingType et)
Controls how the assembleOne() method determines which encoding to return.
Definition: Assembler.h:121
static Assembler * create(SgAsmInterpretation *interp)
Creates an assembler that is appropriate for assembling instructions in the specified interpretation...
Virtual base class for instruction assemblers.
Definition: Assembler.h:49
Exception(const std::string &reason, SgAsmInstruction *insn)
An exception bound to a particular instruction being assembled.
Definition: Assembler.h:55
Exception thrown by the assemblers.
Definition: Assembler.h:52
void set_debug(FILE *f)
Sends assembler diagnostics to the specified output stream.
Definition: Assembler.h:131
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:73
Returns an encoding that matches the SgAsmInstruction::p_raw_bytes.
Definition: Assembler.h:75
EncodingType
Assemblers can often assemble a single instruction various ways.
Definition: Assembler.h:71
Returns the longest encoding.
Definition: Assembler.h:74
Represents an interpretation of a binary container.
EncodingType p_encoding_type
Which encoding should be returned by assembleOne.
Definition: Assembler.h:145