Author: Antonio Cuni <[email protected]>
Branch: x86-dump-labels
Changeset: r44115:e56facc0fa41
Date: 2011-05-12 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/e56facc0fa41/

Log:    teach oparser how to deal with offsets in the logs

diff --git a/pypy/jit/tool/oparser.py b/pypy/jit/tool/oparser.py
--- a/pypy/jit/tool/oparser.py
+++ b/pypy/jit/tool/oparser.py
@@ -312,7 +312,7 @@
                 continue  # a comment or empty line
             newlines.append(line)
         base_indent, inpargs, newlines = self.parse_inpargs(newlines)
-        num, ops = self.parse_ops(base_indent, newlines, 0)
+        num, ops, last_offset = self.parse_ops(base_indent, newlines, 0)
         if num < len(newlines):
             raise ParseError("unexpected dedent at line: %s" % newlines[num])
         loop = ExtendedTreeLoop("loop")
@@ -320,11 +320,13 @@
         loop.token = self.looptoken
         loop.operations = ops
         loop.inputargs = inpargs
+        loop.last_offset = last_offset
         return loop
 
     def parse_ops(self, indent, lines, start):
         num = start
         ops = []
+        last_offset = None
         while num < len(lines):
             line = lines[num]
             if not line.startswith(" " * indent):
@@ -333,9 +335,25 @@
             elif line.startswith(" "*(indent + 1)):
                 raise ParseError("indentation not valid any more")
             else:
-                ops.append(self.parse_next_op(lines[num].strip()))
+                line = line.strip()
+                offset, line = self.parse_offset(line)
+                if line == '--end of the loop--':
+                    last_offset = offset
+                else:
+                    op = self.parse_next_op(line)
+                    if offset:
+                        op.offset = offset
+                ops.append(op)
                 num += 1
-        return num, ops
+        return num, ops, last_offset
+
+    def parse_offset(self, line):
+        if line.startswith('+'):
+            # it begins with an offset, like: "+10: i1 = int_add(...)"
+            offset, _, line = line.partition(':')
+            offset = int(offset)
+            return offset, line.strip()
+        return None, line
 
     def parse_inpargs(self, lines):
         line = lines[0]
diff --git a/pypy/jit/tool/test/test_oparser.py 
b/pypy/jit/tool/test/test_oparser.py
--- a/pypy/jit/tool/test/test_oparser.py
+++ b/pypy/jit/tool/test/test_oparser.py
@@ -1,7 +1,7 @@
-
+import py
 from pypy.rpython.lltypesystem import lltype, llmemory
 
-from pypy.jit.tool.oparser import parse
+from pypy.jit.tool.oparser import parse, ParseError
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.history import AbstractDescr, BoxInt, LoopToken,\
      BoxFloat
@@ -203,3 +203,24 @@
     loop = parse(x, nonstrict=True)
     assert loop.inputargs == []
     assert loop.operations[0].getopname() == 'int_add'
+
+def test_offsets():
+    x = """
+    [i0, i1]
+    +10: i2 = int_add(i0, i1)
+    i3 = int_add(i2, 3)
+    """
+    #    +30: --end of the loop--
+    loop = parse(x)
+    assert loop.operations[0].offset == 10
+    assert not hasattr(loop.operations[1], 'offset')
+
+def test_last_offset():
+    x = """
+    [i0, i1]
+    +10: i2 = int_add(i0, i1)
+    i3 = int_add(i2, 3)
+    +30: --end of the loop--
+    """
+    loop = parse(x)
+    assert loop.last_offset == 30
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to