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.
157 lines
4.0 KiB
157 lines
4.0 KiB
@ascii_0 = global i32 48
|
|
|
|
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 @my_getint() {
|
|
entry:
|
|
%t0 = alloca i32
|
|
%t1 = alloca i32
|
|
store i32 0, i32* %t0
|
|
store i32 0, i32* %t1
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t2 = icmp ne i32 1, 0
|
|
br i1 %t2, label %while.body.2, label %while.end.3
|
|
while.body.2:
|
|
%t3 = call i32 @getch()
|
|
%t4 = sub i32 %t3, 48
|
|
store i32 %t4, i32* %t1
|
|
%t5 = load i32, i32* %t1
|
|
%t6 = icmp slt i32 %t5, 0
|
|
%t7 = zext i1 %t6 to i32
|
|
%t8 = icmp ne i32 %t7, 0
|
|
br i1 %t8, label %if.then.4, label %lor.rhs.7
|
|
while.end.3:
|
|
%t13 = load i32, i32* %t1
|
|
store i32 %t13, i32* %t0
|
|
br label %while.cond.8
|
|
if.then.4:
|
|
br label %while.cond.1
|
|
if.else.5:
|
|
br label %while.end.3
|
|
if.end.6:
|
|
ret i32 0
|
|
lor.rhs.7:
|
|
%t9 = load i32, i32* %t1
|
|
%t10 = icmp sgt i32 %t9, 9
|
|
%t11 = zext i1 %t10 to i32
|
|
%t12 = icmp ne i32 %t11, 0
|
|
br i1 %t12, label %if.then.4, label %if.else.5
|
|
while.cond.8:
|
|
%t14 = icmp ne i32 1, 0
|
|
br i1 %t14, label %while.body.9, label %while.end.10
|
|
while.body.9:
|
|
%t15 = call i32 @getch()
|
|
%t16 = sub i32 %t15, 48
|
|
store i32 %t16, i32* %t1
|
|
%t17 = load i32, i32* %t1
|
|
%t18 = icmp sge i32 %t17, 0
|
|
%t19 = zext i1 %t18 to i32
|
|
%t20 = icmp ne i32 %t19, 0
|
|
br i1 %t20, label %land.rhs.14, label %if.else.12
|
|
while.end.10:
|
|
%t29 = load i32, i32* %t0
|
|
ret i32 %t29
|
|
if.then.11:
|
|
%t25 = load i32, i32* %t0
|
|
%t26 = mul i32 %t25, 10
|
|
%t27 = load i32, i32* %t1
|
|
%t28 = add i32 %t26, %t27
|
|
store i32 %t28, i32* %t0
|
|
br label %if.end.13
|
|
if.else.12:
|
|
br label %while.end.10
|
|
if.end.13:
|
|
br label %while.cond.8
|
|
land.rhs.14:
|
|
%t21 = load i32, i32* %t1
|
|
%t22 = icmp sle i32 %t21, 9
|
|
%t23 = zext i1 %t22 to i32
|
|
%t24 = icmp ne i32 %t23, 0
|
|
br i1 %t24, label %if.then.11, label %if.else.12
|
|
}
|
|
define void @my_putint(i32 %arg.a) {
|
|
entry:
|
|
%t31 = alloca i32, i32 16
|
|
%t32 = alloca i32
|
|
%t30 = alloca i32
|
|
store i32 %arg.a, i32* %t30
|
|
store i32 0, i32* %t32
|
|
br label %while.cond.15
|
|
while.cond.15:
|
|
%t33 = load i32, i32* %t30
|
|
%t34 = icmp sgt i32 %t33, 0
|
|
%t35 = zext i1 %t34 to i32
|
|
%t36 = icmp ne i32 %t35, 0
|
|
br i1 %t36, label %while.body.16, label %while.end.17
|
|
while.body.16:
|
|
%t37 = load i32, i32* %t32
|
|
%t38 = getelementptr inbounds i32, i32* %t31, i32 %t37
|
|
%t39 = load i32, i32* %t30
|
|
%t40 = srem i32 %t39, 10
|
|
%t41 = add i32 %t40, 48
|
|
store i32 %t41, i32* %t38
|
|
%t42 = load i32, i32* %t30
|
|
%t43 = sdiv i32 %t42, 10
|
|
store i32 %t43, i32* %t30
|
|
%t44 = load i32, i32* %t32
|
|
%t45 = add i32 %t44, 1
|
|
store i32 %t45, i32* %t32
|
|
br label %while.cond.15
|
|
while.end.17:
|
|
br label %while.cond.18
|
|
while.cond.18:
|
|
%t46 = load i32, i32* %t32
|
|
%t47 = icmp sgt i32 %t46, 0
|
|
%t48 = zext i1 %t47 to i32
|
|
%t49 = icmp ne i32 %t48, 0
|
|
br i1 %t49, label %while.body.19, label %while.end.20
|
|
while.body.19:
|
|
%t50 = load i32, i32* %t32
|
|
%t51 = sub i32 %t50, 1
|
|
store i32 %t51, i32* %t32
|
|
%t52 = load i32, i32* %t32
|
|
%t53 = getelementptr inbounds i32, i32* %t31, i32 %t52
|
|
%t54 = load i32, i32* %t53
|
|
call void @putch(i32 %t54)
|
|
br label %while.cond.18
|
|
while.end.20:
|
|
ret void
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t56 = alloca i32
|
|
%t62 = alloca i32
|
|
%t57 = call i32 @my_getint()
|
|
store i32 %t57, i32* %t56
|
|
br label %while.cond.21
|
|
while.cond.21:
|
|
%t58 = load i32, i32* %t56
|
|
%t59 = icmp sgt i32 %t58, 0
|
|
%t60 = zext i1 %t59 to i32
|
|
%t61 = icmp ne i32 %t60, 0
|
|
br i1 %t61, label %while.body.22, label %while.end.23
|
|
while.body.22:
|
|
%t63 = call i32 @my_getint()
|
|
store i32 %t63, i32* %t62
|
|
%t64 = load i32, i32* %t62
|
|
call void @my_putint(i32 %t64)
|
|
call void @putch(i32 10)
|
|
%t67 = load i32, i32* %t56
|
|
%t68 = sub i32 %t67, 1
|
|
store i32 %t68, i32* %t56
|
|
br label %while.cond.21
|
|
while.end.23:
|
|
ret i32 0
|
|
}
|