820
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
declare i32 @printf(i8*, ...)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
@.str_nl = private constant [2 x i8] c"\0A\00"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
@.str_star = private constant [2 x i8] c"*\00"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
@.str_space = private constant [2 x i8] c" \00"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
define void @new_line() #0 {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
%t0 = getelementptr [2 x i8], [2 x i8]* @.str_nl, i32 0, i32 0
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
%1 = call i32 (i8*, ...) @printf(i8* %t0)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
define void @print_star() #0 {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
%t0 = getelementptr [2 x i8], [2 x i8]* @.str_star, i32 0, i32 0
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
%1 = call i32 (i8*, ...) @printf(i8* %t0)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
define void @print_space() #0 {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
%t0 = getelementptr [2 x i8], [2 x i8]* @.str_space, i32 0, i32 0
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
%1 = call i32 (i8*, ...) @printf(i8* %t0)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
define void @skip() #0 {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
30 |
@.str = private constant [4 x i8] c"%d\0A\00"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
define void @print_int(i32 %x) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
%t0 = getelementptr [4 x i8], [4 x i8]* @.str, i32 0, i32 0
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
call i32 (i8*, ...) @printf(i8* %t0, i32 %x)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
; END OF BUILD-IN FUNCTIONS (prelude)
|
826
|
39 |
|
820
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
@Max = global i32 10
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
define i32 @sqr (i32 %x) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
%tmp_20 = mul i32 %x, %x
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
ret i32 %tmp_20
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
define void @all (i32 %n) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
%tmp_22 = load i32, i32* @Max
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
%tmp_21 = icmp sle i32 %n, %tmp_22
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
br i1 %tmp_21, label %if_branch_28, label %else_branch_29
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
if_branch_28:
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
%tmp_23 = call i32 @sqr (i32 %n)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
call void @print_int (i32 %tmp_23)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
%tmp_25 = add i32 %n, 1
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
call void @all (i32 %tmp_25)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
else_branch_29:
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
call void @skip ()
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
ret void
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
define i32 @main() {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
call void @all (i32 0)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
ret i32 0
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
|