forked from TDA283-compiler-construction/project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.ll
42 lines (35 loc) · 1.07 KB
/
runtime.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@dnl = internal constant [4 x i8] c"%d\0A\00"
@fnl = internal constant [6 x i8] c"%.1f\0A\00"
@d = internal constant [3 x i8] c"%d\00"
@lf = internal constant [4 x i8] c"%lf\00"
declare i32 @printf(i8*, ...)
declare i32 @scanf(i8*, ...)
declare i32 @puts(i8*)
define void @printInt(i32 %x) {
entry: %t0 = getelementptr [4 x i8], [4 x i8]* @dnl, i32 0, i32 0
call i32 (i8*, ...) @printf(i8* %t0, i32 %x)
ret void
}
define void @printDouble(double %x) {
entry: %t0 = getelementptr [6 x i8], [6 x i8]* @fnl, i32 0, i32 0
call i32 (i8*, ...) @printf(i8* %t0, double %x)
ret void
}
define void @printString(i8* %s) {
entry: call i32 @puts(i8* %s)
ret void
}
define i32 @readInt() {
entry: %res = alloca i32
%t1 = getelementptr [3 x i8], [3 x i8]* @d, i32 0, i32 0
call i32 (i8*, ...) @scanf(i8* %t1, i32* %res)
%t2 = load i32, i32* %res
ret i32 %t2
}
define double @readDouble() {
entry: %res = alloca double
%t1 = getelementptr [4 x i8], [4 x i8]* @lf, i32 0, i32 0
call i32 (i8*, ...) @scanf(i8* %t1, double* %res)
%t2 = load double, double* %res
ret double %t2
}