[pypy-svn] r62918 - pypy/branch/pyjitpl5/pypy/jit/backend/x86

fijal at codespeak.net fijal at codespeak.net
Fri Mar 13 01:14:03 CET 2009


Author: fijal
Date: Fri Mar 13 01:14:03 2009
New Revision: 62918

Added:
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/loopparser.py   (contents, props changed)
Log:
a parser for output + a simple input


Added: pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp	Fri Mar 13 01:14:03 2009
@@ -0,0 +1,12 @@
+merge_point bp(0,135638976),bi(1,210),bi(2,4),bi(3,1),bi(4,1),bi(5,2),bi(6,6)
+guard_value bi(5,2),ci(7,2)
+int_le bi(2,4),ci(8,1)
+  => bi(9,0)
+int_is_true bi(9,0)
+  => bi(10,0)
+guard_false bi(10,0)
+int_mul bi(1,210),bi(2,4)
+  => bi(11,840)
+int_sub bi(2,4),ci(12,1)
+  => bi(13,3)
+jump bp(0,135638976),bi(11,840),bi(13,3),ci(14,1),ci(8,1),ci(15,2),bi(6,6)

Added: pypy/branch/pyjitpl5/pypy/jit/backend/x86/loopparser.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/loopparser.py	Fri Mar 13 01:14:03 2009
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+""" A simple parser for debug output from x86 backend. used to derive
+new tests from crashes
+"""
+
+import sys, py, re
+
+class Parser(object):
+    def __init__(self):
+        self.boxes = {}
+        self.box_creations = []
+        self.operations = []
+
+    def parse_name(self, name):
+        if name == 'bp':
+            return 'BoxPtr'
+        elif name == 'bi':
+            return 'BoxInt'
+        elif name == 'ci':
+            return 'ConstInt'
+        elif name == 'cp':
+            return 'ConstPtr'
+        raise NotImplementedError
+
+    def register_box(self, id, name, val):
+        try:
+            return self.boxes[id]
+        except KeyError:
+            result = name.lower() + '_' + str(id)
+            self.boxes[id] = result
+            if name.endswith('Ptr'):
+                val = 'ptr_%d' % id
+            self.box_creations.append('%s = %s(%s)' % (result, name, val))
+            return result
+
+    def parse_args(self, args):
+        res = []
+        for arg in args:
+            m = re.match('(\w\w)\((\d+),(\d+)\)', arg)
+            name = self.parse_name(m.group(1))
+            id   = int(m.group(2))
+            val  = int(m.group(3))
+            unique_box = self.register_box(id, name, val)
+            res.append(unique_box)
+        return res
+
+    def parse(self, fname):
+        def pairs(lst):
+            res = []
+            for i in range(0, len(lst), 2):
+                res.append(lst[i] + ',' + lst[i + 1])
+            return res
+        
+        operations = []
+        data = py.path.local(fname).read()
+        lines = data.split("\n")
+        i = 0
+        while i < len(lines):
+            line = lines[i]
+            if line:
+                opname, args = line.split(' ')
+                parsed_args = self.parse_args(pairs(args.split(",")))
+                if i + 1 < len(lines) and lines[i + 1].startswith('  =>'):
+                    i += 1
+                    box = lines[i][5:]
+                    [res] = self.parse_args([box])
+                else:
+                    res = None
+                self.operations.append((opname, parsed_args, res))
+            i += 1
+
+    def output(self):
+        for box in self.box_creations:
+            print box
+        print "ops = ["
+        for name, args, res in self.operations:
+            print " " * 4 + "rop.ResOperation(%s, [%s], %s)" % (name.upper(), ", ".join(args), res)
+        print "]"
+        print "ops[-1].jump_target = ops[0]"
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        print __doc__
+        sys.exit(1)
+    parser = Parser()
+    parser.parse(sys.argv[1])
+    parser.output()
+
+def test_loopparser():
+    parser = Parser()
+    parser.parse(py.magic.autopath().join('..', 'inp'))
+    assert len(parser.operations) == 8
+    assert parser.operations[1] == ('guard_value', ['boxint_5', 'constint_7'],
+                                    None)
+    assert len(parser.box_creations) == 8



More information about the Pypy-commit mailing list