From 47f13bf921d980738d7538cbe1c18fa9cfe3a9af Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 27 Jul 2015 04:44:40 +0300 Subject: [PATCH] Always load the personality library in JIT testbench, if available. --- artiq/compiler/testbench/jit.py | 12 +++++------- artiq/compiler/transforms/artiq_ir_generator.py | 2 +- artiq/compiler/transforms/llvm_ir_generator.py | 14 ++++++++------ lit-test/test/exceptions/raise.py | 2 +- lit-test/test/integration/arithmetics.py | 1 + lit-test/test/integration/builtin.py | 1 + lit-test/test/integration/list.py | 1 + lit-test/test/integration/subscript.py | 1 + lit-test/test/lit.cfg | 2 +- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/artiq/compiler/testbench/jit.py b/artiq/compiler/testbench/jit.py index 6c59b7043..9e6fad53e 100644 --- a/artiq/compiler/testbench/jit.py +++ b/artiq/compiler/testbench/jit.py @@ -1,5 +1,4 @@ -import sys, fileinput -from ctypes import CFUNCTYPE +import os, sys, fileinput, ctypes from pythonparser import diagnostic from llvmlite import binding as llvm from .. import Module @@ -10,10 +9,9 @@ llvm.initialize_native_asmprinter() llvm.check_jit_execution() def main(): - while sys.argv[1].startswith("+"): - if sys.argv[1] == "+load": - llvm.load_library_permanently(sys.argv[2]) - del sys.argv[1:3] + libartiq_personality = os.getenv('LIBARTIQ_PERSONALITY') + if libartiq_personality is not None: + llvm.load_library_permanently(libartiq_personality) def process_diagnostic(diag): print("\n".join(diag.render())) @@ -34,7 +32,7 @@ def main(): lljit = llvm.create_mcjit_compiler(llparsedmod, llmachine) lljit.finalize_object() llmain = lljit.get_pointer_to_global(llparsedmod.get_function(llmod.name + ".__modinit__")) - CFUNCTYPE(None)(llmain)() + ctypes.CFUNCTYPE(None)(llmain)() if __name__ == "__main__": main() diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 62f7f995f..50ddffdb6 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -789,7 +789,7 @@ class ARTIQIRGenerator(algorithm.Visitor): lambda: self.alloc_exn(builtins.TValueError(), ir.Constant("slice size {0} is larger than iterable length {1}", builtins.TStr()), - slice_size, iterable_len)) + slice_size, length)) if self.current_assign is None: is_neg_size = self.append(ir.Compare(ast.Lt(loc=None), diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index a88058b96..9f1aecf59 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -103,12 +103,14 @@ class LLVMIRGenerator: linkage = "private" unnamed_addr = True - llstrty = ll.ArrayType(ll.IntType(8), len(as_bytes)) - llconst = ll.GlobalVariable(self.llmodule, llstrty, name) - llconst.global_constant = True - llconst.initializer = ll.Constant(llstrty, bytearray(as_bytes)) - llconst.linkage = linkage - llconst.unnamed_addr = unnamed_addr + llconst = self.llmodule.get_global(name) + if llconst is None: + llstrty = ll.ArrayType(ll.IntType(8), len(as_bytes)) + llconst = ll.GlobalVariable(self.llmodule, llstrty, name) + llconst.global_constant = True + llconst.initializer = ll.Constant(llstrty, bytearray(as_bytes)) + llconst.linkage = linkage + llconst.unnamed_addr = unnamed_addr return llconst.bitcast(ll.IntType(8).as_pointer()) else: diff --git a/lit-test/test/exceptions/raise.py b/lit-test/test/exceptions/raise.py index 307c50df4..dbb221de4 100644 --- a/lit-test/test/exceptions/raise.py +++ b/lit-test/test/exceptions/raise.py @@ -1,4 +1,4 @@ -# RUN: %python -m artiq.compiler.testbench.jit +load %personality %s +# RUN: %python -m artiq.compiler.testbench.jit %s # REQUIRES: exceptions 1/0 diff --git a/lit-test/test/integration/arithmetics.py b/lit-test/test/integration/arithmetics.py index b59d03c91..1963121e6 100644 --- a/lit-test/test/integration/arithmetics.py +++ b/lit-test/test/integration/arithmetics.py @@ -1,5 +1,6 @@ # RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python %s +# REQUIRES: exceptions assert -(-1) == 1 assert -(-1.0) == 1.0 diff --git a/lit-test/test/integration/builtin.py b/lit-test/test/integration/builtin.py index 256abe76e..dbb7e471c 100644 --- a/lit-test/test/integration/builtin.py +++ b/lit-test/test/integration/builtin.py @@ -1,5 +1,6 @@ # RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python %s +# REQUIRES: exceptions assert bool() is False # bool(x) is tested in bool.py diff --git a/lit-test/test/integration/list.py b/lit-test/test/integration/list.py index 660293db7..06f08e426 100644 --- a/lit-test/test/integration/list.py +++ b/lit-test/test/integration/list.py @@ -1,5 +1,6 @@ # RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python %s +# REQUIRES: exceptions [x, y] = [1, 2] assert (x, y) == (1, 2) diff --git a/lit-test/test/integration/subscript.py b/lit-test/test/integration/subscript.py index 15b3651e8..eaa7f8455 100644 --- a/lit-test/test/integration/subscript.py +++ b/lit-test/test/integration/subscript.py @@ -1,5 +1,6 @@ # RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python %s +# REQUIRES: exceptions lst = list(range(10)) assert lst[0] == 0 diff --git a/lit-test/test/lit.cfg b/lit-test/test/lit.cfg index 1d7478215..b27244fba 100644 --- a/lit-test/test/lit.cfg +++ b/lit-test/test/lit.cfg @@ -18,6 +18,6 @@ if os.name == 'posix': lit_config.fatal("Unable to build JIT support library") personality_lib = os.path.join(personality_build, 'libartiq_personality.so') - config.substitutions.append( ('%personality', personality_lib) ) + config.environment['LIBARTIQ_PERSONALITY'] = personality_lib config.available_features.add('exceptions')