diff --git a/src/codegen.rs b/src/codegen.rs index 63397fc..a714cba 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -61,6 +61,9 @@ pub fn compile_program(program: &Program, optlevel: OptLevel, out_name: &Path) { pass_manager.add_pass(pass::conversion::create_to_llvm()); pass_manager.run(&mut module).unwrap(); + let mlir_code = module.as_operation().to_string(); + std::fs::write(out_name.with_extension("mlir"), mlir_code).unwrap(); + // Convert the MLIR to LLVM IR (requires unsafe since we use mlir-sys and llvm-sys for this) let object = unsafe { llvm_compile(&module, optlevel) }; let out_obj = out_name.with_extension("o"); @@ -95,7 +98,7 @@ pub fn compile_program_jit(program: &Program) -> ExecutionEngine { pass_manager.add_pass(pass::conversion::create_to_llvm()); pass_manager.run(&mut module).unwrap(); - println!("{}", module.as_operation().to_string()); + println!("{}", module.as_operation()); ExecutionEngine::new(&module, 3, &[], false) } diff --git a/src/codegen/expressions.rs b/src/codegen/expressions.rs index 8e00769..03ed565 100644 --- a/src/codegen/expressions.rs +++ b/src/codegen/expressions.rs @@ -1,9 +1,11 @@ use std::collections::HashMap; use melior::{ - dialect::{arith, llvm}, helpers::{ArithBlockExt, LlvmBlockExt}, ir::{ + dialect::{arith, llvm}, + helpers::{ArithBlockExt, LlvmBlockExt}, + ir::{ attribute::IntegerAttribute, r#type::IntegerType, Block, BlockRef, Location, Type, Value, - } + }, }; use crate::ast::{Expr, Opcode}; diff --git a/src/codegen/let_stmt.rs b/src/codegen/let_stmt.rs index fc57f23..84d3533 100644 --- a/src/codegen/let_stmt.rs +++ b/src/codegen/let_stmt.rs @@ -1,6 +1,9 @@ use std::collections::HashMap; -use melior::{helpers::LlvmBlockExt, ir::{r#type::IntegerType, Block, Location, Value}}; +use melior::{ + helpers::LlvmBlockExt, + ir::{r#type::IntegerType, Block, Location, Value}, +}; use crate::{ast::LetStmt, codegen::expressions::compile_expr}; diff --git a/src/codegen/return_stmt.rs b/src/codegen/return_stmt.rs index 01f3b37..9bab7f3 100644 --- a/src/codegen/return_stmt.rs +++ b/src/codegen/return_stmt.rs @@ -1,6 +1,9 @@ use std::collections::HashMap; -use melior::{dialect::func, ir::{Block, BlockRef, Location, Value}}; +use melior::{ + dialect::func, + ir::{Block, BlockRef, Location, Value}, +}; use crate::ast::ReturnStmt;