[pypy-svn] r66971 - in pypy/branch/pyjitpl5/pypy/jit/backend: test x86 x86/test
fijal at codespeak.net
fijal at codespeak.net
Wed Aug 19 15:11:13 CEST 2009
Author: fijal
Date: Wed Aug 19 15:11:11 2009
New Revision: 66971
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc.py
Log:
(pedronis, fijal) Cover assembler.py fully by unittests
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py Wed Aug 19 15:11:11 2009
@@ -87,18 +87,30 @@
assert x.value == ord('B')
def test_call(self):
- cpu = self.cpu
- #
- def func(c):
- return chr(ord(c) + 1)
- FPTR = self.Ptr(self.FuncType([lltype.Char], lltype.Char))
- func_ptr = llhelper(FPTR, func)
- calldescr = cpu.calldescrof(deref(FPTR), (lltype.Char,), lltype.Char)
- res = self.execute_operation(rop.CALL,
- [self.get_funcbox(cpu, func_ptr),
- BoxInt(ord('A'))],
- 'int', descr=calldescr)
- assert res.value == ord('B')
+
+ def func_int(a, b):
+ return a + b
+ def func_char(c, c1):
+ return chr(ord(c) + ord(c1))
+
+ functions = [
+ (func_int, lltype.Signed, 655360),
+ (func_int, rffi.SHORT, 1213),
+ (func_char, lltype.Char, 12)
+ ]
+
+ for func, TP, num in functions:
+ cpu = self.cpu
+ #
+ FPTR = self.Ptr(self.FuncType([TP, TP], TP))
+ func_ptr = llhelper(FPTR, func)
+ FUNC = deref(FPTR)
+ calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
+ res = self.execute_operation(rop.CALL,
+ [self.get_funcbox(cpu, func_ptr),
+ BoxInt(num), BoxInt(num)],
+ 'int', descr=calldescr)
+ assert res.value == 2 * num
def test_executor(self):
cpu = self.cpu
@@ -263,7 +275,7 @@
call(ConstClass(fptr), i0, descr=calldescr)
p0 = guard_exception(ConstClass(zdtp))
fail(1)
- fail(0)
+ fail(0, p0)
'''
FPTR = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Void))
fptr = llhelper(FPTR, func)
@@ -276,6 +288,7 @@
self.cpu.set_future_value_int(0, 1)
self.cpu.execute_operations(loop)
assert self.cpu.get_latest_value_int(0) == 0
+ assert self.cpu.get_latest_value_ptr(1) == zdptr
self.cpu.clear_exception()
self.cpu.set_future_value_int(0, 0)
self.cpu.execute_operations(loop)
@@ -316,16 +329,23 @@
#
fielddescr1 = self.cpu.fielddescrof(self.S, 'chr1')
fielddescr2 = self.cpu.fielddescrof(self.S, 'chr2')
+ shortdescr = self.cpu.fielddescrof(self.S, 'short')
self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(250)],
'void', descr=fielddescr2)
self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(133)],
'void', descr=fielddescr1)
+ self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(1331)],
+ 'void', descr=shortdescr)
res = self.execute_operation(rop.GETFIELD_GC, [t_box],
'int', descr=fielddescr2)
assert res.value == 250
res = self.execute_operation(rop.GETFIELD_GC, [t_box],
'int', descr=fielddescr1)
assert res.value == 133
+ res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+ 'int', descr=shortdescr)
+ assert res.value == 1331
+
#
u_box, U_box = self.alloc_instance(self.U)
fielddescr2 = self.cpu.fielddescrof(self.S, 'next')
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py Wed Aug 19 15:11:11 2009
@@ -768,8 +768,6 @@
x = rel32(op.args[0].getint())
else:
x = arglocs[0]
- if isinstance(x, MODRM):
- x = stack_pos(x.position)
self.mc.CALL(x)
self.mark_gc_roots()
self.mc.ADD(esp, imm(WORD * extra_on_stack))
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc.py Wed Aug 19 15:11:11 2009
@@ -9,10 +9,23 @@
from pypy.jit.metainterp.test.oparser import parse
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.annlowlevel import llhelper
+from pypy.rpython.lltypesystem import rclass
class TestRegalloc(object):
cpu = CPU(None, None)
+ def raising_func(i):
+ if i:
+ raise LLException(zero_division_error,
+ zero_division_value)
+ FPTR = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Void))
+ raising_fptr = llhelper(FPTR, raising_func)
+ zero_division_tp, zero_division_value = cpu.get_zero_division_error()
+ zd_addr = cpu.cast_int_to_adr(zero_division_tp)
+ zero_division_error = llmemory.cast_adr_to_ptr(zd_addr,
+ lltype.Ptr(rclass.OBJECT_VTABLE))
+ raising_calldescr = cpu.calldescrof(FPTR.TO, FPTR.TO.ARGS, FPTR.TO.RESULT)
+
namespace = locals().copy()
type_system = 'lltype'
@@ -130,3 +143,18 @@
assert self.getptr(0, lltype.Ptr(S)) == ptr
assert not self.cpu.assembler.fail_boxes_ptr[0]
assert not self.cpu.assembler.fail_boxes_ptr[1]
+
+ def test_exception_bridge_no_exception(self):
+
+
+ ops = '''
+ [i0]
+ call(ConstClass(raising_fptr), i0, descr=raising_calldescr)
+ guard_exception(ConstClass(zero_division_error))
+ guard_no_exception()
+ fail(2)
+ fail(1)
+ fail(0)
+ '''
+ self.interpret(ops, [0])
+ assert self.getint(0) == 1
More information about the Pypy-commit
mailing list