Skip to content

Commit 85e04f3

Browse files
committed
Actually test values as part of examples.
1 parent 2eca72f commit 85e04f3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

examples/sum.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# https://pauladamsmith.com/blog/2015/01/how-to-get-started-with-llvm-c-api.html
22

3+
using Test
4+
35
using LLVM
46

57
if length(ARGS) == 2
@@ -35,7 +37,7 @@ Interpreter(mod) do engine
3537
GenericValue(LLVM.Int32Type(), y)]
3638

3739
res = LLVM.run(engine, sum, args)
38-
println(convert(Int, res))
40+
@test convert(Int, res) == x + y
3941

4042
dispose.(args)
4143
dispose(res)

examples/sum_integrated.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# same as `sum.jl`, but reusing the Julia compiler to compile and execute the IR
22

3+
using Test
4+
35
using LLVM
46
using LLVM.Interop
57

@@ -25,6 +27,5 @@ end
2527

2628
# make Julia compile and execute the function
2729
push!(function_attributes(sum), EnumAttribute("alwaysinline"))
28-
ptr = LLVM.ref(sum)
29-
call_sum(x, y) = Base.llvmcall(ptr, Int32, Tuple{Int32, Int32}, x, y)
30-
@show call_sum(x, y)
30+
@eval call_sum(x, y) = $(call_function(sum, Int32, Tuple{Int32, Int32}, :(x, y)))
31+
@test call_sum(x, y) == x + y

0 commit comments

Comments
 (0)