Skip to content

Commit

Permalink
remove log
Browse files Browse the repository at this point in the history
  • Loading branch information
trdthg committed Jun 9, 2024
1 parent acd03b7 commit 701cc69
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 97 deletions.
5 changes: 0 additions & 5 deletions src/machine/bitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 0 additions & 10 deletions src/machine/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
}

Expand Down
84 changes: 14 additions & 70 deletions src/machine/instruction.test.gendata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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; }

Expand Down Expand Up @@ -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 = " ";
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
}
}
});
}
12 changes: 0 additions & 12 deletions src/machine/instruction.test.gendata.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,4 @@ static const QMap<QString, ADDITIONAL_TB> 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

0 comments on commit 701cc69

Please sign in to comment.