Skip to content

Commit

Permalink
Merge pull request #20 from lambdaclass/progress
Browse files Browse the repository at this point in the history
save mlir code
  • Loading branch information
edg-l authored Dec 10, 2024
2 parents 2c0a0af + d0915aa commit 389d7f2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions src/codegen/expressions.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
5 changes: 4 additions & 1 deletion src/codegen/let_stmt.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
5 changes: 4 additions & 1 deletion src/codegen/return_stmt.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit 389d7f2

Please sign in to comment.