[pypy-svn] r36774 - in pypy/dist/pypy/jit: codegen/dump codegen/llgraph timeshifter/test
arigo at codespeak.net
arigo at codespeak.net
Mon Jan 15 13:13:56 CET 2007
Author: arigo
Date: Mon Jan 15 13:13:54 2007
New Revision: 36774
Added:
pypy/dist/pypy/jit/timeshifter/test/conftest.py (contents, props changed)
Modified:
pypy/dist/pypy/jit/codegen/dump/rgenop.py
pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
Log:
Add a --dump option to the timeshifter tests. They will then use the
dump backend instead of the llgraph one, producing a log of operations
and writing them as pseudo-Python source in
/tmp/usession-<yourname>/rdumpgenop.py.
Note that the tests fail when run this way, because no code is really
generated. Trying to execute it gives a FinishedGeneratingCannotExecute
exception.
Modified: pypy/dist/pypy/jit/codegen/dump/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/dump/rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/dump/rgenop.py Mon Jan 15 13:13:54 2007
@@ -1,7 +1,21 @@
-from pypy.rlib.objectmodel import specialize
+"""
+This backend records all operations that the JIT front-end tries to do,
+and writes them as pseudo-Python source in
+
+ /tmp/usession-<yourname>/rdumpgenop.py.
+"""
+import os
+from pypy.rlib.objectmodel import specialize, we_are_translated
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
+from pypy.tool.udir import udir
+
+LOGFILE = str(udir.join('rdumpgenop.py'))
+
+
+class FinishedGeneratingCannotExecute(Exception):
+ pass
class Label(GenLabel):
@@ -15,6 +29,9 @@
class DummyConst(GenConst):
def __init__(self, name):
self.name = name
+ @specialize.arg(1)
+ def revealconst(self, T):
+ raise FinishedGeneratingCannotExecute
class IntConst(GenConst):
def __init__(self, value):
@@ -33,7 +50,11 @@
class AddrConst(GenConst):
def __init__(self, addr):
self.addr = addr
- self.name = '<address %x>' % self.revealconst(lltype.Signed)
+ if we_are_translated():
+ intaddr = llmemory.cast_adr_to_int(self.addr)
+ self.name = '<address %s>' % intaddr
+ else:
+ self.name = repr(addr)
@specialize.arg(1)
def revealconst(self, T):
@@ -237,14 +258,17 @@
pass
def log(self, msg):
- print 'log:', msg
+ self.rgenop.dump('# log: %s' % (msg,))
class RDumpGenOp(AbstractRGenOp):
+ create_dump = True
def __init__(self):
self.keepalive_gc_refs = []
self.counters = {}
+ if self.create_dump:
+ self.dump("# ------------------------------------------------------------")
def count(self, prefix):
count = self.counters.get(prefix, 0)
@@ -253,6 +277,15 @@
def dump(self, text):
print text
+ text += '\n'
+ fd = os.open(LOGFILE, os.O_WRONLY|os.O_CREAT, 0666)
+ os.lseek(fd, 0, 2)
+ while text:
+ count = os.write(fd, text)
+ if count == 0:
+ raise IOError
+ text = text[count:]
+ os.close(fd)
def check_no_open_mc(self):
pass
@@ -326,5 +359,9 @@
else:
assert 0, "XXX not implemented"
-global_rgenop = RDumpGenOp()
+
+class RGlobalDumpGenOp(RDumpGenOp):
+ create_dump = False
+
+global_rgenop = RGlobalDumpGenOp()
RDumpGenOp.constPrebuiltGlobal = global_rgenop.genconst
Modified: pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/llgraph/rgenop.py Mon Jan 15 13:13:54 2007
@@ -61,7 +61,10 @@
l_case = llimpl.add_case(self.b, gv_case.v)
b = llimpl.closelinktofreshblock(l_case, self.args_gv, self.l_default)
builder = LLBuilder(self.rgenop, self.gv_f, b)
- debug_assert(self.rgenop.currently_writing is None,
+ debug_assert(self.rgenop.currently_writing is None or
+ # special case: we stop replaying and add a case after
+ # a call to flexswitch() on a replay builder
+ self.rgenop.currently_writing.is_default_builder,
"add_case: currently_writing elsewhere")
self.rgenop.currently_writing = builder
return builder
@@ -74,10 +77,12 @@
debug_assert(self.rgenop.currently_writing is None,
"_add_default: currently_writing elsewhere")
self.rgenop.currently_writing = builder
+ builder.is_default_builder = True
return builder
class LLBuilder(GenBuilder):
jumped_from = None
+ is_default_builder = False
def __init__(self, rgenop, g, block):
self.rgenop = rgenop
@@ -345,9 +350,9 @@
def replay(self, label, kinds):
builder = LLBuilder(self, label.g, llimpl.nullblock)
args_gv = builder._newblock(kinds)
- debug_assert(self.rgenop.currently_writing is None,
+ debug_assert(self.currently_writing is None,
"replay: currently_writing")
- self.rgenop.currently_writing = builder
+ self.currently_writing = builder
return builder, args_gv
#def stop_replay(self, endblock, kinds):
Added: pypy/dist/pypy/jit/timeshifter/test/conftest.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/timeshifter/test/conftest.py Mon Jan 15 13:13:54 2007
@@ -0,0 +1,9 @@
+import py
+
+Option = py.test.Config.Option
+
+option = py.test.Config.addoptions("timeshifter tests options",
+ Option('--dump', action="store_true", default=False,
+ dest="use_dump_backend",
+ help="uses the dump backend, to log the backend operations"),
+ )
Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Mon Jan 15 13:13:54 2007
@@ -64,6 +64,10 @@
small = True
def setup_class(cls):
+ from pypy.jit.timeshifter.test.conftest import option
+ if option.use_dump_backend:
+ from pypy.jit.codegen.dump.rgenop import RDumpGenOp
+ cls.RGenOp = RDumpGenOp
cls._cache = {}
cls._cache_order = []
More information about the Pypy-commit
mailing list