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