2015-07-27 09:44:40 +08:00
|
|
|
import os, sys, fileinput, ctypes
|
2015-07-22 09:10:15 +08:00
|
|
|
from pythonparser import diagnostic
|
2015-07-29 18:54:00 +08:00
|
|
|
from llvmlite_artiq import binding as llvm
|
2015-11-26 10:23:59 +08:00
|
|
|
from ..module import Module, Source
|
2015-07-30 01:35:16 +08:00
|
|
|
from ..targets import NativeTarget
|
2015-07-22 09:10:15 +08:00
|
|
|
|
|
|
|
def main():
|
2016-02-03 04:57:25 +08:00
|
|
|
libartiq_support = os.getenv("LIBARTIQ_SUPPORT")
|
2015-08-31 23:59:33 +08:00
|
|
|
if libartiq_support is not None:
|
|
|
|
llvm.load_library_permanently(libartiq_support)
|
2015-07-27 09:16:04 +08:00
|
|
|
|
2015-07-22 09:10:15 +08:00
|
|
|
def process_diagnostic(diag):
|
|
|
|
print("\n".join(diag.render()))
|
|
|
|
if diag.level in ("fatal", "error"):
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
engine = diagnostic.Engine()
|
|
|
|
engine.process = process_diagnostic
|
|
|
|
|
2015-07-23 13:09:25 +08:00
|
|
|
source = "".join(fileinput.input())
|
|
|
|
source = source.replace("#ARTIQ#", "")
|
2015-08-06 13:24:41 +08:00
|
|
|
mod = Module(Source.from_string(source.expandtabs(), engine=engine))
|
2015-07-22 09:10:15 +08:00
|
|
|
|
2015-07-30 01:35:16 +08:00
|
|
|
target = NativeTarget()
|
|
|
|
llmod = mod.build_llvm_ir(target)
|
2015-07-22 09:10:15 +08:00
|
|
|
llparsedmod = llvm.parse_assembly(str(llmod))
|
2015-07-23 12:57:35 +08:00
|
|
|
llparsedmod.verify()
|
2015-07-30 01:35:16 +08:00
|
|
|
|
|
|
|
llmachine = llvm.Target.from_triple(target.triple).create_target_machine()
|
2015-07-22 09:10:15 +08:00
|
|
|
lljit = llvm.create_mcjit_compiler(llparsedmod, llmachine)
|
2016-03-31 16:16:03 +08:00
|
|
|
llmain = lljit.get_function_address(llmod.name + ".__modinit__")
|
2015-07-27 09:44:40 +08:00
|
|
|
ctypes.CFUNCTYPE(None)(llmain)()
|
2015-07-22 09:10:15 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|