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.

227 lines
6.4 KiB

@TAPE_LEN = global i32 65536
@BUFFER_LEN = global i32 32768
@tape = global [65536 x i32] zeroinitializer
@program = global [32768 x i32] zeroinitializer
@ptr11 = global i32 0
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 @read_program() {
entry:
%t0 = alloca i32
%t1 = alloca i32
store i32 0, i32* %t0
%t2 = call i32 @getint()
store i32 %t2, i32* %t1
br label %while.cond.1
while.cond.1:
%t3 = load i32, i32* %t0
%t4 = load i32, i32* %t1
%t5 = icmp slt 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* %t0
%t9 = getelementptr inbounds [32768 x i32], [32768 x i32]* @program, i32 0, i32 %t8
%t10 = call i32 @getch()
store i32 %t10, i32* %t9
%t11 = load i32, i32* %t0
%t12 = add i32 %t11, 1
store i32 %t12, i32* %t0
br label %while.cond.1
while.end.3:
%t13 = load i32, i32* %t0
%t14 = getelementptr inbounds [32768 x i32], [32768 x i32]* @program, i32 0, i32 %t13
store i32 0, i32* %t14
ret void
}
define void @interpret(i32* %arg.input) {
entry:
%t15 = alloca i32
%t16 = alloca i32
%t17 = alloca i32
store i32 0, i32* %t15
store i32 0, i32* %t16
store i32 0, i32* %t17
br label %while.cond.4
while.cond.4:
%t18 = load i32, i32* %t17
%t19 = getelementptr inbounds i32, i32* %arg.input, i32 %t18
%t20 = load i32, i32* %t19
%t21 = icmp ne i32 %t20, 0
br i1 %t21, label %while.body.5, label %while.end.6
while.body.5:
%t22 = load i32, i32* %t17
%t23 = getelementptr inbounds i32, i32* %arg.input, i32 %t22
%t24 = load i32, i32* %t23
store i32 %t24, i32* %t15
%t25 = load i32, i32* %t15
%t26 = icmp eq i32 %t25, 62
%t27 = zext i1 %t26 to i32
%t28 = icmp ne i32 %t27, 0
br i1 %t28, label %if.then.7, label %if.else.8
while.end.6:
ret void
if.then.7:
%t29 = load i32, i32* @ptr11
%t30 = add i32 %t29, 1
store i32 %t30, i32* @ptr11
br label %if.end.9
if.else.8:
%t31 = load i32, i32* %t15
%t32 = icmp eq i32 %t31, 60
%t33 = zext i1 %t32 to i32
%t34 = icmp ne i32 %t33, 0
br i1 %t34, label %if.then.10, label %if.else.11
if.end.9:
%t101 = load i32, i32* %t17
%t102 = add i32 %t101, 1
store i32 %t102, i32* %t17
br label %while.cond.4
if.then.10:
%t35 = load i32, i32* @ptr11
%t36 = sub i32 %t35, 1
store i32 %t36, i32* @ptr11
br label %if.end.12
if.else.11:
%t37 = load i32, i32* %t15
%t38 = icmp eq i32 %t37, 43
%t39 = zext i1 %t38 to i32
%t40 = icmp ne i32 %t39, 0
br i1 %t40, label %if.then.13, label %if.else.14
if.end.12:
br label %if.end.9
if.then.13:
%t41 = load i32, i32* @ptr11
%t42 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t41
%t43 = load i32, i32* @ptr11
%t44 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t43
%t45 = load i32, i32* %t44
%t46 = add i32 %t45, 1
store i32 %t46, i32* %t42
br label %if.end.15
if.else.14:
%t47 = load i32, i32* %t15
%t48 = icmp eq i32 %t47, 45
%t49 = zext i1 %t48 to i32
%t50 = icmp ne i32 %t49, 0
br i1 %t50, label %if.then.16, label %if.else.17
if.end.15:
br label %if.end.12
if.then.16:
%t51 = load i32, i32* @ptr11
%t52 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t51
%t53 = load i32, i32* @ptr11
%t54 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t53
%t55 = load i32, i32* %t54
%t56 = sub i32 %t55, 1
store i32 %t56, i32* %t52
br label %if.end.18
if.else.17:
%t57 = load i32, i32* %t15
%t58 = icmp eq i32 %t57, 46
%t59 = zext i1 %t58 to i32
%t60 = icmp ne i32 %t59, 0
br i1 %t60, label %if.then.19, label %if.else.20
if.end.18:
br label %if.end.15
if.then.19:
%t61 = load i32, i32* @ptr11
%t62 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t61
%t63 = load i32, i32* %t62
call void @putch(i32 %t63)
br label %if.end.21
if.else.20:
%t65 = load i32, i32* %t15
%t66 = icmp eq i32 %t65, 44
%t67 = zext i1 %t66 to i32
%t68 = icmp ne i32 %t67, 0
br i1 %t68, label %if.then.22, label %if.else.23
if.end.21:
br label %if.end.18
if.then.22:
%t69 = load i32, i32* @ptr11
%t70 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t69
%t71 = call i32 @getch()
store i32 %t71, i32* %t70
br label %if.end.24
if.else.23:
%t72 = load i32, i32* %t15
%t73 = icmp eq i32 %t72, 93
%t74 = zext i1 %t73 to i32
%t75 = icmp ne i32 %t74, 0
br i1 %t75, label %land.rhs.27, label %if.end.26
if.end.24:
br label %if.end.21
if.then.25:
store i32 1, i32* %t16
br label %while.cond.28
if.end.26:
br label %if.end.24
land.rhs.27:
%t76 = load i32, i32* @ptr11
%t77 = getelementptr inbounds [65536 x i32], [65536 x i32]* @tape, i32 0, i32 %t76
%t78 = load i32, i32* %t77
%t79 = icmp ne i32 %t78, 0
br i1 %t79, label %if.then.25, label %if.end.26
while.cond.28:
%t80 = load i32, i32* %t16
%t81 = icmp sgt i32 %t80, 0
%t82 = zext i1 %t81 to i32
%t83 = icmp ne i32 %t82, 0
br i1 %t83, label %while.body.29, label %while.end.30
while.body.29:
%t84 = load i32, i32* %t17
%t85 = sub i32 %t84, 1
store i32 %t85, i32* %t17
%t86 = load i32, i32* %t17
%t87 = getelementptr inbounds i32, i32* %arg.input, i32 %t86
%t88 = load i32, i32* %t87
store i32 %t88, i32* %t15
%t89 = load i32, i32* %t15
%t90 = icmp eq i32 %t89, 91
%t91 = zext i1 %t90 to i32
%t92 = icmp ne i32 %t91, 0
br i1 %t92, label %if.then.31, label %if.else.32
while.end.30:
br label %if.end.26
if.then.31:
%t93 = load i32, i32* %t16
%t94 = sub i32 %t93, 1
store i32 %t94, i32* %t16
br label %if.end.33
if.else.32:
%t95 = load i32, i32* %t15
%t96 = icmp eq i32 %t95, 93
%t97 = zext i1 %t96 to i32
%t98 = icmp ne i32 %t97, 0
br i1 %t98, label %if.then.34, label %if.end.35
if.end.33:
br label %while.cond.28
if.then.34:
%t99 = load i32, i32* %t16
%t100 = add i32 %t99, 1
store i32 %t100, i32* %t16
br label %if.end.35
if.end.35:
br label %if.end.33
}
define i32 @main() {
entry:
call void @read_program()
%t104 = getelementptr inbounds [32768 x i32], [32768 x i32]* @program, i32 0, i32 0
call void @interpret(i32* %t104)
ret i32 0
}