From: Andrew Waterman Date: Sun, 15 Sep 2013 11:27:07 +0000 (-0700) Subject: Add helper disassembly program X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=620d8bc0fe8cf8e8d3425db7ea2e6aaba145c86d;p=riscv-isa-sim.git Add helper disassembly program --- diff --git a/riscv/riscv-dis.cc b/riscv/riscv-dis.cc new file mode 100644 index 0000000..62d522e --- /dev/null +++ b/riscv/riscv-dis.cc @@ -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 +#include +#include +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; +} diff --git a/riscv/riscv.mk.in b/riscv/riscv.mk.in index 781a1a3..fc2982e 100644 --- a/riscv/riscv.mk.in +++ b/riscv/riscv.mk.in @@ -7,6 +7,7 @@ riscv_subproject_deps = \ riscv_install_prog_srcs = \ spike.cc \ + riscv-dis.cc \ xspike.cc \ termios-xspike.cc \