[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:
water111
2021-01-24 16:39:15 -05:00
committed by GitHub
parent 27f0a7ca44
commit 2f722e6379
28 changed files with 1440 additions and 247 deletions
+17 -3
View File
@@ -2,9 +2,13 @@
#include "decompiler/Function/Function.h"
#include "decompiler/IR2/Form.h"
#include "decompiler/IR2/FormStack.h"
#include "decompiler/util/DecompilerTypeSystem.h"
namespace decompiler {
bool convert_to_expressions(Form* top_level_form, FormPool& pool, const Function& f) {
bool convert_to_expressions(Form* top_level_form,
FormPool& pool,
const Function& f,
const DecompilerTypeSystem& dts) {
assert(top_level_form);
try {
@@ -31,12 +35,22 @@ bool convert_to_expressions(Form* top_level_form, FormPool& pool, const Function
FormStack stack;
for (auto& entry : top_level_form->elts()) {
fmt::print("push {} to stack\n", entry->to_form(f.ir2.env).print());
// fmt::print("push {} to stack\n", entry->to_form(f.ir2.env).print());
entry->push_to_stack(f.ir2.env, pool, stack);
}
std::vector<FormElement*> new_entries;
if (f.type.last_arg() != TypeSpec("none")) {
new_entries = stack.rewrite_to_get_reg(pool, Register(Reg::GPR, Reg::V0));
auto v0 = Register(Reg::GPR, Reg::V0);
new_entries = stack.rewrite_to_get_reg(pool, v0, f.ir2.env);
auto reg_return_type = f.ir2.env.get_types_after_op(f.ir2.atomic_ops->ops.size() - 1).get(v0);
if (!dts.ts.typecheck(f.type.last_arg(), reg_return_type.typespec(), "", false, false)) {
// we need to cast the final value.
auto to_cast = new_entries.back();
new_entries.pop_back();
auto cast = pool.alloc_element<CastElement>(f.type.last_arg(),
pool.alloc_single_form(nullptr, to_cast));
new_entries.push_back(cast);
}
} else {
new_entries = stack.rewrite(pool);
}