-
Notifications
You must be signed in to change notification settings - Fork 10
/
call.R
53 lines (35 loc) · 988 Bytes
/
call.R
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
42
43
44
45
46
47
48
49
library(Rllvm)
# Verify we can call one routine from another.
# We changed createCall for LLVM 11.0 to use a FunctionCallee
# so checking it works.
# Create a routine that multiplies its value by 3
m = Module("call")
a = Function("a", Int32Type, list(x = Int32Type), module = m)
b = Block(a)
ir = IRBuilder(b)
x = getParameters(a)$x
ans = ir$binOp(Mul, x, 3L)
ir$createRet(ans)
.llvm(a, 2L)
# Now create a routine b that calls a(), passing its only argument to a
b = Function("b", Int32Type, list(x = Int32Type), module = m)
bl = Block(b)
ir = IRBuilder(bl)
x = getParameters(b)$x
v = ir$createCall(a, x)
ir$createRet(v)
.llvm(b, 4)
# Now routines with no arguments.
m = Module("call")
f = Function("f", Int32Type, module = m)
bl = Block(f)
ir = IRBuilder(bl)
ir$createRet(ir$createConstant(3L))
.llvm(f)
# Now create a routine g that calls a(),
g = Function("g", Int32Type, module = m)
bl = Block(g)
ir = IRBuilder(bl)
v = ir$createCall(f)
ir$createRet(v)
.llvm(g)