mirror of
https://github.com/open-goal/jak-project
synced 2026-08-05 17:44:39 -04:00
[Decompiler] Expression Building (#211)
* up to ash * add more expressions * fix some return variable usage nonsense * bfloat print working * basic-type working * type working, fix decompiler on all files * clang format
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "decompiler/analysis/cfg_builder.h"
|
||||
#include "decompiler/analysis/expression_build.h"
|
||||
#include "common/goos/PrettyPrinter.h"
|
||||
#include "decompiler/IR2/Form.h"
|
||||
|
||||
using namespace decompiler;
|
||||
|
||||
@@ -80,6 +81,7 @@ std::unique_ptr<FormRegressionTest::TestData> FormRegressionTest::make_function(
|
||||
test->file.words_by_seg.resize(3);
|
||||
test->file.labels = program.labels;
|
||||
test->func.ir2.env.file = &test->file;
|
||||
test->func.ir2.env.dts = dts.get();
|
||||
test->func.instructions = program.instructions;
|
||||
test->func.guessed_name.set_as_global("test-function");
|
||||
test->func.type = function_type;
|
||||
@@ -113,19 +115,33 @@ std::unique_ptr<FormRegressionTest::TestData> FormRegressionTest::make_function(
|
||||
EXPECT_TRUE(test->func.ir2.top_form);
|
||||
|
||||
// for now, just test that this can at least be called.
|
||||
VariableSet vars;
|
||||
test->func.ir2.top_form->collect_vars(vars);
|
||||
if (test->func.ir2.top_form) {
|
||||
VariableSet vars;
|
||||
test->func.ir2.top_form->collect_vars(vars);
|
||||
|
||||
if (do_expressions) {
|
||||
bool success =
|
||||
convert_to_expressions(test->func.ir2.top_form, test->func.ir2.form_pool, test->func);
|
||||
if (do_expressions) {
|
||||
bool success = convert_to_expressions(test->func.ir2.top_form, *test->func.ir2.form_pool,
|
||||
test->func, *dts);
|
||||
|
||||
EXPECT_TRUE(success);
|
||||
if (!success) {
|
||||
return nullptr;
|
||||
EXPECT_TRUE(success);
|
||||
if (!success) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i = 0; i < int(test->func.ir2.atomic_ops->ops.size()); i++) {
|
||||
// auto& op = test->func.ir2.atomic_ops->ops.at(i);
|
||||
// auto& info = test->func.ir2.env.reg_use().op.at(i);
|
||||
// fmt::print("{} - {}: ", op->to_string(test->func.ir2.env),
|
||||
// test->func.ir2.env.get_types_after_op(i).print_gpr_masked(
|
||||
// regs_to_gpr_mask({Register(Reg::GPR, Reg::V0)})));
|
||||
// for (auto live : info.live) {
|
||||
// fmt::print("{} ", live.to_charp());
|
||||
// }
|
||||
// fmt::print("\n");
|
||||
// }
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
@@ -141,14 +157,15 @@ void FormRegressionTest::test(const std::string& code,
|
||||
ASSERT_TRUE(test);
|
||||
auto expected_form =
|
||||
pretty_print::get_pretty_printer_reader().read_from_string(expected, false).as_pair()->car;
|
||||
ASSERT_TRUE(test->func.ir2.top_form);
|
||||
auto actual_form =
|
||||
pretty_print::get_pretty_printer_reader()
|
||||
.read_from_string(test->func.ir2.top_form->to_form(test->func.ir2.env).print(), false)
|
||||
.as_pair()
|
||||
->car;
|
||||
if (expected_form != actual_form) {
|
||||
printf("Got:\n%s\n\nExpected\n%s\n", actual_form.print().c_str(),
|
||||
expected_form.print().c_str());
|
||||
printf("Got:\n%s\n\nExpected\n%s\n", pretty_print::to_string(actual_form).c_str(),
|
||||
pretty_print::to_string(expected_form).c_str());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(expected_form == actual_form);
|
||||
|
||||
Reference in New Issue
Block a user