Skip to content

Commit 986d9d9

Browse files
author
whitequark
committedJul 22, 2015
Add artiq.compiler.testbench.run.
1 parent 86e0068 commit 986d9d9

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed
 

Diff for: ‎artiq/compiler/testbench/llvmgen.py

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ def process_diagnostic(diag):
1313
engine.process = process_diagnostic
1414

1515
llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir
16-
17-
# Add main so that the result can be executed with lli
18-
llmain = ll.Function(llmod, ll.FunctionType(ll.VoidType(), []), "main")
19-
llbuilder = ll.IRBuilder(llmain.append_basic_block("entry"))
20-
llbuilder.call(llmod.get_global(llmod.name + ".__modinit__"), [])
21-
llbuilder.ret_void()
22-
2316
print(llmod)
2417

2518
if __name__ == "__main__":

Diff for: ‎artiq/compiler/testbench/run.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys, fileinput
2+
from ctypes import CFUNCTYPE
3+
from pythonparser import diagnostic
4+
from llvmlite import binding as llvm
5+
from .. import Module
6+
7+
llvm.initialize()
8+
llvm.initialize_native_target()
9+
llvm.initialize_native_asmprinter()
10+
llvm.check_jit_execution()
11+
12+
def main():
13+
def process_diagnostic(diag):
14+
print("\n".join(diag.render()))
15+
if diag.level in ("fatal", "error"):
16+
exit(1)
17+
18+
engine = diagnostic.Engine()
19+
engine.process = process_diagnostic
20+
21+
llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir
22+
23+
lltarget = llvm.Target.from_default_triple()
24+
llmachine = lltarget.create_target_machine()
25+
llparsedmod = llvm.parse_assembly(str(llmod))
26+
lljit = llvm.create_mcjit_compiler(llparsedmod, llmachine)
27+
lljit.finalize_object()
28+
llmain = lljit.get_pointer_to_global(llparsedmod.get_function(llmod.name + ".__modinit__"))
29+
CFUNCTYPE(None)(llmain)()
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.