@@ -12,7 +12,6 @@ random_arg_code_mask(const ArgumentDesc *arg_desc, const InstructionMap *im, int
1212 = QRandomGenerator::global ()->bounded (int32_t (arg_desc->min ), int32_t (arg_desc->max ));
1313
1414 // set fields from value
15- printf (" \n ::random_arg_code_mask\n " );
1615 uint32_t code_mask = arg_desc->arg .encode (value);
1716
1817 switch (arg_desc->name ) {
@@ -24,8 +23,6 @@ random_arg_code_mask(const ArgumentDesc *arg_desc, const InstructionMap *im, int
2423 }
2524 }
2625
27- printf (" gen: [%x > %x < %x]\n " , arg_desc->min , value, arg_desc->max );
28-
2926 // set to zero if needed
3027 if (zero_mask_tb.count (im->name )) { code_mask &= zero_mask_tb[im->name ].zero_mask ; }
3128
@@ -131,8 +128,6 @@ GeneratedInst random_inst_from_im(const InstructionMap *im, const InstructionMap
131128 Instruction::Type t = im->type ;
132129 if (im_source != nullptr ) { t = im_source->type ; }
133130
134- printf (
135- " ::random_inst_from_im code code: %10x, code-masked: %10x\n " , code, code & im->mask );
136131 code &= im->mask ;
137132
138133 QString next_delim = " " ;
@@ -170,17 +165,12 @@ GeneratedInst random_inst_from_im(const InstructionMap *im, const InstructionMap
170165 }
171166 case ' E' : {
172167 QString csr_name = CSR::REGISTERS[CSR::REGISTER_MAP.at (CSR::Address (field))].name ;
173- DEBUG &&printf (
174- " csr code_mask: 0x%x, name: %s\n " , code_mask >> 20 , qPrintable (csr_name));
175168 string_data += csr_name;
176169 break ;
177170 };
178171 }
179172
180- DEBUG &&printf (" code_mask bef: 0x%x, name: %s\n " , code, qPrintable (string_data));
181173 code |= code_mask;
182- printf (" \n result code: [%x] mask: [%x] field: [%d]\n " , code, code_mask, field);
183- DEBUG &&printf (" code_mask aft: 0x%x, name: %s\n " , code, qPrintable (string_data));
184174 }
185175 }
186176 return GeneratedInst { code, string_data, im, im_source };
@@ -263,65 +253,19 @@ void WalkInstructionMap(
263253int main () {
264254 fill_argdesbycode ();
265255 instruction_from_string_build_base ();
266-
267- // char *s = "0xFFF\0";
268- // long long res = strtoll(s, nullptr, 10);
269- // printf("res: %lld", res);
270- // return 0;
271-
272- struct {
273- uint32_t code;
274- QString string_data;
275- } a[] {
276- { 0x34b358f3 , " csrrwi x17, mtval2, 0x6" },
277- };
278- for (int i = 0 ; i < sizeof (a) / sizeof (a[0 ]); i++) {
279- uint32_t code = a[i].code ;
280- QString string_data = a[i].string_data ;
281-
282- QString parsed_string_data = Instruction (code).to_str ();
283-
284- // DEBUG LOG
285- printf (
286- " test to_str: 0x%x, %s => { %s }\n " , code, qPrintable (string_data),
287- qPrintable (parsed_string_data));
288-
289- try {
290- uint32_t parsed_code;
291- Instruction::code_from_string (
292- &parsed_code, parsed_string_data.length (), string_data, Address (0x0 ));
293- printf (
294- " test from_string: 0x%x, %s => { 0x%x }\n " , code, qPrintable (string_data),
295- parsed_code);
296- } catch (const Instruction::ParseError &e) {
297- printf (" test from_string: failed, reason: %s\n " , qPrintable (e.message ));
298- }
299- printf (" \n " );
300- /* data */
301- };
302- printf (" ----------------------------------------------------------------------------\n " );
303-
304- QFile outfile (" instruction.test.data.def" );
305- if (outfile.open (QIODevice::WriteOnly | QIODevice::Text)) {
306- QTextStream out (&outfile);
307- WalkInstructionMap ([](const InstructionMap *im, const InstructionMap *im_source) {
308- printf (" \n\n " );
309-
310- printf (" inst: [%s] \n\n " , im->name );
311- for (int i = 0 ; i < 30 ; i++) {
312- printf (" - inst - test-[%d] \n " , i);
313- auto generated = random_inst_from_im (im, im_source);
314- if (generated.im != nullptr ) {
315- printf (" code: [%10x] " , generated.code );
316- printf (" str: [%30s] " , qPrintable (generated.string_data ));
317- printf (" \n " );
318- if (!generated.check ()) { throw Instruction::ParseError (" " ); }
319- }
256+ WalkInstructionMap ([](const InstructionMap *im, const InstructionMap *im_source) {
257+ printf (" \n\n " );
258+
259+ printf (" inst: [%s] \n\n " , im->name );
260+ for (int i = 0 ; i < 100 ; i++) {
261+ printf (" - inst - test-[%d] \n " , i);
262+ auto generated = random_inst_from_im (im, im_source);
263+ if (generated.im != nullptr ) {
264+ printf (" code: [%10x] " , generated.code );
265+ printf (" str: [%30s] " , qPrintable (generated.string_data ));
266+ printf (" \n " );
267+ if (!generated.check ()) { throw Instruction::ParseError (" " ); }
320268 }
321- });
322- outfile.close ();
323- } else {
324- printf (" open output file failed\n " );
325- exit (1 );
326- }
269+ }
270+ });
327271}
0 commit comments