Example #1
0
    def testCreateVectorType(self):
        ty = Type.int8()
        a = Type.vector(ty, 2)
        self.assertEqual(2, a.vector_size())

        t = a.element_type()
        self.assertEqual(ty.name, t.name)
Example #2
0
    def testCreateVectorType(self):
        ty = Type.int8()
        a = Type.vector(ty, 2)
        self.assertEqual(2, a.vector_size())

        t = a.element_type()
        self.assertEqual(ty.name, t.name)
Example #3
0
def add4impl(lfunc):
    '''For LLVMBackend, the implementation receives an empty
    llvm.core.Function to begin implementation.
    '''
    bb = lfunc.append_basic_block('entry')
    builder = Builder.new(bb)
    arg0, arg1 = lfunc.args
    pvty = Type.pointer(Type.vector(Type.float(), 4))
    v0 = builder.load(builder.bitcast(arg0, pvty))
    v1 = builder.load(builder.bitcast(arg1, pvty))
    vs = builder.fadd(v0, v1)
    builder.store(vs, builder.bitcast(arg0, pvty))
    builder.ret_void()
Example #4
0
def llvm_type(type, memo=None):
    if memo is None:
        memo = {}
    if hashable(type) and type in memo:
        return memo[type]

    ty = type.__class__
    if ty == Boolean:
        result = Type.int(1)
    elif ty == Integral:
        result = Type.int(type.bits)
    elif type == Float32:
        result = Type.float()
    elif type == Float64:
        result = Type.double()
    elif ty == Array:
        result = Type.array(llvm_type(type.base, memo), type.count)
    elif ty == Vector:
        result = Type.vector(llvm_type(type.base, memo), type.count)
    elif ty == Struct:
        result = handle_struct(type, memo)
    elif ty == Pointer:
        if type.base.is_void:
            return Type.pointer(Type.int(8))
        result = Type.pointer(llvm_type(type.base, memo))
    elif ty == Function:
        result = Type.function(
            llvm_type(type.restype, memo),
            [llvm_type(argtype, memo) for argtype in type.argtypes],
            var_arg=type.varargs)
    elif ty == VoidT:
        result = Type.void()
    else:
        raise TypeError("Cannot convert type %s" % (type,))

    memo[type] = result
    return result
Example #5
0
PY3 = bool(sys.version_info[0] == 3)

#------------------------------------------------------------------------
# LLVM Types
#------------------------------------------------------------------------

ptrsize = ctypes.sizeof(ctypes.c_void_p)

int_type   = lc.Type.int()
float_type = lc.Type.double()
bool_type  = lc.Type.int(1)
void_type  = lc.Type.void()
char_type  = lc.Type.int(8)

vec_type = lambda width, elt_type: Type.vector(elt_type, width)

pointer = Type.pointer

any_type = pointer(Type.int(ptrsize))
string_type = pointer(char_type)

# naive array
array_type = lambda elt_type: Type.struct([
    pointer(elt_type), # data      | (<type>)*
    int_type,          # nd        | int
    pointer(int_type), # strides   | int*
], name='ndarray_' + str(elt_type))

intp_type = Type.pointer(int_type)
Example #6
0
 def value(self, backend):
     '''Representation when used in a function and as a return value.
         '''
     return Type.pointer(Type.vector(Type.float(), 4))
Example #7
0
def vector(ty, ct):
    return Type.vector(ty, 4)
Example #8
0
def vector(ty, ct):
    return Type.vector(ty, 4)