[Decompiler] Begin expression conversion, rearrange tests (#209)

* refactor tests and analysis passes

* identity test working

* combine test categories with only a few cases

* more fixes
This commit is contained in:
water111
2021-01-23 16:32:56 -05:00
committed by GitHub
parent 4a97e15b40
commit 27f0a7ca44
95 changed files with 1192 additions and 1120 deletions
+124 -2
View File
@@ -28,7 +28,7 @@ std::string FormElement::to_string(const Env& env) const {
return to_form(env).print();
}
void FormElement::push_to_stack(const Env& env, FormStack&) {
void FormElement::push_to_stack(const Env& env, FormPool&, FormStack&) {
throw std::runtime_error("push_to_stack not implemented for " + to_string(env));
}
@@ -83,7 +83,8 @@ void Form::collect_vars(VariableSet& vars) const {
// SimpleExpressionElement
/////////////////////////////
SimpleExpressionElement::SimpleExpressionElement(SimpleExpression expr) : m_expr(std::move(expr)) {}
SimpleExpressionElement::SimpleExpressionElement(SimpleExpression expr, int my_idx)
: m_expr(std::move(expr)), m_my_idx(my_idx) {}
goos::Object SimpleExpressionElement::to_form(const Env& env) const {
return m_expr.to_form(env.file->labels, &env);
@@ -761,4 +762,125 @@ void ConditionalMoveFalseElement::collect_vars(VariableSet& vars) const {
vars.insert(dest);
source->collect_vars(vars);
}
/////////////////////////////
// GenericElement
/////////////////////////////
GenericOperator GenericOperator::make_fixed(FixedOperatorKind kind) {
GenericOperator op;
op.m_kind = Kind::FIXED_OPERATOR;
op.m_fixed_kind = kind;
return op;
}
void GenericOperator::collect_vars(VariableSet&) const {
switch (m_kind) {
case Kind::FIXED_OPERATOR:
return;
default:
assert(false);
}
}
goos::Object GenericOperator::to_form(const Env&) const {
switch (m_kind) {
case Kind::FIXED_OPERATOR:
return pretty_print::to_symbol(fixed_operator_to_string(m_fixed_kind));
default:
assert(false);
}
}
void GenericOperator::apply(const std::function<void(FormElement*)>&) {
switch (m_kind) {
case Kind::FIXED_OPERATOR:
break;
default:
assert(false);
}
}
void GenericOperator::apply_form(const std::function<void(Form*)>&) {
switch (m_kind) {
case Kind::FIXED_OPERATOR:
break;
default:
assert(false);
}
}
std::string fixed_operator_to_string(FixedOperatorKind kind) {
switch (kind) {
case FixedOperatorKind::GPR_TO_FPR:
return "gpr->fpr";
case FixedOperatorKind::DIVISION:
return "/";
case FixedOperatorKind::ADDITION:
return "+";
default:
assert(false);
}
}
GenericElement::GenericElement(GenericOperator op) : m_head(op) {}
GenericElement::GenericElement(GenericOperator op, Form* arg) : m_head(op), m_elts({arg}) {}
GenericElement::GenericElement(GenericOperator op, Form* arg0, Form* arg1)
: m_head(op), m_elts({arg0, arg1}) {}
GenericElement::GenericElement(GenericOperator op, std::vector<Form*> forms)
: m_head(op), m_elts(std::move(forms)) {}
goos::Object GenericElement::to_form(const Env& env) const {
std::vector<goos::Object> result;
result.push_back(m_head.to_form(env));
for (auto x : m_elts) {
result.push_back(x->to_form(env));
}
return pretty_print::build_list(result);
}
void GenericElement::apply(const std::function<void(FormElement*)>& f) {
f(this);
m_head.apply(f);
for (auto x : m_elts) {
x->apply(f);
}
}
void GenericElement::apply_form(const std::function<void(Form*)>& f) {
m_head.apply_form(f);
for (auto x : m_elts) {
x->apply_form(f);
}
}
void GenericElement::collect_vars(VariableSet& vars) const {
m_head.collect_vars(vars);
for (auto x : m_elts) {
x->collect_vars(vars);
}
}
/////////////////////////////
// CastElement
/////////////////////////////
CastElement::CastElement(TypeSpec type, Form* source) : m_type(std::move(type)), m_source(source) {}
goos::Object CastElement::to_form(const Env& env) const {
return pretty_print::build_list("the-as", m_type.print(), m_source->to_form(env));
}
void CastElement::apply(const std::function<void(FormElement*)>& f) {
f(this);
m_source->apply(f);
}
void CastElement::apply_form(const std::function<void(Form*)>& f) {
m_source->apply_form(f);
}
void CastElement::collect_vars(VariableSet& vars) const {
m_source->collect_vars(vars);
}
} // namespace decompiler