[pypy-svn] pypy default: always store the .code attribute on TraceForOpcode instances, it makes everything much simpler
antocuni
commits-noreply at bitbucket.org
Wed Feb 23 15:34:32 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r42228:54d9ff95c7af
Date: 2011-02-23 15:12 +0100
http://bitbucket.org/pypy/pypy/changeset/54d9ff95c7af/
Log: always store the .code attribute on TraceForOpcode instances, it
makes everything much simpler
diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -1,5 +1,4 @@
import re, sys
-from lib_pypy.disassembler import dis
from pypy.jit.metainterp.resoperation import rop, opname
from pypy.jit.tool.oparser import OpParser
@@ -92,6 +91,7 @@
self.bytecode_no = int(bytecode_no)
self.operations = operations
self.storage = storage
+ self.code = storage.disassemble_code(self.filename, self.startlineno)
def repr(self):
if self.filename is None:
@@ -100,8 +100,6 @@
self.startlineno)
def getcode(self):
- if self.code is None and self.filename is not None:
- self.code = dis(self.storage.load_code(self.filename)[self.startlineno])
return self.code
def getlineno(self):
diff --git a/pypy/tool/jitlogparser/storage.py b/pypy/tool/jitlogparser/storage.py
--- a/pypy/tool/jitlogparser/storage.py
+++ b/pypy/tool/jitlogparser/storage.py
@@ -3,7 +3,9 @@
for all loops and bridges, so http requests can refer to them by name
"""
+import py
import os
+from lib_pypy.disassembler import dis
from pypy.tool.jitlogparser.parser import Function
from pypy.tool.jitlogparser.module_finder import gather_all_code_objs
@@ -12,6 +14,7 @@
self.loops = None
self.functions = {}
self.codes = {}
+ self.disassembled_codes = {}
self.extrapath = extrapath
def load_code(self, fname):
@@ -27,6 +30,17 @@
self.codes[fname] = res
return res
+ def disassemble_code(self, fname, startlineno):
+ if py.path.local(fname).check(file=False):
+ return None # cannot find source file
+ key = (fname, startlineno)
+ try:
+ return self.disassembled_codes[key]
+ except KeyError:
+ res = dis(self.load_code(fname)[startlineno])
+ self.disassembled_codes[key] = res
+ return res
+
def reconnect_loops(self, loops):
""" Re-connect loops in a way that entry bridges are filtered out
and normal bridges are associated with guards. Returning list of
diff --git a/pypy/tool/jitlogparser/test/test_parser.py b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -34,10 +34,10 @@
def test_split():
ops = parse('''
[i0]
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #10 ADD", 0)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #10 ADD", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #11 SUB", 0)
i1 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #11 SUB", 0)
i2 = int_add(i1, 1)
''')
res = Function.from_operations(ops.operations, LoopStorage())
@@ -68,27 +68,27 @@
def test_name():
ops = parse('''
[i0]
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #10 ADD", 0)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 201> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #10 ADD", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 201> #11 SUB", 0)
i1 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 202> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 202> #11 SUB", 0)
i2 = int_add(i1, 1)
''')
res = Function.from_operations(ops.operations, LoopStorage())
assert res.repr() == res.chunks[0].repr()
- assert res.repr() == "stuff, file '/tmp/x.py', line 200"
+ assert res.repr() == "stuff, file '/I/dont/exist.py', line 200"
assert res.startlineno == 200
- assert res.filename == '/tmp/x.py'
+ assert res.filename == '/I/dont/exist.py'
assert res.name == 'stuff'
def test_name_no_first():
ops = parse('''
[i0]
i3 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #10 ADD", 0)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 201> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #10 ADD", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 201> #11 SUB", 0)
i1 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 202> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 202> #11 SUB", 0)
i2 = int_add(i1, 1)
''')
res = Function.from_operations(ops.operations, LoopStorage())
More information about the Pypy-commit
mailing list