diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2013-09-15 04:27:07 -0700 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2013-09-15 04:27:07 -0700 |
commit | 620d8bc0fe8cf8e8d3425db7ea2e6aaba145c86d (patch) | |
tree | afb7a4b929210185ac992d38bc5c58ce47f13cf5 /riscv | |
parent | df5e10921db293341827f58a816b294c3b523906 (diff) | |
download | spike-620d8bc0fe8cf8e8d3425db7ea2e6aaba145c86d.zip spike-620d8bc0fe8cf8e8d3425db7ea2e6aaba145c86d.tar.gz spike-620d8bc0fe8cf8e8d3425db7ea2e6aaba145c86d.tar.bz2 |
Add helper disassembly program
Diffstat (limited to 'riscv')
-rw-r--r-- | riscv/riscv-dis.cc | 41 | ||||
-rw-r--r-- | riscv/riscv.mk.in | 1 |
2 files changed, 42 insertions, 0 deletions
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 <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; +} 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 \ |