refactor disassembler, and add hwacha disassembler
[riscv-isa-sim.git] / riscv / riscv-dis.cc
1 // See LICENSE for license details.
2
3 // This little program finds occurrences of strings like
4 // DASM(ffabc013)
5 // in its input, then replaces them with the disassembly
6 // enclosed hexadecimal number, interpreted as a RISC-V
7 // instruction.
8
9 #include "disasm.h"
10 #include <iostream>
11 #include <string>
12 #include <cstdint>
13 using namespace std;
14
15 int main()
16 {
17 string s;
18 disassembler_t d;
19
20 while (getline(cin, s))
21 {
22 for (size_t start = 0; (start = s.find("DASM(", start)) != string::npos; )
23 {
24 size_t end = s.find(')', start);
25 if (end == string::npos)
26 break;
27
28 size_t numstart = start + strlen("DASM(");
29 uint32_t n = strtoul(&s[numstart], NULL, 16);
30
31 string dis = d.disassemble(*(insn_t*)&n);
32
33 s = s.substr(0, start) + dis + s.substr(end+1);
34 start += dis.length();
35 }
36
37 cout << s << '\n';
38 }
39
40 return 0;
41 }