[pypy-svn] r37600 - in pypy/dist/pypy/jit/codegen: dump dump/test llgraph

arigo at codespeak.net arigo at codespeak.net
Tue Jan 30 15:18:27 CET 2007


Author: arigo
Date: Tue Jan 30 15:18:25 2007
New Revision: 37600

Added:
   pypy/dist/pypy/jit/codegen/dump/test/test_dump.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/codegen/dump/rgenop.py
   pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
   pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
Log:
Hack hack hack until the dump backend can produce rgenop.genconst(X)
where X is really the repr() for the original constant.  Fixes 0/1
versus False/True issues.


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	Tue Jan 30 15:18:25 2007
@@ -333,14 +333,7 @@
             if not gv.is_const:
                 name = self.count('v')
             else:
-                try:
-                    value = gv.revealconst(lltype.Signed)
-                except Exception:
-                    if we_are_translated():
-                        raise
-                    name = self.count('gv_')
-                else:
-                    name = 'rgenop.genconst(%d)' % value
+                name = 'rgenop.genconst(%s)' % gv.revealconstrepr()
             self.vnames[gv] = name
             return name
 
@@ -408,7 +401,7 @@
         builder, gv_callable, inputargs_gv = llrgenop.RGenOp.newgraph(
             self, sigtoken, name)
         builder = Builder(self, builder)
-        self.dump("# new graph at address %s" % self.vname(gv_callable))
+        self.dump("# new graph %s" % self.vname(gv_callable))
         self.dump("%s, gv_callable, %s = rgenop.newgraph(%s, '%s')" % (
             builder.name,
             self.vlistassname(inputargs_gv),

Added: pypy/dist/pypy/jit/codegen/dump/test/test_dump.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/dump/test/test_dump.py	Tue Jan 30 15:18:25 2007
@@ -0,0 +1,38 @@
+import os
+from pypy.rpython.lltypesystem import lltype
+from pypy.jit.codegen.dump.rgenop import RDumpGenOp, LOGFILE
+
+
+# XXX very incomplete
+
+FUNC0 = lltype.FuncType([], lltype.Signed)
+
+
+class TestRDumpGenOp:
+
+    def setup_method(self, meth):
+        try:
+            os.unlink(LOGFILE)
+        except OSError:
+            pass
+
+    def getlog(self):
+        f = open(LOGFILE, 'r')
+        data = f.read()
+        f.close()
+        os.unlink(LOGFILE)
+        return data
+
+    def test_genconst(self):
+        rgenop = RDumpGenOp()
+        builder, gv_callable, inputargs_gv = rgenop.newgraph(
+            RDumpGenOp.sigToken(FUNC0), "foobar")
+        builder.start_writing()
+        builder.genop_same_as(RDumpGenOp.kindToken(lltype.Signed),
+                              rgenop.genconst(0))
+        log = self.getlog()
+        assert 'rgenop.genconst(0)' in log
+        builder.genop_same_as(RDumpGenOp.kindToken(lltype.Bool),
+                              rgenop.genconst(False))
+        log = self.getlog()
+        assert 'rgenop.genconst(False)' in log

Modified: pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/llimpl.py	(original)
+++ pypy/dist/pypy/jit/codegen/llgraph/llimpl.py	Tue Jan 30 15:18:25 2007
@@ -218,6 +218,10 @@
     assert isinstance(c, flowmodel.Constant)
     return _generalcast(T, c.value)
 
+def revealconstrepr(gv_value):
+    c = from_opaque_object(gv_value)
+    return LLSupport.to_rstr(repr(c.value))
+
 def isconst(gv_value):
     c = from_opaque_object(gv_value)
     return isinstance(c, flowmodel.Constant)
@@ -549,6 +553,8 @@
 setannotation(cast, s_ConstOrVar)
 setannotation(revealconst, lambda s_T, s_gv: annmodel.lltype_to_annotation(
                                                   s_T.const))
+from pypy.rpython.lltypesystem.rstr import STR
+setannotation(revealconstrepr, annmodel.SomePtr(lltype.Ptr(STR)))
 setannotation(isconst, annmodel.SomeBool())
 setannotation(closeblock1, s_Link)
 setannotation(closeblock2, s_LinkPair)

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	Tue Jan 30 15:18:25 2007
@@ -4,6 +4,7 @@
 from pypy.jit.codegen.model import GenVar, GenConst, CodeGenSwitch
 from pypy.jit.codegen.llgraph import llimpl
 from pypy.rpython.lltypesystem.rclass import fishllattr
+from pypy.rpython.module.support import LLSupport
 
 
 class LLVar(GenVar):
@@ -22,6 +23,9 @@
     def revealconst(self, T):
         return llimpl.revealconst(T, self.v)
 
+    def revealconstrepr(self):
+        return LLSupport.from_rstr(llimpl.revealconstrepr(self.v))
+
     def __repr__(self):
         return repr(RGenOp.reveal(self))
 



More information about the Pypy-commit mailing list