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

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Jan 10 12:01:01 CET 2006


Author: ericvrp
Date: Tue Jan 10 12:00:59 2006
New Revision: 21866

Modified:
   pypy/dist/pypy/translator/llvm/codewriter.py
   pypy/dist/pypy/translator/llvm/opwriter.py
   pypy/dist/pypy/translator/llvm/test/test_lladdresses.py
Log:
Added genllvm support for allocating data on the stack with
flavored_malloc. Explicit flavored_free operations on stack
allocated data is skipped. Includes testcase.


Modified: pypy/dist/pypy/translator/llvm/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/codewriter.py	Tue Jan 10 12:00:59 2006
@@ -167,6 +167,9 @@
                                                 functionref,
                                                 args))
 
+    def alloca(self, targetvar, vartype):
+        self._indent("%s = alloca %s" % (targetvar, vartype))
+
     def malloc(self, targetvar, vartype):
         self._indent("%s = malloc %s" % (targetvar, vartype))
 

Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Tue Jan 10 12:00:59 2006
@@ -282,6 +282,8 @@
         type_  = opr.rettype[:-1] #XXX stripping of *
         if flavor == "raw": 
             self.codewriter.malloc(opr.retref, type_)
+        elif flavor == "alloca": 
+            self.codewriter.alloca(opr.retref, type_)
         else:
             raise NotImplementedError
 
@@ -289,6 +291,8 @@
         flavor = opr.op.args[0].value
         if flavor == "raw":
             self.codewriter.free(opr.argtypes[1], opr.argrefs[1])
+        elif flavor == "alloca":
+            self.codewriter.comment('***Skipping free of stack allocated data')
         else:
             raise NotImplementedError
 

Modified: pypy/dist/pypy/translator/llvm/test/test_lladdresses.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lladdresses.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_lladdresses.py	Tue Jan 10 12:00:59 2006
@@ -103,7 +103,7 @@
     res = fc()
     assert res == int('011100' * 2, 2)
 
-def test_flavored_malloc():
+def test_flavored_malloci_raw():
     class A(object):
         _alloc_flavor_ = "raw"
         def __init__(self, val):
@@ -115,3 +115,16 @@
         return result
     fn = compile(f, [int])
     assert fn(1) == 2 
+
+def test_flavored_malloc_alloca():
+    class A(object):
+        _alloc_flavor_ = "alloca"
+        def __init__(self, val):
+            self.val = val
+    def f(x):
+        a = A(x + 1)
+        result = a.val
+        free_non_gc_object(a)
+        return result
+    fn = compile(f, [int])
+    assert fn(1) == 2 



More information about the Pypy-commit mailing list