diff --git a/src/compilation.rs b/src/compilation.rs index 944cc8e..29dd773 100644 --- a/src/compilation.rs +++ b/src/compilation.rs @@ -1,6 +1,8 @@ extern crate llvm_sys; use std::collections::HashMap; +use std::fs::File; +use std::io::Write; use self::llvm_sys::prelude::*; use self::llvm_sys::{LLVMIntPredicate, LLVMRealPredicate}; @@ -20,7 +22,12 @@ pub fn compilation_sequence(ast: AST, sourcefile: &str) { _ => panic!("Bad filename {}", sourcefile), }; - compile_ast(ast, ll_filename, false); + let llvm_code = compile_ast(ast); + println!("Compilation process finished for {}", ll_filename); + File::create(ll_filename) + .and_then(|mut f| f.write_all(llvm_code.as_bytes())) + .expect("Error writing file"); + let llc_output = Command::new("llc") .arg("-filetype=obj") .arg(ll_filename) @@ -58,7 +65,7 @@ struct CompilationData { current_function: Option, } -pub fn compile_ast(ast: AST, filename: &str, return_string: bool) -> Option { +pub fn compile_ast(ast: AST) -> String { println!("Compiling!"); let names: VariableMap = HashMap::new(); @@ -86,20 +93,12 @@ pub fn compile_ast(ast: AST, filename: &str, return_string: bool) -> Option Repl<'a> { } if self.show_llvm_ir { - let s = compile_ast(ast, "«repl llvm»", true).unwrap(); + let s = compile_ast(ast); output.push_str(&s); } else { // for now only handle last output