[pypy-svn] r63643 - in pypy/branch/pyjitpl5-simplify/pypy/jit/backend: llgraph test
fijal at codespeak.net
fijal at codespeak.net
Sun Apr 5 00:14:04 CEST 2009
Author: fijal
Date: Sun Apr 5 00:14:03 2009
New Revision: 63643
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
Log:
casts test
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py Sun Apr 5 00:14:03 2009
@@ -113,6 +113,8 @@
'strlen' : (('ptr',), 'int'),
'strgetitem' : (('ptr', 'int'), 'int'),
'strsetitem' : (('ptr', 'int', 'int'), None),
+ 'cast_ptr_to_int' : (('ptr',), 'int'),
+ 'cast_int_to_ptr' : (('int',), 'ptr'),
#'getitem' : (('void', 'ptr', 'int'), 'int'),
#'setitem' : (('void', 'ptr', 'int', 'int'), None),
#'newlist' : (('void', 'varargs'), 'ptr'),
@@ -605,12 +607,17 @@
def op_new_array(self, arraydescr, count):
return do_new_array(arraydescr.ofs, count)
+ def op_cast_ptr_to_int(self, descr, ptr):
+ return cast_to_int(ptr, self.memocast)
+
+ def op_cast_int_to_ptr(self, descr, val):
+ return cast_from_int(llmemory.GCREF, val, self.memocast)
+
# ____________________________________________________________
def cast_to_int(x, memocast):
TP = lltype.typeOf(x)
if isinstance(TP, lltype.Ptr):
- assert TP.TO._gckind == 'raw'
return cast_adr_to_int(memocast, llmemory.cast_ptr_to_adr(x))
if TP == llmemory.Address:
return cast_adr_to_int(memocast, x)
@@ -618,7 +625,6 @@
def cast_from_int(TYPE, x, memocast):
if isinstance(TYPE, lltype.Ptr):
- assert TYPE.TO._gckind == 'raw'
return llmemory.cast_adr_to_ptr(cast_int_to_adr(memocast, x), TYPE)
elif TYPE == llmemory.Address:
return cast_int_to_adr(memocast, x)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py Sun Apr 5 00:14:03 2009
@@ -341,13 +341,13 @@
llimpl.do_call_void(func, self.memo_cast)
def do_cast_int_to_ptr(self, args, descr=None):
- return history.BoxPtr(llmemory.cast_adr_to_ptr(
- self.cast_int_to_adr(args[0].getint()),
- llmemory.GCREF))
+ return history.BoxPtr(llimpl.cast_from_int(llmemory.GCREF,
+ args[0].getint(),
+ self.memo_cast))
def do_cast_ptr_to_int(self, args, descr=None):
- return history.BoxInt(self.cast_adr_to_int(llmemory.cast_ptr_to_adr(
- args[0].getptr_base())))
+ return history.BoxInt(llimpl.cast_to_int(args[0].getptr_base(),
+ self.memo_cast))
# ____________________________________________________________
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py Sun Apr 5 00:14:03 2009
@@ -63,3 +63,14 @@
assert x.value == 142
s = execute(cpu, rop.NEWSTR, [BoxInt(8)])
assert len(s.getptr(lltype.Ptr(rstr.STR)).chars) == 8
+
+ def test_casts(self):
+ from pypy.rpython.lltypesystem import lltype, llmemory
+ TP = lltype.GcStruct('x')
+ x = lltype.malloc(TP)
+ x = lltype.cast_opaque_ptr(llmemory.GCREF, x)
+ res = self.execute_operation(rop.CAST_PTR_TO_INT,
+ [BoxPtr(x)], 'int').value
+ res2 = self.execute_operation(rop.CAST_INT_TO_PTR,
+ [BoxInt(res)], 'ptr').value
+ assert res2 == x
More information about the Pypy-commit
mailing list