Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r48316:9a6c4ff948c1
Date: 2011-10-21 17:37 +0200
http://bitbucket.org/pypy/pypy/changeset/9a6c4ff948c1/
Log: (arigo, cfbolz): also split up the nonfuncnodes according to where
they are used. slightly obscure (just as the rest of the C backend)
diff --git a/pypy/translator/c/database.py b/pypy/translator/c/database.py
--- a/pypy/translator/c/database.py
+++ b/pypy/translator/c/database.py
@@ -176,7 +176,7 @@
# introduced by the GC transformer, or the type_info_table
return node
- def get(self, obj):
+ def get(self, obj, funcgen=None):
if isinstance(obj, CConstant):
return obj.c_name # without further checks
T = typeOf(obj)
@@ -228,6 +228,8 @@
return '((%s) %d)' % (cdecl(self.gettype(T), ''),
obj._obj)
node = self.getcontainernode(container)
+ if node._funccodegen_owner is None:
+ node._funccodegen_owner = funcgen
return node.getptrname()
else:
return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
@@ -284,14 +286,16 @@
finish_callbacks.append(('GC transformer: finished tables',
self.gctransformer.get_finish_tables()))
- def add_dependencies(newdependencies):
+ def add_dependencies(newdependencies, parent=None):
for value in newdependencies:
#if isinstance(value, _uninitialized):
# continue
if isinstance(typeOf(value), ContainerType):
- self.getcontainernode(value)
+ node = self.getcontainernode(value)
+ if parent and node._funccodegen_owner is not None:
+ node._funccodegen_owner = parent._funccodegen_owner
else:
- self.get(value)
+ self.get(value, parent and parent._funccodegen_owner)
while True:
while True:
@@ -303,7 +307,7 @@
if i == len(self.containerlist):
break
node = self.containerlist[i]
- add_dependencies(node.enum_dependencies())
+ add_dependencies(node.enum_dependencies(), node)
i += 1
self.completedcontainers = i
if i == show_i:
diff --git a/pypy/translator/c/gc.py b/pypy/translator/c/gc.py
--- a/pypy/translator/c/gc.py
+++ b/pypy/translator/c/gc.py
@@ -170,6 +170,7 @@
nodekind = 'refcnt rtti'
globalcontainer = True
typename = 'void (@)(void *)'
+ _funccodegen_owner = None
def __init__(self, db, T, obj):
assert T == RuntimeTypeInfo
@@ -266,6 +267,7 @@
nodekind = 'boehm rtti'
globalcontainer = True
typename = 'char @'
+ _funccodegen_owner = None
def __init__(self, db, T, obj):
assert T == RuntimeTypeInfo
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -682,8 +682,7 @@
def getbasecfilefornode(self, node, basecname):
# For FuncNode instances, use the python source filename (relative to
# the top directory):
- if hasattr(node.obj, 'graph'):
- g = node.obj.graph
+ def invent_nice_name(g):
# Lookup the filename from the function.
# However, not all FunctionGraph objs actually have a "func":
if hasattr(g, 'func'):
@@ -693,6 +692,15 @@
if pypkgpath:
relpypath = localpath.relto(pypkgpath)
return relpypath.replace('.py', '.c')
+ return None
+ if hasattr(node.obj, 'graph'):
+ name = invent_nice_name(node.obj.graph)
+ if name is not None:
+ return name
+ elif node._funccodegen_owner is not None:
+ name = invent_nice_name(node._funccodegen_owner.graph)
+ if name is not None:
+ return "data_" + name
return basecname
def splitnodesimpl(self, basecname, nodes, nextra, nbetween,
diff --git a/pypy/translator/c/node.py b/pypy/translator/c/node.py
--- a/pypy/translator/c/node.py
+++ b/pypy/translator/c/node.py
@@ -485,6 +485,7 @@
__slots__ = """db obj
typename implementationtypename
name
+ _funccodegen_owner
globalcontainer""".split()
eci_name = '_compilation_info'
@@ -509,6 +510,7 @@
if self.typename != self.implementationtypename:
if db.gettypedefnode(T).extra_union_for_varlength:
self.name += '.b'
+ self._funccodegen_owner = None
def getptrname(self):
return '(&%s)' % self.name
@@ -842,6 +844,9 @@
if self.funcgens:
argnames = self.funcgens[0].argnames() #Assume identical for all
funcgens
self.implementationtypename = self.db.gettype(self.T,
argnames=argnames)
+ self._funccodegen_owner = self.funcgens[0]
+ else:
+ self._funccodegen_owner = None
def basename(self):
return self.obj._name
@@ -1005,6 +1010,7 @@
globalcontainer = True
typename = 'PyObject @'
implementationtypename = 'PyObject *@'
+ _funccodegen_owner = None
def __init__(self, db, T, obj):
# obj is a _pyobject here; obj.value is the underlying CPython object
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit