Exemple #1
0
def rewrite_externs(func, env):
    """Rewrite external symbol references

    Base on flypy.compiler.lower.constants.rewrite_constants
    """
    if env['flypy.state.opaque']:
        return
    target = env['flypy.target']
    # For each operation
    for op in func.ops:
        # Only for call operation
        if op.opcode == 'call':
            # For each constant
            constants = ir.collect_constants(op)
            new_constants = []
            for c in constants:
                extern = c.const

                if extern_support.is_extern_symbol(extern):
                    # Make a declare-only function
                    argtypes = extern.type.argtypes
                    restype = extern.type.restype

                    if target == "cpu":
                        # Install external symbol for CPU target
                        extern.install()

                    functype = ptypes.Function(lltype(restype),
                                               [lltype(t) for t in argtypes],
                                               extern.type.varargs)
                    # Note: Global value should really be part inserted into
                    # a module.  But there are no module support at this point.
                    replacment = ir.GlobalValue(extern.name, functype,
                                                external=True)
                else:
                    # No change
                    replacment = c
                # Add replacement
                new_constants.append(replacment)
            # Replace
            ir.substitute_args(op, constants, new_constants)
Exemple #2
0
def rewrite_externs(func, env):
    """Rewrite external symbol references

    Base on flypy.compiler.lower.constants.rewrite_constants
    """
    if env["flypy.state.opaque"]:
        return
    target = env["flypy.target"]
    # For each operation
    for op in func.ops:
        # Only for call operation
        if op.opcode == "call":
            # For each constant
            constants = ir.collect_constants(op)
            new_constants = []
            for c in constants:
                extern = c.const

                if extern_support.is_extern_symbol(extern):
                    # Make a declare-only function
                    argtypes = extern.type.argtypes
                    restype = extern.type.restype

                    if target == "cpu":
                        # Install external symbol for CPU target
                        extern.install()

                    functype = ptypes.Function(lltype(restype), [lltype(t) for t in argtypes], extern.type.varargs)
                    # Note: Global value should really be part inserted into
                    # a module.  But there are no module support at this point.
                    replacment = ir.GlobalValue(extern.name, functype, external=True)
                else:
                    # No change
                    replacment = c
                # Add replacement
                new_constants.append(replacment)
            # Replace
            ir.substitute_args(op, constants, new_constants)
Exemple #3
0
def ptrcast(builder, argtypes, value, type):
    valtype, typetype = argtypes # e.g. `int, Type[double]`
    type = typetype.parameters[0]
    result = builder.ptrcast(lltype(type), value)
    builder.ret(result)
Exemple #4
0
def convert_impl(builder, argtypes, value, type):
    valtype, typetype = argtypes # e.g. `int, Type[double]`
    type = typetype.parameters[0]
    result = builder.convert(lltype(type), value)
    builder.ret(result)
Exemple #5
0
def result_type(argtypes):
    return lltype(argtypes[1].parameters[0])
Exemple #6
0
def result_type(argtypes):
    return lltype(argtypes[1].parameters[0])
Exemple #7
0
def ptrcast(builder, argtypes, value, type):
    valtype, typetype = argtypes  # e.g. `int, Type[double]`
    type = typetype.parameters[0]
    result = builder.ptrcast(lltype(type), value)
    builder.ret(result)
Exemple #8
0
def convert_impl(builder, argtypes, value, type):
    valtype, typetype = argtypes  # e.g. `int, Type[double]`
    type = typetype.parameters[0]
    result = builder.convert(lltype(type), value)
    builder.ret(result)
Exemple #9
0
def restype_undef(argtypes):
    type = argtypes[0]
    if type.impl == Type:
        type = type.parameters[0]
    (restype,) = type
    return lltype(restype)
Exemple #10
0
    def __nonzero__(self):
        return True

    @staticmethod
    def toobject(obj, type):
        return type.parameters[0]


@jit('Constructor[a]')
class Constructor(object):
    layout = [] #('ctor', 'a')]

    @cjit('Constructor[a] -> Type[b] -> c',
          opaque=True, infer_restype=index_type)
    def __getitem__(self, item):
        raise NotImplementedError

    @cjit('a -> bool')
    def __nonzero__(self):
        return True

#===------------------------------------------------------------------===
# Low-level Implementation
#===------------------------------------------------------------------===

def firstarg(builder, argtypes, *args):
    builder.ret(args[0])

add_impl_cls(Constructor, "__getitem__", firstarg,
             restype_func=lambda argtypes: lltype(argtypes[1]))
Exemple #11
0
 def impl(builder, argtypes, *args):
     [ty] = argtypes
     lty = lltype(ty)
     return builder.ret(builder.call_math(lty, mathname, list(args)))
Exemple #12
0
 def impl(builder, argtypes, *args):
     [ty] = argtypes
     lty = lltype(ty)
     return builder.ret(builder.call_math(lty, mathname, list(args)))
Exemple #13
0
def restype_undef(argtypes):
    type = argtypes[0]
    if type.impl == Type:
        type = type.parameters[0]
    (restype, ) = type
    return lltype(restype)