Files
cs420/examples/ir1/struct4.ir
2025-04-11 13:20:10 +09:00

34 lines
729 B
Plaintext

struct Foo : { x:i32 }
var i32 @nonce = 1
fun struct Foo @f () {
init:
bid: b0
allocations:
%l0:struct Foo:x
block b0:
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
%b0:i1:i32 = load @nonce:i32*
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
%b0:i3:struct Foo = load %l0:struct Foo*
ret %b0:i3:struct Foo
}
fun i32 @main () {
init:
bid: b0
allocations:
%l0:i32:x
%l1:struct Foo:t0
block b0:
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
%b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo*
%b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64
%b0:i3:i32 = load %b0:i2:i32*
%b0:i4:unit = store %b0:i3:i32 %l0:i32*
%b0:i5:i32 = load %l0:i32*
ret %b0:i5:i32
}