Exemple #1
0
def copy_module(module, temper=None):
    raise NotImplementedError("not finished, needs to insert all functions"
                              "in valuemap first")

    new_module = Module(temper=temper)
    valuemap = {}

    ### Copy Globals
    for name, gv in module.globals.iteritems():
        name = new_module.temp(name)
        new_global = GlobalValue(name, gv.type, gv.external, gv.address,
                                 gv.value)
        new_module.add_global(new_global)

        valuemap[gv] = new_global

    ### Copy Functions
    for name, func in module.functions.iteritems():
        new_func, _ = copy_function(func, module=new_module)
        new_func.name = new_module.temp(name)
        new_module.add_function(new_func)

        valuemap[func] = new_func

    return new_module
Exemple #2
0
 def assign(self, varname, rhs):
     if self.in_function:
         # Local variable
         type = self.local_vars[varname]
         self.assignvar(varname, self.visit(rhs, type=type))
     else:
         # Global variable
         type = self.global_vars[varname]
         self.mod.add_global(
             GlobalValue(varname,
                         type=self.type,
                         value=self.visit(rhs, type=type)))
Exemple #3
0
    def visit_Decl(self, decl):
        if decl.name in self.vars:
            error(decl, "Var '%s' already declared!" % (decl.name, ))

        type = self.visit(decl.type)
        self.vars[decl.name] = type
        if decl.init:
            self.assign(decl.name, decl.init)
        elif not self.in_function:
            extern = decl.storage == 'external'
            self.mod.add_global(GlobalValue(decl.name, type, external=extern))

        return type
Exemple #4
0
    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)
Exemple #5
0
def _build_global(type, args):
    return GlobalValue(args[1], args[3])