Exemple #1
0
def representation_type(ty):
    """
    Get the low-level representation type for a high-level (user-defined) type.

    Returns
    =======
    The pykit type for the object layout.
    """

    from flypy.lib import vectorobject
    from flypy.lib import arrayobject
    from flypy.runtime.obj import pointerobject

    # NOTE: special cases should be kept to an absolute minimum here. They
    #       should probably be introduced only if ctypes cannot represent the
    #       type
    if ty.impl == vectorobject.Vector:
        base, count = ty.parameters
        return ptypes.Vector(representation_type(base), count)
    elif ty.impl == pointerobject.Pointer:
        # type pointed to may not be supported by ctypes
        (base, ) = ty.parameters
        if base.impl == vectorobject.Vector:
            return ptypes.Pointer(representation_type(base))

    cty = conversion.ctype(ty)
    result_type = ctypes_support.from_ctypes_type(cty)

    # struct uses pointer
    if result_type.is_struct:
        result_type = ptypes.Pointer(result_type)

    return result_type
Exemple #2
0
def implement_from_array(builder, argtypes, parray):
    base, count = argtypes[0]
    vector_type = ptypes.Vector(base, count)
    ptr_type = ptypes.Pointer(vector_type)
    pv = builder.bitcast(parray, ptr_type)
    v = builder.ptrload(p)
    return builder.ret(v)
Exemple #3
0
 def shufflevector(self, vec1, vec2, mask, **kwds):
     assert vec1.type.is_vector
     if vec2:
         assert vec2.type == vec1.type
     assert mask.type.is_vector
     assert mask.type.base.is_int
     restype = types.Vector(vec1.type.base, mask.type.count)
     return super(OpBuilder, self).shufflevector(restype, vec1, vec2, mask,
                                                 **kwds)
Exemple #4
0
    def test_unit(self):
        self.assertEqual(types.Void, types.Void)
        self.assertEqual(types.Bool, types.Bool)
        self.assertEqual(types.Int32, types.Int32)
        self.assertEqual(types.Float32, types.Float32)
        self.assertEqual(types.Pointer(types.Int32),
                         types.Pointer(types.Int32))
        self.assertEqual(types.Vector(types.Int32, 4),
                         types.Vector(types.Int32, 4))


        self.assertNotEqual(types.Void, types.Bool)
        self.assertNotEqual(types.Pointer(types.Void),
                            types.Pointer(types.Bool))
        self.assertNotEqual(types.Vector(types.Int32, 4),
                            types.Vector(types.Int32, 5))
        self.assertNotEqual(types.Vector(types.Int32, 4),
                            types.Vector(types.Int64, 4))
Exemple #5
0
def restype_from_int(argtypes):
    (bits, ), count = argtypes[0]
    base_t = argtypes[1]
    assert bits % base_t.bits == 0
    return ptypes.Vector(base_t, bits / base_t.bits)
Exemple #6
0
def restype_from_array(argtypes):
    base, count = argtypes[0]
    return ptypes.Vector(base, count)