Add helper disassembly program
authorAndrew Waterman <waterman@cs.berkeley.edu>
Sun, 15 Sep 2013 11:27:07 +0000 (04:27 -0700)
committerAndrew Waterman <waterman@cs.berkeley.edu>
Sun, 15 Sep 2013 11:27:07 +0000 (04:27 -0700)
riscv/riscv-dis.cc [new file with mode: 0644]
riscv/riscv.mk.in

diff --git a/riscv/riscv-dis.cc b/riscv/riscv-dis.cc
new file mode 100644 (file)
index 0000000..62d522e
--- /dev/null
@@ -0,0 +1,41 @@
+// See LICENSE for license details.
+
+// This little program finds occurrences of strings like
+//  DASM(ffabc013)
+// in its input, then replaces them with the disassembly
+// enclosed hexadecimal number, interpreted as a RISC-V
+// instruction.
+
+#include "disasm.h"
+#include <iostream>
+#include <string>
+#include <cstdint>
+using namespace std;
+
+int main()
+{
+  string s;
+  disassembler d;
+
+  while (getline(cin, s))
+  {
+    for (size_t start = 0; (start = s.find("DASM(", start)) != string::npos; )
+    {
+      size_t end = s.find(')', start);
+      if (end == string::npos)
+        break;
+
+      size_t numstart = start + strlen("DASM(");
+      uint32_t n = strtoul(&s[numstart], NULL, 16);
+
+      string dis = d.disassemble(*(insn_t*)&n);
+
+      s = s.substr(0, start) + dis + s.substr(end+1);
+      start += dis.length();
+    }
+
+    cout << s << '\n';
+  }
+
+  return 0;
+}
index 781a1a33c0f7078d1868981e6634c67d3a1c009a..fc2982e5a87c7cdffffae0f53efeec1d4e38a168 100644 (file)
@@ -7,6 +7,7 @@ riscv_subproject_deps = \
 
 riscv_install_prog_srcs = \
        spike.cc \
+       riscv-dis.cc \
        xspike.cc \
        termios-xspike.cc \