From e9aab4f43e7f80fbad706dc1a4e199df3b34d35d Mon Sep 17 00:00:00 2001 From: sofia Date: Wed, 2 Aug 2023 18:48:56 +0300 Subject: [PATCH] Use print to string instead of dump --- src/llvm_ir.rs | 8 +++----- src/main.rs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) 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()); }