diff --git a/src/compilation.rs b/src/compilation.rs index cc112e9..06f6714 100644 --- a/src/compilation.rs +++ b/src/compilation.rs @@ -1,10 +1,6 @@ extern crate llvm_sys; use self::llvm_sys::prelude::*; -use self::llvm_sys::core; -use std::ptr; -use std::ffi::CString; - use parser::{ParseResult, AST, ASTNode, Prototype, Function, Expression}; use llvm_wrap as LLVMWrap; @@ -20,6 +16,7 @@ pub fn compilation_sequence(ast: AST, sourcefile: &str) { _ => panic!("Bad filename {}", sourcefile), }; + compile_ast(ast, ll_filename); Command::new("llc") .arg("-filetype=obj") @@ -67,10 +64,7 @@ fn compile_ast(ast: AST, filename: &str) { LLVMWrap::BuildRet(builder, value); - unsafe { - let out_file = CString::new(filename).unwrap(); - core::LLVMPrintModuleToFile(module, out_file.as_ptr(), ptr::null_mut()); - } + LLVMWrap::PrintModuleToFile(module, filename); // Clean up. Values created in the context mostly get cleaned up there. LLVMWrap::DisposeBuilder(builder); diff --git a/src/llvm_wrap.rs b/src/llvm_wrap.rs index 96e67d0..f024d29 100644 --- a/src/llvm_wrap.rs +++ b/src/llvm_wrap.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] +#![allow(dead_code)] extern crate llvm_sys; use self::llvm_sys::prelude::*; @@ -138,3 +140,10 @@ pub fn BuildSRem(builder: LLVMBuilderRef, lhs: LLVMValueRef, rhs: LLVMValueRef, core::LLVMBuildSRem(builder, lhs, rhs, name.as_ptr()) } } + +pub fn PrintModuleToFile(module: LLVMModuleRef, filename: &str) -> LLVMBool { + let out_file = CString::new(filename).unwrap(); + unsafe { + core::LLVMPrintModuleToFile(module, out_file.as_ptr(), ptr::null_mut()) + } +}