89c4b742014ee45200b4c85c80035637c408f8ba
1 // See LICENSE for license details.
3 // This little program finds occurrences of strings like
5 // in its input, then replaces them with the disassembly
6 // enclosed hexadecimal number, interpreted as a RISC-V
10 #include "extension.h"
14 #include <fesvr/option_parser.h>
17 int main(int argc
, char** argv
)
22 std::function
<extension_t
*()> extension
;
23 option_parser_t parser
;
24 parser
.option(0, "extension", 1, [&](const char* s
){extension
= find_extension(s
);});
26 while (getline(cin
, s
))
28 for (size_t start
= 0; (start
= s
.find("DASM(", start
)) != string::npos
; )
30 size_t end
= s
.find(')', start
);
31 if (end
== string::npos
)
34 size_t numstart
= start
+ strlen("DASM(");
35 uint32_t n
= strtoul(&s
[numstart
], NULL
, 16);
37 string dis
= d
.disassemble(*(insn_t
*)&n
);
39 s
= s
.substr(0, start
) + dis
+ s
.substr(end
+1);
40 start
+= dis
.length();