[pypy-svn] r68245 - in pypy/branch/gc-compress/pypy/translator/c: . src test
arigo at codespeak.net
arigo at codespeak.net
Thu Oct 8 12:01:27 CEST 2009
Author: arigo
Date: Thu Oct 8 12:01:27 2009
New Revision: 68245
Added:
pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h (contents, props changed)
Modified:
pypy/branch/gc-compress/pypy/translator/c/database.py
pypy/branch/gc-compress/pypy/translator/c/node.py
pypy/branch/gc-compress/pypy/translator/c/primitive.py
pypy/branch/gc-compress/pypy/translator/c/src/g_include.h
pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py
Log:
Support for llgroups in the C backend.
Modified: pypy/branch/gc-compress/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/database.py (original)
+++ pypy/branch/gc-compress/pypy/translator/c/database.py Thu Oct 8 12:01:27 2009
@@ -5,6 +5,7 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.llmemory import WeakRef, _WeakRefType, GCREF
from pypy.rpython.lltypesystem.rffi import CConstant
+from pypy.rpython.lltypesystem import llgroup
from pypy.tool.sourcetools import valid_identifier
from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
from pypy.translator.c.node import StructDefNode, ArrayDefNode
@@ -141,6 +142,8 @@
#raise Exception("don't know about opaque type %r" % (T,))
return 'struct %s @' % (
valid_identifier('pypy_opaque_' + T.tag),)
+ elif isinstance(T, llgroup.GroupType):
+ return 'XXX-dont-use-me @'
else:
raise Exception("don't know about type %r" % (T,))
Modified: pypy/branch/gc-compress/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/node.py (original)
+++ pypy/branch/gc-compress/pypy/translator/c/node.py Thu Oct 8 12:01:27 2009
@@ -3,7 +3,7 @@
GcStruct, GcArray, RttiStruct, ContainerType, \
parentlink, Ptr, PyObject, Void, OpaqueType, Float, \
RuntimeTypeInfo, getRuntimeTypeInfo, Char, _subarray
-from pypy.rpython.lltypesystem import llmemory
+from pypy.rpython.lltypesystem import llmemory, llgroup
from pypy.translator.c.funcgen import FunctionCodeGenerator
from pypy.translator.c.external import CExternalFunctionCodeGenerator
from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
@@ -464,11 +464,15 @@
return hasattr(self.T, "_hints") and self.T._hints.get('thread_local')
def forward_declaration(self):
+ if llgroup.member_of_group(self.obj):
+ return
yield '%s;' % (
forward_cdecl(self.implementationtypename,
self.name, self.db.standalone, self.is_thread_local()))
def implementation(self):
+ if llgroup.member_of_group(self.obj):
+ return []
lines = list(self.initializationexpr())
lines[0] = '%s = %s' % (
cdecl(self.implementationtypename, self.name, self.is_thread_local()),
@@ -898,6 +902,58 @@
#obj._converted_weakref = container # hack for genllvm :-/
return db.getcontainernode(container, _dont_write_c_code=False)
+class GroupNode(ContainerNode):
+ nodekind = 'group'
+ count_members = None
+
+ def __init__(self, *args):
+ ContainerNode.__init__(self, *args)
+ self.implementationtypename = 'struct group_%s_s @' % self.name
+
+ def basename(self):
+ return self.obj.name
+
+ def enum_dependencies(self):
+ for member in self.obj.members:
+ yield member._as_ptr()
+
+ def _fix_members(self):
+ if self.count_members is None:
+ self.count_members = len(self.obj.members)
+ else:
+ # make sure no new member showed up, because it's too late
+ assert len(self.obj.members) == self.count_members
+
+ def forward_declaration(self):
+ self._fix_members()
+ ctype = ['%s {' % cdecl(self.implementationtypename, '')]
+ for i, member in enumerate(self.obj.members):
+ structtypename = self.db.gettype(typeOf(member))
+ ctype.append('\t%s;' % cdecl(structtypename, 'member%d' % i))
+ ctype.append('} @')
+ ctype = '\n'.join(ctype)
+ yield '%s;' % (
+ forward_cdecl(ctype, self.name, self.db.standalone,
+ self.is_thread_local()))
+ for i, member in enumerate(self.obj.members):
+ structnode = self.db.getcontainernode(member)
+ yield '#define %s %s.member%d' % (structnode.name,
+ self.name, i)
+
+ def initializationexpr(self):
+ self._fix_members()
+ lines = ['{']
+ lasti = len(self.obj.members) - 1
+ for i, member in enumerate(self.obj.members):
+ structnode = self.db.getcontainernode(member)
+ lines1 = list(structnode.initializationexpr())
+ lines1[0] += '\t/* member%d: %s */' % (i, structnode.name)
+ if i != lasti:
+ lines1[-1] += ','
+ lines.extend(lines1)
+ lines.append('}')
+ return lines
+
ContainerNodeFactory = {
Struct: StructNode,
@@ -909,4 +965,5 @@
OpaqueType: opaquenode_factory,
PyObjectType: PyObjectNode,
llmemory._WeakRefType: weakrefnode_factory,
+ llgroup.GroupType: GroupNode,
}
Modified: pypy/branch/gc-compress/pypy/translator/c/primitive.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/primitive.py (original)
+++ pypy/branch/gc-compress/pypy/translator/c/primitive.py Thu Oct 8 12:01:27 2009
@@ -3,7 +3,7 @@
from pypy.rlib.objectmodel import CDefinedIntSymbolic
from pypy.rlib.rarithmetic import r_longlong, isinf, isnan
from pypy.rpython.lltypesystem.lltype import *
-from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import rffi, llgroup
from pypy.rpython.lltypesystem.llmemory import Address, \
AddressOffset, ItemOffset, ArrayItemsOffset, FieldOffset, \
CompositeOffset, ArrayLengthOffset, \
@@ -136,6 +136,19 @@
else:
return 'NULL'
+def name_ushort(value, db):
+ if isinstance(value, Symbolic):
+ if isinstance(value, llgroup.GroupMemberOffset):
+ groupnode = db.getcontainernode(value.grpptr._as_obj())
+ structnode = db.getcontainernode(value.member._as_obj())
+ return 'GROUP_MEMBER_OFFSET(%s, %s)' % (
+ groupnode.name,
+ structnode.name,
+ )
+ else:
+ raise Exception("unimplemented symbolic %r" % value)
+ return str(value)
+
# On 64 bit machines, SignedLongLong and Signed are the same, so the
# order matters, because we want the Signed implementation.
PrimitiveName = {
@@ -151,6 +164,7 @@
Void: name_void,
Address: name_address,
GCREF: name_gcref,
+ rffi.USHORT: name_ushort,
}
PrimitiveType = {
@@ -166,6 +180,7 @@
Void: 'void @',
Address: 'void* @',
GCREF: 'void* @',
+ rffi.USHORT: 'unsigned short @',
}
def define_c_primitive(ll_type, c_name):
@@ -181,7 +196,7 @@
for ll_type, c_name in [(rffi.SIGNEDCHAR, 'signed char'),
(rffi.UCHAR, 'unsigned char'),
(rffi.SHORT, 'short'),
- (rffi.USHORT, 'unsigned short'),
+ #(rffi.USHORT, 'unsigned short'),
(rffi.INT, 'int'),
(rffi.UINT, 'unsigned int'),
(rffi.LONG, 'long'),
Modified: pypy/branch/gc-compress/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/src/g_include.h (original)
+++ pypy/branch/gc-compress/pypy/translator/c/src/g_include.h Thu Oct 8 12:01:27 2009
@@ -34,6 +34,7 @@
#ifndef AVR
#include "src/unichar.h"
#endif
+#include "src/llgroup.h"
#include "src/instrument.h"
Added: pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h
==============================================================================
--- (empty file)
+++ pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h Thu Oct 8 12:01:27 2009
@@ -0,0 +1,10 @@
+
+
+#define GROUP_MEMBER_OFFSET(group, membername) \
+ ((unsigned short)((((char*)&membername) - ((char*)&group)) / sizeof(long)))
+
+#define OP_GET_GROUP_MEMBER(groupptr, compactoffset, r) \
+ r = ((char*)groupptr) + ((long)compactoffset)*sizeof(long)
+
+#define OP_GET_NEXT_GROUP_MEMBER(groupptr, compactoffset, skipoffset, r) \
+ r = ((char*)groupptr) + ((long)compactoffset)*sizeof(long) + skipoffset
Modified: pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py Thu Oct 8 12:01:27 2009
@@ -701,5 +701,9 @@
fn = self.getcompiled(llf)
fn()
-
-
+ def test_llgroup(self):
+ from pypy.rpython.lltypesystem.test import test_llgroup
+ f = test_llgroup.build_test()
+ fn = self.getcompiled(f)
+ res = fn()
+ assert res == 42
More information about the Pypy-commit
mailing list