From a8e2bf904ebe7a2c668fbad50ab7433a427607c6 Mon Sep 17 00:00:00 2001 From: Oxore Date: Sun, 14 May 2023 22:43:54 +0300 Subject: Move instruction related data into separate Op struct --- main.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index a3f64fd..3ce4a7d 100644 --- a/main.cpp +++ b/main.cpp @@ -134,12 +134,12 @@ static const char *ReferenceTypeToString(ReferenceType type) return "UNKN"; } -static bool ShouldPrintAsRaw(const DisasmNode& node) +static constexpr bool ShouldPrintAsRaw(const Op& op) { - if (node.arg1.type == ArgType::kImmediate) { - if (node.opcode == OpCode::kADD || node.opcode == OpCode::kSUB || - node.opcode == OpCode::kAND || node.opcode == OpCode::kOR || - node.opcode == OpCode::kEOR || node.opcode == OpCode::kCMP) + if (op.arg1.type == ArgType::kImmediate) { + if (op.opcode == OpCode::kADD || op.opcode == OpCode::kSUB || + op.opcode == OpCode::kAND || op.opcode == OpCode::kOR || + op.opcode == OpCode::kEOR || op.opcode == OpCode::kCMP) { return true; } @@ -173,22 +173,19 @@ static void RenderDisassembly( } } assert(node->opcode != OpCode::kNone); - if (ShouldPrintAsRaw(*node)) { - auto raw = DisasmNode{TracedNodeType::kInstruction, node->offset}; - raw.opcode = OpCode::kRaw; - raw.opcode = OpCode::kRaw; - raw.arg1 = Arg::Raw(GetU16BE(code.buffer + raw.offset)); + if (ShouldPrintAsRaw(node->op)) { + auto raw = Op::Raw(GetU16BE(code.buffer + node->offset)); raw.FPrint(output, s); uint32_t i = kInstructionSizeStepBytes; for (; i < node->size; i += kInstructionSizeStepBytes) { char arg_str[kArgsBufferSize]{}; - const auto arg = Arg::Raw(GetU16BE(code.buffer + raw.offset + i)); + const auto arg = Arg::Raw(GetU16BE(code.buffer + node->offset + i)); arg.SNPrint(arg_str, kArgsBufferSize, s); fprintf(output, ", %s", arg_str); } fprintf(output, "\n"); } else { - node->FPrint(output, s); + node->op.FPrint(output, s); } if (node->has_branch_addr && s.xrefs_to) { char branch_addr[12]{}; -- cgit v1.2.3