Update README
[riscv-isa-sim.git] / spike_main / spike-dasm.cc
index aecaa0a05ec3c3c13cf174572fe8be3c38949414..1161825c2ec8d65c32c02f592b24ce19fd5c64c0 100644 (file)
@@ -17,36 +17,44 @@ using namespace std;
 int main(int argc, char** argv)
 {
   string s;
-  disassembler_t d;
+  const char* isa = DEFAULT_ISA;
 
   std::function<extension_t*()> extension;
   option_parser_t parser;
   parser.option(0, "extension", 1, [&](const char* s){extension = find_extension(s);});
+  parser.option(0, "isa", 1, [&](const char* s){isa = s;});
   parser.parse(argv);
 
-  if (extension) {
-    for (auto disasm_insn : extension()->get_disasms())
-      d.add_insn(disasm_insn);
-  }
+  processor_t p(isa, 0, 0);
+  if (extension)
+    p.register_extension(extension());
 
   while (getline(cin, s))
   {
-    for (size_t start = 0; (start = s.find("DASM(", start)) != string::npos; )
+    for (size_t pos = 0; (pos = s.find("DASM(", pos)) != string::npos; )
     {
-      size_t end = s.find(')', start);
-      if (end == string::npos)
-        break;
+      size_t start = pos;
+
+      pos += strlen("DASM(");
+
+      if (s[pos] == '0' && (s[pos+1] == 'x' || s[pos+1] == 'X'))
+        pos += 2;
+
+      if (!isxdigit(s[pos]))
+        continue;
 
       char* endp;
-      size_t numstart = start + strlen("DASM(");
-      int64_t bits = strtoull(&s[numstart], &endp, 16);
-      size_t nbits = 4 * (endp - &s[numstart]);
+      int64_t bits = strtoull(&s[pos], &endp, 16);
+      if (*endp != ')')
+        continue;
+
+      size_t nbits = 4 * (endp - &s[pos]);
       if (nbits < 64)
         bits = bits << (64 - nbits) >> (64 - nbits);
 
-      string dis = d.disassemble(bits);
-      s = s.substr(0, start) + dis + s.substr(end+1);
-      start += dis.length();
+      string dis = p.get_disassembler()->disassemble(bits);
+      s = s.substr(0, start) + dis + s.substr(endp - &s[0] + 1);
+      pos = start + dis.length();
     }
 
     cout << s << '\n';