[pypy-svn] r49063 - in pypy/dist/pypy/translator/llvm: . test

rxe at codespeak.net rxe at codespeak.net
Sun Nov 25 10:00:11 CET 2007


Author: rxe
Date: Sun Nov 25 10:00:10 2007
New Revision: 49063

Modified:
   pypy/dist/pypy/translator/llvm/database.py
   pypy/dist/pypy/translator/llvm/externs2ll.py
   pypy/dist/pypy/translator/llvm/gc.py
   pypy/dist/pypy/translator/llvm/genllvm.py
   pypy/dist/pypy/translator/llvm/opwriter.py
   pypy/dist/pypy/translator/llvm/test/test_standalone.py
Log:
more fixing debug print.  use database to store externs that call back into rpython code (needed for fastcc -> ccc conversions)

Modified: pypy/dist/pypy/translator/llvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/database.py	(original)
+++ pypy/dist/pypy/translator/llvm/database.py	Sun Nov 25 10:00:10 2007
@@ -39,6 +39,9 @@
 
         self.debugstringnodes = []
 
+        # call back into rpython code from c code
+        self.extern_to_funcnodes = []
+
 
     #_______debuggging______________________________________
 
@@ -317,6 +320,9 @@
         self._tmpcount += 1
         return "%tmp_" + str(count) 
 
+    def add_extern_to_funcnode(self, name): 
+        self.extern_to_funcnodes.append(name)
+
     # __________________________________________________________
     # Other helpers
 

Modified: pypy/dist/pypy/translator/llvm/externs2ll.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/externs2ll.py	(original)
+++ pypy/dist/pypy/translator/llvm/externs2ll.py	Sun Nov 25 10:00:10 2007
@@ -33,17 +33,18 @@
         includestr += "-I %s " % ii
     return includestr
 
-# call entrypoint needs to be fastcc
 # call boehm finalizers need to be fastcc
 
 def generate_ll(ccode, default_cconv, c_include_dirs, call_funcnames=[]):
-
-    call_funcnames += ['@LLVM_RPython_StartupCode']
+    call_funcnames = ['@LLVM_RPython_StartupCode'] + call_funcnames
     define_funcnames = ['@pypy_malloc',
                         '@pypy_malloc_atomic',
                         '@pypy_gc__collect',
-                        '@pypy_register_finalizer']
-    declare_funcnames = ['@LLVM_RPython_StartupCode']
+                        '@pypy_register_finalizer',
+                        '@raw_malloc',
+                        '@raw_free',
+                        ]
+    declare_funcnames = call_funcnames
 
     filename = str(udir.join("ccode.c"))
     f = open(filename, "w")

Modified: pypy/dist/pypy/translator/llvm/gc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/gc.py	(original)
+++ pypy/dist/pypy/translator/llvm/gc.py	Sun Nov 25 10:00:10 2007
@@ -75,7 +75,6 @@
 
         # malloc_size is unsigned right now
         codewriter.malloc(targetvar, "i8", size)
-        # XXX uses own cconv
         codewriter.call(None, 'void', '@llvm.memset' + postfix(),
                         ['i8*', 'i8', word, word],
                         [targetvar, 0, size, boundary_size],

Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Sun Nov 25 10:00:10 2007
@@ -45,8 +45,6 @@
     return new_entrypoint
 
 class GenLLVM(object):
-    debug = False
-    
     # see create_codewriter() below
     function_count = {}
 
@@ -96,7 +94,7 @@
             if hasattr(node, 'writeimpl'):
                 node.writeimpl(codewriter)
 
-        self._debug()
+        self._debug(codewriter)
         
         codewriter.comment("End of file")
         codewriter.close()
@@ -125,7 +123,7 @@
         # get entry point
         entry_point = self.get_entry_point(func)
         self._checkpoint('get_entry_point')
-        
+
         # set up all nodes
         self.db.setup_all()
         
@@ -181,6 +179,7 @@
         else:
             self.function_count[name] = 1
 
+        self.db.add_extern_to_funcnode(name)
         self.entry_name = name[6:]
         return c.value._obj 
 
@@ -199,7 +198,7 @@
                 c_sources[source] = True
 
         ccode = generate_c(self.db, self.entrynode, c_includes, c_sources, self.standalone)
-        self.llcode = generate_ll(ccode, codewriter.cconv, c_include_dirs)
+        self.llcode = generate_ll(ccode, codewriter.cconv, c_include_dirs, self.db.extern_to_funcnodes)
         
     def create_codewriter(self):
         # prevent running the same function twice in a test
@@ -267,12 +266,11 @@
         for s in stats:
             log('STATS %s' % str(s))
 
-    def _debug(self):
-        if self.debug:
-            if self.db.debugstringnodes:            
-                codewriter.header_comment("Debug string")
-                for node in self.db.debugstringnodes:
-                    node.writeglobalconstants(codewriter)
+    def _debug(self, codewriter):
+        if self.db.debugstringnodes:            
+            codewriter.header_comment("Debug string")
+            for node in self.db.debugstringnodes:
+                node.writeglobalconstants(codewriter)
 
             #print "Start"
             #print self.db.dump_pbcs()

Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Sun Nov 25 10:00:10 2007
@@ -126,6 +126,7 @@
 
         if self.db.genllvm.config.translation.llvm.debug:
             self.codewriter.comment(str(op))
+            #self.codewriter.debug_print(str(op) + "\n")
 
         if op.opname in ("direct_call", 'indirect_call'):
             opr = OpReprCall(op, self.db)
@@ -307,6 +308,9 @@
             value = opr.op.args[0].value._obj        
             if getattr(value, 'external', None) == 'C':
                 cconv = 'ccc'
+
+        #self.codewriter.debug_print(str(opr.op) + "\n")
+        #self.codewriter.debug_print(str(cconv) + "\n")
             
         # if we are external node - should use standard calling conventions
         self.codewriter.call(opr.retref, opr.rettype, opr.argrefs[0],
@@ -323,6 +327,8 @@
         self.db.gcpolicy._zeromalloc(self.codewriter, opr.retref, opr.argrefs[0], atomic=True)
 
     def boehm_register_finalizer(self, opr):
+        # XXX point in note - the registeree here have fastcc.... not sure if llvm is dealing with this
+        # because it is a pointer... - presumably
         tmpvar = self._tmp()
         self.codewriter.cast(tmpvar, opr.argtypes[1], opr.argrefs[1], 'i8 *')
         self.codewriter.call(None, 'void', '@pypy_register_finalizer',  ['i8 *', 'i8 *'], [opr.argrefs[0], tmpvar])

Modified: pypy/dist/pypy/translator/llvm/test/test_standalone.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_standalone.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_standalone.py	Sun Nov 25 10:00:10 2007
@@ -37,3 +37,44 @@
     data = cmdexec(exe_name, 'hi', 'there')
     assert data.startswith('''hello world\nargument count: 2\n   'hi'\n   'there'\n''')
 
+def test__del__():
+    from pypy.rpython.lltypesystem import lltype
+    from pypy.rpython.lltypesystem.lloperation import llop
+    class State:
+        pass
+    s = State()
+    class A(object):
+        def __del__(self):
+            s.a_dels += 1
+    class B(A):
+        def __del__(self):
+            s.b_dels += 1
+    class C(A):
+        pass
+    def f():
+        s.a_dels = 0
+        s.b_dels = 0
+        A()
+        B()
+        C()
+        A()
+        B()
+        C()
+        llop.gc__collect(lltype.Void)
+        return s.a_dels * 10 + s.b_dels
+
+    def entry_point(args):
+        res = 0
+        res += f()
+        res += f()
+        print 'count %d' % res
+        return 0
+
+    exe_name = 'test__del__'
+    compile_standalone(entry_point, exe_name=exe_name)
+    data = cmdexec(exe_name, 'abc', 'def')
+    print data
+    #assert data.startswith('argument count: 3')
+
+    #assert 0 < res <= 84 
+



More information about the Pypy-commit mailing list