Exemple #1
0
def subscribe(module):
    return ir.Function(
        module,
        ir.FunctionType(
            layout.ObjectPtrType(),
            [layout.ObjectPtrType(), ir.IntType(32)],
            var_arg=True), subscribe_function)
Exemple #2
0
    def codegen(self, builder: IRBuilder, ctx: Context):
        fnTy = ir.FunctionType(layout.ObjectPtrType(),
                               [layout.ObjectPtrType() for arg in self.args])
        fun = ir.Function(ctx.module, fnTy, name=self.name)
        ctx.parameters = dict(zip(self.args, fun.args))
        ctx.start_function(fun)

        top = fun.append_basic_block()
        builder.position_at_end(top)
        ctx.label = top
        for child in self.children:
            child.codegen(builder, ctx)

        ctx.end_function()
Exemple #3
0
 def codegen(self, builder: IRBuilder, ctx: Context):
     if ctx.is_global(self.name):
         if ctx.global_exists(self.name):
             gv = ctx.get_global(self.name)
             # Se e' globale e gia' esiste, carico l'oggetto dall'indirizzo della globale
             return builder.load(gv)
         else:
             gv = ir.GlobalVariable(ctx.module, layout.ObjectPtrType(),
                                    self.name)
             gv.linkage = "internal"
             address = builder.call(
                 ctx.get_function(fn.alloc_global_function), [])
             builder.store(address, gv)
             ctx.set_global(self.name, gv)
             # Se e' globale ma non esiste, la creo A = object**, alloco un B = object, ne prendo l'indirizzo e lo salvo dentro (*B = &A)
             return address
     else:
         var = ctx.get_variable(self.name)
         if var is None:
             raise UnknownVariableError(self.name)
         return var
Exemple #4
0
    def codegen(self, builder: IRBuilder, ctx: Context):
        self.check_children()
        if len(self.children) == 0:
            return  # Da vedere se fare un collect manuale

        value = self.children[0].codegen(builder, ctx)

        if ctx.is_global(self.name):
            dest = None
            if ctx.global_exists(self.name):
                gv = ctx.get_global(self.name)
                dest = builder.load(gv)
            else:
                # Se e' globale e non esiste, la creo su LLVM, poi la assegno un valore creato con alloc_global
                gv = ir.GlobalVariable(ctx.module, layout.ObjectPtrType(),
                                       self.name)
                gv.linkage = "internal"
                address = builder.call(
                    ctx.get_function(fn.alloc_global_function), [])
                ctx.set_global(self.name, gv)
                builder.store(address, gv)
                dest = address
            f = ctx.get_function(fn.copy_function)
            builder.call(f, [value, dest])
        elif not ctx.variable_exists(self.name):
            dest = None
            if isinstance(self.children[0], ReferenceNode):
                f = ctx.get_function(fn.assign_object_function)
                dest = builder.call(f, [value])
            else:
                dest = value
            ctx.set_variable(self.name, dest)
        else:
            if ctx.is_parameter(self.name):
                raise ParameterReferenceError(self.name)
            dest = ctx.get_variable(self.name)
            f = ctx.get_function(fn.copy_function)
            builder.call(f, [value, dest])
Exemple #5
0
def return_and_collect(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]),
        return_and_collect_function)
Exemple #6
0
def negation(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]),
        negation_function)
Exemple #7
0
def copy(module):
    return ir.Function(
        module,
        ir.FunctionType(ir.VoidType(),
                        [layout.ObjectPtrType(),
                         layout.ObjectPtrType()]), copy_function)
Exemple #8
0
def assign_empty(module):
    return ir.Function(module, ir.FunctionType(layout.ObjectPtrType(), []),
                       assign_empty_function)
Exemple #9
0
def assign_concatenation(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(), [ir.IntType(32)],
                        var_arg=True), assign_concatenation_function)
Exemple #10
0
def assign_string(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(),
                        [ir.PointerType(ir.IntType(8))]),
        assign_string_function)
Exemple #11
0
def assign_int(module):
    return ir.Function(
        module, ir.FunctionType(layout.ObjectPtrType(), [ir.IntType(32)]),
        assign_int_function)
Exemple #12
0
def assign_object(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]),
        assign_object_function)
Exemple #13
0
def div_(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(),
                        [layout.ObjectPtrType(),
                         layout.ObjectPtrType()]), div_function)
Exemple #14
0
def meq(module):
    return ir.Function(
        module,
        ir.FunctionType(ir.IntType(8),
                        [layout.ObjectPtrType(),
                         layout.ObjectPtrType()]), meq_function)
Exemple #15
0
def length(module):
    return ir.Function(
        module,
        ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]),
        length_function)
Exemple #16
0
def base_output(module):
    return ir.Function(
        module, ir.FunctionType(ir.VoidType(), [layout.ObjectPtrType()]),
        output_function)
Exemple #17
0
def base_input(module):
    return ir.Function(module, ir.FunctionType(layout.ObjectPtrType(), []),
                       input_function)
Exemple #18
0
def alloc_global(module):
    return ir.Function(module, ir.FunctionType(layout.ObjectPtrType(), []),
                       alloc_global_function)