[pypy-commit] pypy llimpl: Create rtyper.backend and use it to choose the implementation when using register_external()
rlamy
pypy.commits at gmail.com
Sun Feb 7 13:41:28 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: llimpl
Changeset: r82108:cea1893831f4
Date: 2016-02-07 18:40 +0000
http://bitbucket.org/pypy/pypy/changeset/cea1893831f4/
Log: Create rtyper.backend and use it to choose the implementation when
using register_external()
diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py
--- a/rpython/memory/test/test_transformed_gc.py
+++ b/rpython/memory/test/test_transformed_gc.py
@@ -14,6 +14,7 @@
from rpython.conftest import option
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rarithmetic import LONG_BIT
+from rpython.rtyper.rtyper import llinterp_backend
WORD = LONG_BIT // 8
@@ -29,9 +30,11 @@
t.config.set(**extraconfigopts)
ann = t.buildannotator()
ann.build_types(func, inputtypes)
+ rtyper = t.buildrtyper()
+ rtyper.backend = llinterp_backend
if specialize:
- t.buildrtyper().specialize()
+ rtyper.specialize()
if backendopt:
from rpython.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py
--- a/rpython/rtyper/extfunc.py
+++ b/rpython/rtyper/extfunc.py
@@ -1,3 +1,4 @@
+from rpython.tool.sourcetools import func_with_new_name
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr, _ptr
from rpython.annotator.model import unionof
@@ -33,6 +34,7 @@
return self.signature_result
def specialize_call(self, hop):
+ from rpython.rtyper.rtyper import llinterp_backend
rtyper = hop.rtyper
signature_args = self.normalize_args(*hop.args_s)
args_r = [rtyper.getrepr(s_arg) for s_arg in signature_args]
@@ -49,14 +51,18 @@
if isinstance(impl, _ptr):
obj = impl
else:
- # store some attributes to the 'impl' function, where
- # the eventual call to rtyper.getcallable() will find them
- # and transfer them to the final lltype.functionptr().
- impl._llfnobjattrs_ = {'_name': self.name}
- if hasattr(self, 'lltypefakeimpl'):
- impl._llfnobjattrs_['_fakeimpl'] = fakeimpl
- obj = rtyper.getannmixlevel().delayedfunction(
- impl, signature_args, hop.s_result)
+ if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend:
+ FT = FuncType(args_ll, ll_result)
+ obj = functionptr(FT, name, _external_name=self.name,
+ _callable=fakeimpl,
+ _safe_not_sandboxed=self.safe_not_sandboxed)
+ else:
+ # store some attributes to the 'impl' function, where
+ # the eventual call to rtyper.getcallable() will find them
+ # and transfer them to the final lltype.functionptr().
+ impl._llfnobjattrs_ = {'_name': self.name}
+ obj = rtyper.getannmixlevel().delayedfunction(
+ impl, signature_args, hop.s_result)
else:
FT = FuncType(args_ll, ll_result)
obj = functionptr(FT, name, _external_name=self.name,
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -32,11 +32,24 @@
from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline
+class RTyperBackend(object):
+ pass
+
+class GenCBackend(RTyperBackend):
+ pass
+genc_backend = GenCBackend()
+
+class LLInterpBackend(RTyperBackend):
+ pass
+llinterp_backend = LLInterpBackend()
+
+
class RPythonTyper(object):
from rpython.rtyper.rmodel import log
- def __init__(self, annotator):
+ def __init__(self, annotator, backend=genc_backend):
self.annotator = annotator
+ self.backend = backend
self.lowlevel_ann_policy = LowLevelAnnotatorPolicy(self)
self.reprs = {}
self._reprs_must_call_setup = []
diff --git a/rpython/rtyper/test/test_llinterp.py b/rpython/rtyper/test/test_llinterp.py
--- a/rpython/rtyper/test/test_llinterp.py
+++ b/rpython/rtyper/test/test_llinterp.py
@@ -13,7 +13,7 @@
from rpython.rlib.rarithmetic import r_uint, ovfcheck
from rpython.tool import leakfinder
from rpython.conftest import option
-
+from rpython.rtyper.rtyper import llinterp_backend
# switch on logging of interp to show more info on failing tests
@@ -39,6 +39,7 @@
t.view()
global typer # we need it for find_exception
typer = t.buildrtyper()
+ typer.backend = llinterp_backend
typer.specialize()
#t.view()
t.checkgraphs()
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -913,6 +913,7 @@
return []
def new_funcnode(db, T, obj, forcename=None):
+ from rpython.rtyper.rtyper import llinterp_backend
if db.sandbox:
if (getattr(obj, 'external', None) is not None and
not obj._safe_not_sandboxed):
@@ -934,6 +935,9 @@
return ExternalFuncNode(db, T, obj, name)
elif hasattr(obj._callable, "c_name"):
return ExternalFuncNode(db, T, obj, name) # this case should only be used for entrypoints
+ elif db.translator.rtyper.backend is llinterp_backend:
+ # on llinterp, anything goes
+ return ExternalFuncNode(db, T, obj, name)
else:
raise ValueError("don't know how to generate code for %r" % (obj,))
More information about the pypy-commit
mailing list