clean up casts around conds with elses (#904)

This commit is contained in:
water111
2021-10-16 12:02:49 -04:00
committed by GitHub
parent 7e91fc1f3c
commit 9225d28444
25 changed files with 712 additions and 1079 deletions
+12 -5
View File
@@ -3345,6 +3345,9 @@ void CondNoElseElement::push_to_stack(const Env& env, FormPool& pool, FormStack&
stack.push_value_to_reg(write_as_value, as_ppointer_to_process, true,
env.get_variable_type(final_destination, false));
} else {
// fmt::print("func {} final destination {} type {}\n", env.func->name(),
// final_destination.to_string(env),
// env.get_variable_type(final_destination, false).print());
stack.push_value_to_reg(write_as_value, pool.alloc_single_form(nullptr, this), true,
env.get_variable_type(final_destination, false));
}
@@ -3437,7 +3440,9 @@ void CondWithElseElement::push_to_stack(const Env& env, FormPool& pool, FormStac
rewrite_as_set = false;
break;
}
source_types.push_back(last_in_body->src_type());
// note: we use the dest type here because the rewrite will leave behind a cast to this.
auto type = env.get_variable_type(last_in_body->dst(), true);
source_types.push_back(type);
}
last_var = last_in_body->dst();
}
@@ -3507,10 +3512,12 @@ void CondWithElseElement::push_to_stack(const Env& env, FormPool& pool, FormStac
// (set! x (if y z (expr))) and z requires a cast, but the move from z to x is
// eliminated by GOAL's register allocator.
// fmt::print("checking:\n");
// for (auto& t : source_types) {
// fmt::print(" {}\n", t.print());
// }
// fmt::print("func: {}\n", env.func->name());
// fmt::print("checking:\n");
// for (auto& t : source_types) {
// fmt::print(" {}\n", t.print());
// }
auto expected_type = env.get_variable_type(*last_var, true);
// fmt::print("The expected type is {}\n", expected_type.print());