Skip to content

Commit

Permalink
Rename to opt
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Sep 25, 2024
1 parent 22cc2bc commit 1ad7abd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#![allow(dead_code)]

mod compile;
mod dialect;
mod ir;
mod opt;
pub mod parser;
mod typ;

pub use compile::compile;
pub use ir::attribute::Attribute;
pub use ir::attribute::Attributes;
pub use ir::operation::Operation;
pub use ir::Block;
pub use opt::opt;
pub use parser::Parse;
pub use parser::Parser;

Expand Down
17 changes: 12 additions & 5 deletions src/compile.rs → src/opt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::parser::BuiltinParse;
use crate::parser::Parser;
use core::fmt::Error;
use core::fmt::Write;

Expand All @@ -15,9 +17,14 @@ impl Transform for MLIRToLLVMIRTranslation {
}
}

pub fn compile(src: &str) -> String {
let step = MLIRToLLVMIRTranslation {};
let mut out = String::new();
step.transform(src, &mut out).unwrap();
out
pub struct Options {
canonicalize: bool,
}

pub fn opt(src: &str, options: Options) -> String {
let module = Parser::<BuiltinParse>::parse(src).unwrap();
if options.canonicalize {
println!("canonicalize");
}
format!("{}", module)
}
16 changes: 10 additions & 6 deletions tests/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ fn parse_addi() {
let src = "
func.func @test_addi(%arg0 : i64) -> i64 {
%0 = arith.constant 1 : i64
%1 = arith.addi %arg0, %0 : i64
return %1 : i64
%1 = arith.constant 2 : i64
%2 = arith.addi %0, %1 : i64
%3 = arith.addi %arg0, %2 : i64
return %3 : i64
}
";
let module = Parser::<BuiltinParse>::parse(src).unwrap();
Expand All @@ -19,8 +21,10 @@ fn parse_addi() {
assert_eq!(lines[0], "module {");
assert_eq!(lines[1], " func.func @test_addi(%arg0 : i64) -> i64 {");
assert_eq!(lines[2], " %0 = arith.constant 1 : i64");
assert_eq!(lines[3], " %1 = arith.addi %arg0, %0 : i64");
assert_eq!(lines[4], " return %1 : i64");
assert_eq!(lines[5], " }");
assert_eq!(lines[6], "}");
assert_eq!(lines[3], " %1 = arith.constant 2 : i64");
assert_eq!(lines[4], " %2 = arith.addi %0, %1 : i64");
assert_eq!(lines[5], " %3 = arith.addi %arg0, %2 : i64");
assert_eq!(lines[6], " return %3 : i64");
assert_eq!(lines[7], " }");
assert_eq!(lines[8], "}");
}
2 changes: 1 addition & 1 deletion tests/llvmir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(unused)]
extern crate rrcf;

use rrcf::compile;
use rrcf::opt;

#[test]
fn test_translate() {
Expand Down

0 comments on commit 1ad7abd

Please sign in to comment.