Files
cs420/examples/ir3/pointer.ir
Jaewoo Kim 32283f2ed1 Update model solution.
- Stop calculating operands for & operators.
- Evaluate the lhs of compound operators only once.
- Add `side-effect.c` example.
2025-04-07 11:03:18 +00:00

38 lines
828 B
Plaintext

fun i32* @foo (i32*) {
init:
bid: b0
allocations:
block b0:
%b0:p0:i32*:a
ret %b0:p0:i32*
}
fun i32 @main () {
init:
bid: b0
allocations:
%l0:i32:a
%l1:i32*:p
block b0:
%b0:i0:unit = store 1:i32 %l0:i32*
%b0:i1:unit = store %l0:i32* %l1:i32**
%b0:i2:i32* = load %l1:i32**
%b0:i3:i32* = load %l1:i32**
%b0:i4:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i3:i32*)
%b0:i5:i32 = load %b0:i4:i32*
%b0:i6:i32 = add %b0:i5:i32 1:i32
%b0:i7:unit = store %b0:i6:i32 %b0:i4:i32*
%b0:i8:i32* = call @foo:[ret:i32* params:(i32*)]*(%b0:i2:i32*)
%b0:i9:i32 = load %b0:i8:i32*
%b0:i10:i32 = add %b0:i9:i32 1:i32
%b0:i11:unit = store %b0:i10:i32 %b0:i8:i32*
%b0:i12:i32 = load %l0:i32*
%b0:i13:u1 = cmp eq %b0:i12:i32 3:i32
%b0:i14:i32 = typecast %b0:i13:u1 to i32
ret %b0:i14:i32
}