[pypy-svn] r39863 - in pypy/dist/pypy/translator/llvm: . test
rxe at codespeak.net
rxe at codespeak.net
Sun Mar 4 12:23:22 CET 2007
Author: rxe
Date: Sun Mar 4 12:23:21 2007
New Revision: 39863
Modified:
pypy/dist/pypy/translator/llvm/opwriter.py
pypy/dist/pypy/translator/llvm/structnode.py
pypy/dist/pypy/translator/llvm/test/test_lltype.py
Log:
(mwh, rxe) implement direct_xxx. all tests in test_lltype pass now
Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py (original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py Sun Mar 4 12:23:21 2007
@@ -39,16 +39,6 @@
else:
self.functionref = '%pypyop_' + op.opname
-def arrayindices(arg):
- ARRAYTYPE = arg.concretetype.TO
- if isinstance(ARRAYTYPE, lltype.Array):
- # skip the length field
- indices = [("uint", 1)]
- else:
- assert isinstance(ARRAYTYPE, lltype.FixedSizeArray)
- indices = []
- return indices
-
class OpWriter(object):
binary_operations = {
@@ -102,6 +92,16 @@
else:
return [self.db.repr_tmpvar() for ii in range(count)]
+ def _arrayindices(self, arg):
+ ARRAYTYPE = arg.concretetype.TO
+ if isinstance(ARRAYTYPE, lltype.Array):
+ # skip the length field
+ indices = [(self.uword, 1)]
+ else:
+ assert isinstance(ARRAYTYPE, lltype.FixedSizeArray)
+ indices = []
+ return indices
+
def write_operation(self, op):
#log(op)
@@ -350,17 +350,17 @@
assert index != -1
tmpvar = self._tmp()
self.codewriter.getelementptr(tmpvar, opr.argtypes[0],
- opr.argrefs[0], [("uint", index)])
+ opr.argrefs[0], [(self.uword, index)])
# get element ptr gets a pointer to the right type, except the generated code really expected
# an array of size 1... so we just cast it
- element_type = self.db.repr_type(op.result.concretetype.TO.OF)+'*'
+ element_type = self.db.repr_type(op.result.concretetype.TO.OF) + '*'
self.codewriter.cast(opr.retref, element_type, tmpvar, opr.rettype)
def getsubstruct(self, opr):
index = getindexhelper(opr.op.args[1].value,
opr.op.args[0].concretetype.TO)
assert opr.rettype != "void"
- indices = [("uint", index)]
+ indices = [(self.uword, index)]
self.codewriter.getelementptr(opr.retref, opr.argtypes[0],
opr.argrefs[0], indices)
@@ -371,7 +371,7 @@
index = getindexhelper(op.args[1].value,
op.args[0].concretetype.TO)
self.codewriter.getelementptr(tmpvar, opr.argtypes[0],
- opr.argrefs[0], [("uint", index)])
+ opr.argrefs[0], [(self.uword, index)])
self.codewriter.store(opr.argtypes[2], opr.argrefs[2], tmpvar)
else:
self._skipped(opr)
@@ -387,21 +387,41 @@
arraytype, indextype = opr.argtypes
tmpvar = self._tmp()
- indices = arrayindices(opr.op.args[0]) + [(indextype, index)]
+ indices = self._arrayindices(opr.op.args[0]) + [(self.word, index)]
self.codewriter.getelementptr(tmpvar, arraytype, array, indices)
self.codewriter.load(opr.retref, opr.rettype, tmpvar)
def direct_arrayitems(self, opr):
- array, index = opr.argrefs
- arraytype, indextype = opr.argtypes
- indices = arrayindices(opr.op.args[0]) + [(indextype, index)]
- self.codewriter.getelementptr(opr.retref, arraytype, array, indices)
+ assert opr.rettype != "void"
+
+ array = opr.argrefs[0]
+ arraytype = opr.argtypes[0]
+ indices = self._arrayindices(opr.op.args[0]) + [(self.word, 0)]
+ tmpvar = self._tmp()
+ self.codewriter.getelementptr(tmpvar, arraytype, array, indices)
+ # get element ptr gets a pointer to the right type, except the generated code really expected
+ # an array of size 1... so we just cast it
+ element_type = self.db.repr_type(opr.op.result.concretetype.TO.OF) + '*'
+ self.codewriter.cast(opr.retref, element_type, tmpvar, opr.rettype)
+
+ def direct_ptradd(self, opr):
+ array, incr = opr.argrefs
+ arraytype, _ = opr.argtypes
+
+ tmpvar = self._tmp()
+ self.codewriter.getelementptr(tmpvar, arraytype, array, [(self.word, incr)])
+
+ # get element ptr gets a pointer to the right type, except the generated code really expected
+ # an array of size 1... so we just cast it
+ element_type = self.db.repr_type(opr.op.result.concretetype.TO.OF) + '*'
+ self.codewriter.cast(opr.retref, element_type, tmpvar, opr.rettype)
+
def getarraysubstruct(self, opr):
array, index = opr.argrefs
arraytype, indextype = opr.argtypes
- indices = arrayindices(opr.op.args[0]) + [(indextype, index)]
+ indices = self._arrayindices(opr.op.args[0]) + [(self.word, index)]
self.codewriter.getelementptr(opr.retref, arraytype, array, indices)
def setarrayitem(self, opr):
@@ -413,7 +433,7 @@
self._skipped(opr)
return
- indices = arrayindices(opr.op.args[0]) + [(indextype, index)]
+ indices = self._arrayindices(opr.op.args[0]) + [(self.word, index)]
self.codewriter.getelementptr(tmpvar, arraytype, array, indices)
self.codewriter.store(valuetype, valuevar, tmpvar)
bare_setarrayitem = setarrayitem
@@ -423,7 +443,7 @@
assert isinstance(ARRAYTYPE, lltype.Array)
tmpvar = self._tmp()
self.codewriter.getelementptr(tmpvar, opr.argtypes[0],
- opr.argrefs[0], [("uint", 0)])
+ opr.argrefs[0], [(self.uword, 0)])
self.codewriter.load(opr.retref, opr.rettype, tmpvar)
def adr_delta(self, opr):
Modified: pypy/dist/pypy/translator/llvm/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/structnode.py (original)
+++ pypy/dist/pypy/translator/llvm/structnode.py Sun Mar 4 12:23:21 2007
@@ -157,14 +157,16 @@
def get_ref(self):
""" Returns a reference as used for operations in blocks. """
- if self._get_ref_cache:
- return self._get_ref_cache
+ # XXX cache here is **dangerous** considering it can return different values :-(
+ # XXX should write a test to prove this
+ #if self._get_ref_cache:
+ # return self._get_ref_cache
p, c = lltype.parentlink(self.value)
if p is None:
ref = self.ref
else:
ref = self.db.get_childref(p, c)
- self._get_ref_cache = ref
+ #XXXself._get_ref_cache = ref
return ref
def get_pbcref(self, toptr):
@@ -181,6 +183,11 @@
class FixedSizeArrayNode(StructNode):
prefix = '%fixarrayinstance_'
+ def __init__(self, db, struct):
+ super(FixedSizeArrayNode, self).__init__(db, struct)
+ self.array = struct
+ self.arraytype = self.structtype.OF
+
def __str__(self):
return "<FixedSizeArrayNode %r>" % (self.ref,)
@@ -190,14 +197,25 @@
all_values = ",\n ".join(values)
return "%s [\n %s\n ]\n" % (self.get_typerepr(), all_values)
+ def get_ref(self):
+ p, c = lltype.parentlink(self.value)
+ if p is None:
+ ref = self.ref
+ else:
+ assert isinstance(self.value, lltype._subarray)
+ ref = self.db.get_childref(p, c)
+
+ # ptr -> array of len 1
+ ref = "cast(%s* %s to %s*)" % (self.db.repr_type(self.arraytype),
+ ref,
+ self.db.repr_type(lltype.typeOf(self.value)))
+ return ref
+
def get_childref(self, index):
- ptr_type = self.db.repr_type(self.structtype.OF) + '*'
- to_one_type = self.db.repr_type(lltype.FixedSizeArray(self.structtype.OF, 1)) + '*'
- ptr = "getelementptr(%s* %s, int 0, int %s)" % (
+ return "getelementptr(%s* %s, int 0, int %s)" % (
self.get_typerepr(),
self.get_ref(),
index)
- return "cast(%s %s to %s)" % (ptr_type, ptr, to_one_type)
def setup(self):
if isinstance(self.value, lltype._subarray):
Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lltype.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_lltype.py Sun Mar 4 12:23:21 2007
@@ -352,7 +352,6 @@
assert res == -1
def test_direct_arrayitems():
- py.test.skip("wip")
for a in [malloc(GcArray(Signed), 5),
malloc(FixedSizeArray(Signed, 5), immortal=True)]:
a[0] = 0
@@ -411,7 +410,6 @@
assert res == 142
def test_prebuilt_subarrays():
- py.test.skip("wip")
a1 = malloc(GcArray(Signed), 5, zero=True)
a2 = malloc(FixedSizeArray(Signed, 5), immortal=True)
s = malloc(GcStruct('S', ('x', Signed), ('y', Signed)))
More information about the Pypy-commit
mailing list