Roll back optimization changes.

This commit is contained in:
2020-09-17 20:14:39 -07:00
parent 02f8306c7b
commit 8a352ed3ea
14 changed files with 78 additions and 833 deletions

View File

@@ -17,7 +17,6 @@
void compiler::add_default_types() {
global_env->bind_type("Int", type_ptr(new type_base("Int")));
global_env->bind_type("Bool", type_ptr(new type_base("Bool")));
}
void compiler::add_binop_type(binop op, type_ptr type) {
@@ -31,24 +30,11 @@ void compiler::add_default_function_types() {
assert(int_type != nullptr);
type_ptr int_type_app = type_ptr(new type_app(int_type));
type_ptr bool_type = global_env->lookup_type("Bool");
assert(bool_type != nullptr);
type_ptr bool_type_app = type_ptr(new type_app(bool_type));
type_ptr closed_int_op_type(
new type_arr(int_type_app, type_ptr(new type_arr(int_type_app, int_type_app))));
type_ptr compare_int_op_type(
new type_arr(int_type_app, type_ptr(new type_arr(int_type_app, bool_type_app))));
constexpr binop closed_ops[] = { PLUS, MINUS, TIMES, DIVIDE, MODULO };
constexpr binop compare_ops[] = { EQUALS, LESS_EQUALS };
constexpr binop closed_ops[] = { PLUS, MINUS, TIMES, DIVIDE };
for(auto& op : closed_ops) add_binop_type(op, closed_int_op_type);
for(auto& op : compare_ops) add_binop_type(op, compare_int_op_type);
for(auto name : { "True", "False" }) {
global_env->bind(name, bool_type_app, visibility::global);
global_env->set_mangled_name(name, mng.new_mangled_name(name));
}
}
void compiler::parse() {
@@ -94,25 +80,10 @@ void compiler::create_llvm_binop(binop op) {
ctx.get_builder().CreateRetVoid();
}
void compiler::create_llvm_bool(bool b) {
auto new_function = ctx.create_custom_function(
global_env->get_mangled_name(b ? "True" : "False"), 0);
std::vector<instruction_ptr> instructions;
instructions.push_back(instruction_ptr(new instruction_pushint(b)));
instructions.push_back(instruction_ptr(new instruction_update(0)));
ctx.get_builder().SetInsertPoint(&new_function->getEntryBlock());
for(auto& instruction : instructions) {
instruction->gen_llvm(ctx, new_function);
}
ctx.get_builder().CreateRetVoid();
}
void compiler::generate_llvm() {
for(auto op : all_binops) {
create_llvm_binop(op);
}
create_llvm_bool(true);
create_llvm_bool(false);
global_scp.generate_llvm(ctx);
}