instruction memory progammer: is in and works in simulations
[calu.git] / 3c_disasm / disasm.cpp
index b389d0361a501c5418b77ccbc7eefd5681876783..c117bb047730a625063677756586cef00999d3d8 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,19 +35,25 @@ 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;