[pypy-svn] r14193 - in pypy/dist/pypy/translator/llvm2: . test

bert at codespeak.net bert at codespeak.net
Sun Jul 3 21:27:00 CEST 2005


Author: bert
Date: Sun Jul  3 21:26:59 2005
New Revision: 14193

Modified:
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/pyxwrapper.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
added GC_get_heap_size to be able to test the boehm GC in llvm2 backend


Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py	Sun Jul  3 21:26:59 2005
@@ -1,5 +1,5 @@
 from os.path import exists
-use_boehm_gc = exists('/usr/lib/libgc.so')
+use_boehm_gc = exists('/usr/lib/libgc.so') or exists('/usr/lib/libgc.a')
 
 import py
 from pypy.translator.llvm2 import build_llvm_module
@@ -60,8 +60,7 @@
     pyxsource = llvmsource.new(basename=llvmsource.purebasename+'_wrapper'+'.pyx')
     write_pyx_wrapper(entrynode, pyxsource)    
     
-    mod = build_llvm_module.make_module_from_llvm(llvmsource, pyxsource)
-    return getattr(mod, func.func_name + "_wrapper")
+    return build_llvm_module.make_module_from_llvm(llvmsource, pyxsource)
 
 def llvm_is_on_path():
     try:

Modified: pypy/dist/pypy/translator/llvm2/pyxwrapper.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/pyxwrapper.py	(original)
+++ pypy/dist/pypy/translator/llvm2/pyxwrapper.py	Sun Jul  3 21:26:59 2005
@@ -1,5 +1,6 @@
 from pypy.translator.llvm2.log import log 
 from pypy.rpython import lltype 
+from pypy.translator.llvm2.genllvm import use_boehm_gc
 log = log.pyrex 
 
 PRIMITIVES_TO_C = {lltype.Signed: "int",
@@ -23,6 +24,11 @@
     inputargs = funcgen.db.repr_arg_multi(funcgen.graph.startblock.inputargs)
     inputargs = [x.strip("%") for x in inputargs]
     append("cdef extern " + c_declaration())
+    if use_boehm_gc:
+	append("cdef extern int GC_get_heap_size()")
+	append("")
+	append("def GC_get_heap_size_wrapper():")
+	append("    return GC_get_heap_size()")
     append("")
     append("def %s_wrapper(%s):" % (funcgen.ref.strip("%"), ", ".join(inputargs)))
     append("    return %s(%s)" % (funcgen.ref.strip("%"), ", ".join(inputargs)))

Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	Sun Jul  3 21:26:59 2005
@@ -19,7 +19,7 @@
 ## def setup_module(mod):
 ##     mod.llvm_found = is_on_path("llvm-as")
 
-def compile_function(function, annotate, view=False):
+def compile_module(function, annotate, view=False):
     t = Translator(function)
     a = t.annotate(annotate)
     t.specialize()
@@ -28,12 +28,20 @@
         t.view()
     return genllvm(t)
 
+def compile_function(function, annotate, view=False):
+    mod = compile_module(function, annotate, view)
+    return getattr(mod, function.func_name + "_wrapper")
+
+def compile_module_function(function, annotate, view=False):
+    mod = compile_module(function, annotate, view)
+    f = getattr(mod, function.func_name + "_wrapper")
+    return mod, f
+
 def test_GC_malloc(): 
     if not use_boehm_gc:
         py.test.skip("test_GC_malloc skipped because Boehm collector library was not found")
         return
     def tuple_getitem(n): 
-        start_heap_size = GC_get_heap_size()
         x = 0
         i = 0
         while i < n:
@@ -41,14 +49,14 @@
             x += l[2]
             i += 1
         return x
-    f = compile_function(tuple_getitem, [int])
-    heap_size_start = get_heap_size_wrapper()
+    mod,f = compile_module_function(tuple_getitem, [int])
+    get_heap_size = getattr(mod, "GC_get_heap_size_wrapper")
+    heap_size_start = get_heap_size()
     for i in range(0,10):
         f(10000)
         heap_size_used = get_heap_size() - heap_size_start
         print 'heap_size_used=%d' % heap_size_used
-        assert heap_size_used < 5000
-
+        assert heap_size_used < 100000
 
 def test_return1():
     def simple1():



More information about the Pypy-commit mailing list