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.
185 lines
5.3 KiB
185 lines
5.3 KiB
@ans = global [50 x i32] zeroinitializer
|
|
@sum = global i32 0
|
|
@n = global i32 0
|
|
@row = global [50 x i32] zeroinitializer
|
|
@line1 = global [50 x i32] zeroinitializer
|
|
@line2 = global [100 x i32] zeroinitializer
|
|
|
|
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 void @printans() {
|
|
entry:
|
|
%t2 = alloca i32
|
|
%t0 = load i32, i32* @sum
|
|
%t1 = add i32 %t0, 1
|
|
store i32 %t1, i32* @sum
|
|
store i32 1, i32* %t2
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t3 = load i32, i32* %t2
|
|
%t4 = load i32, i32* @n
|
|
%t5 = icmp sle i32 %t3, %t4
|
|
%t6 = zext i1 %t5 to i32
|
|
%t7 = icmp ne i32 %t6, 0
|
|
br i1 %t7, label %while.body.2, label %while.end.3
|
|
while.body.2:
|
|
%t8 = load i32, i32* %t2
|
|
%t9 = getelementptr inbounds [50 x i32], [50 x i32]* @ans, i32 0, i32 %t8
|
|
%t10 = load i32, i32* %t9
|
|
call void @putint(i32 %t10)
|
|
%t12 = load i32, i32* %t2
|
|
%t13 = load i32, i32* @n
|
|
%t14 = icmp eq i32 %t12, %t13
|
|
%t15 = zext i1 %t14 to i32
|
|
%t16 = icmp ne i32 %t15, 0
|
|
br i1 %t16, label %if.then.4, label %if.else.5
|
|
while.end.3:
|
|
ret void
|
|
if.then.4:
|
|
call void @putch(i32 10)
|
|
ret void
|
|
if.else.5:
|
|
call void @putch(i32 32)
|
|
br label %if.end.6
|
|
if.end.6:
|
|
%t19 = load i32, i32* %t2
|
|
%t20 = add i32 %t19, 1
|
|
store i32 %t20, i32* %t2
|
|
br label %while.cond.1
|
|
}
|
|
define void @f(i32 %arg.step) {
|
|
entry:
|
|
%t22 = alloca i32
|
|
%t21 = alloca i32
|
|
store i32 %arg.step, i32* %t21
|
|
store i32 1, i32* %t22
|
|
br label %while.cond.7
|
|
while.cond.7:
|
|
%t23 = load i32, i32* %t22
|
|
%t24 = load i32, i32* @n
|
|
%t25 = icmp sle i32 %t23, %t24
|
|
%t26 = zext i1 %t25 to i32
|
|
%t27 = icmp ne i32 %t26, 0
|
|
br i1 %t27, label %while.body.8, label %while.end.9
|
|
while.body.8:
|
|
%t28 = load i32, i32* %t22
|
|
%t29 = getelementptr inbounds [50 x i32], [50 x i32]* @row, i32 0, i32 %t28
|
|
%t30 = load i32, i32* %t29
|
|
%t31 = icmp ne i32 %t30, 1
|
|
%t32 = zext i1 %t31 to i32
|
|
%t33 = icmp ne i32 %t32, 0
|
|
br i1 %t33, label %land.rhs.13, label %if.end.11
|
|
while.end.9:
|
|
ret void
|
|
if.then.10:
|
|
%t52 = load i32, i32* %t21
|
|
%t53 = getelementptr inbounds [50 x i32], [50 x i32]* @ans, i32 0, i32 %t52
|
|
%t54 = load i32, i32* %t22
|
|
store i32 %t54, i32* %t53
|
|
%t55 = load i32, i32* %t21
|
|
%t56 = load i32, i32* @n
|
|
%t57 = icmp eq i32 %t55, %t56
|
|
%t58 = zext i1 %t57 to i32
|
|
%t59 = icmp ne i32 %t58, 0
|
|
br i1 %t59, label %if.then.14, label %if.end.15
|
|
if.end.11:
|
|
%t88 = load i32, i32* %t22
|
|
%t89 = add i32 %t88, 1
|
|
store i32 %t89, i32* %t22
|
|
br label %while.cond.7
|
|
land.rhs.12:
|
|
%t42 = load i32, i32* @n
|
|
%t43 = load i32, i32* %t21
|
|
%t44 = add i32 %t42, %t43
|
|
%t45 = load i32, i32* %t22
|
|
%t46 = sub i32 %t44, %t45
|
|
%t47 = getelementptr inbounds [100 x i32], [100 x i32]* @line2, i32 0, i32 %t46
|
|
%t48 = load i32, i32* %t47
|
|
%t49 = icmp eq i32 %t48, 0
|
|
%t50 = zext i1 %t49 to i32
|
|
%t51 = icmp ne i32 %t50, 0
|
|
br i1 %t51, label %if.then.10, label %if.end.11
|
|
land.rhs.13:
|
|
%t34 = load i32, i32* %t21
|
|
%t35 = load i32, i32* %t22
|
|
%t36 = add i32 %t34, %t35
|
|
%t37 = getelementptr inbounds [50 x i32], [50 x i32]* @line1, i32 0, i32 %t36
|
|
%t38 = load i32, i32* %t37
|
|
%t39 = icmp eq i32 %t38, 0
|
|
%t40 = zext i1 %t39 to i32
|
|
%t41 = icmp ne i32 %t40, 0
|
|
br i1 %t41, label %land.rhs.12, label %if.end.11
|
|
if.then.14:
|
|
call void @printans()
|
|
br label %if.end.15
|
|
if.end.15:
|
|
%t61 = load i32, i32* %t22
|
|
%t62 = getelementptr inbounds [50 x i32], [50 x i32]* @row, i32 0, i32 %t61
|
|
store i32 1, i32* %t62
|
|
%t63 = load i32, i32* %t21
|
|
%t64 = load i32, i32* %t22
|
|
%t65 = add i32 %t63, %t64
|
|
%t66 = getelementptr inbounds [50 x i32], [50 x i32]* @line1, i32 0, i32 %t65
|
|
store i32 1, i32* %t66
|
|
%t67 = load i32, i32* @n
|
|
%t68 = load i32, i32* %t21
|
|
%t69 = add i32 %t67, %t68
|
|
%t70 = load i32, i32* %t22
|
|
%t71 = sub i32 %t69, %t70
|
|
%t72 = getelementptr inbounds [100 x i32], [100 x i32]* @line2, i32 0, i32 %t71
|
|
store i32 1, i32* %t72
|
|
%t73 = load i32, i32* %t21
|
|
%t74 = add i32 %t73, 1
|
|
call void @f(i32 %t74)
|
|
%t76 = load i32, i32* %t22
|
|
%t77 = getelementptr inbounds [50 x i32], [50 x i32]* @row, i32 0, i32 %t76
|
|
store i32 0, i32* %t77
|
|
%t78 = load i32, i32* %t21
|
|
%t79 = load i32, i32* %t22
|
|
%t80 = add i32 %t78, %t79
|
|
%t81 = getelementptr inbounds [50 x i32], [50 x i32]* @line1, i32 0, i32 %t80
|
|
store i32 0, i32* %t81
|
|
%t82 = load i32, i32* @n
|
|
%t83 = load i32, i32* %t21
|
|
%t84 = add i32 %t82, %t83
|
|
%t85 = load i32, i32* %t22
|
|
%t86 = sub i32 %t84, %t85
|
|
%t87 = getelementptr inbounds [100 x i32], [100 x i32]* @line2, i32 0, i32 %t86
|
|
store i32 0, i32* %t87
|
|
br label %if.end.11
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t90 = alloca i32
|
|
%t91 = call i32 @getint()
|
|
store i32 %t91, i32* %t90
|
|
br label %while.cond.16
|
|
while.cond.16:
|
|
%t92 = load i32, i32* %t90
|
|
%t93 = icmp sgt i32 %t92, 0
|
|
%t94 = zext i1 %t93 to i32
|
|
%t95 = icmp ne i32 %t94, 0
|
|
br i1 %t95, label %while.body.17, label %while.end.18
|
|
while.body.17:
|
|
%t96 = call i32 @getint()
|
|
store i32 %t96, i32* @n
|
|
call void @f(i32 1)
|
|
%t98 = load i32, i32* %t90
|
|
%t99 = sub i32 %t98, 1
|
|
store i32 %t99, i32* %t90
|
|
br label %while.cond.16
|
|
while.end.18:
|
|
%t100 = load i32, i32* @sum
|
|
ret i32 %t100
|
|
}
|