2015-07-21 09:54:34 +08:00
|
|
|
import sys, fileinput
|
|
|
|
from pythonparser import diagnostic
|
2021-08-12 11:54:36 +08:00
|
|
|
from llvmlite import ir as ll
|
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-21 09:54:34 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-08-06 13:24:41 +08:00
|
|
|
mod = Module(Source.from_string("".join(fileinput.input()).expandtabs(), engine=engine))
|
2015-07-30 01:35:16 +08:00
|
|
|
|
|
|
|
target = NativeTarget()
|
|
|
|
llmod = mod.build_llvm_ir(target=target)
|
2015-07-22 23:34:52 +08:00
|
|
|
|
|
|
|
# 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"))
|
2015-12-10 23:08:05 +08:00
|
|
|
llbuilder.call(llmod.get_global(llmod.name + ".__modinit__"), [
|
|
|
|
ll.Constant(ll.IntType(8).as_pointer(), None)])
|
2015-07-22 23:34:52 +08:00
|
|
|
llbuilder.ret_void()
|
|
|
|
|
2015-07-22 00:48:44 +08:00
|
|
|
print(llmod)
|
2015-07-21 09:54:34 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|