Example #1
0
 def getentrypointptr(self):
     entrypoints = []
     bk = self.translator.annotator.bookkeeper
     for f, _ in self.functions:
         graph = bk.getdesc(f).getuniquegraph()
         entrypoints.append(getfunctionptr(graph))
     return entrypoints
Example #2
0
 def compress(self, signaturecodes, rtyper):
     """This returns sufficient information to be able to build the
     entries that will go in the global array of restart
     information."""
     if self.resume_point_count > 0:
         bk = rtyper.annotator.bookkeeper
         graph = self.func_or_graph
         if not isinstance(graph, FunctionGraph):
             graph = bk.getdesc(graph).getuniquegraph()
         funcptr = getfunctionptr(graph)
         FUNC = lltype.typeOf(funcptr).TO
         rettype_index = STORAGE_TYPES.index(storage_type(FUNC.RESULT))
         cache = signaturecodes[rettype_index]
         key = tuple([storage_type(ARG) for ARG in FUNC.ARGS])
         try:
             signature_index = cache[key]
         except KeyError:
             signature_index = len(cache) * (storage_type_bitmask + 1)
             signature_index |= rettype_index
             cache[key] = signature_index
         assert (signature_index & storage_type_bitmask) == rettype_index
         result = [(llmemory.cast_ptr_to_adr(funcptr), signature_index)]
         for i in range(1, self.resume_point_count):
             result.append((llmemory.NULL, i))
     else:
         result = []
     return result
Example #3
0
 def compress(self, signaturecodes, rtyper):
     """This returns sufficient information to be able to build the
     entries that will go in the global array of restart
     information."""
     if self.resume_point_count > 0:
         bk = rtyper.annotator.bookkeeper
         graph = self.func_or_graph
         if not isinstance(graph, FunctionGraph):
             graph = bk.getdesc(graph).getuniquegraph()
         funcptr = getfunctionptr(graph)
         FUNC = lltype.typeOf(funcptr).TO
         rettype_index = STORAGE_TYPES.index(storage_type(FUNC.RESULT))
         cache = signaturecodes[rettype_index]
         key = tuple([storage_type(ARG) for ARG in FUNC.ARGS])
         try:
             signature_index = cache[key]
         except KeyError:
             signature_index = len(cache) * (storage_type_bitmask+1)
             signature_index |= rettype_index
             cache[key] = signature_index
         assert (signature_index & storage_type_bitmask) == rettype_index
         result = [(llmemory.cast_ptr_to_adr(funcptr), signature_index)]
         for i in range(1, self.resume_point_count):
             result.append((llmemory.NULL, i))
     else:
         result = []
     return result
Example #4
0
 def getentrypointptr(self):
     entrypoints = []
     bk = self.translator.annotator.bookkeeper
     for f, _ in self.functions:
         graph = bk.getdesc(f).getuniquegraph()
         entrypoints.append(getfunctionptr(graph))
     return entrypoints
Example #5
0
 def handle_residual_call(self, op, newgraph, newnodes):
     fspecptr = getfunctionptr(newgraph)
     newargs = [Constant(fspecptr, concretetype=lltype.typeOf(fspecptr))]
     newargs += self.expand_nodes(newnodes)
     newresult = self.make_rt_result(op.result)
     newop = SpaceOperation('direct_call', newargs, newresult)
     return [newop]
Example #6
0
 def handle_residual_call(self, op, newgraph, newnodes):
     fspecptr = getfunctionptr(newgraph)
     newargs = [Constant(fspecptr,
                         concretetype=lltype.typeOf(fspecptr))]
     newargs += self.expand_nodes(newnodes)
     newresult = self.make_rt_result(op.result)
     newop = SpaceOperation('direct_call', newargs, newresult)
     return [newop]
Example #7
0
    def get_entry_point(self, func):
        assert func is not None
        self.entrypoint = func

        bk = self.translator.annotator.bookkeeper
        ptr = getfunctionptr(bk.getdesc(func).getuniquegraph())
        c = inputconst(lltype.typeOf(ptr), ptr)
        self.db.prepare_arg_value(c)
        self.entry_func_name = func.func_name
        return c.value._obj 
Example #8
0
    def build_database(self):
        translator = self.translator

        gcpolicyclass = self.get_gcpolicyclass()

        if self.config.translation.gcrootfinder == "asmgcc":
            if not self.standalone:
                raise NotImplementedError("--gcrootfinder=asmgcc requires standalone")

        if self.config.translation.stackless:
            if not self.standalone:
                raise Exception("stackless: only for stand-alone builds")
            
            from pypy.translator.stackless.transform import StacklessTransformer
            stacklesstransformer = StacklessTransformer(
                translator, self.originalentrypoint,
                stackless_gc=gcpolicyclass.requires_stackless)
            self.entrypoint = stacklesstransformer.slp_entry_point
        else:
            stacklesstransformer = None

        db = LowLevelDatabase(translator, standalone=self.standalone,
                              gcpolicyclass=gcpolicyclass,
                              stacklesstransformer=stacklesstransformer,
                              thread_enabled=self.config.translation.thread,
                              sandbox=self.config.translation.sandbox)
        self.db = db
        
        # give the gc a chance to register interest in the start-up functions it
        # need (we call this for its side-effects of db.get())
        list(db.gcpolicy.gc_startup_code())

        # build entrypoint and eventually other things to expose
        pf = self.getentrypointptr()
        if isinstance(pf, list):
            for one_pf in pf:
                db.get(one_pf)
            self.c_entrypoint_name = None
        else:
            pfname = db.get(pf)

            for func, _ in self.secondary_entrypoints:
                bk = translator.annotator.bookkeeper
                db.get(getfunctionptr(bk.getdesc(func).getuniquegraph()))

            self.c_entrypoint_name = pfname

        for obj in exports.EXPORTS_obj2name.keys():
            db.getcontainernode(obj)
        exports.clear()
        db.complete()

        self.collect_compilation_info(db)
        return db
Example #9
0
def test_malloc():
    S = GcStruct('testing', ('x', Signed), ('y', Signed))
    def ll_f(x):
        p = malloc(S)
        p.x = x
        p.y = x+1
        return p.x * p.y
    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t)
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Example #10
0
def test_malloc():
    S = GcStruct('testing', ('x', Signed), ('y', Signed))

    def ll_f(x):
        p = malloc(S)
        p.x = x
        p.y = x + 1
        return p.x * p.y

    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t)
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Example #11
0
    def build_database(self):
        translator = self.translator

        gcpolicyclass = self.get_gcpolicyclass()

        if self.config.translation.gcrootfinder == "asmgcc":
            if not self.standalone:
                raise NotImplementedError(
                    "--gcrootfinder=asmgcc requires standalone")

        db = LowLevelDatabase(translator,
                              standalone=self.standalone,
                              cpython_extension=self.cpython_extension,
                              gcpolicyclass=gcpolicyclass,
                              thread_enabled=self.config.translation.thread,
                              sandbox=self.config.translation.sandbox)
        self.db = db

        # give the gc a chance to register interest in the start-up functions it
        # need (we call this for its side-effects of db.get())
        list(db.gcpolicy.gc_startup_code())

        # build entrypoint and eventually other things to expose
        pf = self.getentrypointptr()
        if isinstance(pf, list):
            for one_pf in pf:
                db.get(one_pf)
            self.c_entrypoint_name = None
        else:
            pfname = db.get(pf)

            for func, _ in self.secondary_entrypoints:
                bk = translator.annotator.bookkeeper
                db.get(getfunctionptr(bk.getdesc(func).getuniquegraph()))

            self.c_entrypoint_name = pfname

        for obj in exports.EXPORTS_obj2name.keys():
            db.getcontainernode(obj)
        exports.clear()
        db.complete()

        self.collect_compilation_info(db)
        return db
Example #12
0
def test_multiple_malloc():
    S1 = GcStruct('testing1', ('x', Signed), ('y', Signed))
    S = GcStruct('testing', ('ptr1', Ptr(S1)),
                            ('ptr2', Ptr(S1)),
                            ('z', Signed))
    def ll_f(x):
        ptr1 = malloc(S1)
        ptr1.x = x
        ptr2 = malloc(S1)
        ptr2.x = x+1
        s = malloc(S)
        s.ptr1 = ptr1
        s.ptr2 = ptr2
        return s.ptr1.x * s.ptr2.x
    t, graph = makegraph(ll_f, [int])
    
    db = LowLevelDatabase(t)
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Example #13
0
def test_multiple_malloc():
    S1 = GcStruct('testing1', ('x', Signed), ('y', Signed))
    S = GcStruct('testing', ('ptr1', Ptr(S1)), ('ptr2', Ptr(S1)),
                 ('z', Signed))

    def ll_f(x):
        ptr1 = malloc(S1)
        ptr1.x = x
        ptr2 = malloc(S1)
        ptr2.x = x + 1
        s = malloc(S)
        s.ptr1 = ptr1
        s.ptr2 = ptr2
        return s.ptr1.x * s.ptr2.x

    t, graph = makegraph(ll_f, [int])

    db = LowLevelDatabase(t)
    db.get(getfunctionptr(graph))
    db.complete()
    dump_on_stdout(db)
Example #14
0
    def get_entry_point(self, func):
        assert func is not None
        self.entrypoint = func

        bk = self.translator.annotator.bookkeeper
        ptr = getfunctionptr(bk.getdesc(func).getuniquegraph())
        c = inputconst(lltype.typeOf(ptr), ptr)
        self.db.prepare_arg(c)

        # ensure unqiue entry node name for testing
        entry_node = self.db.obj2node[c.value._obj]
        name = entry_node.name
        if name in self.function_count:
            self.function_count[name] += 1
            Node.nodename_count[name] = self.function_count[name] + 1
            name += '_%d' % self.function_count[name]
            entry_node.name = name
        else:
            self.function_count[name] = 1

        self.entry_name = name[6:]
        return c.value._obj
Example #15
0
 def getentrypointptr(self):
     # XXX check that the entrypoint has the correct
     # signature:  list-of-strings -> int
     bk = self.translator.annotator.bookkeeper
     return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
Example #16
0
 def getentrypointptr(self):
     bk = self.translator.annotator.bookkeeper
     graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
     return [getfunctionptr(graph) for graph in graphs]
Example #17
0
def new_wrapper(func, translator, newname=None):
    # The basic idea is to produce a flow graph from scratch, using the
    # help of the rtyper for the conversion of the arguments after they
    # have been decoded.
    
    bk = translator.annotator.bookkeeper
    graph = bk.getdesc(func).getuniquegraph()

    f = getfunctionptr(graph)
    FUNCTYPE = typeOf(f).TO

    newops = LowLevelOpList(translator.rtyper)

    varguments = []
    for var in graph.startblock.inputargs:
        v = Variable(var)
        v.concretetype = PyObjPtr
        varguments.append(v)

    wrapper_inputargs = varguments[:]
    # use the rtyper to produce the conversions
    inputargs = f._obj.graph.getargs()
    for i in range(len(varguments)):
        if FUNCTYPE.ARGS[i] != PyObjPtr:
            rtyper = translator.rtyper
            r_arg = rtyper.bindingrepr(inputargs[i])
            # give the rtyper a chance to know which function we are wrapping
            rtyper.set_wrapper_context(func)
            varguments[i] = newops.convertvar(varguments[i],
                                              r_from = pyobj_repr,
                                              r_to = r_arg)
            rtyper.set_wrapper_context(None)

    vlist = [inputconst(typeOf(f), f)] + varguments
    vresult = newops.genop('direct_call', vlist, resulttype=FUNCTYPE.RESULT)

    if FUNCTYPE.RESULT != PyObjPtr:
        # convert "result" back to a PyObject
        rtyper = translator.rtyper
        assert rtyper is not None, (
            "needs the rtyper to perform function result conversions")
        r_result = rtyper.bindingrepr(f._obj.graph.getreturnvar())
        vresult = newops.convertvar(vresult,
                                    r_from = r_result,
                                    r_to = pyobj_repr)

    # "return result"
    block = Block(wrapper_inputargs)
    wgraph = FunctionGraph('pyfn_' + (newname or func.func_name), block)
    translator.update_call_graph(wgraph, graph, object())
    translator.graphs.append(wgraph)
    block.operations[:] = newops
    block.closeblock(Link([vresult], wgraph.returnblock))
    wgraph.getreturnvar().concretetype = PyObjPtr
    checkgraph(wgraph)

    # the above convertvar()s may have created and annotated new helpers
    # that need to be specialized now
    translator.rtyper.specialize_more_blocks()

    return functionptr(FuncType([PyObjPtr] * len(wrapper_inputargs),
                                PyObjPtr),
                       wgraph.name,
                       graph = wgraph,
                       exception_policy = "CPython")
Example #18
0
 def getentrypointptr(self):
     # XXX check that the entrypoint has the correct
     # signature:  list-of-strings -> int
     bk = self.translator.annotator.bookkeeper
     return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
Example #19
0
 def getentrypointptr(self):
     bk = self.translator.annotator.bookkeeper
     graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
     return [getfunctionptr(graph) for graph in graphs]