aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codegen.rs
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2021-09-18 00:18:28 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2021-09-18 00:18:28 +0200
commitcd62c3f8ccce0d834c333edafe2a825126c2bef6 (patch)
treeb84918a15fcc3ee801914afe15f8e2626bc50ffb /src/codegen.rs
parentb0cad668398c0102b726336871bac28ddfac347c (diff)
downloadllvm-kaleidoscope-rs-cd62c3f8ccce0d834c333edafe2a825126c2bef6.tar.gz
llvm-kaleidoscope-rs-cd62c3f8ccce0d834c333edafe2a825126c2bef6.zip
llvm: split into sub-modules
Diffstat (limited to 'src/codegen.rs')
-rw-r--r--src/codegen.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/codegen.rs b/src/codegen.rs
index 0a7893e..08c3039 100644
--- a/src/codegen.rs
+++ b/src/codegen.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use crate::llvm::{Builder, FnValue, FunctionPassManager, Module, Value};
+use crate::llvm::{FnValue, FunctionPassManager, IRBuilder, Module, Value};
use crate::parser::{ExprAST, FunctionAST, PrototypeAST};
use crate::Either;
@@ -9,7 +9,7 @@ type CodegenResult<T> = Result<T, String>;
/// Code generator from kaleidoscope AST to LLVM IR.
pub struct Codegen<'llvm, 'a> {
module: &'llvm Module,
- builder: &'a Builder<'llvm>,
+ builder: &'a IRBuilder<'llvm>,
fpm: &'a FunctionPassManager<'llvm>,
}
@@ -21,7 +21,7 @@ impl<'llvm, 'a> Codegen<'llvm, 'a> {
) -> CodegenResult<FnValue<'llvm>> {
let cg = Codegen {
module,
- builder: &Builder::with_ctx(module),
+ builder: &IRBuilder::with_ctx(module),
fpm: &FunctionPassManager::with_ctx(module),
};
let mut variables = HashMap::new();
@@ -129,7 +129,10 @@ impl<'llvm, 'a> Codegen<'llvm, 'a> {
if let Ok(ret) = self.codegen_expr(body, named_values) {
self.builder.ret(ret);
assert!(the_function.verify());
+
+ // Run the optimization passes on the function.
self.fpm.run(the_function);
+
Ok(the_function)
} else {
todo!("Failed to codegen function body, erase from module!");