Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88343:343bfb83a4bb
Date: 2016-11-13 14:05 +0000
http://bitbucket.org/pypy/pypy/changeset/343bfb83a4bb/

Log:    in-progress

diff --git a/pypy/module/pypyjit/test_pypy_c/model.py 
b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -11,37 +11,24 @@
 from rpython.tool.jitlogparser.storage import LoopStorage
 
 
-def find_ids_range(code):
+def find_id_linenos(code):
     """
     Parse the given function and return a dictionary mapping "ids" to
-    "line ranges".  Ids are identified by comments with a special syntax::
+    "line number".  Ids are identified by comments with a special syntax::
 
         # "myid" corresponds to the whole line
         print 'foo' # ID: myid
     """
     result = {}
-    start_lineno = code.co.co_firstlineno
+    start_lineno = code.startlineno
     for i, line in enumerate(py.code.Source(code.source)):
         m = re.search('# ID: (\w+)', line)
         if m:
             name = m.group(1)
             lineno = start_lineno+i
-            result[name] = xrange(lineno, lineno+1)
+            result.setdefault(name, lineno)
     return result
 
-def find_ids(code):
-    """
-    Parse the given function and return a dictionary mapping "ids" to
-    "opcodes".
-    """
-    ids = {}
-    ranges = find_ids_range(code)
-    for name, linerange in ranges.iteritems():
-        opcodes = [opcode for opcode in code.opcodes
-                   if opcode.lineno in linerange]
-        ids[name] = opcodes
-    return ids
-
 
 class Log(object):
     def __init__(self, rawtraces):
@@ -107,13 +94,12 @@
     def compute_ids(self, ids):
         #
         # 1. compute the ids of self, i.e. the outer function
-        id2opcodes = find_ids(self.code)
-        all_my_opcodes = self.get_set_of_opcodes()
-        for id, opcodes in id2opcodes.iteritems():
-            if not opcodes:
-                continue
-            target_opcodes = set(opcodes)
-            if all_my_opcodes.intersection(target_opcodes):
+        id2lineno = find_id_linenos(self.code)
+        all_my_opcodes = self.get_list_of_opcodes()
+        for id, lineno in id2lineno.iteritems():
+            opcodes = [opcode for opcode in all_my_opcodes
+                              if opcode.lineno == lineno]
+            if opcodes:
                 ids[id] = opcodes
         #
         # 2. compute the ids of all the inlined functions
@@ -121,12 +107,11 @@
             if isinstance(chunk, TraceWithIds) and chunk.code:
                 chunk.compute_ids(ids)
 
-    def get_set_of_opcodes(self):
-        result = set()
+    def get_list_of_opcodes(self):
+        result = []
         for chunk in self.chunks:
             if isinstance(chunk, TraceForOpcode):
-                opcode = chunk.getopcode()
-                result.add(opcode)
+                result.append(chunk)
         return result
 
     def has_id(self, id):
diff --git a/pypy/module/pypyjit/test_pypy_c/test_00_model.py 
b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_00_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
@@ -3,12 +3,16 @@
 import types
 import subprocess
 import py, pytest
-from rpython.tool import disassembler
 from rpython.tool.udir import udir
 from rpython.tool import logparser
 from rpython.jit.tool.jitoutput import parse_prof
+from rpython.tool.jitlogparser import storage
 from pypy.module.pypyjit.test_pypy_c.model import \
-    Log, find_ids_range, find_ids, OpMatcher, InvalidMatch
+    Log, find_id_linenos, OpMatcher, InvalidMatch
+
+my_file = __file__
+if my_file.endswith('pyc'):
+    my_file = my_file[:-1]
 
 
 class BaseTestPyPyC(object):
@@ -121,31 +125,16 @@
 
 
 class TestLog(object):
-    def test_find_ids_range(self):
+    def test_find_id_linenos(self):
         def f():
             a = 0 # ID: myline
             return a
         #
         start_lineno = f.func_code.co_firstlineno
-        code = disassembler.dis(f)
-        ids = find_ids_range(code)
-        assert len(ids) == 1
-        myline_range = ids['myline']
-        assert list(myline_range) == range(start_lineno+1, start_lineno+2)
-
-    def test_find_ids(self):
-        def f():
-            i = 0
-            x = 0
-            z = x + 3 # ID: myline
-            return z
-        #
-        code = disassembler.dis(f)
-        ids = find_ids(code)
-        assert len(ids) == 1
+        code = storage.GenericCode(my_file, start_lineno, 'f')
+        ids = find_id_linenos(code)
         myline = ids['myline']
-        opcodes_names = [opcode.__class__.__name__ for opcode in myline]
-        assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 
'STORE_FAST']
+        assert myline == start_lineno + 1
 
 
 class TestOpMatcher_(object):
@@ -486,7 +475,7 @@
         log = self.run(f)
         loop, = log.loops_by_id('increment')
         assert loop.filename == self.filepath
-        assert loop.code.co.co_name == 'f'
+        assert loop.code.name == 'f'
         #
         ops = loop.allops()
         assert log.opnames(ops) == [
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to