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.
183 lines
5.1 KiB
183 lines
5.1 KiB
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 @get_next(i32* %arg.str, i32* %arg.next) {
|
|
entry:
|
|
%t1 = alloca i32
|
|
%t2 = alloca i32
|
|
%t0 = getelementptr inbounds i32, i32* %arg.next, i32 0
|
|
store i32 -1, i32* %t0
|
|
store i32 0, i32* %t1
|
|
store i32 -1, i32* %t2
|
|
br label %while.cond.1
|
|
while.cond.1:
|
|
%t3 = load i32, i32* %t1
|
|
%t4 = getelementptr inbounds i32, i32* %arg.str, i32 %t3
|
|
%t5 = load i32, i32* %t4
|
|
%t6 = icmp ne i32 %t5, 0
|
|
br i1 %t6, label %while.body.2, label %while.end.3
|
|
while.body.2:
|
|
%t7 = load i32, i32* %t2
|
|
%t8 = icmp eq i32 %t7, -1
|
|
%t9 = zext i1 %t8 to i32
|
|
%t10 = icmp ne i32 %t9, 0
|
|
br i1 %t10, label %if.then.4, label %lor.rhs.7
|
|
while.end.3:
|
|
ret void
|
|
if.then.4:
|
|
%t20 = load i32, i32* %t2
|
|
%t21 = add i32 %t20, 1
|
|
store i32 %t21, i32* %t2
|
|
%t22 = load i32, i32* %t1
|
|
%t23 = add i32 %t22, 1
|
|
store i32 %t23, i32* %t1
|
|
%t24 = load i32, i32* %t1
|
|
%t25 = getelementptr inbounds i32, i32* %arg.next, i32 %t24
|
|
%t26 = load i32, i32* %t2
|
|
store i32 %t26, i32* %t25
|
|
br label %if.end.6
|
|
if.else.5:
|
|
%t27 = load i32, i32* %t2
|
|
%t28 = getelementptr inbounds i32, i32* %arg.next, i32 %t27
|
|
%t29 = load i32, i32* %t28
|
|
store i32 %t29, i32* %t2
|
|
br label %if.end.6
|
|
if.end.6:
|
|
br label %while.cond.1
|
|
lor.rhs.7:
|
|
%t11 = load i32, i32* %t1
|
|
%t12 = getelementptr inbounds i32, i32* %arg.str, i32 %t11
|
|
%t13 = load i32, i32* %t12
|
|
%t14 = load i32, i32* %t2
|
|
%t15 = getelementptr inbounds i32, i32* %arg.str, i32 %t14
|
|
%t16 = load i32, i32* %t15
|
|
%t17 = icmp eq i32 %t13, %t16
|
|
%t18 = zext i1 %t17 to i32
|
|
%t19 = icmp ne i32 %t18, 0
|
|
br i1 %t19, label %if.then.4, label %if.else.5
|
|
}
|
|
define i32 @KMP(i32* %arg.dst, i32* %arg.src) {
|
|
entry:
|
|
%t30 = alloca i32, i32 4096
|
|
%t32 = alloca i32
|
|
%t33 = alloca i32
|
|
call void @get_next(i32* %arg.dst, i32* %t30)
|
|
store i32 0, i32* %t32
|
|
store i32 0, i32* %t33
|
|
br label %while.cond.8
|
|
while.cond.8:
|
|
%t34 = load i32, i32* %t33
|
|
%t35 = getelementptr inbounds i32, i32* %arg.src, i32 %t34
|
|
%t36 = load i32, i32* %t35
|
|
%t37 = icmp ne i32 %t36, 0
|
|
br i1 %t37, label %while.body.9, label %while.end.10
|
|
while.body.9:
|
|
%t38 = load i32, i32* %t32
|
|
%t39 = getelementptr inbounds i32, i32* %arg.dst, i32 %t38
|
|
%t40 = load i32, i32* %t39
|
|
%t41 = load i32, i32* %t33
|
|
%t42 = getelementptr inbounds i32, i32* %arg.src, i32 %t41
|
|
%t43 = load i32, i32* %t42
|
|
%t44 = icmp eq i32 %t40, %t43
|
|
%t45 = zext i1 %t44 to i32
|
|
%t46 = icmp ne i32 %t45, 0
|
|
br i1 %t46, label %if.then.11, label %if.else.12
|
|
while.end.10:
|
|
ret i32 -1
|
|
if.then.11:
|
|
%t47 = load i32, i32* %t32
|
|
%t48 = add i32 %t47, 1
|
|
store i32 %t48, i32* %t32
|
|
%t49 = load i32, i32* %t33
|
|
%t50 = add i32 %t49, 1
|
|
store i32 %t50, i32* %t33
|
|
%t51 = load i32, i32* %t32
|
|
%t52 = getelementptr inbounds i32, i32* %arg.dst, i32 %t51
|
|
%t53 = load i32, i32* %t52
|
|
%t54 = icmp eq i32 %t53, 0
|
|
%t55 = zext i1 %t54 to i32
|
|
%t56 = icmp ne i32 %t55, 0
|
|
br i1 %t56, label %if.then.14, label %if.end.15
|
|
if.else.12:
|
|
%t58 = load i32, i32* %t32
|
|
%t59 = getelementptr inbounds i32, i32* %t30, i32 %t58
|
|
%t60 = load i32, i32* %t59
|
|
store i32 %t60, i32* %t32
|
|
%t61 = load i32, i32* %t32
|
|
%t62 = icmp eq i32 %t61, -1
|
|
%t63 = zext i1 %t62 to i32
|
|
%t64 = icmp ne i32 %t63, 0
|
|
br i1 %t64, label %if.then.16, label %if.end.17
|
|
if.end.13:
|
|
br label %while.cond.8
|
|
if.then.14:
|
|
%t57 = load i32, i32* %t33
|
|
ret i32 %t57
|
|
if.end.15:
|
|
br label %if.end.13
|
|
if.then.16:
|
|
%t65 = load i32, i32* %t32
|
|
%t66 = add i32 %t65, 1
|
|
store i32 %t66, i32* %t32
|
|
%t67 = load i32, i32* %t33
|
|
%t68 = add i32 %t67, 1
|
|
store i32 %t68, i32* %t33
|
|
br label %if.end.17
|
|
if.end.17:
|
|
br label %if.end.13
|
|
}
|
|
define i32 @read_str(i32* %arg.buf) {
|
|
entry:
|
|
%t69 = alloca i32
|
|
store i32 0, i32* %t69
|
|
br label %while.cond.18
|
|
while.cond.18:
|
|
%t70 = icmp ne i32 1, 0
|
|
br i1 %t70, label %while.body.19, label %while.end.20
|
|
while.body.19:
|
|
%t71 = load i32, i32* %t69
|
|
%t72 = getelementptr inbounds i32, i32* %arg.buf, i32 %t71
|
|
%t73 = call i32 @getch()
|
|
store i32 %t73, i32* %t72
|
|
%t74 = load i32, i32* %t69
|
|
%t75 = getelementptr inbounds i32, i32* %arg.buf, i32 %t74
|
|
%t76 = load i32, i32* %t75
|
|
%t77 = icmp eq i32 %t76, 10
|
|
%t78 = zext i1 %t77 to i32
|
|
%t79 = icmp ne i32 %t78, 0
|
|
br i1 %t79, label %if.then.21, label %if.end.22
|
|
while.end.20:
|
|
%t82 = load i32, i32* %t69
|
|
%t83 = getelementptr inbounds i32, i32* %arg.buf, i32 %t82
|
|
store i32 0, i32* %t83
|
|
%t84 = load i32, i32* %t69
|
|
ret i32 %t84
|
|
if.then.21:
|
|
br label %while.end.20
|
|
if.end.22:
|
|
%t80 = load i32, i32* %t69
|
|
%t81 = add i32 %t80, 1
|
|
store i32 %t81, i32* %t69
|
|
br label %while.cond.18
|
|
}
|
|
define i32 @main() {
|
|
entry:
|
|
%t85 = alloca i32, i32 4096
|
|
%t86 = alloca i32, i32 4096
|
|
%t87 = call i32 @read_str(i32* %t85)
|
|
%t88 = call i32 @read_str(i32* %t86)
|
|
%t89 = call i32 @KMP(i32* %t85, i32* %t86)
|
|
call void @putint(i32 %t89)
|
|
call void @putch(i32 10)
|
|
ret i32 0
|
|
}
|