[pypy-svn] r34056 - in pypy/dist/pypy/jit/codegen/llvm: . test
ericvrp at codespeak.net
ericvrp at codespeak.net
Thu Nov 2 12:30:48 CET 2006
Author: ericvrp
Date: Thu Nov 2 12:30:47 2006
New Revision: 34056
Modified:
pypy/dist/pypy/jit/codegen/llvm/llvmjit.py
pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py
Log:
attempt to add a nice helper (for calling jit-ed functions) which is not translatable.
Modified: pypy/dist/pypy/jit/codegen/llvm/llvmjit.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/llvmjit.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/llvmjit.py Thu Nov 2 12:30:47 2006
@@ -34,3 +34,12 @@
execute = llvmjit.execute
execute.restype = c_int
execute.argtypes = [c_void_p, c_int]
+
+#helpers...
+class FindFunction(object):
+ def __init__(self, function_name):
+ self.function = find_function(function_name)
+
+ def __call__(self, param): #XXX this does not seem to translate, how to do it instead?
+ return execute(self.function, param)
+
Modified: pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py Thu Nov 2 12:30:47 2006
@@ -27,9 +27,10 @@
#helpers
def execute(llsource, function_name, param):
assert llvmjit.compile(llsource)
- function = llvmjit.find_function(function_name)
- assert function
- return llvmjit.execute(function, param)
+ f = llvmjit.FindFunction(function_name)
+ assert f.function
+ return llvmjit.execute(f.function, param)
+ #return function(param) #XXX this does not seem to translate, how to do it instead?
#tests...
def test_restart():
@@ -48,14 +49,6 @@
assert llvmjit.find_function('square')
assert llvmjit.find_function('square')
-def test_execute_translation():
- llvmjit.restart()
- def f(x):
- return execute(llsquare, 'square', x + 5)
- fn = compile(f, [int])
- res = fn(1)
- assert res == 36
-
def test_compile():
llvmjit.restart()
assert llvmjit.compile(llsquare)
@@ -74,6 +67,16 @@
assert llvmjit.execute(square, i) == i * i
assert llvmjit.execute(mul2 , i) == i * 2
+def test_call_found_function():
+ llvmjit.restart()
+ llvmjit.compile(llsquare)
+ llvmjit.compile(llmul2)
+ square = llvmjit.FindFunction('square')
+ mul2 = llvmjit.FindFunction('mul2')
+ for i in range(5):
+ assert square(i) == i * i
+ assert mul2(i) == i * 2
+
def DONTtest_execute_accross_module():
pass
@@ -94,3 +97,11 @@
def DONTtest_layers_of_codegenerators(): #e.g. i386 code until function stabilizes then llvm
pass
+
+def test_execute_translation(): #put this one last because it takes the most time
+ llvmjit.restart()
+ def f(x):
+ return execute(llsquare, 'square', x + 5)
+ fn = compile(f, [int])
+ res = fn(1)
+ assert res == 36
More information about the Pypy-commit
mailing list