From 44e7b99792228a9e845f2fcac23bf73c449953f1 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 19 Dec 2014 12:43:13 +0800 Subject: [PATCH] py2llvm/VNone: bugfixes --- artiq/py2llvm/base_types.py | 7 +++++++ artiq/py2llvm/lists.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/artiq/py2llvm/base_types.py b/artiq/py2llvm/base_types.py index c218facc8..9e6f809ef 100644 --- a/artiq/py2llvm/base_types.py +++ b/artiq/py2llvm/base_types.py @@ -10,6 +10,13 @@ class VNone(VGeneric): def alloca(self, builder, name): pass + def set_const_value(self, builder, v): + assert v is None + + def set_value(self, builder, other): + if not isinstance(other, VNone): + raise TypeError + def o_bool(self, builder): r = VBool() if builder is not None: diff --git a/artiq/py2llvm/lists.py b/artiq/py2llvm/lists.py index d8f814ff0..14e59622d 100644 --- a/artiq/py2llvm/lists.py +++ b/artiq/py2llvm/lists.py @@ -1,7 +1,7 @@ import llvmlite.ir as ll from artiq.py2llvm.values import VGeneric -from artiq.py2llvm.base_types import VInt +from artiq.py2llvm.base_types import VInt, VNone class VList(VGeneric): @@ -12,9 +12,12 @@ class VList(VGeneric): def get_llvm_type(self): count = 0 if self.alloc_count is None else self.alloc_count - return ll.LiteralStructType([ll.IntType(32), - ll.ArrayType(self.el_type.get_llvm_type(), - count)]) + if isinstance(self.el_type, VNone): + return ll.LiteralStructType([ll.IntType(32)]) + else: + return ll.LiteralStructType([ + ll.IntType(32), ll.ArrayType(self.el_type.get_llvm_type(), + count)]) def __repr__(self): return "".format( @@ -52,7 +55,7 @@ class VList(VGeneric): def o_subscript(self, index, builder): r = self.el_type.new() - if builder is not None: + if builder is not None and not isinstance(r, VNone): index = index.o_int(builder).auto_load(builder) ssa_r = builder.gep(self.llvm_value, [ ll.Constant(ll.IntType(32), 0),