Пример #1
0
class RuntimeLowering(object):
    """
    Lower assembly Operations into runtime calls, e.g.
        Op("thread_start") -> Op("call", "thread_start", [])
    """
    def __init__(self, func):
        self.mod = func.module
        self.builder = Builder(func)
        self.func = func

    def lower_ops_into_runtime(self, names, insert_decl=False):
        """Lower all ops listed in `names` into runtime calls"""
        names = set(names)
        for op in self.func.ops:
            if op.opcode in names:
                self.lower_into_runtime(op, insert_decl)

    def lower_into_runtime(self, op, insert_decl=False):
        """
        Lower op into a runtime call.

        :param decl: Whether to insert an external declaration if not present
        """
        _verify_args(op)
        if insert_decl and not self.mod.get_global(op.opcode):
            signature = types.Function(op.type, [arg.type for arg in op.args],
                                       False)
            self.mod.add_global(
                GlobalValue(op.opcode, signature, external=True))

        call = self.builder.gen_call_external(op.opcode, op.args, op.result)
        op.replace(call)
Пример #2
0
class RuntimeLowering(object):
    """
    Lower assembly Operations into runtime calls, e.g.
        Op("thread_start") -> Op("call", "thread_start", [])
    """

    def __init__(self, func):
        self.mod = func.module
        self.builder = Builder(func)
        self.func = func

    def lower_ops_into_runtime(self, names, insert_decl=False):
        """Lower all ops listed in `names` into runtime calls"""
        names = set(names)
        for op in self.func.ops:
            if op.opcode in names:
                self.lower_into_runtime(op, insert_decl)

    def lower_into_runtime(self, op, insert_decl=False):
        """
        Lower op into a runtime call.

        :param decl: Whether to insert an external declaration if not present
        """
        _verify_args(op)
        if insert_decl and not self.mod.get_global(op.opcode):
            signature = types.Function(op.type, [arg.type for arg in op.args])
            self.mod.add_global(GlobalValue(op.opcode, signature, external=True))

        call = self.builder.gen_call_external(op.opcode, op.args, op.result)
        op.replace(call)
Пример #3
0
class LowerConversions(object):

    def __init__(self, func, conversion_table):
        self.conversion_table = conversion_table
        self.builder = Builder(func)

    def op_convert(self, op):
        arg = op.args[0]
        if (op.type, arg.type) in self.conversion_table:
            funcname = self.conversion_table[op.type, arg.type]
            return self.builder.gen_call_external(funcname, [arg])