forked from M-Labs/artiq
1
0
Fork 0

Add artiq.compiler.testbench.run.

This commit is contained in:
whitequark 2015-07-22 04:10:15 +03:00
parent 86e006830c
commit 986d9d944f
2 changed files with 32 additions and 7 deletions

View File

@ -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__":

View 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()