[pypy-svn] r56029 - pypy/branch/oo-jit/pypy/jit/codegen/llgraph

antocuni at codespeak.net antocuni at codespeak.net
Mon Jun 23 11:15:50 CEST 2008


Author: antocuni
Date: Mon Jun 23 11:15:48 2008
New Revision: 56029

Modified:
   pypy/branch/oo-jit/pypy/jit/codegen/llgraph/llimpl.py
Log:
introduce our own erasedType function, which knows about both lltype
and ootype.  This is needed, but not sufficient, to make test_0tlc
passing on ootype.



Modified: pypy/branch/oo-jit/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/llgraph/llimpl.py	(original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/llgraph/llimpl.py	Mon Jun 23 11:15:48 2008
@@ -51,6 +51,15 @@
         assert isinstance(TYPE, ootype.StaticMethod)
         return ootype.static_meth(TYPE, name, **attrs)
 
+def erasedType(T):
+    if isinstance(T, ootype.Instance):
+        if T is ootype.ROOT:
+            return T
+        while T._superclass is not ootype.ROOT:
+            T = T._superclass
+        return T
+    return lltype.erasedType(T)
+
 def newgraph(gv_FUNCTYPE, name):
     FUNCTYPE = _from_opaque(gv_FUNCTYPE).value
     # 'name' is just a way to track things
@@ -62,7 +71,7 @@
         v.concretetype = ARG
         inputargs.append(v)
         v = flowmodel.Variable()
-        v.concretetype = lltype.erasedType(ARG)
+        v.concretetype = erasedType(ARG)
         erasedinputargs.append(v)
     startblock = flowmodel.Block(inputargs)
     # insert an exploding operation here which is removed by
@@ -77,7 +86,7 @@
     return_var.concretetype = FUNCTYPE.RESULT
     graph = flowmodel.FunctionGraph(name, startblock, return_var)
     v1 = flowmodel.Variable()
-    v1.concretetype = lltype.erasedType(FUNCTYPE.RESULT)
+    v1.concretetype = erasedType(FUNCTYPE.RESULT)
     graph.prereturnblock = flowmodel.Block([v1])
     casting_link(graph.prereturnblock, [v1], graph.returnblock)
     substartblock = flowmodel.Block(erasedinputargs)
@@ -112,7 +121,7 @@
     assert block.exits == [], "block already closed"
     CONCRETE_TYPE = _from_opaque(gv_CONCRETE_TYPE).value
     v = flowmodel.Variable()
-    v.concretetype = lltype.erasedType(CONCRETE_TYPE)
+    v.concretetype = erasedType(CONCRETE_TYPE)
     block.inputargs.append(v)
     return _to_opaque(v)
 
@@ -155,12 +164,9 @@
             opname = 'cast_opaque_ptr'
         elif isinstance(TYPE, ootype.Instance):
             FROMTYPE = v.concretetype
-            if ootype.isSubclass(FROMTYPE, TYPE):
-                opname = 'ooupcast'
-            else:
-                opname = 'oodowncast'
+            opname = erasing_op(FROMTYPE, TYPE)
         else:
-            assert v.concretetype == lltype.erasedType(TYPE)
+            assert v.concretetype == erasedType(TYPE)
             opname = 'cast_pointer'
         block = _from_opaque(block)
         v2 = flowmodel.Variable()
@@ -170,20 +176,21 @@
         v = v2
     return _to_opaque(v)
 
+def erasing_op(FROMTYPE, TYPE):
+    if isinstance(TYPE, ootype.Instance):
+        if ootype.isSubclass(FROMTYPE, TYPE):
+            return 'ooupcast'
+        else:
+            return 'oodowncast'
+    return 'cast_pointer'
+
 def erasedvar(v, block):
-    T = lltype.erasedType(v.concretetype)
+    T = erasedType(v.concretetype)
     if T != v.concretetype:
         v2 = flowmodel.Variable()
         v2.concretetype = T
-        op = flowmodel.SpaceOperation("cast_pointer", [v], v2)
-        block.operations.append(op)
-        return v2
-    elif isinstance(T, ootype.Instance):
-        while T._superclass is not ootype.ROOT:
-            T = T._superclass
-        v2 = flowmodel.Variable()
-        v2.concretetype = T
-        op = flowmodel.SpaceOperation("ooupcast", [v], v2)
+        opname = erasing_op(v.concretetype, T)
+        op = flowmodel.SpaceOperation(opname, [v], v2)
         block.operations.append(op)
         return v2
     return v
@@ -244,9 +251,12 @@
         v.concretetype = lltype.Void
         return _to_opaque(v)
     T = lltype.typeOf(llvalue)
-    T1 = lltype.erasedType(T)
+    T1 = erasedType(T)
     if T1 != T:
-        llvalue = lltype.cast_pointer(T1, llvalue)
+        if isinstance(T1, ootype.Instance):
+            llvalue = ootype.ooupcast(T1, llvalue)
+        else:
+            llvalue = lltype.cast_pointer(T1, llvalue)
     v = flowmodel.Constant(llvalue)
     v.concretetype = T1
     if v.concretetype == lltype.Void: # XXX genconst should not really be used for Void constants
@@ -255,7 +265,7 @@
 
 def genzeroconst(gv_TYPE):
     TYPE = _from_opaque(gv_TYPE).value
-    TYPE = lltype.erasedType(TYPE)
+    TYPE = erasedType(TYPE)
     c = flowmodel.Constant(TYPE._defl())
     c.concretetype = TYPE
     return _to_opaque(c)
@@ -276,6 +286,11 @@
     elif isinstance(T, ootype.StaticMethod):
         fn = value._obj
         return ootype._static_meth(T, graph=fn.graph, _callable=fn._callable)
+    elif isinstance(T, ootype.Instance):
+        T1 = lltype.typeOf(value)
+        if ootype.isSubclass(T, T1):
+            return ootype.oodowncast(T, value)
+        return ootype.ooupcast(T, value)
     else:
         T1 = lltype.typeOf(value)
         if isinstance(T1, ootype.OOType) and T is ootype.Signed:
@@ -635,7 +650,8 @@
         else:
             erasedv = flowmodel.Variable()
             erasedv.concretetype = target_v.concretetype
-            source.operations.append(flowmodel.SpaceOperation('cast_pointer',
+            opname = erasing_op(v.concretetype, erasedv.concretetype)
+            source.operations.append(flowmodel.SpaceOperation(opname,
                                                               [v],
                                                               erasedv))
             linkargs.append(erasedv)



More information about the Pypy-commit mailing list