00001 #ifndef ROSE_ASSEMBLER_H 00002 #define ROSE_ASSEMBLER_H 00003 00049 class Assembler { 00050 public: 00052 class Exception { 00053 public: 00055 Exception(const std::string &reason, SgAsmInstruction *insn) 00056 : mesg(reason), insn(insn) 00057 {} 00059 Exception(const std::string &reason) 00060 : mesg(reason), insn(NULL) 00061 {} 00062 void print(std::ostream&) const; 00063 friend std::ostream& operator<<(std::ostream&, const Exception&); 00064 00065 std::string mesg; 00066 SgAsmInstruction *insn; 00067 }; 00068 00072 enum EncodingType { 00073 ET_SHORTEST, 00074 ET_LONGEST, 00075 ET_MATCHES, 00078 }; 00079 00080 Assembler() 00081 : p_debug(NULL), p_encoding_type(ET_SHORTEST) 00082 {} 00083 00084 virtual ~Assembler() {} 00085 00087 static Assembler *create(SgAsmInterpretation *interp); 00088 00090 static Assembler *create(SgAsmGenericHeader*); 00091 00092 /*========================================================================================================================== 00093 * Main public assembly methods 00094 *========================================================================================================================== */ 00095 public: 00099 virtual SgUnsignedCharList assembleOne(SgAsmInstruction *insn) = 0; 00100 00104 SgUnsignedCharList assembleBlock(SgAsmBlock*); 00105 00109 SgUnsignedCharList assembleBlock(const std::vector<SgAsmInstruction*> &insns, rose_addr_t starting_rva); 00110 00112 virtual SgUnsignedCharList assembleProgram(const std::string &source) = 0; 00113 00114 00115 00116 /*========================================================================================================================== 00117 * Assembler properties and settings 00118 *========================================================================================================================== */ 00119 public: 00121 void set_encoding_type(EncodingType et) { 00122 p_encoding_type = et; 00123 } 00124 00126 EncodingType get_encoding_type() const { 00127 return p_encoding_type; 00128 } 00129 00131 void set_debug(FILE *f) { 00132 p_debug = f; 00133 } 00134 00136 FILE *get_debug() const { 00137 return p_debug; 00138 } 00139 00140 /*========================================================================================================================== 00141 * Data members 00142 *========================================================================================================================== */ 00143 protected: 00144 FILE *p_debug; 00145 EncodingType p_encoding_type; 00146 }; 00147 00148 #endif
1.4.7