-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.t
50 lines (42 loc) · 1.23 KB
/
import.t
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
50
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
require("export_decl")
local uname = io.popen("uname","r"):read("*a")
if uname == "Darwin\n" then
terralib.linklibrary("./libexport.dylib")
elseif uname == "Linux\n" then
terralib.linklibrary("./libexport.so")
else
error("OS Unknown")
end
local function load_external_implementation(func, name)
assert(terralib.isfunction(func), tostring(func) .. " is not a function")
name = name or func.name
assert(func:isdefined() == false,
"Cannot load external implementation as "
.. func.name .. " already has an implementation")
local impl = terralib.externfunction(name, &func.type)
func:adddefinition(impl)
assert(func:isdefined())
end
for _, f in pairs(_G) do
if terralib.isfunction(f) then
load_external_implementation(f)
end
end
local io = terralib.includec("stdio.h")
terra main()
io.printf("Test addtwo\n")
io.printf("%d %d %d\n", 1, 2, addtwo(1, 2))
io.printf("Test setone_float\n")
var mat32 = new_float(1)
setone_float(mat32)
del_float(mat32)
io.printf("Test setone_double\n")
var mat64 = new_double(2)
setone_double(mat64)
del_double(mat64)
end
main()