From 1ad7abd1f4a6f61814895e5f946c270cb2f3a2a0 Mon Sep 17 00:00:00 2001 From: Rik Huijzer Date: Wed, 25 Sep 2024 08:37:33 +0200 Subject: [PATCH] Rename to `opt` --- src/lib.rs | 4 ++-- src/{compile.rs => opt.rs} | 17 ++++++++++++----- tests/arith.rs | 16 ++++++++++------ tests/llvmir.rs | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) rename src/{compile.rs => opt.rs} (58%) diff --git a/src/lib.rs b/src/lib.rs index 9e9c1a93..e2bfcfb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/compile.rs b/src/opt.rs similarity index 58% rename from src/compile.rs rename to src/opt.rs index f91de0ac..b8de0b61 100644 --- a/src/compile.rs +++ b/src/opt.rs @@ -1,3 +1,5 @@ +use crate::parser::BuiltinParse; +use crate::parser::Parser; use core::fmt::Error; use core::fmt::Write; @@ -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::::parse(src).unwrap(); + if options.canonicalize { + println!("canonicalize"); + } + format!("{}", module) } diff --git a/tests/arith.rs b/tests/arith.rs index 993f4b0f..54e657c6 100644 --- a/tests/arith.rs +++ b/tests/arith.rs @@ -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::::parse(src).unwrap(); @@ -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], "}"); } diff --git a/tests/llvmir.rs b/tests/llvmir.rs index a9c04c1a..0c35a400 100644 --- a/tests/llvmir.rs +++ b/tests/llvmir.rs @@ -2,7 +2,7 @@ #![allow(unused)] extern crate rrcf; -use rrcf::compile; +use rrcf::opt; #[test] fn test_translate() {