forked from M-Labs/artiq
Add artiq.compiler.testbench.run.
This commit is contained in:
parent
86e006830c
commit
986d9d944f
@ -13,13 +13,6 @@ def main():
|
||||
engine.process = process_diagnostic
|
||||
|
||||
llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir
|
||||
|
||||
# Add main so that the result can be executed with lli
|
||||
llmain = ll.Function(llmod, ll.FunctionType(ll.VoidType(), []), "main")
|
||||
llbuilder = ll.IRBuilder(llmain.append_basic_block("entry"))
|
||||
llbuilder.call(llmod.get_global(llmod.name + ".__modinit__"), [])
|
||||
llbuilder.ret_void()
|
||||
|
||||
print(llmod)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
32
artiq/compiler/testbench/run.py
Normal file
32
artiq/compiler/testbench/run.py
Normal file
@ -0,0 +1,32 @@
|
||||
import sys, fileinput
|
||||
from ctypes import CFUNCTYPE
|
||||
from pythonparser import diagnostic
|
||||
from llvmlite import binding as llvm
|
||||
from .. import Module
|
||||
|
||||
llvm.initialize()
|
||||
llvm.initialize_native_target()
|
||||
llvm.initialize_native_asmprinter()
|
||||
llvm.check_jit_execution()
|
||||
|
||||
def main():
|
||||
def process_diagnostic(diag):
|
||||
print("\n".join(diag.render()))
|
||||
if diag.level in ("fatal", "error"):
|
||||
exit(1)
|
||||
|
||||
engine = diagnostic.Engine()
|
||||
engine.process = process_diagnostic
|
||||
|
||||
llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir
|
||||
|
||||
lltarget = llvm.Target.from_default_triple()
|
||||
llmachine = lltarget.create_target_machine()
|
||||
llparsedmod = llvm.parse_assembly(str(llmod))
|
||||
lljit = llvm.create_mcjit_compiler(llparsedmod, llmachine)
|
||||
lljit.finalize_object()
|
||||
llmain = lljit.get_pointer_to_global(llparsedmod.get_function(llmod.name + ".__modinit__"))
|
||||
CFUNCTYPE(None)(llmain)()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user