[pypy-svn] r35301 - in pypy/branch/jit-real-world/pypy: jit/codegen/i386 translator/tool translator/tool/pygame
arigo at codespeak.net
arigo at codespeak.net
Tue Dec 5 15:09:13 CET 2006
Author: arigo
Date: Tue Dec 5 15:08:43 2006
New Revision: 35301
Added:
pypy/branch/jit-real-world/pypy/jit/codegen/i386/autopath.py
- copied unchanged from r35295, pypy/branch/jit-real-world/pypy/tool/autopath.py
Modified:
pypy/branch/jit-real-world/pypy/jit/codegen/i386/codebuf.py
pypy/branch/jit-real-world/pypy/jit/codegen/i386/viewcode.py
pypy/branch/jit-real-world/pypy/translator/tool/make_dot.py
pypy/branch/jit-real-world/pypy/translator/tool/pygame/drawgraph.py
pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphclient.py
pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphdisplay.py
Log:
(arre, pedronis, arigo)
Dump generated machine code if the PYPYJITLOG env var is set (then it
dumps to the file named in $PYPYJITLOG).
Improve the viewcode.py viewer to use a fixed-size font and expand the
tabs into columns manually.
Modified: pypy/branch/jit-real-world/pypy/jit/codegen/i386/codebuf.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/codegen/i386/codebuf.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/codegen/i386/codebuf.py Tue Dec 5 15:08:43 2006
@@ -2,9 +2,6 @@
from ctypes import POINTER, cast, c_char, c_void_p, CFUNCTYPE, c_int
from ri386 import I386CodeBuilder
-# Set this to enable/disable the CODE_DUMP stdout lines
-CODE_DUMP = False
-
# ____________________________________________________________
@@ -51,21 +48,46 @@
def done(self):
# normally, no special action is needed here
- if CODE_DUMP:
- self.dump_range(self._last_dump_start, self._pos)
- self._last_dump_start = self._pos
+ if machine_code_dumper.enabled:
+ machine_code_dumper.dump(self)
+
- def dump_range(self, start, end):
+class MachineCodeDumper:
+ enabled = True
+ log_fd = -1
+
+ def dump(self, cb):
+ if self.log_fd < 0:
+ # check the environment for a file name
+ from pypy.rlib.ros import getenv
+ s = getenv('PYPYJITLOG')
+ if not s:
+ self.enabled = False
+ return
+ try:
+ flags = os.O_WRONLY|os.O_CREAT|os.O_TRUNC
+ self.log_fd = os.open(s, flags, 0666)
+ except OSError:
+ os.write(2, "could not create log file\n")
+ self.enabled = False
+ return
+ self.dump_range(cb, cb._last_dump_start, cb._pos)
+ cb._last_dump_start = cb._pos
+
+ def dump_range(self, cb, start, end):
HEX = '0123456789ABCDEF'
dump = []
for p in range(start, end):
- o = ord(self._data.contents[p])
+ o = ord(cb._data.contents[p])
dump.append(HEX[o >> 4])
dump.append(HEX[o & 15])
if (p & 3) == 3:
dump.append(':')
- os.write(2, 'CODE_DUMP @%x +%d %s\n' % (self.tell() - self._pos,
- start, ''.join(dump)))
+ line = 'CODE_DUMP @%x +%d %s\n' % (cb.tell() - cb._pos,
+ start, ''.join(dump))
+ os.write(self.log_fd, line)
+
+machine_code_dumper = MachineCodeDumper()
class MachineCodeBlock(InMemoryCodeBuilder):
Modified: pypy/branch/jit-real-world/pypy/jit/codegen/i386/viewcode.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/codegen/i386/viewcode.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/codegen/i386/viewcode.py Tue Dec 5 15:08:43 2006
@@ -8,6 +8,7 @@
/tmp/usession-xxx/testing_1/testing_1 -var 4 2>&1 | ./viewcode.py
"""
+import autopath
import operator, sys, os, re, py
# don't use pypy.tool.udir here to avoid removing old usessions which
@@ -153,14 +154,40 @@
def show(self):
g1 = Graph('codedump')
for r in self.ranges:
- text = r.disassemble().replace('\t', ' ')
+ text, width = tab2columns(r.disassemble())
text = '0x%x\n\n%s' % (r.addr, text)
- g1.emit_node('N_%x' % r.addr, shape="box", label=text)
+ g1.emit_node('N_%x' % r.addr, shape="box", label=text,
+ width=str(width*0.125))
for lineno, targetaddr in r.findjumps():
g1.emit_edge('N_%x' % r.addr, 'N_%x' % targetaddr)
g1.display()
+def tab2columns(text):
+ lines = text.split('\n')
+ columnwidth = []
+ for line in lines:
+ columns = line.split('\t')
+ while len(columnwidth) < len(columns):
+ columnwidth.append(0)
+ for i, s in enumerate(columns):
+ width = len(s.strip())
+ if not s.endswith(':'):
+ width += 2
+ columnwidth[i] = max(columnwidth[i], width)
+ result = []
+ for line in lines:
+ columns = line.split('\t')
+ text = []
+ for width, s in zip(columnwidth, columns):
+ text.append(s.strip().ljust(width))
+ result.append(' '.join(text))
+ if result:
+ totalwidth = len(result[0])
+ else:
+ totalwidth = 1
+ return '\\l'.join(result), totalwidth
+
# ____________________________________________________________
# XXX pasted from
# http://codespeak.net/svn/user/arigo/hack/misc/graphlib.py
@@ -201,6 +228,8 @@
return _PageContent(self.graph_builder)
class _PageContent:
+ fixedfont = True
+
def __init__(self, graph_builder):
if callable(graph_builder):
graph = graph_builder()
Modified: pypy/branch/jit-real-world/pypy/translator/tool/make_dot.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/translator/tool/make_dot.py (original)
+++ pypy/branch/jit-real-world/pypy/translator/tool/make_dot.py Tue Dec 5 15:08:43 2006
@@ -67,10 +67,11 @@
color="black",
fillcolor="white",
style="filled",
+ width="0.75",
):
d = locals()
attrs = [('%s="%s"' % (x, d[x].replace('"', '\\"').replace('\n', '\\n')))
- for x in ['shape', 'label', 'color', 'fillcolor', 'style']]
+ for x in ['shape', 'label', 'color', 'fillcolor', 'style', 'width']]
self.emit('%s [%s];' % (safename(name), ", ".join(attrs)))
Modified: pypy/branch/jit-real-world/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/translator/tool/pygame/drawgraph.py (original)
+++ pypy/branch/jit-real-world/pypy/translator/tool/pygame/drawgraph.py Tue Dec 5 15:08:43 2006
@@ -11,6 +11,7 @@
FONT = os.path.join(autopath.this_dir, 'cyrvetic.ttf')
+FIXEDFONT = os.path.join(autopath.this_dir, 'VeraMoBd.ttf')
COLOR = {
'black': (0,0,0),
'white': (255,255,255),
@@ -52,6 +53,7 @@
class GraphLayout:
+ fixedfont = False
def __init__(self, filename):
# parse the layout file (.plain format)
@@ -297,7 +299,11 @@
self.FONTCACHE[size] = None
return None
else:
- font = self.FONTCACHE[size] = pygame.font.Font(FONT, size)
+ if self.graphlayout.fixedfont:
+ filename = FIXEDFONT
+ else:
+ filename = FONT
+ font = self.FONTCACHE[size] = pygame.font.Font(filename, size)
return font
def setoffset(self, offsetx, offsety):
Modified: pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphclient.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphclient.py (original)
+++ pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphclient.py Tue Dec 5 15:08:43 2006
@@ -134,6 +134,8 @@
key = page
page = page.content()
layout = ClientGraphLayout(self, key, page.source, page.links)
+ if getattr(page, 'fixedfont', False):
+ layout.fixedfont = True
return layout
def initiate_display(self, page, link=None, do_display=False):
Modified: pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphdisplay.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphdisplay.py (original)
+++ pypy/branch/jit-real-world/pypy/translator/tool/pygame/graphdisplay.py Tue Dec 5 15:08:43 2006
@@ -3,7 +3,7 @@
import os, time, sys
import pygame
from pygame.locals import *
-from pypy.translator.tool.pygame.drawgraph import GraphRenderer
+from pypy.translator.tool.pygame.drawgraph import GraphRenderer, FIXEDFONT
from pypy.translator.tool.pygame.drawgraph import Node, Edge
from pypy.translator.tool.pygame.drawgraph import EventQueue, wait_for_events
@@ -59,7 +59,7 @@
self.screen = pygame.display.set_mode((w, h), HWSURFACE|RESIZABLE, 32)
class GraphDisplay(Display):
- STATUSBARFONT = os.path.join(autopath.this_dir, 'VeraMoBd.ttf')
+ STATUSBARFONT = FIXEDFONT
ANIM_STEP = 0.07
KEY_REPEAT = (500, 30)
STATUSBAR_ALPHA = 0.75
More information about the pypy-svn
mailing list