This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MLIR.lean
53 lines (49 loc) · 1.75 KB
/
MLIR.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- import MLIR.Bitfid.Decide FIXME: commented out because it needs mathlib.
import MLIR.Doc
import MLIR.CParser
import MLIR.FFI
import MLIR.AST
import MLIR.P
import MLIR.EDSL
import MLIR.Tests.TestLib
import MLIR.Tests.AllTests
import MLIR.Examples.FinIntBruteforce
-- Testing imports for semantics
import MLIR.Dialects.ToySemantics
import MLIR.Dialects.PDLSemantics
-- import MLIR.Dialects.ControlFlowSemantics
import MLIR.Dialects.ScfSemantics
import MLIR.Dialects.LinalgSemantics
import MLIR.Dialects.VectorSemantics
open MLIR.P
open MLIR.Doc
open MLIR.AST
open IO
open System
-- https://github.com/leanprover/lean4/blob/master/tests/playground/file.lean
def main (xs: List String): IO UInt32 := do
if xs.length == 0 then
IO.println "usage: mlir [--run-test-suite] [--extract-semantic-tests]"
return 0
else if xs == ["--run-test-suite"] then
-- | do-notation improvements.
return (if (← TestLib.runTestSuite AllTests.testSuite) then 0 else 1)
else if H:(xs.length == 2) && xs.head! == "--extract-semantic-tests" then
SemanticsTests.semanticTests.forM fun t => do
let (SemanticsTests.SemanticTest.mk S name r) := t
let fn: Op (S + scf) :=
.mk
(name := "func.func") -- argument names
(res := [])
(args := [])
(regions := [r])
(attrs := [mlir_attr_dict| { "sym_name" = "main"}]) -- macros
let rgn: Region (S + scf) := .mk "entry" [] [fn]
let m: Op (S + scf) := .mk "builtin.module" [] [] [rgn] .empty
let out_folder := List.getF xs (by { exact 1 }) (by { simp_all; }) -- proof
IO.println s!"extracting {out_folder}/{name}..." -- string interpolation
let code := layout80col <| Pretty.doc m
FS.writeFile s!"{out_folder}/{name}" code
return 0
else
return 0