uart: swap status with config half word
[calu.git] / 3c_disasm / disasm.cpp
index b389d0361a501c5418b77ccbc7eefd5681876783..0cb75facc2420342e0d02e9f8d197aceb7da389f 100644 (file)
@@ -4,14 +4,19 @@
 
 using namespace boost;
 
-std::string disasm::decode(std::string str)
+Iinstr* disasm::decode(std::string str)
 {
        /* we need 0x prefix */
        string hex = "0x";
        hex.append(str);
 
-       unsigned int val =  lexical_cast<uint32_from_hex>(hex);
+       CDat val =  lexical_cast<uint32_from_hex>(hex);
+       return this->decodeNum(val);
+}
+
 
+Iinstr* disasm::decodeNum(CDat val)
+{
        dynamic_bitset<> bits(32,val), opcode(32,val), condition(9), args(32);
 
        args = opcode;
@@ -30,23 +35,29 @@ std::string disasm::decode(std::string str)
                instr->decodeCondition(condition.to_ulong());
                instr->loadBits(args);
                instr->evalInstr();
-               return instr->toString();
+               return instr;
        }
        catch(std::string &e) {
                cerr << " Error: " << e << endl;
        }
-       return "";
+       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()) {
-               return iter->second;
+               Iinstr* p = (iter->second)->getNew();
+               return p;
        }
        else {
                stringstream err;
-               err << "opcode not found" << endl;
+               err << "opcode not found. in was " << opcode  << endl;
                throw err.str();
        }
 }