debug output cleanup

This commit is contained in:
xensik 2022-03-25 12:18:50 +01:00
parent 5225086e4b
commit 699227259c
4 changed files with 88 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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