diff --git a/src/llvm_ir.rs b/src/llvm_ir.rs index b971d37..218be82 100644 --- a/src/llvm_ir.rs +++ b/src/llvm_ir.rs @@ -1,4 +1,4 @@ -use std::ffi::CString; +use std::ffi::{CStr, CString}; use std::mem; use llvm_sys::{core::*, prelude::*, LLVMBuilder, LLVMContext, LLVMModule}; @@ -80,10 +80,8 @@ impl IRModule { } } - pub fn dump(&mut self) { - unsafe { - LLVMDumpModule(self.module); - } + pub fn print_to_string(&mut self) -> Result<&str, std::str::Utf8Error> { + unsafe { CStr::from_ptr(LLVMPrintModuleToString(self.module)).to_str() } } } diff --git a/src/main.rs b/src/main.rs index 38b3a6c..80dbff2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,5 +36,5 @@ fn main() { for statement in statements { statement.codegen(&mut module); } - module.dump(); + println!("{}", module.print_to_string().unwrap()); }