#include #include #include "disasm.h" using namespace boost; Iinstr* disasm::decode(std::string str) { /* we need 0x prefix */ string hex = "0x"; hex.append(str); CDat val = lexical_cast(hex); return this->decodeNum(val); } Iinstr* disasm::decodeNum(CDat val) { dynamic_bitset<> bits(32,val), opcode(32,val), condition(9), args(32); args = opcode; args.resize(23); opcode >>= 23; condition = opcode; opcode.resize(5); condition >>= 5; condition.resize(4); //cout << "<" << hex << "> is in int " << val << "\t is binary " << bits << " opcode?" << opcode << " condition " << condition << endl; try { Iinstr* instr = decodeOpcode(opcode.to_ulong()); instr->decodeCondition(condition.to_ulong()); instr->loadBits(args); instr->evalInstr(); return instr; } catch(std::string &e) { cerr << " Error: " << e << endl; } return NULL; } std::string disasm::decodeToString(std::string str) { return this->decode(str)->toString(); } Iinstr* disasm::decodeOpcode(short opcode) { auto iter = instrs.find(opcode); if(iter != instrs.end()) { Iinstr* p = (iter->second)->getNew(); return p; } else { stringstream err; err << "opcode not found. in was " << opcode << endl; throw err.str(); } }