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
);});
28 for (auto disasm_insn
: extension()->get_disasms())
29 d
.add_insn(disasm_insn
);
32 while (getline(cin
, s
))
34 for (size_t start
= 0; (start
= s
.find("DASM(", start
)) != string::npos
; )
36 size_t end
= s
.find(')', start
);
37 if (end
== string::npos
)
41 size_t numstart
= start
+ strlen("DASM(");
42 int64_t bits
= strtoull(&s
[numstart
], &endp
, 16);
43 size_t nbits
= 4 * (endp
- &s
[numstart
]);
45 bits
= bits
<< (64 - nbits
) >> (64 - nbits
);
47 string dis
= d
.disassemble(bits
);
48 s
= s
.substr(0, start
) + dis
+ s
.substr(end
+1);
49 start
+= dis
.length();