File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ struct BlockIterator
7
7
region:: Region
8
8
end
9
9
10
+ Base. IteratorSize (:: Core.Type{BlockIterator} ) = Base. SizeUnknown ()
11
+ Base. eltype (:: BlockIterator ) = Block
12
+
10
13
function Base. iterate (it:: BlockIterator )
11
14
reg = it. region
12
15
raw_block = API. mlirRegionGetFirstBlock (reg)
@@ -37,6 +40,9 @@ struct RegionIterator
37
40
op:: Operation
38
41
end
39
42
43
+ Base. eltype (:: RegionIterator ) = Region
44
+ Base. length (it:: RegionIterator ) = nregions (it. op)
45
+
40
46
function Base. iterate (it:: RegionIterator )
41
47
raw_region = API. mlirOperationGetFirstRegion (it. op)
42
48
if mlirIsNull (raw_region)
@@ -66,6 +72,9 @@ struct OperationIterator
66
72
block:: Block
67
73
end
68
74
75
+ Base. IteratorSize (:: Core.Type{OperationIterator} ) = Base. SizeUnknown ()
76
+ Base. eltype (:: OperationIterator ) = Operation
77
+
69
78
function Base. iterate (it:: OperationIterator )
70
79
raw_op = API. mlirBlockGetFirstOperation (it. block)
71
80
if mlirIsNull (raw_op)
Original file line number Diff line number Diff line change 31
31
@test_throws AssertionError IR. Module (arith. constant (; value= true , result= IR. Type (Bool)))
32
32
end
33
33
end
34
+
35
+ @testset " Iterators" begin
36
+ IR. context! (IR. Context ()) do
37
+ mod = if LLVM. version () >= v " 15"
38
+ IR. load_all_available_dialects ()
39
+ IR. get_or_load_dialect! (IR. DialectHandle (:func ))
40
+ parse (IR. Module, """
41
+ module {
42
+ func.func @f() {
43
+ return
44
+ }
45
+ }
46
+ """ )
47
+ else
48
+ IR. get_or_load_dialect! (IR. DialectHandle (:std ))
49
+ parse (IR. Module, """
50
+ module {
51
+ func @f() {
52
+ std.return
53
+ }
54
+ }
55
+ """ )
56
+ end
57
+ b = IR. body (mod)
58
+ ops = collect (IR. OperationIterator (b))
59
+ @test ops isa Vector{Operation}
60
+ @test length (ops) == 1
61
+
62
+ op = only (ops)
63
+ regions = collect (IR. RegionIterator (op))
64
+ @test regions isa Vector{Region}
65
+ @test length (regions) == 1
66
+
67
+ region = only (regions)
68
+ blocks = collect (IR. BlockIterator (region))
69
+ @test blocks isa Vector{Block}
70
+ @test length (blocks) == 1
71
+ end
72
+ end
You can’t perform that action at this time.
0 commit comments