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 { 00074 ET_SHORTEST, 00075 ET_LONGEST, 00076 ET_MATCHES 00079 }; 00080 00081 Assembler() 00082 : p_debug(NULL), p_encoding_type(ET_SHORTEST) 00083 {} 00084 00085 virtual ~Assembler() {} 00086 00088 static Assembler *create(SgAsmInterpretation *interp); 00089 00091 static Assembler *create(SgAsmGenericHeader*); 00092 00093 /*========================================================================================================================== 00094 * Main public assembly methods 00095 *========================================================================================================================== */ 00096 public: 00100 virtual SgUnsignedCharList assembleOne(SgAsmInstruction *insn) = 0; 00101 00105 SgUnsignedCharList assembleBlock(SgAsmBlock*); 00106 00110 SgUnsignedCharList assembleBlock(const std::vector<SgAsmInstruction*> &insns, rose_addr_t starting_rva); 00111 00113 virtual SgUnsignedCharList assembleProgram(const std::string &source) = 0; 00114 00115 00116 00117 /*========================================================================================================================== 00118 * Assembler properties and settings 00119 *========================================================================================================================== */ 00120 public: 00122 void set_encoding_type(EncodingType et) { 00123 p_encoding_type = et; 00124 } 00125 00127 EncodingType get_encoding_type() const { 00128 return p_encoding_type; 00129 } 00130 00132 void set_debug(FILE *f) { 00133 p_debug = f; 00134 } 00135 00137 FILE *get_debug() const { 00138 return p_debug; 00139 } 00140 00141 /*========================================================================================================================== 00142 * Data members 00143 *========================================================================================================================== */ 00144 protected: 00145 FILE *p_debug; 00146 EncodingType p_encoding_type; 00147 }; 00148 00149 #endif
1.4.7