コード例 #1
0
ファイル: target.py プロジェクト: fkaufer/impyla
 def get_constant_struct(self, builder, ty, val):
     # override for converting literals to *Vals, incl. None
     if ty in self._impala_types and val is None:
         iv = TYPE_LAYOUT[ty](self, builder)
         _set_is_null(builder, iv, cgutils.true_bit)
         return iv._getvalue()
     elif ty == BooleanVal:
         const = lc.Constant.int(lc.Type.int(8), val)
         return BooleanVal_ctor(self, builder, None, [const])
     elif ty == TinyIntVal:
         const = lc.Constant.int(lc.Type.int(8), val)
         return TinyIntVal_ctor(self, builder, None, [const])
     elif ty == SmallIntVal:
         const = lc.Constant.int(lc.Type.int(16), val)
         return SmallIntVal_ctor(self, builder, None, [const])
     elif ty == IntVal:
         const = lc.Constant.int(lc.Type.int(32), val)
         return IntVal_ctor(self, builder, None, [const])
     elif ty == BigIntVal:
         const = lc.Constant.int(lc.Type.int(64), val)
         return BigIntVal_ctor(self, builder, None, [const])
     elif ty == FloatVal:
         const = lc.Constant.real(lc.Type.float(), val)
         return FloatVal_ctor(self, builder, None, [const])
     elif ty == DoubleVal:
         const = lc.Constant.real(lc.Type.double(), val)
         return DoubleVal_ctor(self, builder, None, [const])
     elif ty == StringVal:
         iv = StringValStruct(self, builder)
         _set_is_null(builder, iv, cgutils.false_bit)
         iv.len = lc.Constant.int(lc.Type.int(32), len(val))
         iv.ptr = self.get_constant_string(builder, ntypes.string, val)
         return iv._getvalue()
     else:
         return super(ImpalaTargetContext, self).get_constant_struct(builder, ty, val)
コード例 #2
0
ファイル: abi.py プロジェクト: vamseeyarla/impyla
def raise_return_type(context, builder, ty, val):
    if ty == BooleanVal:
        bv = BooleanValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, bv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(16), 8))
        bv.val = builder.trunc(shifted, lc.Type.int(8))
        return bv._getvalue()
    elif ty == TinyIntVal:
        tiv = TinyIntValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, tiv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(16), 8))
        tiv.val = builder.trunc(shifted, lc.Type.int(8))
        return tiv._getvalue()
    elif ty == SmallIntVal:
        siv = SmallIntValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, siv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(32), 16))
        siv.val = builder.trunc(shifted, lc.Type.int(16))
        return siv._getvalue()
    elif ty == IntVal:
        iv = IntValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, iv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(64), 32))
        iv.val = builder.trunc(shifted, lc.Type.int(32))
        return iv._getvalue()
    elif ty == BigIntVal:
        biv = BigIntValStruct(context, builder)
        is_null = builder.extract_value(val, 0)
        _set_is_null(builder, biv, is_null)
        biv.val = builder.extract_value(val, 1)
        return biv._getvalue()
    elif ty == FloatVal:
        fv = FloatValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, fv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(64), 32))
        truncated = builder.trunc(shifted, lc.Type.int(32))
        fv.val = builder.bitcast(truncated, lc.Type.float())
        return fv._getvalue()
    elif ty == DoubleVal:
        dv = DoubleValStruct(context, builder)
        is_null = builder.extract_value(val, 0)
        _set_is_null(builder, dv, is_null)
        dv.val = builder.extract_value(val, 1)
        return dv._getvalue()
    elif ty == StringVal:
        sv = StringValStruct(context, builder)
        packed = builder.extract_value(val, 0)
        is_null = builder.trunc(packed, lc.Type.int(8))
        _set_is_null(builder, sv, is_null)
        shifted = builder.lshr(packed, lc.Constant.int(lc.Type.int(64), 32))
        sv.len = builder.trunc(shifted, lc.Type.int(32))
        sv.ptr = builder.extract_value(val, 1)
        return sv._getvalue()
    else:
        return val
コード例 #3
0
ファイル: abi.py プロジェクト: awleblang/impyla
def raise_return_type(context, builder, ty, val):
    if ty == BooleanVal:
        bv = BooleanValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, bv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(16), 8))
        bv.val = builder.trunc(shifted, lc.Type.int(8))
        return bv._getvalue()
    elif ty == TinyIntVal:
        tiv = TinyIntValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, tiv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(16), 8))
        tiv.val = builder.trunc(shifted, lc.Type.int(8))
        return tiv._getvalue()
    elif ty == SmallIntVal:
        siv = SmallIntValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, siv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(32), 16))
        siv.val = builder.trunc(shifted, lc.Type.int(16))
        return siv._getvalue()
    elif ty == IntVal:
        iv = IntValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, iv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(64), 32))
        iv.val = builder.trunc(shifted, lc.Type.int(32))
        return iv._getvalue()
    elif ty == BigIntVal:
        biv = BigIntValStruct(context, builder)
        is_null = builder.extract_value(val, 0)
        _set_is_null(builder, biv, is_null)
        biv.val = builder.extract_value(val, 1)
        return biv._getvalue()
    elif ty == FloatVal:
        fv = FloatValStruct(context, builder)
        is_null = builder.trunc(val, lc.Type.int(8))
        _set_is_null(builder, fv, is_null)
        shifted = builder.lshr(val, lc.Constant.int(lc.Type.int(64), 32))
        truncated = builder.trunc(shifted, lc.Type.int(32))
        fv.val = builder.bitcast(truncated, lc.Type.float())
        return fv._getvalue()
    elif ty == DoubleVal:
        dv = DoubleValStruct(context, builder)
        is_null = builder.extract_value(val, 0)
        _set_is_null(builder, dv, is_null)
        dv.val = builder.extract_value(val, 1)
        return dv._getvalue()
    elif ty == StringVal:
        sv = StringValStruct(context, builder)
        packed = builder.extract_value(val, 0)
        is_null = builder.trunc(packed, lc.Type.int(8))
        _set_is_null(builder, sv, is_null)
        shifted = builder.lshr(packed, lc.Constant.int(lc.Type.int(64), 32))
        sv.len = builder.trunc(shifted, lc.Type.int(32))
        sv.ptr = builder.extract_value(val, 1)
        return sv._getvalue()
    else:
        return val
コード例 #4
0
ファイル: target.py プロジェクト: fkaufer/impyla
def StringVal_ctor(context, builder, sig, args):
    """StringVal(ntypes.string)"""
    [x] = args
    iv = StringValStruct(context, builder)
    _set_is_null(builder, iv, cgutils.false_bit)
    fndesc = lowering.ExternalFunctionDescriptor('strlen', ntypes.uintp,
            [ntypes.CPointer(ntypes.char)])
    func = context.declare_external_function(cgutils.get_module(builder), fndesc)
    strlen_x = context.call_external_function(builder, func, fndesc.argtypes, [x])
    len_x = builder.trunc(strlen_x, lc.Type.int(32))
    iv.len = len_x
    iv.ptr = x
    return iv._getvalue()
コード例 #5
0
def StringVal_ctor(context, builder, sig, args):
    """StringVal(ntypes.string)"""
    [x] = args
    iv = StringValStruct(context, builder)
    _set_is_null(builder, iv, cgutils.false_bit)
    fndesc = lowering.ExternalFunctionDescriptor(
        'strlen', ntypes.uintp, [ntypes.CPointer(ntypes.char)])
    func = context.declare_external_function(cgutils.get_module(builder),
                                             fndesc)
    strlen_x = context.call_external_function(builder, func, fndesc.argtypes,
                                              [x])
    len_x = builder.trunc(strlen_x, lc.Type.int(32))
    iv.len = len_x
    iv.ptr = x
    return iv._getvalue()
コード例 #6
0
 def get_constant_struct(self, builder, ty, val):
     # override for converting literals to *Vals, incl. None
     if ty in self._impala_types and val is None:
         iv = TYPE_LAYOUT[ty](self, builder)
         _set_is_null(builder, iv, cgutils.true_bit)
         return iv._getvalue()
     elif ty == BooleanVal:
         const = lc.Constant.int(lc.Type.int(8), val)
         return BooleanVal_ctor(self, builder, None, [const])
     elif ty == TinyIntVal:
         const = lc.Constant.int(lc.Type.int(8), val)
         return TinyIntVal_ctor(self, builder, None, [const])
     elif ty == SmallIntVal:
         const = lc.Constant.int(lc.Type.int(16), val)
         return SmallIntVal_ctor(self, builder, None, [const])
     elif ty == IntVal:
         const = lc.Constant.int(lc.Type.int(32), val)
         return IntVal_ctor(self, builder, None, [const])
     elif ty == BigIntVal:
         const = lc.Constant.int(lc.Type.int(64), val)
         return BigIntVal_ctor(self, builder, None, [const])
     elif ty == FloatVal:
         const = lc.Constant.real(lc.Type.float(), val)
         return FloatVal_ctor(self, builder, None, [const])
     elif ty == DoubleVal:
         const = lc.Constant.real(lc.Type.double(), val)
         return DoubleVal_ctor(self, builder, None, [const])
     elif ty == StringVal:
         iv = StringValStruct(self, builder)
         _set_is_null(builder, iv, cgutils.false_bit)
         iv.len = lc.Constant.int(lc.Type.int(32), len(val))
         iv.ptr = self.get_constant_string(builder, ntypes.string, val)
         return iv._getvalue()
     else:
         return super(ImpalaTargetContext,
                      self).get_constant_struct(builder, ty, val)