Make compiler.testbench.llvmgen emit a main() function.

This commit is contained in:
whitequark 2015-07-21 19:48:44 +03:00
parent 7301a76d68
commit 8c9d9cb5a1
1 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import sys, fileinput import sys, fileinput
from pythonparser import diagnostic from pythonparser import diagnostic
from llvmlite import ir as ll
from .. import Module from .. import Module
def main(): def main():
@ -11,8 +12,15 @@ def main():
engine = diagnostic.Engine() engine = diagnostic.Engine()
engine.process = process_diagnostic engine.process = process_diagnostic
mod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine) llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir
print(mod.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__": if __name__ == "__main__":
main() main()