From 701cc69339d347d0d57ff1d51ed54ae0133954bd Mon Sep 17 00:00:00 2001 From: trdthg Date: Sun, 9 Jun 2024 13:44:50 +0000 Subject: [PATCH] remove log --- src/machine/bitfield.h | 5 -- src/machine/instruction.cpp | 10 --- src/machine/instruction.test.gendata.cpp | 84 ++++-------------------- src/machine/instruction.test.gendata.h | 12 ---- 4 files changed, 14 insertions(+), 97 deletions(-) diff --git a/src/machine/bitfield.h b/src/machine/bitfield.h index a7453102..9253f533 100644 --- a/src/machine/bitfield.h +++ b/src/machine/bitfield.h @@ -40,17 +40,12 @@ struct SplitBitField { } [[nodiscard]] typename decltype(fields)::const_iterator end() const { return fields.cend(); } [[nodiscard]] uint32_t decode(uint32_t ins) const { - printf(" decode\n"); uint32_t ret = 0; size_t offset = 0; for (BitField field : *this) { ret |= field.decode(ins) << offset; offset += field.count; } - printf(" - ret_unshift: %x\n", ret); - printf(" - val_shift: %x\n", value_shift); - printf(" - str_shift: %x\n", str_shift); - printf(" - res: %x\n", ret << value_shift); return ret << value_shift; } [[nodiscard]] uint32_t decode_str(uint32_t ins) const { diff --git a/src/machine/instruction.cpp b/src/machine/instruction.cpp index 2f840620..74d6ff83 100644 --- a/src/machine/instruction.cpp +++ b/src/machine/instruction.cpp @@ -49,13 +49,7 @@ struct ArgumentDesc { [[nodiscard]] constexpr bool is_value_in_field_range(RegisterValue val) const { if (min < 0) { int32_t val_ = val.as_i32(); - printf("---------<<< filed_value: %d ", val_); val_ >>= arg.str_shift; - printf("val_: %d ", val_); - printf("str_shift: %d ", arg.str_shift); - printf("val_shift: %d ", arg.value_shift); - printf("min: %d ", min); - printf("max: %d\n", max); return val_ <= max && val_ >= min; } else { uint64_t val_ = val.as_u64() >> arg.str_shift; @@ -800,9 +794,7 @@ QString Instruction::to_str(Address inst_addr) const { continue; } - printf("this->dt: %x\n", this->dt); auto field = (int32_t)arg_desc->arg.decode_str(this->dt); - printf("field: : %x\n", field); if (arg_desc->min < 0) { field = extend(field, [&]() { int sum = (int)arg_desc->arg.str_shift; @@ -825,7 +817,6 @@ QString Instruction::to_str(Address inst_addr) const { case 'a': { field += (int32_t)inst_addr.get_raw(); QString a = str::asHex(field); - printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: field: %x, asHex: %s\n", field, qPrintable(a)); res.append(str::asHex(field)); break; } @@ -1330,7 +1321,6 @@ uint32_t Instruction::parse_field( if (effective_mod != Modifier::NONE) { val = modify_pseudoinst_imm(effective_mod, val); } else if (!adesc->is_value_in_field_range(val)) { - printf("field: %s, val: %d, val_i: %d\n", qPrintable(field_token), val, (int64_t)val); throw ParseError("argument range exceed"); } diff --git a/src/machine/instruction.test.gendata.cpp b/src/machine/instruction.test.gendata.cpp index f4d41132..3969ac08 100644 --- a/src/machine/instruction.test.gendata.cpp +++ b/src/machine/instruction.test.gendata.cpp @@ -12,7 +12,6 @@ random_arg_code_mask(const ArgumentDesc *arg_desc, const InstructionMap *im, int = QRandomGenerator::global()->bounded(int32_t(arg_desc->min), int32_t(arg_desc->max)); // set fields from value - printf("\n ::random_arg_code_mask\n"); uint32_t code_mask = arg_desc->arg.encode(value); switch (arg_desc->name) { @@ -24,8 +23,6 @@ random_arg_code_mask(const ArgumentDesc *arg_desc, const InstructionMap *im, int } } - printf(" gen: [%x > %x < %x]\n", arg_desc->min, value, arg_desc->max); - // set to zero if needed if (zero_mask_tb.count(im->name)) { code_mask &= zero_mask_tb[im->name].zero_mask; } @@ -131,8 +128,6 @@ GeneratedInst random_inst_from_im(const InstructionMap *im, const InstructionMap Instruction::Type t = im->type; if (im_source != nullptr) { t = im_source->type; } - printf( - " ::random_inst_from_im code code: %10x, code-masked: %10x\n", code, code & im->mask); code &= im->mask; QString next_delim = " "; @@ -170,17 +165,12 @@ GeneratedInst random_inst_from_im(const InstructionMap *im, const InstructionMap } case 'E': { QString csr_name = CSR::REGISTERS[CSR::REGISTER_MAP.at(CSR::Address(field))].name; - DEBUG &&printf( - "csr code_mask: 0x%x, name: %s\n", code_mask >> 20, qPrintable(csr_name)); string_data += csr_name; break; }; } - DEBUG &&printf("code_mask bef: 0x%x, name: %s\n", code, qPrintable(string_data)); code |= code_mask; - printf("\n result code: [%x] mask: [%x] field: [%d]\n", code, code_mask, field); - DEBUG &&printf("code_mask aft: 0x%x, name: %s\n", code, qPrintable(string_data)); } } return GeneratedInst { code, string_data, im, im_source }; @@ -263,65 +253,19 @@ void WalkInstructionMap( int main() { fill_argdesbycode(); instruction_from_string_build_base(); - - // char *s = "0xFFF\0"; - // long long res = strtoll(s, nullptr, 10); - // printf("res: %lld", res); - // return 0; - - struct { - uint32_t code; - QString string_data; - } a[] { - { 0x34b358f3, "csrrwi x17, mtval2, 0x6" }, - }; - for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) { - uint32_t code = a[i].code; - QString string_data = a[i].string_data; - - QString parsed_string_data = Instruction(code).to_str(); - - // DEBUG LOG - printf( - "test to_str: 0x%x, %s => { %s }\n", code, qPrintable(string_data), - qPrintable(parsed_string_data)); - - try { - uint32_t parsed_code; - Instruction::code_from_string( - &parsed_code, parsed_string_data.length(), string_data, Address(0x0)); - printf( - "test from_string: 0x%x, %s => { 0x%x }\n", code, qPrintable(string_data), - parsed_code); - } catch (const Instruction::ParseError &e) { - printf("test from_string: failed, reason: %s\n", qPrintable(e.message)); - } - printf("\n"); - /* data */ - }; - printf("----------------------------------------------------------------------------\n"); - - QFile outfile("instruction.test.data.def"); - if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream out(&outfile); - WalkInstructionMap([](const InstructionMap *im, const InstructionMap *im_source) { - printf("\n\n"); - - printf("inst: [%s] \n\n", im->name); - for (int i = 0; i < 30; i++) { - printf(" - inst - test-[%d] \n", i); - auto generated = random_inst_from_im(im, im_source); - if (generated.im != nullptr) { - printf(" code: [%10x] ", generated.code); - printf(" str: [%30s] ", qPrintable(generated.string_data)); - printf("\n"); - if (!generated.check()) { throw Instruction::ParseError(""); } - } + WalkInstructionMap([](const InstructionMap *im, const InstructionMap *im_source) { + printf("\n\n"); + + printf("inst: [%s] \n\n", im->name); + for (int i = 0; i < 100; i++) { + printf(" - inst - test-[%d] \n", i); + auto generated = random_inst_from_im(im, im_source); + if (generated.im != nullptr) { + printf(" code: [%10x] ", generated.code); + printf(" str: [%30s] ", qPrintable(generated.string_data)); + printf("\n"); + if (!generated.check()) { throw Instruction::ParseError(""); } } - }); - outfile.close(); - } else { - printf("open output file failed\n"); - exit(1); - } + } + }); } \ No newline at end of file diff --git a/src/machine/instruction.test.gendata.h b/src/machine/instruction.test.gendata.h index 2ffa3059..3f7a3a19 100644 --- a/src/machine/instruction.test.gendata.h +++ b/src/machine/instruction.test.gendata.h @@ -95,16 +95,4 @@ static const QMap zero_mask_tb = { { "csrrs", { ~MASK_I_RS1.mask() } } }; -class MockInstruction : public Instruction { - Type _type; - -public: - MockInstruction(uint32_t inst, Type type) { - this->dt = inst; - this->_type = type; - }; - - enum Type type() const { return this->_type; } -}; - #endif \ No newline at end of file