[pypy-svn] r48811 - pypy/dist/pypy/translator/llvm

rxe at codespeak.net rxe at codespeak.net
Tue Nov 20 11:50:28 CET 2007


Author: rxe
Date: Tue Nov 20 11:50:28 2007
New Revision: 48811

Modified:
   pypy/dist/pypy/translator/llvm/database.py
   pypy/dist/pypy/translator/llvm/opwriter.py
   pypy/dist/pypy/translator/llvm/typedefnode.py
Log:
make an array of no length a pointer in llvm backend

Modified: pypy/dist/pypy/translator/llvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/database.py	(original)
+++ pypy/dist/pypy/translator/llvm/database.py	Tue Nov 20 11:50:28 2007
@@ -529,7 +529,7 @@
         return repr
     
     def repr_offset(self, value):
-        from_, indices, to = self.get_offset(value)
+        from_, indices, to = self.get_offset(value, [])
 
         # void array special cases
         if isinstance(from_, lltype.Array) and from_.OF is lltype.Void:
@@ -554,12 +554,15 @@
                                                                      r(from_),
                                                                      indices_as_str)
 
-    def get_offset(self, value, initialindices=None):
+    def get_offset(self, value, indices):
         " return (from_type, (indices, ...), to_type) "
+
         word = self.database.get_machine_word()
-        indices = initialindices or [(word, 0)]
 
         if isinstance(value, llmemory.ItemOffset):
+            if not indices:
+                indices.append((word, 0))
+            
             # skips over a fixed size item (eg array access)
             from_ = value.TYPE
             lasttype, lastvalue = indices[-1]
@@ -568,6 +571,9 @@
             to = value.TYPE
         
         elif isinstance(value, llmemory.FieldOffset):
+            if not indices:
+                indices.append((word, 0))
+
             # jumps to a field position in a struct
             from_ = value.TYPE
             pos = getindexhelper(value.fldname, value.TYPE)
@@ -575,19 +581,32 @@
             to = getattr(value.TYPE, value.fldname)            
 
         elif isinstance(value, llmemory.ArrayLengthOffset):
+            assert not value.TYPE._hints.get("nolength", False)
+
+            if not indices:
+                indices.append((word, 0))
+
             # jumps to the place where the array length is stored
             from_ = value.TYPE     # <Array of T> or <GcArray of T>
             assert isinstance(value.TYPE, lltype.Array)
-            if not value.TYPE._hints.get("nolength", False):
-                indices.append((word, 0))
+            indices.append((word, 0))
             to = lltype.Signed
 
         elif isinstance(value, llmemory.ArrayItemsOffset):
+            if not indices:
+                if isinstance(value.TYPE, lltype.Array) and value.TYPE._hints.get("nolength", False):
+                    pass
+                else:
+                    indices.append((word, 0))
+                    
             # jumps to the beginning of array area
             from_ = value.TYPE
             if not isinstance(value.TYPE, lltype.FixedSizeArray) and not value.TYPE._hints.get("nolength", False):
                 indices.append((word, 1))
-            indices.append((word, 0))    # go to the 1st item
+                indices.append((word, 0)) # go to the 1st item
+            if isinstance(value.TYPE, lltype.FixedSizeArray):
+                indices.append((word, 0)) # go to the 1st item
+                            
             to = value.TYPE.OF
 
         elif isinstance(value, llmemory.CompositeOffset):

Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Tue Nov 20 11:50:28 2007
@@ -113,9 +113,11 @@
         if isinstance(ARRAYTYPE, lltype.Array):
             if not ARRAYTYPE._hints.get("nolength", False):
                 # skip the length field
+                indices.append((self.word, 0))
                 indices.append((self.word, 1))
         else:
             assert isinstance(ARRAYTYPE, lltype.FixedSizeArray)
+            indices.append((self.word, 0))
         return indices
 
     def write_operation(self, op):
@@ -313,7 +315,10 @@
                              [word], [opr.argrefs[0]])
 
     def to_getelementptr(self, TYPE, args):
-        indices = []
+        if isinstance(TYPE, lltype.Array) and TYPE._hints.get("nolength", False):
+            indices = []
+        else:
+            indices = [("i32", 0)]
         for arg in args:
             name = None
             # this is because FixedSizeArray can sometimes be accessed like an
@@ -351,7 +356,7 @@
             op = opr.op
             _, indices = self.to_getelementptr(op.args[0].concretetype.TO, op.args[1:])
             tmpvar = self._tmp()
-            self.codewriter.getelementptr(tmpvar, opr.argtypes[0], opr.argrefs[0], indices)
+            self.codewriter.getelementptr(tmpvar, opr.argtypes[0], opr.argrefs[0], indices, getptr=False)
             self.codewriter.load(opr.retref, opr.rettype, tmpvar)
         else:
             self._skipped(opr)
@@ -365,7 +370,7 @@
         assert opr.rettype != "void"
         op = opr.op
         _, indices = self.to_getelementptr(op.args[0].concretetype.TO, op.args[1:])
-        self.codewriter.getelementptr(opr.retref, opr.argtypes[0], opr.argrefs[0], indices)
+        self.codewriter.getelementptr(opr.retref, opr.argtypes[0], opr.argrefs[0], indices, getptr=False)
 
     # struct, name
     getsubstruct = _getinteriorpointer
@@ -377,7 +382,7 @@
         if opr.argtypes[-1] != "void":
             _, indices = self.to_getelementptr(op.args[0].concretetype.TO, op.args[1:-1])
             tmpvar = self._tmp()
-            self.codewriter.getelementptr(tmpvar, opr.argtypes[0], opr.argrefs[0], indices)
+            self.codewriter.getelementptr(tmpvar, opr.argtypes[0], opr.argrefs[0], indices, getptr=False)
             self.codewriter.store(opr.argtypes[-1], opr.argrefs[-1], tmpvar)
         else:
             self._skipped(opr)            
@@ -392,10 +397,11 @@
         op = opr.op
         TYPE, indices = self.to_getelementptr(op.args[0].concretetype.TO, op.args[1:])
         if isinstance(TYPE, lltype.Array):
+            assert not TYPE._hints.get("nolength", False) 
             # gets the length
             indices.append(("i32", 0))
             lengthref = self._tmp()
-            self.codewriter.getelementptr(lengthref, opr.argtypes[0], opr.argrefs[0], indices)
+            self.codewriter.getelementptr(lengthref, opr.argtypes[0], opr.argrefs[0], indices, getptr=False)
         else:
             assert False, "known at compile time"
 
@@ -428,7 +434,7 @@
         arraytype = opr.argtypes[0]
         indices = self._arrayindices(opr.op.args[0]) + [(self.word, 0)]
         tmpvar = self._tmp()
-        self.codewriter.getelementptr(tmpvar, arraytype, array, indices)
+        self.codewriter.getelementptr(tmpvar, arraytype, array, indices, getptr=False)
 
         # getelementptr gets a pointer to the right type, except the generated code really expected 
         # an array of size 1... so we just cast it
@@ -440,7 +446,13 @@
         arraytype, _ = opr.argtypes
         
         tmpvar = self._tmp()
-        self.codewriter.getelementptr(tmpvar, arraytype, array, [(self.word, incr)])
+
+        indices = []
+        ARRAY = opr.op.args[0].concretetype.TO
+        if not (isinstance(ARRAY, lltype.Array) and ARRAY._hints.get("nolength", False)):
+            indices.append( (self.word, 0))
+        indices.append((self.word, incr))
+        self.codewriter.getelementptr(tmpvar, arraytype, array, indices, getptr=False)
 
         # getelementptr gets a pointer to the right type, except the generated code really expected 
         # an array of size 1... so we just cast it

Modified: pypy/dist/pypy/translator/llvm/typedefnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/typedefnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/typedefnode.py	Tue Nov 20 11:50:28 2007
@@ -34,7 +34,7 @@
     def writetypedef(self, codewriter):
         if self.ARRAY._hints.get("nolength", False):
             codewriter.typedef(self.ref, 
-                               "[0 x %s]" % self.db.repr_type(self.ARRAY.OF))
+                               "%s" % self.db.repr_type(self.ARRAY.OF))
         else:
             codewriter.typedef(self.ref, 
                                "{ %s, [0 x %s] }" % (self.db.get_machine_word(),



More information about the Pypy-commit mailing list