Skip to content

Commit 0b5e622

Browse files
committed
fix generator
1 parent ee7edf4 commit 0b5e622

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

src/machine/instruction.test.data.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
{0x10e083, "lwu x1, 1(x1)"},
88
{0xf, "fence"},
99
{0x100f, "fence.i"},
10-
{0x8093, "addi x1, x1, 0", "mv x1, x1"}, // failed
10+
{0x8093, "addi x1, x1, 0", "mv x1, x1"},
1111
{0x108093, "addi x1, x1, 1"},
1212
{0x109093, "slli x1, x1, 0x1"},
1313
{0x10a093, "slti x1, x1, 1"},
14-
{0x10b093, "sltiu x1, x1, 1", "seqz x1, x1"}, // failed
14+
{0x10b093, "sltiu x1, x1, 1", "seqz x1, x1"},
1515
{0x10b093, "sltiu x1, x1, 1"},
16-
{0xfff0c093, "xori x1, x1, -1", "not x1, x1"}, // failed
16+
{0xfff0c093, "xori x1, x1, -1", "not x1, x1"},
1717
{0x10c093, "xori x1, x1, 1"},
1818
{0x10d093, "srli x1, x1, 0x1"},
1919
{0x4010d093, "srai x1, x1, 0x1"},
2020
{0x10e093, "ori x1, x1, 1"},
21-
{0xff0f093, "andi x1, x1, 255", "zext.b x1, x1"}, // failed
21+
{0xff0f093, "andi x1, x1, 255", "zext.b x1, x1"},
2222
{0x10f093, "andi x1, x1, 1"},
2323
{0x1097, "auipc x1, 0x1"},
24-
{0x809b, "addiw x1, x1, 0", "sext.w x1, x1"}, // failed
24+
{0x809b, "addiw x1, x1, 0", "sext.w x1, x1"},
2525
{0x10809b, "addiw x1, x1, 1"},
2626
{0x10909b, "slliw x1, x1, 0x1"},
2727
{0x10d09b, "srliw x1, x1, 0x1"},
@@ -119,13 +119,13 @@
119119
{0xe410b0af, "amomaxu.d.aq x1, x1, (x1)"},
120120
{0xe610b0af, "amomaxu.d.aqrl x1, x1, (x1)"},
121121
{0x1080b3, "add x1, x1, x1"},
122-
{0x401000b3, "sub x1, x0, x1", "neg x1, x1"}, // failed
122+
{0x401000b3, "sub x1, x0, x1", "neg x1, x1"},
123123
{0x401080b3, "sub x1, x1, x1"},
124124
{0x1090b3, "sll x1, x1, x1"},
125-
{0xa0b3, "slt x1, x1, x0", "sltz x1, x1"}, // failed
126-
{0x1020b3, "slt x1, x0, x1", "sgtz x1, x1"}, // failed
125+
{0xa0b3, "slt x1, x1, x0", "sltz x1, x1"},
126+
{0x1020b3, "slt x1, x0, x1", "sgtz x1, x1"},
127127
{0x10a0b3, "slt x1, x1, x1"},
128-
{0x1030b3, "sltu x1, x0, x1", "snez x1, x1"}, // failed
128+
{0x1030b3, "sltu x1, x0, x1", "snez x1, x1"},
129129
{0x10b0b3, "sltu x1, x1, x1"},
130130
{0x10c0b3, "xor x1, x1, x1"},
131131
{0x10d0b3, "srl x1, x1, x1"},
@@ -142,7 +142,7 @@
142142
{0x210f0b3, "remu x1, x1, x1"},
143143
{0x10b7, "lui x1, 0x1"},
144144
{0x1080bb, "addw x1, x1, x1"},
145-
{0x401000bb, "subw x1, x0, x1", "negw x1, x1"}, // failed
145+
{0x401000bb, "subw x1, x0, x1", "negw x1, x1"},
146146
{0x401080bb, "subw x1, x1, x1"},
147147
{0x1090bb, "sllw x1, x1, x1"},
148148
{0x10d0bb, "srlw x1, x1, x1"},
@@ -152,39 +152,39 @@
152152
{0x210d0bb, "divuw x1, x1, x1"},
153153
{0x210e0bb, "remw x1, x1, x1"},
154154
{0x210f0bb, "remuw x1, x1, x1"},
155-
{0x8163, "beq x1, x0, 0x2", "beqz x1, 0x2"}, // failed
155+
{0x8163, "beq x1, x0, 0x2", "beqz x1, 0x2"},
156156
{0x108163, "beq x1, x1, 0x2"},
157-
{0x9163, "bne x1, x0, 0x2", "bnez x1, 0x2"}, // failed
157+
{0x9163, "bne x1, x0, 0x2", "bnez x1, 0x2"},
158158
{0x109163, "bne x1, x1, 0x2"},
159-
{0xc163, "blt x1, x0, 0x2", "bltz x1, 0x2"}, // failed
160-
{0x104163, "blt x0, x1, 0x2", "bgtz x1, 0x2"}, // failed
161-
{0x10c163, "blt x1, x1, 0x2", "bgt x1, x1, 0x2"}, // failed
159+
{0xc163, "blt x1, x0, 0x2", "bltz x1, 0x2"},
160+
{0x104163, "blt x0, x1, 0x2", "bgtz x1, 0x2"},
161+
{0x10c163, "blt x1, x1, 0x2", "bgt x1, x1, 0x2"},
162162
{0x10c163, "blt x1, x1, 0x2"},
163-
{0xd163, "bge x1, x0, 0x2", "bgez x1, 0x2"}, // failed
164-
{0x10d163, "bge x1, x1, 0x2", "ble x1, x1, 0x2"}, // failed
165-
{0x105163, "bge x0, x1, 0x2", "blez x1, 0x2"}, // failed
163+
{0xd163, "bge x1, x0, 0x2", "bgez x1, 0x2"},
164+
{0x10d163, "bge x1, x1, 0x2", "ble x1, x1, 0x2"},
165+
{0x105163, "bge x0, x1, 0x2", "blez x1, 0x2"},
166166
{0x10d163, "bge x1, x1, 0x2"},
167-
{0x10e163, "bltu x1, x1, 0x2", "bgtu x1, x1, 0x2"}, // failed
167+
{0x10e163, "bltu x1, x1, 0x2", "bgtu x1, x1, 0x2"},
168168
{0x10e163, "bltu x1, x1, 0x2"},
169-
{0x10f163, "bgeu x1, x1, 0x2", "bleu x1, x1, 0x2"}, // failed
169+
{0x10f163, "bgeu x1, x1, 0x2", "bleu x1, x1, 0x2"},
170170
{0x10f163, "bgeu x1, x1, 0x2"},
171-
{0x8067, "jalr x0, 0(x1)", "ret"}, // failed
172-
{0x8067, "jalr x0, 0(x1)", "jr x1"}, // failed
173-
{0x108067, "jalr x0, 1(x1)", "jr 1(x1)"}, // failed
174-
{0x80e7, "jalr x1, 0(x1)", "jalr x1"}, // failed
175-
{0x1080e7, "jalr x1, 1(x1)", "jalr 1(x1)"}, // failed
176-
{0x1080e7, "jalr x1, 1(x1)", "jalr x1, x1, 1"}, // failed
171+
{0x8067, "jalr x0, 0(x1)", "ret"},
172+
{0x8067, "jalr x0, 0(x1)", "jr x1"},
173+
{0x108067, "jalr x0, 1(x1)", "jr 1(x1)"},
174+
{0x80e7, "jalr x1, 0(x1)", "jalr x1"},
175+
{0x1080e7, "jalr x1, 1(x1)", "jalr 1(x1)"},
176+
{0x1080e7, "jalr x1, 1(x1)", "jalr x1, x1, 1"},
177177
{0x1080e7, "jalr x1, 1(x1)"},
178-
{0x20006f, "jal x0, 0x2", "j 0x2"}, // failed
179-
{0x2000ef, "jal x1, 0x2", "jal 0x2"}, // failed
178+
{0x20006f, "jal x0, 0x2", "j 0x2"},
179+
{0x2000ef, "jal x1, 0x2", "jal 0x2"},
180180
{0x2000ef, "jal x1, 0x2"},
181181
{0x73, "ecall"},
182182
{0x100073, "ebreak"},
183183
{0x10200073, "sret"},
184184
{0x30200073, "mret"},
185-
{0x109073, "csrrw x0, 0x1, x1", "csrw 0x1, x1"}, // failed
185+
{0x109073, "csrrw x0, 0x1, x1", "csrw 0x1, x1"},
186186
{0x1090f3, "csrrw x1, 0x1, x1"},
187-
{0x1020f3, "csrrs x1, 0x1, x0", "csrr x1, 0x1"}, // failed
187+
{0x1020f3, "csrrs x1, 0x1, x0", "csrr x1, 0x1"},
188188
{0x10a0f3, "csrrs x1, 0x1, x1"},
189189
{0x10b0f3, "csrrc x1, 0x1, x1"},
190190
{0x10d0f3, "csrrwi x1, 0x1, 0x1"},

src/machine/instruction.test.gendata.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,25 @@ void generate_code_and_string_data(QTextStream& out, const InstructionMap* im_it
133133
}
134134

135135
QString enum_str;;
136-
136+
bool check_failed = false;
137+
QString parsed_string_data = Instruction(code).to_str();
137138
if (alias_parent == nullptr) {
138139
enum_str = QString::asprintf("{0x%x, \"%s\"},", code, qPrintable(string_data));
140+
if (parsed_string_data != string_data) {
141+
check_failed = true;
142+
}
139143
} else {
140-
enum_str = QString::asprintf("{0x%x, \"%s\", \"%s\"},", code, qPrintable(Instruction(code).to_str()), qPrintable(string_data));
144+
enum_str = QString::asprintf("{0x%x, \"%s\", \"%s\"},", code, qPrintable(parsed_string_data), qPrintable(string_data));
141145
}
142-
if (Instruction(code).to_str() != string_data) {
146+
uint32_t parsed_code;
147+
Instruction::code_from_string(&parsed_code, parsed_string_data.length(), string_data, Address(0x0));
148+
if (parsed_code != code) {
149+
check_failed = true;
150+
}
151+
if (check_failed) {
143152
enum_str += " // failed";
144153
}
154+
145155
enum_str += "\n";
146156
out << enum_str;
147157
}

0 commit comments

Comments
 (0)