beaver-lodge / beaver

MLIR Toolkit in Elixir and Zig.
MIT License
162 stars 8 forks source link

Use builtin mod and func in ex prototype #235

Closed jackalcooper closed 11 months ago

jackalcooper commented 11 months ago
module {
  module @TwoFuncMod {
    func.func @add_two_literal() -> !ex.dyn {
      %0 = "ex.lit_int"() {value = 1 : i64} : () -> i64
      %1 = "ex.lit_int"() {value = 2 : i64} : () -> i64
      %2 = "ex.add"(%0, %1) : (i64, i64) -> !ex.dyn
      %3 = "ex.var"() {name = "a"} : () -> !ex.unbound
      %4 = "ex.bind"(%3, %2) : (!ex.unbound, !ex.dyn) -> !ex.bound
      %5 = "ex.var"() {name = "a"} : () -> !ex.dyn
      %6 = "ex.lit_int"() {value = 3 : i64} : () -> i64
      %7 = "ex.add"(%5, %6) : (!ex.dyn, i64) -> !ex.dyn
      %8 = "ex.var"() {name = "b"} : () -> !ex.unbound
      %9 = "ex.bind"(%8, %7) : (!ex.unbound, !ex.dyn) -> !ex.bound
      %10 = "ex.var"() {name = "b"} : () -> !ex.dyn
      return %10 : !ex.dyn
    }
    func.func @main() -> !ex.dyn {
      %0 = "ex.call"() {name = "add_two_literal"} : () -> !ex.dyn
      return %0 : !ex.dyn
    }
  }
  module @OneFuncMod {
    func.func @add_two_literal() -> !ex.dyn {
      %0 = "ex.lit_int"() {value = 1 : i64} : () -> i64
      %1 = "ex.lit_int"() {value = 2 : i64} : () -> i64
      %2 = "ex.add"(%0, %1) : (i64, i64) -> !ex.dyn
      %3 = "ex.var"() {name = "a"} : () -> !ex.unbound
      %4 = "ex.bind"(%3, %2) : (!ex.unbound, !ex.dyn) -> !ex.bound
      %5 = "ex.var"() {name = "a"} : () -> !ex.dyn
      %6 = "ex.lit_int"() {value = 3 : i64} : () -> i64
      %7 = "ex.add"(%5, %6) : (!ex.dyn, i64) -> !ex.dyn
      %8 = "ex.var"() {name = "b"} : () -> !ex.unbound
      %9 = "ex.bind"(%8, %7) : (!ex.unbound, !ex.dyn) -> !ex.bound
      %10 = "ex.var"() {name = "b"} : () -> !ex.dyn
      return %10 : !ex.dyn
    }
  }
}