Use PATH_MAX instead of NAME_MAX
[riscv-isa-sim.git] / spike_main / spike-dasm.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 "extension.h"
11 #include <iostream>
12 #include <string>
13 #include <cstdint>
14 #include <fesvr/option_parser.h>
15 using namespace std;
16
17 int main(int argc, char** argv)
18 {
19 string s;
20 disassembler_t d;
21
22 std::function<extension_t*()> extension;
23 option_parser_t parser;
24 parser.option(0, "extension", 1, [&](const char* s){extension = find_extension(s);});
25
26 while (getline(cin, s))
27 {
28 for (size_t start = 0; (start = s.find("DASM(", start)) != string::npos; )
29 {
30 size_t end = s.find(')', start);
31 if (end == string::npos)
32 break;
33
34 size_t numstart = start + strlen("DASM(");
35 insn_bits_t bits = strtoull(&s[numstart], NULL, 16);
36 string dis = d.disassemble(bits);
37 s = s.substr(0, start) + dis + s.substr(end+1);
38 start += dis.length();
39 }
40
41 cout << s << '\n';
42 }
43
44 return 0;
45 }