diff options
author | Andrew Waterman <aswaterman@gmail.com> | 2015-01-04 17:31:11 -0800 |
---|---|---|
committer | Andrew Waterman <aswaterman@gmail.com> | 2015-01-04 18:48:04 -0800 |
commit | 17fd25f26773c7c313c8379bf2413f74e55d7511 (patch) | |
tree | dfad3c94b25fee02bdbb33fdf7c75228d1a49e64 /spike_main/spike-dasm.cc | |
parent | f971129cb6f6f097f47b74eb3ce9b1872d6d253a (diff) | |
download | spike-17fd25f26773c7c313c8379bf2413f74e55d7511.zip spike-17fd25f26773c7c313c8379bf2413f74e55d7511.tar.gz spike-17fd25f26773c7c313c8379bf2413f74e55d7511.tar.bz2 |
Rename riscv-dis to spike-dasm
This is a better name, since it looks for the string DASM(xxx), and it
fixes tab completion for the cross compiler.
Diffstat (limited to 'spike_main/spike-dasm.cc')
-rw-r--r-- | spike_main/spike-dasm.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spike_main/spike-dasm.cc b/spike_main/spike-dasm.cc new file mode 100644 index 0000000..d0af451 --- /dev/null +++ b/spike_main/spike-dasm.cc @@ -0,0 +1,45 @@ +// 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 "extension.h" +#include <iostream> +#include <string> +#include <cstdint> +#include <fesvr/option_parser.h> +using namespace std; + +int main(int argc, char** argv) +{ + string s; + disassembler_t d; + + std::function<extension_t*()> extension; + option_parser_t parser; + parser.option(0, "extension", 1, [&](const char* s){extension = find_extension(s);}); + + 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("); + insn_bits_t bits = strtoull(&s[numstart], NULL, 16); + string dis = d.disassemble(bits); + s = s.substr(0, start) + dis + s.substr(end+1); + start += dis.length(); + } + + cout << s << '\n'; + } + + return 0; +} |