From 699227259c4603a37fa001fb7fe689a6b8c15838 Mon Sep 17 00:00:00 2001 From: xensik Date: Fri, 25 Mar 2022 12:18:50 +0100 Subject: [PATCH] debug output cleanup --- src/t6/xsk/compiler.cpp | 82 +++++++++++++++++++++++-------------- src/t6/xsk/decompiler.cpp | 8 ++-- src/t6/xsk/decompiler.hpp | 2 +- src/t6/xsk/disassembler.cpp | 39 ++++++++++++++---- 4 files changed, 88 insertions(+), 43 deletions(-) diff --git a/src/t6/xsk/compiler.cpp b/src/t6/xsk/compiler.cpp index 8946cee2..d8a78fd4 100644 --- a/src/t6/xsk/compiler.cpp +++ b/src/t6/xsk/compiler.cpp @@ -2374,41 +2374,63 @@ void compiler::print_function(const function::ptr& func) void compiler::print_instruction(const instruction::ptr& inst) { + output_->write_string(utils::string::va("\t\t%s(", resolver::opcode_name(inst->opcode).data())); + switch (opcode(inst->opcode)) { - /*case opcode::OP_endswitch: - output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data())); - output_->write_string(utils::string::va(" %s\n", inst->data[0].data())); - { - std::uint32_t totalcase = std::stoul(inst->data[0]); - auto index = 0; - for (auto casenum = 0u; casenum < totalcase; casenum++) + case opcode::OP_GetHash: + case opcode::OP_GetString: + case opcode::OP_GetIString: + case opcode::OP_ClearFieldVariable: + case opcode::OP_EvalFieldVariable: + case opcode::OP_EvalFieldVariableRef: + output_->write_string(utils::string::va("\"%s\"", inst->data[0].data())); + break; + case opcode::OP_GetAnimation: + case opcode::OP_GetFunction: + case opcode::OP_CallBuiltin: + case opcode::OP_CallBuiltinMethod: + case opcode::OP_ScriptFunctionCall: + case opcode::OP_ScriptMethodCall: + case opcode::OP_ScriptThreadCall: + case opcode::OP_ScriptMethodThreadCall: + output_->write_string(utils::string::va("\"%s\", \"%s\"", inst->data[0].data(), inst->data[1].data())); + break; + case opcode::OP_SafeCreateLocalVariables: + for (const auto& d : inst->data) { - if (inst->data[1 + index] == "case") - { - output_->write_string(utils::string::va("\t\t\t%s %s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data(), inst->data[1 + index + 2].data())); - index += 3; - } - else if (inst->data[1 + index] == "default") - { - output_->write_string(utils::string::va("\t\t\t%s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data())); - index += 2; - } - output_->write_string("\n"); + output_->write_string(utils::string::va("\"%s\"%s", d.data(), &d == &inst->data.back() ? "" : ", ")); } - } - break;*/ - default: - output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data())); - - for (auto& d : inst->data) - { - output_->write_string(utils::string::va(" %s", d.data())); - } - - output_->write_string("\n"); - break; + break; + case opcode::OP_EndSwitch: + output_->write_string(utils::string::va("%s", inst->data[0].data())); + { + std::uint32_t totalcase = std::stoul(inst->data[0]); + auto index = 0; + for (auto casenum = 0u; casenum < totalcase; casenum++) + { + if (inst->data[1 + index] == "case") + { + output_->write_string(utils::string::va(", %s, \"%s\", %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data(), inst->data[1 + index + 2].data())); + index += 3; + } + else if (inst->data[1 + index] == "default") + { + output_->write_string(utils::string::va(", %s, %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data())); + index += 2; + } + } + } + break; + default: + for (const auto& d : inst->data) + { + output_->write_string(utils::string::va("%s%s", d.data(), &d == &inst->data.back() ? "" : ", ")); + } + break; } + + output_->write_string(");\n"); } } // namespace xsk::arc::t6 diff --git a/src/t6/xsk/decompiler.cpp b/src/t6/xsk/decompiler.cpp index 42c50bf0..c2d945d7 100644 --- a/src/t6/xsk/decompiler.cpp +++ b/src/t6/xsk/decompiler.cpp @@ -2725,11 +2725,11 @@ void decompiler::process_field_variable(const ast::expr_field::ptr& expr) process_expr(expr->obj); } -void decompiler::process_expr_vector(const ast::expr_vector::ptr& vec) +void decompiler::process_expr_vector(const ast::expr_vector::ptr& expr) { - process_expr(vec->z); - process_expr(vec->y); - process_expr(vec->x); + process_expr(expr->z); + process_expr(expr->y); + process_expr(expr->x); } } // namespace xsk::arc::t6 diff --git a/src/t6/xsk/decompiler.hpp b/src/t6/xsk/decompiler.hpp index ed68aa2e..b6407f4c 100644 --- a/src/t6/xsk/decompiler.hpp +++ b/src/t6/xsk/decompiler.hpp @@ -93,7 +93,7 @@ private: void process_expr_size(const ast::expr_size::ptr& expr); void process_array_variable(const ast::expr_array::ptr& expr); void process_field_variable(const ast::expr_field::ptr& expr); - void process_expr_vector(const ast::expr_vector::ptr& vec); + void process_expr_vector(const ast::expr_vector::ptr& expr); }; } // namespace xsk::arc::t6 diff --git a/src/t6/xsk/disassembler.cpp b/src/t6/xsk/disassembler.cpp index 76b0cac1..4d4af7a8 100644 --- a/src/t6/xsk/disassembler.cpp +++ b/src/t6/xsk/disassembler.cpp @@ -626,12 +626,36 @@ void disassembler::print_function(const function::ptr& func) void disassembler::print_instruction(const instruction::ptr& inst) { - output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data())); + output_->write_string(utils::string::va("\t\t%s(", resolver::opcode_name(inst->opcode).data())); switch (opcode(inst->opcode)) { + case opcode::OP_GetHash: + case opcode::OP_GetString: + case opcode::OP_GetIString: + case opcode::OP_ClearFieldVariable: + case opcode::OP_EvalFieldVariable: + case opcode::OP_EvalFieldVariableRef: + output_->write_string(utils::string::va("\"%s\"", inst->data[0].data())); + break; + case opcode::OP_GetAnimation: + case opcode::OP_GetFunction: + case opcode::OP_CallBuiltin: + case opcode::OP_CallBuiltinMethod: + case opcode::OP_ScriptFunctionCall: + case opcode::OP_ScriptMethodCall: + case opcode::OP_ScriptThreadCall: + case opcode::OP_ScriptMethodThreadCall: + output_->write_string(utils::string::va("\"%s\", \"%s\"", inst->data[0].data(), inst->data[1].data())); + break; + case opcode::OP_SafeCreateLocalVariables: + for (const auto& d : inst->data) + { + output_->write_string(utils::string::va("\"%s\"%s", d.data(), &d == &inst->data.back() ? "" : ", ")); + } + break; case opcode::OP_EndSwitch: - output_->write_string(utils::string::va(" %s\n", inst->data[0].data())); + output_->write_string(utils::string::va("%s", inst->data[0].data())); { std::uint32_t totalcase = std::stoul(inst->data[0]); auto index = 0; @@ -639,27 +663,26 @@ void disassembler::print_instruction(const instruction::ptr& inst) { if (inst->data[1 + index] == "case") { - output_->write_string(utils::string::va("\t\t\t%s %s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data(), inst->data[1 + index + 2].data())); + output_->write_string(utils::string::va(", %s, \"%s\", %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data(), inst->data[1 + index + 2].data())); index += 3; } else if (inst->data[1 + index] == "default") { - output_->write_string(utils::string::va("\t\t\t%s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data())); + output_->write_string(utils::string::va(", %s, %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data())); index += 2; } - output_->write_string("\n"); } } break; default: for (const auto& d : inst->data) { - output_->write_string(utils::string::va(" %s", d.data())); + output_->write_string(utils::string::va("%s%s", d.data(), &d == &inst->data.back() ? "" : ", ")); } - - output_->write_string("\n"); break; } + + output_->write_string(");\n"); } } // namespace xsk::arc::t6