示例#1
0
    def test_opaque(self):
        # Create an opaque type
        ts = Type.opaque("mystruct")
        self.assertTrue("type opaque" in str(ts))
        self.assertTrue(ts.is_opaque)
        self.assertTrue(ts.is_identified)
        self.assertFalse(ts.is_literal)
        # print(ts)

        # Create a recursive type
        ts.set_body([Type.int(), Type.pointer(ts)])

        self.assertEqual(ts.elements[0], Type.int())
        self.assertEqual(ts.elements[1], Type.pointer(ts))
        self.assertEqual(ts.elements[1].pointee, ts)
        self.assertFalse(ts.is_opaque)  # is not longer a opaque type
        # print(ts)

        with self.assertRaises(llvm.LLVMException):
            # Cannot redefine
            ts.set_body([])
示例#2
0
    def test_opaque(self):
        # Create an opaque type
        ts = Type.opaque('mystruct')
        self.assertTrue('type opaque' in str(ts))
        self.assertTrue(ts.is_opaque)
        self.assertTrue(ts.is_identified)
        self.assertFalse(ts.is_literal)
        #print(ts)

        # Create a recursive type
        ts.set_body([Type.int(), Type.pointer(ts)])

        self.assertEqual(ts.elements[0], Type.int())
        self.assertEqual(ts.elements[1], Type.pointer(ts))
        self.assertEqual(ts.elements[1].pointee, ts)
        self.assertFalse(ts.is_opaque)  # is not longer a opaque type
        #print(ts)

        with self.assertRaises(llvm.LLVMException):
            # Cannot redefine
            ts.set_body([])
示例#3
0
def handle_struct(type, memo):
    # Check the cache with a hashable struct type
    key = type

    if key in memo:
        return memo[key]
    if key in opaque_memo:
        return opaque_memo[key]

    # Allocate and pre-order cache dummy struct
    struct_type = Type.opaque('dummy_struct_type')
    memo[key] = struct_type
    opaque_memo[key] = struct_type

    # Process fields and re-cache
    fields = [llvm_type(ftype, memo) for ftype in type.types]
    result = Type.struct(fields)
    struct_type.set_body([result])

    memo[key] = result
    opaque_memo[key] = result

    return result
示例#4
0
char_type  = Type.int(8)

pointer = Type.pointer

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

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

# opaque for now
blaze_type = lambda datashape: Type.opaque(name="blaze")

#------------------------------------------------------------------------
# Constants
#------------------------------------------------------------------------

false = Constant.int(bool_type, 0)
true  = Constant.int(bool_type, 1)
zero  = Constant.int(int_type, 0)

#------------------------------------------------------------------------
# Type Relations
#------------------------------------------------------------------------

typemap = {
    'int'    : int_type,
示例#5
0

import llvm.core as llc
from llvm.core import Type as lltype  

ty_void = lltype.void()
ty_int8 = lltype.int(8)
ty_int16 = lltype.int(16) 
ty_int32 = lltype.int(32) 
ty_int64 = lltype.int(64) 


ty_float32 = lltype.float()
ty_float64 = lltype.double()

ty_pyobj = lltype.opaque("PyObj")
ty_ptr_pyobj = lltype.pointer(ty_pyobj)

ty_ptr_int8 = lltype.pointer(ty_int8)
ty_ptr_int16 = lltype.pointer(ty_int16)
ty_ptr_int32 = lltype.pointer(ty_int32)
ty_ptr_int64 = lltype.pointer(ty_int64)

ty_ptr_float32 = lltype.pointer(ty_float32)
ty_ptr_float64 = lltype.pointer(ty_float64)

python_to_lltype_mappings = {
  np.int8 : ty_int8,             
  np.int16 : ty_int16, 
  np.int32 : ty_int32, 
  np.int64 : ty_int64, 
示例#6
0
 def test_opaque_with_no_name(self):
     with self.assertRaises(llvm.LLVMException):
         Type.opaque('')
示例#7
0
pointer = Type.pointer

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

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

# opaque for now
blaze_type = lambda datashape: Type.opaque(name="blaze")

#------------------------------------------------------------------------
# Constants
#------------------------------------------------------------------------

false = Constant.int(bool_type, 0)
true = Constant.int(bool_type, 1)
zero = Constant.int(int_type, 0)

#------------------------------------------------------------------------
# Type Relations
#------------------------------------------------------------------------

typemap = {
    'int': int_type,
示例#8
0
 def test_opaque_with_no_name(self):
     with self.assertRaises(llvm.LLVMException):
         Type.opaque("")
示例#9
0
'''
Implementations of built-in functions in Pascal-86.
'''

from . import symtab as s
from . import log

from llvm import core
from llvm.core import Type
from llvm.core import Constant
from llvm_cbuilder import CDefinition
from llvm_cbuilder import CTemp
from llvm_cbuilder import CVar


mutant_t = Type.opaque('P86.mutant_t')
mutant_t.set_body([Type.int(32), Type.pointer(Type.int(8)),
                  Type.pointer(mutant_t)])


class New(CDefinition):
    '''
    Allocate heap memory
    '''
    _name_ = 'P86.new'
    _retty_ = Type.void()
    _argtys_ = [('ptr', Type.pointer(Type.pointer(Type.int(8)))),
                ('length', Type.int(32))]

    def body(self, ptr, length):
        mem = self.builder.malloc_array(Type.int(8), length.value)