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

ericvrp at codespeak.net ericvrp at codespeak.net
Sun Jul 3 17:23:25 CEST 2005


Author: ericvrp
Date: Sun Jul  3 17:23:24 2005
New Revision: 14156

Modified:
   pypy/dist/pypy/translator/llvm2/build_llvm_module.py
   pypy/dist/pypy/translator/llvm2/codewriter.py
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
(ericvrp, bert):

Added Garbage Collection using Boehm collector C library. Working nicely but we have no proper test yet.
note: the use of the GC is enabled when /usr/lib/libgc.so exists.


Modified: pypy/dist/pypy/translator/llvm2/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/build_llvm_module.py	(original)
+++ pypy/dist/pypy/translator/llvm2/build_llvm_module.py	Sun Jul  3 17:23:24 2005
@@ -12,6 +12,7 @@
 from pypy.translator.pyrex.genpyrex import GenPyrex
 from pypy.translator.tool.buildpyxmodule import make_c_from_pyxfile
 from pypy.translator.tool import stdoutcapture
+from pypy.translator.llvm2.genllvm import use_boehm_gc
 
 debug = True
 
@@ -20,7 +21,7 @@
 
 OPTIMIZATION_SWITCHES = "-simplifycfg -mem2reg -instcombine -dce -inline"
 
-def compile_module(module, source_files, object_files):
+def compile_module(module, source_files, object_files, library_files):
     open("%s_setup.py" % module, "w").write(str(py.code.Source(
         '''
         from distutils.core import setup
@@ -29,6 +30,7 @@
             ext_modules = [Extension(
                 name = "%(module)s",
                 sources = %(source_files)s,
+                libraries = %(library_files)s,
                 extra_objects = %(object_files)s)])
         ''' % locals())))
     cmd = "python %s_setup.py build_ext --inplace" % module
@@ -44,6 +46,9 @@
     b = llvmfile.purebasename
     source_files = [ "%s.c" % modname ]
     object_files = []
+    library_files = []
+    if use_boehm_gc:
+        library_files.append('gc')
 
     if sys.maxint == 2147483647:        #32 bit platform
         if optimize:
@@ -76,7 +81,7 @@
                     if debug: print cmd
                     cmdexec(cmd)
                 make_c_from_pyxfile(pyxfile)
-                compile_module(modname, source_files, object_files)
+                compile_module(modname, source_files, object_files, library_files)
             finally:
                 foutput, foutput = c.done()
         except:

Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py	Sun Jul  3 17:23:24 2005
@@ -1,19 +1,16 @@
 import py
 from itertools import count
 from pypy.translator.llvm2.log import log 
+from pypy.translator.llvm2.genllvm import use_boehm_gc
 
 log = log.codewriter 
 show_line_numbers = True
 count = count().next
 
-#hack
-from os import getenv
-use_boehm_gc = getenv('USER','') in ('eric',)
-#/hack
-
 class CodeWriter(object): 
     def __init__(self): 
         self._lines = []
+        self.append('declare sbyte* %GC_malloc(uint)')
 
     def append(self, line): 
         if show_line_numbers:
@@ -102,7 +99,7 @@
             cnt = count()
             self.indent("%%malloc.Size.%(cnt)d = getelementptr %(type_)s* null, int %(size)d" % locals())
             self.indent("%%malloc.SizeU.%(cnt)d = cast %(type_)s* %%malloc.Size.%(cnt)d to uint" % locals())
-            self.indent("%%malloc.Ptr.%(cnt)d = malloc sbyte, uint %%malloc.SizeU.%(cnt)d" % locals())
+            self.indent("%%malloc.Ptr.%(cnt)d = call sbyte* %%GC_malloc(uint %%malloc.SizeU.%(cnt)d)" % locals())
             self.indent("%(targetvar)s = cast sbyte* %%malloc.Ptr.%(cnt)d to %(type_)s*" % locals())
         else:
             self.indent("%(targetvar)s = malloc %(type_)s, uint %(size)s" % locals())

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 17:23:24 2005
@@ -1,3 +1,6 @@
+from os.path import exists
+use_boehm_gc = exists('/usr/lib/libgc.so')
+
 import py
 from pypy.translator.llvm2 import build_llvm_module
 from pypy.translator.llvm2.database import Database 

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 17:23:24 2005
@@ -5,6 +5,7 @@
 
 from pypy.translator.translator import Translator
 from pypy.translator.llvm2.genllvm import genllvm
+from pypy.translator.llvm2.genllvm import use_boehm_gc
 from pypy.translator.llvm2.test import llvmsnippet
 from pypy.objspace.flow.model import Constant, Variable
 
@@ -27,6 +28,24 @@
         t.view()
     return genllvm(t)
 
+def test_GC_malloc(): 
+    if not use_boehm_gc:
+        py.test.skip("test_GC_malloc skipped because Boehm collector library was not found")
+        return
+    py.test.skip("test_GC_malloc skipped because test not yet correct (Boehm collector IS used anyway)")
+    return
+    def tuple_getitem(n): 
+        x = 0
+        i = 0
+        while i < n:
+            l = (1,2,i,234,23,23,23,234,234,234,234)
+            x += l[2]
+            i += 1
+        return x
+    f = compile_function(tuple_getitem, [int])
+    t = 1024*1024*100
+    f(t) #assert f(t) == t
+
 def test_return1():
     def simple1():
         return 1



More information about the Pypy-commit mailing list