[pypy-svn] r22791 - pypy/branch/genc-gc-refactoring

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Jan 28 15:15:12 CET 2006


Author: cfbolz
Date: Sat Jan 28 15:15:09 2006
New Revision: 22791

Modified:
   pypy/branch/genc-gc-refactoring/funcgen.py
Log:
(mwh, cfbolz):
attach blocknum to function generator


Modified: pypy/branch/genc-gc-refactoring/funcgen.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/funcgen.py	(original)
+++ pypy/branch/genc-gc-refactoring/funcgen.py	Sat Jan 28 15:15:09 2006
@@ -24,7 +24,8 @@
                        vars
                        lltypes
                        functionname
-                       currentblock""".split()
+                       currentblock
+                       blocknum""".split()
 
     def __init__(self, graph, db, cpython_exc=False, functionname=None):
         self.graph = graph
@@ -35,6 +36,7 @@
         # apply the gc transformation
         self.db.gctransformer.transform_graph(self.graph)
         
+        self.blocknum = {}
         #
         # collect all variables and constants used in the body,
         # and get their types now
@@ -44,6 +46,7 @@
         mix = [self.graph.getreturnvar()]
         self.more_ll_values = []
         for block in graph.iterblocks():
+            self.blocknum[block] = len(self.blocknum)
             mix.extend(block.inputargs)
             for op in block.operations:
                 mix.extend(op.args)
@@ -159,21 +162,11 @@
     def cfunction_body(self):
         graph = self.graph
 
-        blocknum = {}
-        allblocks = []
-
-        # collect all blocks
-        for block in graph.iterblocks():
-            allblocks.append(block)
-            blocknum[block] = len(blocknum)
-
-        assert graph.startblock is allblocks[0]
-
         # generate the body of each block
         push_alive_op_result = self.gcpolicy.push_alive_op_result
-        for block in allblocks:
+        for block in graph.iterblocks():
             self.currentblock = block
-            myblocknum = blocknum[block]
+            myblocknum = self.blocknum[block]
             yield ''
             yield 'block%d:' % myblocknum
             to_release = list(block.inputargs)
@@ -207,7 +200,7 @@
             elif block.exitswitch is None:
                 # single-exit block
                 assert len(block.exits) == 1
-                for op in self.gen_link(block.exits[0], to_release, blocknum):
+                for op in self.gen_link(block.exits[0], to_release):
                     yield op
                 yield ''
             elif block.exitswitch == c_last_exception:
@@ -215,7 +208,7 @@
                 # we handle the non-exceptional case first
                 link = block.exits[0]
                 assert link.exitcase is None
-                for op in self.gen_link(link, to_release, blocknum):
+                for op in self.gen_link(link, to_release):
                     yield op
                 # we must catch the exception raised by the last operation,
                 # which goes to the last err%d_%d label written above.
@@ -253,7 +246,7 @@
                         d[link.last_exc_value] = 'exc_value'
                     else:
                         yield '\t' + self.pop_alive_expr('exc_value', T2)
-                    for op in self.gen_link(link, to_release, blocknum, d):
+                    for op in self.gen_link(link, to_release, d):
                         yield '\t' + op
                     yield '}'
                 fallthrough = True
@@ -275,14 +268,14 @@
                             else:
                                 expr = '%s == Py_False' % expr
                         yield 'if (%s) {' % expr
-                        for op in self.gen_link(link, to_release, blocknum):
+                        for op in self.gen_link(link, to_release):
                             yield '\t' + op
                         yield '}'
                     link = block.exits[-1]
                     assert link.exitcase in (False, True)
                     #yield 'assert(%s == %s);' % (self.expr(block.exitswitch),
                     #                       self.genc.nameofvalue(link.exitcase, ct))
-                    for op in self.gen_link(block.exits[-1], to_release, blocknum):
+                    for op in self.gen_link(block.exits[-1], to_release):
                         yield op
                     yield ''
                 elif TYPE in (Signed, Unsigned, SignedLongLong,
@@ -295,7 +288,7 @@
                             defaultlink = link
                             continue
                         yield 'case %s:' % self.db.get(link.llexitcase)
-                        for op in self.gen_link(link, to_release, blocknum):
+                        for op in self.gen_link(link, to_release):
                             yield '\t' + op
                         yield 'break;'
                         
@@ -303,7 +296,7 @@
                     if defaultlink is None:
                         raise TypeError('switches must have a default case.')
                     yield 'default:'
-                    for op in self.gen_link(defaultlink, to_release, blocknum):
+                    for op in self.gen_link(defaultlink, to_release):
                         yield '\t' + op
 
                     yield '}'
@@ -322,7 +315,7 @@
                 else:
                     yield self.pop_alive(to_release[i-1])
 
-    def gen_link(self, link, to_release, blocknum, linklocalvars=None):
+    def gen_link(self, link, to_release, linklocalvars=None):
         "Generate the code to jump across the given Link."
         is_alive = {}
         linklocalvars = linklocalvars or {}
@@ -341,7 +334,7 @@
             assignments.append((a2typename, dest, src))
         for line in gen_assignments(assignments):
             yield line
-        yield 'goto block%d;' % blocknum[link.target]
+        yield 'goto block%d;' % self.blocknum[link.target]
 
     def gen_op(self, op, err):
         macro = 'OP_%s' % op.opname.upper()



More information about the Pypy-commit mailing list