forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.6 KiB
103 lines
2.6 KiB
@a = global i32 -1
|
|
@b = global i32 1
|
|
|
|
declare i32 @getint()
|
|
declare float @getfloat()
|
|
declare i32 @getarray(i32* %arg.a)
|
|
declare i32 @getfarray(float* %arg.a)
|
|
declare i32 @getch()
|
|
declare void @putint(i32 %arg.x)
|
|
declare void @putfloat(float %arg.x)
|
|
declare void @putarray(i32 %arg.n, i32* %arg.a)
|
|
declare void @putfarray(i32 %arg.n, float* %arg.a)
|
|
declare void @putch(i32 %arg.x)
|
|
declare void @starttime()
|
|
declare void @stoptime()
|
|
define i32 @inc_a() {
|
|
entry:
|
|
%t0 = alloca i32
|
|
%t1 = load i32, i32* @a
|
|
store i32 %t1, i32* %t0
|
|
%t2 = load i32, i32* %t0
|
|
%t3 = add i32 %t2, 1
|
|
store i32 %t3, i32* %t0
|
|
%t4 = load i32, i32* %t0
|
|
store i32 %t4, i32* @a
|
|
%t5 = load i32, i32* @a
|
|
ret i32 %t5
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t6 = alloca i32
|
|
store i32 5, i32* %t6
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t7 = load i32, i32* %t6
|
|
%t8 = icmp sge i32 %t7, 0
|
|
%t9 = zext i1 %t8 to i32
|
|
%t10 = icmp ne i32 %t9, 0
|
|
br i1 %t10, label %while.body.2, label %while.end.3
|
|
while.body.2:
|
|
%t11 = call i32 @inc_a()
|
|
%t12 = icmp ne i32 %t11, 0
|
|
br i1 %t12, label %land.rhs.7, label %if.end.5
|
|
while.end.3:
|
|
%t42 = load i32, i32* @a
|
|
call void @putint(i32 %t42)
|
|
call void @putch(i32 32)
|
|
%t45 = load i32, i32* @b
|
|
call void @putint(i32 %t45)
|
|
call void @putch(i32 10)
|
|
%t48 = load i32, i32* @a
|
|
ret i32 %t48
|
|
if.then.4:
|
|
%t17 = load i32, i32* @a
|
|
call void @putint(i32 %t17)
|
|
call void @putch(i32 32)
|
|
%t20 = load i32, i32* @b
|
|
call void @putint(i32 %t20)
|
|
call void @putch(i32 10)
|
|
br label %if.end.5
|
|
if.end.5:
|
|
%t23 = call i32 @inc_a()
|
|
%t24 = icmp slt i32 %t23, 14
|
|
%t25 = zext i1 %t24 to i32
|
|
%t26 = icmp ne i32 %t25, 0
|
|
br i1 %t26, label %if.then.8, label %lor.rhs.11
|
|
land.rhs.6:
|
|
%t15 = call i32 @inc_a()
|
|
%t16 = icmp ne i32 %t15, 0
|
|
br i1 %t16, label %if.then.4, label %if.end.5
|
|
land.rhs.7:
|
|
%t13 = call i32 @inc_a()
|
|
%t14 = icmp ne i32 %t13, 0
|
|
br i1 %t14, label %land.rhs.6, label %if.end.5
|
|
if.then.8:
|
|
%t34 = load i32, i32* @a
|
|
call void @putint(i32 %t34)
|
|
call void @putch(i32 10)
|
|
%t37 = load i32, i32* @b
|
|
%t38 = mul i32 %t37, 2
|
|
store i32 %t38, i32* @b
|
|
br label %if.end.10
|
|
if.else.9:
|
|
%t39 = call i32 @inc_a()
|
|
br label %if.end.10
|
|
if.end.10:
|
|
%t40 = load i32, i32* %t6
|
|
%t41 = sub i32 %t40, 1
|
|
store i32 %t41, i32* %t6
|
|
br label %while.cond.1
|
|
lor.rhs.11:
|
|
%t27 = call i32 @inc_a()
|
|
%t28 = icmp ne i32 %t27, 0
|
|
br i1 %t28, label %land.rhs.12, label %if.else.9
|
|
land.rhs.12:
|
|
%t29 = call i32 @inc_a()
|
|
%t30 = call i32 @inc_a()
|
|
%t31 = sub i32 %t29, %t30
|
|
%t32 = add i32 %t31, 1
|
|
%t33 = icmp ne i32 %t32, 0
|
|
br i1 %t33, label %if.then.8, label %if.else.9
|
|
}
|