[pypy-svn] r51858 - in pypy/branch/jit-refactoring/pypy/jit/rainbow: . test

arigo at codespeak.net arigo at codespeak.net
Mon Feb 25 20:29:05 CET 2008


Author: arigo
Date: Mon Feb 25 20:29:04 2008
New Revision: 51858

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/dump.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py
Log:
In dump(), show where the operations put their result.  This is done
with the help of comments inserted in the "assembler" source by
codewriter.py.


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	Mon Feb 25 20:29:04 2008
@@ -220,9 +220,9 @@
         self.emit(label(block))
         reds, greens = self.sort_by_color(block.inputargs)
         for arg in reds:
-            self.register_redvar(arg)
+            self.register_redvar(arg, verbose=False)
         for arg in greens:
-            self.register_greenvar(arg)
+            self.register_greenvar(arg, verbose=False)
         self.insert_merges(block)
         for op in block.operations:
             self.serialize_op(op)
@@ -364,10 +364,10 @@
             # already converted
             return self.redvar_positions[arg, block]
         self.emit("make_redbox")
-        resultindex = self.register_redvar((arg, block))
         argindex = self.green_position(arg)
         self.emit(argindex)
         self.emit(self.type_position(arg.concretetype))
+        resultindex = self.register_redvar((arg, block))
         return resultindex
 
     def opcolor(self, op):
@@ -385,22 +385,26 @@
             color = "red"
         return color
         
-    def register_redvar(self, arg, where=-1):
+    def register_redvar(self, arg, where=-1, verbose=True):
         assert arg not in self.redvar_positions
         if where == -1:
             where = self.free_red[self.current_block]
             self.free_red[self.current_block] += 1
+            if verbose:
+                self.emit('# => r%d' % (where,))
         self.redvar_positions[arg] = where
         return where
 
     def redvar_position(self, arg):
         return self.redvar_positions[arg]
 
-    def register_greenvar(self, arg, where=None, check=True):
+    def register_greenvar(self, arg, where=None, check=True, verbose=True):
         assert isinstance(arg, flowmodel.Variable) or not check
         if where is None:
             where = self.free_green[self.current_block]
             self.free_green[self.current_block] += 1
+            if verbose:
+                self.emit('# => g%d' % (where,))
         self.greenvar_positions[arg] = where
         return where
 
@@ -1045,6 +1049,8 @@
         result.append(chr(index & 0xff))
     for arg in args:
         if isinstance(arg, str):
+            if arg.startswith('#'):     # skip comments
+                continue
             opcode = interpreter.find_opcode(arg)
             assert opcode >= 0, "unknown opcode %s" % (arg, )
             emit_2byte(opcode)

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/dump.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/dump.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/dump.py	Mon Feb 25 20:29:04 2008
@@ -66,7 +66,7 @@
 
     def load_jumptarget(self):
         tlbl = self.get(codewriter.tlabel, 4)
-        return self.labelpos[tlbl.name]
+        return 'pc: %d' % self.labelpos[tlbl.name]
 
 
 class CustomRepr:
@@ -94,7 +94,6 @@
             opcode = interpreter.find_opcode(opname)
             opimpl = interpreter.opcode_implementations[opcode]
             argtypes = opimpl.argspec
-            resulttype = opimpl.resultspec
             args = []
 
             for argspec in argtypes:
@@ -150,9 +149,19 @@
                     assert 0, "unknown argtype declaration"
 
             args = map(str, args)
-            # XXX we should print the result from resultspec too,
-            # but it's not obvious how to do that
-            line = '%5d |  %-20s %s' % (startpc, opname, ', '.join(args))
+
+            comments = []
+            while (not src.finished() and isinstance(src.peek(), str)
+                   and src.peek().startswith('#')):
+                # comment, used to tell where the result of the previous
+                # operation goes
+                comments.append(src.get(str, 0)[1:].strip())
+
+            if startpc == 0:
+                startpc = 'pc: 0'
+            line = '%5s |  %-20s %-16s %s' % (startpc, opname,
+                                              ', '.join(args),
+                                              ', '.join(comments))
             print >> file, line.rstrip()
         elif isinstance(arg, codewriter.label):
             if src.pc not in noblankline:    # no duplicate blank lines

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	Mon Feb 25 20:29:04 2008
@@ -145,7 +145,7 @@
                 return
             return val
         wrapped.func_name = "wrap_" + func.func_name
-        wrapped.argspec = argtypes
+        wrapped.argspec = tuple(argtypes)
         wrapped.resultspec = result
         return wrapped
     return decorator

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py	Mon Feb 25 20:29:04 2008
@@ -229,13 +229,13 @@
         # xxx slightly fragile test, it will break whenever we tweak dump.py
         expected = """\
 JITCODE 'f'
-    0 |  make_redbox          (0), 0
+pc: 0 |  make_redbox          (0), 0           => r1
     6 |  make_new_redvars     [r0, r1]
    14 |  make_new_greenvars   []
       |
    18 |  local_merge          0, None
-   24 |  red_int_is_true      r0
-   28 |  red_goto_iftrue      r2, 48
+   24 |  red_int_is_true      r0               => r2
+   28 |  red_goto_iftrue      r2, pc: 48
    36 |  make_new_redvars     [r1]
    42 |  make_new_greenvars   []
       |
@@ -244,12 +244,12 @@
    48 |  make_new_redvars     [r0, r1]
    56 |  make_new_greenvars   []
       |
-   60 |  red_int_add          r1, r0
-   66 |  make_redbox          (1), 0
-   72 |  red_int_sub          r0, r3
+   60 |  red_int_add          r1, r0           => r2
+   66 |  make_redbox          (1), 0           => r3
+   72 |  red_int_sub          r0, r3           => r4
    78 |  make_new_redvars     [r4, r2]
    86 |  make_new_greenvars   []
-   90 |  goto                 18
+   90 |  goto                 pc: 18
         """.rstrip()
         assert result == expected
 



More information about the Pypy-commit mailing list