llvm.org GIT mirror llvm / ffcaa7b
Add calls to print results in fib, simpleadd and sumarray. indirectcall is the same as fib but uses function pointers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@996 91177308-0d34-0410-b5e6-96231b3b80d8 Vikram S. Adve 19 years ago
2 changed file(s) with 59 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 implementation
1
2 declare int "atoi"(sbyte *)
3
4 ulong "fib"(ulong %n)
5 begin
6 setlt ulong %n, 2 ; {bool}:0
7 br bool %0, label %BaseCase, label %RecurseCase
8
9 BaseCase:
10 ret ulong 1
11
12 RecurseCase:
13 %n2 = sub ulong %n, 2
14 %n1 = sub ulong %n, 1
15 %f2 = call ulong(ulong) * %fib(ulong %n2)
16 %f1 = call ulong(ulong) * %fib(ulong %n1)
17 %result = add ulong %f2, %f1
18 ret ulong %result
19 end
20
21 ulong "realmain"(int %argc, sbyte ** %argv)
22 begin
23 seteq int %argc, 2 ; {bool}:0
24 br bool %0, label %HasArg, label %Continue
25 HasArg:
26 ; %n1 = atoi(argv[1])
27 %n1 = add int 1, 1
28 br label %Continue
29
30 Continue:
31 %n = phi int [%n1, %HasArg], [1, %0]
32 %N = cast int %n to ulong
33 %F = call ulong(ulong) *%fib(ulong %N)
34 ret ulong %F
35 end
36
37 ulong "trampoline"(ulong %n, ulong(ulong)* %fibfunc)
38 begin
39 %F = call ulong(ulong) *%fibfunc(ulong %n)
40 ret ulong %F
41 end
42
43 int "main"()
44 begin
45 %Result = call ulong %trampoline(ulong 10, ulong(ulong) *%fib)
46 %Result = cast ulong %Result to int
47 ret int %Result
48 end
49
None implementation
0 %FmtString1 = constant [ubyte] c"fib = \00"
1 %FmtString2 = constant [ubyte] c"\0A\00"
12
23 declare int "atoi"(sbyte *)
4 declare void "printInt"(int)
5 declare void "printString"([ubyte]*)
6
7 implementation
38
49 ulong "fib"(ulong %n)
510 begin
3843 begin
3944 %Result = call ulong %fib(ulong 10)
4045 %Result = cast ulong %Result to int
46 call void %printString([ubyte]* %FmtString1)
47 call void %printInt(int %Result)
48 call void %printString([ubyte]* %FmtString2)
4149 ret int %Result
4250 end
4351