def subscribe(module): return ir.Function( module, ir.FunctionType( layout.ObjectPtrType(), [layout.ObjectPtrType(), ir.IntType(32)], var_arg=True), subscribe_function)
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()
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
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])
def return_and_collect(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]), return_and_collect_function)
def negation(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]), negation_function)
def copy(module): return ir.Function( module, ir.FunctionType(ir.VoidType(), [layout.ObjectPtrType(), layout.ObjectPtrType()]), copy_function)
def assign_empty(module): return ir.Function(module, ir.FunctionType(layout.ObjectPtrType(), []), assign_empty_function)
def assign_concatenation(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [ir.IntType(32)], var_arg=True), assign_concatenation_function)
def assign_string(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [ir.PointerType(ir.IntType(8))]), assign_string_function)
def assign_int(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [ir.IntType(32)]), assign_int_function)
def assign_object(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]), assign_object_function)
def div_(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType(), layout.ObjectPtrType()]), div_function)
def meq(module): return ir.Function( module, ir.FunctionType(ir.IntType(8), [layout.ObjectPtrType(), layout.ObjectPtrType()]), meq_function)
def length(module): return ir.Function( module, ir.FunctionType(layout.ObjectPtrType(), [layout.ObjectPtrType()]), length_function)
def base_output(module): return ir.Function( module, ir.FunctionType(ir.VoidType(), [layout.ObjectPtrType()]), output_function)
def base_input(module): return ir.Function(module, ir.FunctionType(layout.ObjectPtrType(), []), input_function)
def alloc_global(module): return ir.Function(module, ir.FunctionType(layout.ObjectPtrType(), []), alloc_global_function)