[pypy-svn] r37520 - in pypy/dist/pypy/jit/codegen: . llgraph llgraph/test test
arigo at codespeak.net
arigo at codespeak.net
Mon Jan 29 12:33:22 CET 2007
Author: arigo
Date: Mon Jan 29 12:33:19 2007
New Revision: 37520
Modified:
pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
pypy/dist/pypy/jit/codegen/llgraph/test/test_rgenop.py
pypy/dist/pypy/jit/codegen/model.py
pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
Log:
Add a static method get_python_callable() on RGenOp for tests.
Fix test_unaliasing_variables_direct().
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 29 12:33:19 2007
@@ -400,4 +400,16 @@
def write_frame_place(T, base, place, value):
llimpl.write_frame_var(base, place.info, 0, value)
+
+ @staticmethod
+ def get_python_callable(FUNC, gv):
+ # return a closure that will run the graph on the llinterp
+ from pypy.jit.codegen.llgraph.llimpl import testgengraph
+ ptr = gv.revealconst(FUNC)
+ graph = ptr._obj.graph
+ def runner(*args):
+ return testgengraph(graph, list(args))
+ return runner
+
+
rgenop = RGenOp() # no real point in using a full class in llgraph
Modified: pypy/dist/pypy/jit/codegen/llgraph/test/test_rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/test/test_rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/llgraph/test/test_rgenop.py Mon Jan 29 12:33:19 2007
@@ -9,13 +9,6 @@
class TestLLGraphRGenop(AbstractRGenOpTests):
RGenOp = RGenOp
- def cast(self, gv, nb_args):
- F1 = lltype.FuncType([lltype.Signed] * nb_args, lltype.Signed)
- ptr = gv.revealconst(lltype.Ptr(F1))
- def runner(*args):
- return testgengraph(ptr._obj.graph, list(args))
- return runner
-
def getcompiled(self, runner, argtypes, annotatorpolicy):
def quasi_compiled_runner(*args):
return interpret(runner, args, policy=annotatorpolicy)
Modified: pypy/dist/pypy/jit/codegen/model.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/model.py (original)
+++ pypy/dist/pypy/jit/codegen/model.py Mon Jan 29 12:33:19 2007
@@ -332,6 +332,24 @@
# 'base' is the frame stack pointer captured by the operation
# generated by genop_get_frame_base()."""
+ @staticmethod
+ def get_python_callable(FUNC, gv):
+ """NOT_RPYTHON
+ Turn a GenConst containing the address of a function into a
+ Python callable object, for testing purposes.
+ """
+ from pypy.rpython.lltypesystem import lltype
+ from ctypes import cast, c_void_p, CFUNCTYPE, c_int, c_float
+ def _to_ctypes(t): #limited type support for now
+ if t == lltype.Float:
+ return c_float
+ if t == lltype.Void:
+ return None
+ return c_int
+ ctypestypes = [_to_ctypes(t) for t in FUNC.TO.ARGS]
+ ctypesres = _to_ctypes(FUNC.TO.RESULT)
+ return cast(c_void_p(gv.value), CFUNCTYPE(ctypesres, *ctypestypes))
+
class CodeGenSwitch(object):
'''A CodeGenSwitch is a flexible switch on a given GenVar that can have cases added
Modified: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/rgenop_tests.py (original)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py Mon Jan 29 12:33:19 2007
@@ -711,8 +711,8 @@
annotatorpolicy = GENOP_POLICY)
def cast(self, gv, nb_args):
- print gv.value
- return cast(c_void_p(gv.value), CFUNCTYPE(c_int, *[c_int]*nb_args))
+ F1 = lltype.FuncType([lltype.Signed] * nb_args, lltype.Signed)
+ return self.RGenOp.get_python_callable(lltype.Ptr(F1), gv)
def directtesthelper(self, FUNCTYPE, func):
# for machine code backends: build a ctypes function pointer
@@ -1296,7 +1296,8 @@
builder, gv_callable, [gv_x, gv_y] = rgenop.newgraph(sigtoken, "f")
builder.start_writing()
- false_builder = builder.jump_if_false(gv_x, [])
+ gv_cond = builder.genop1("int_is_true", gv_x)
+ false_builder = builder.jump_if_false(gv_cond, [])
args_gv = [gv_y, gv_y]
label = builder.enter_next_block([signed_kind, signed_kind], args_gv)
@@ -1308,8 +1309,9 @@
false_builder.start_writing()
false_builder.finish_and_goto([rgenop.genconst(2), rgenop.genconst(1)], label)
+ builder.end()
- fnptr = self.cast(gv_callable, 1)
+ fnptr = self.cast(gv_callable, 2)
res = fnptr(20, 2)
assert res == 4
More information about the Pypy-commit
mailing list