Author: Ronan Lamy <[email protected]>
Branch: exctrans
Changeset: r81388:c5365dc26aa4
Date: 2015-12-19 02:55 +0100
http://bitbucket.org/pypy/pypy/changeset/c5365dc26aa4/
Log: Wrap FunctionCodeGenerator constructor in a factory function
+ Move some of its side-effecting code there
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -18,6 +18,16 @@
KEEP_INLINED_GRAPHS = False
+def make_funcgen(graph, db, exception_policy=None, functionname=None):
+ graph._seen_by_the_backend = True
+ # apply the exception transformation
+ if db.exctransformer:
+ db.exctransformer.create_exception_handling(graph)
+ # apply the gc transformation
+ if db.gctransformer:
+ db.gctransformer.transform_graph(graph)
+ return FunctionCodeGenerator(graph, db, exception_policy, functionname)
+
class FunctionCodeGenerator(object):
"""
Collects information about a function which we have to generate
@@ -25,21 +35,13 @@
"""
def __init__(self, graph, db, exception_policy=None, functionname=None):
- graph._seen_by_the_backend = True
self.graph = graph
self.db = db
self.gcpolicy = db.gcpolicy
self.exception_policy = exception_policy
self.functionname = functionname
- # apply the exception transformation
- if self.db.exctransformer:
- self.db.exctransformer.create_exception_handling(self.graph)
- # apply the gc transformation
- if self.db.gctransformer:
- self.db.gctransformer.transform_graph(self.graph)
- #self.graph.show()
+
self.collect_var_and_types()
-
for v in self.vars:
T = v.concretetype
# obscure: skip forward references and hope for the best
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
@@ -3,7 +3,7 @@
Void, OpaqueType, Float, RuntimeTypeInfo, getRuntimeTypeInfo, Char,
_subarray)
from rpython.rtyper.lltypesystem import llmemory, llgroup
-from rpython.translator.c.funcgen import FunctionCodeGenerator
+from rpython.translator.c.funcgen import make_funcgen
from rpython.translator.c.support import USESLOTS # set to False if necessary
while refactoring
from rpython.translator.c.support import cdecl, forward_cdecl, somelettersfrom
from rpython.translator.c.support import c_char_array_constant, barebonearray
@@ -901,7 +901,7 @@
from rpython.translator.sandbox import rsandbox
graph = rsandbox.get_external_function_sandbox_graph(fnobj, db,
force_stub=True)
- return FunctionCodeGenerator(graph, db)
+ return make_funcgen(graph, db)
def sandbox_transform(fnobj, db):
# for --sandbox: replace a function like os_open_llimpl() with
@@ -909,7 +909,7 @@
# perform the operation.
from rpython.translator.sandbox import rsandbox
graph = rsandbox.get_external_function_sandbox_graph(fnobj, db)
- return FunctionCodeGenerator(graph, db)
+ return make_funcgen(graph, db)
def select_function_code_generators(fnobj, db, functionname):
sandbox = db.need_sandboxing(fnobj)
@@ -918,8 +918,7 @@
# apply the sandbox transformation
return sandbox_transform(fnobj, db)
exception_policy = getattr(fnobj, 'exception_policy', None)
- return FunctionCodeGenerator(
- fnobj.graph, db, exception_policy, functionname)
+ return make_funcgen(fnobj.graph, db, exception_policy, functionname)
elif getattr(fnobj, 'external', None) is not None:
if sandbox:
return sandbox_stub(fnobj, db)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit