From 8c9d9cb5a14ece74e33f4a0ecf299a1fed5e01b5 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 21 Jul 2015 19:48:44 +0300 Subject: [PATCH] Make compiler.testbench.llvmgen emit a main() function. --- artiq/compiler/testbench/llvmgen.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/artiq/compiler/testbench/llvmgen.py b/artiq/compiler/testbench/llvmgen.py index bb3d6ec3d..c32ceb98e 100644 --- a/artiq/compiler/testbench/llvmgen.py +++ b/artiq/compiler/testbench/llvmgen.py @@ -1,5 +1,6 @@ import sys, fileinput from pythonparser import diagnostic +from llvmlite import ir as ll from .. import Module def main(): @@ -11,8 +12,15 @@ def main(): engine = diagnostic.Engine() engine.process = process_diagnostic - mod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine) - print(mod.llvm_ir) + 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__": main()