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 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();