[Decompiler] Expressions (Part 3) (#213)

* before inserting bonus instruction

* first part of refactor for return values

* find parent method working
This commit is contained in:
water111
2021-01-25 22:08:58 -05:00
committed by GitHub
parent 2f722e6379
commit b59e33c005
22 changed files with 782 additions and 81 deletions
+43
View File
@@ -1307,4 +1307,47 @@ bool get_as_reg_offset(const SimpleExpression& expr, IR2_RegOffset* out) {
}
return false;
}
/////////////////////////////
// FunctionEndOp
/////////////////////////////
FunctionEndOp::FunctionEndOp(int my_idx)
: AtomicOp(my_idx), m_return_reg(VariableMode::READ, Register(Reg::GPR, Reg::V0), my_idx) {}
goos::Object FunctionEndOp::to_form(const std::vector<DecompilerLabel>&, const Env* env) const {
if (m_function_has_return_value) {
return pretty_print::build_list("ret-value", m_return_reg.to_string(env));
} else {
return pretty_print::build_list("ret-none");
}
}
bool FunctionEndOp::operator==(const AtomicOp& other) const {
if (typeid(FunctionEndOp) != typeid(other)) {
return false;
}
auto po = dynamic_cast<const FunctionEndOp*>(&other);
assert(po);
return m_function_has_return_value == po->m_function_has_return_value;
}
bool FunctionEndOp::is_sequence_point() const {
return true;
}
Variable FunctionEndOp::get_set_destination() const {
throw std::runtime_error("FunctionEndOp cannot be treated as a set! operation");
}
void FunctionEndOp::update_register_info() {
m_read_regs.push_back(Register(Reg::GPR, Reg::V0));
}
void FunctionEndOp::collect_vars(VariableSet& vars) const {
if (m_function_has_return_value) {
vars.insert(m_return_reg);
}
}
} // namespace decompiler