-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdecoder_test.cpp
More file actions
43 lines (36 loc) · 1.41 KB
/
Copy pathdecoder_test.cpp
File metadata and controls
43 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <array>
#include <fstream>
#include <iss/instruction_decoder.h>
#include <vector>
enum class opcode_e {
C__LBU = 116,
C__LHU = 117,
C__LH = 118,
C__SB = 119,
C__SH = 120,
};
struct instruction_descriptor {
uint32_t length;
uint32_t value;
uint32_t mask;
opcode_e op;
};
const std::array<instruction_descriptor, 2> instr_descr = {{//{16, 0b1000000000000000, 0b1111110000000011, opcode_e::C__LBU},
{16, 0b1000010000000000, 0b1111110001000011, opcode_e::C__LHU},
{16, 0b1000010001000000, 0b1111110001000011, opcode_e::C__LH}}};
int main(int argc, char* argv[]) {
iss::decoder instr_decoder([]() {
std::vector<iss::generic_instruction_descriptor> g_instr_descr;
g_instr_descr.reserve(instr_descr.size());
for(uint32_t i = 0; i < instr_descr.size(); ++i) {
iss::generic_instruction_descriptor new_instr_descr{instr_descr[i].value, instr_descr[i].mask, i};
g_instr_descr.push_back(new_instr_descr);
}
return std::move(g_instr_descr);
}());
std::ofstream json_out{"idecode_tree.json"};
json_out << instr_decoder.print_tree_as_json();
auto inst_index1 = instr_decoder.decode_instr(0x8440);
auto inst_index2 = instr_decoder.decode_instr(0x86b0);
return inst_index1 == inst_index2 ? 0 : 1;
}