From 4f412b8c34388d476433eb85aabf41e7aca21ea5 Mon Sep 17 00:00:00 2001 From: fedor Date: Tue, 3 Aug 1999 16:37:08 +0000 Subject: [PATCH] Hacks for mframes with small structs git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4693 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++ Source/NSInvocation.m | 9 ++++ Source/mframe/sparc/solaris2.6 | 87 ++++++++++++++++++++++++++++++++++ Testing/invocation_int.m | 3 ++ Testing/invocation_long.m | 3 ++ Testing/invocation_short.m | 1 + 6 files changed, 110 insertions(+) create mode 100644 Source/mframe/sparc/solaris2.6 diff --git a/ChangeLog b/ChangeLog index 144d27bb5..5279c03dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Aug 3 12:36:54 1999 Adam Fedor + + * Source/NSInvocation.m (-initWithTarget:selector:): Hack for + sparc and ppc machines to align structs on word boundaries. + * mframe/sparc/solaris2.6: New file with fix for putting small + structures at correct offset. + Mon Aug 2 8:10:00 1999 Richard Frith-Macdonald * Source/propList.h: parseQuotedString() fix for parsing octal escape diff --git a/Source/NSInvocation.m b/Source/NSInvocation.m index 4a21e9230..6f0c17bd1 100644 --- a/Source/NSInvocation.m +++ b/Source/NSInvocation.m @@ -591,6 +591,15 @@ CASE_TYPE(_C_FLT, float); CASE_TYPE(_C_DBL, double); CASE_TYPE(_C_PTR, void*); + case _C_STRUCT_B: +#if MFRAME_STRUCT_BYREF + /* FIXME: This only appears on sparc and ppc machines so far. + structures appear to be aligned on word boundaries. + Hopefully there is a more general way to figure this out */ + size = (sizearg_regs+sizeof(void*)): (void*)0) + +#define MFRAME_SET_STRUCT_ADDR(ARGS, TYPES, ADDR) \ +({if (*(TYPES)==_C_STRUCT_B || *(TYPES)==_C_UNION_B || *(TYPES)==_C_ARY_B) \ + *(void**)((ARGS)->arg_regs+sizeof(void*)) = (ADDR);}) + +#define IN_REGS 0 +#define ON_STACK 1 + +struct sparc_args { + int offsets[2]; /* 0 for args in regs, 1 for the rest of args on stack */ + int onStack; +}; + +#define MFRAME_ARGS struct sparc_args + +#define MFRAME_INIT_ARGS(CUM, RTYPE) \ +({ \ + (CUM).offsets[0] = 8; /* encoding in regs starts from 8 */ \ + (CUM).offsets[1] = 20; /* encoding on stack starts from 20 or 24 */ \ + (CUM).onStack = NO; \ +}) + +#define GET_SPARC_ARG_LOCATION(CUM, CSTRING_TYPE, TYPESIZE) \ +((CUM).onStack \ + ? ON_STACK \ + : ((CUM).offsets[IN_REGS] + TYPESIZE <= 6 * sizeof(int) + 8 \ + ? (((CUM).offsets[IN_REGS] + TYPESIZE <= 6 * sizeof(int) + 4 \ + ? 0 : ((CUM).offsets[ON_STACK] += 4)),\ + IN_REGS) \ + : ((CUM).onStack = YES, ON_STACK))) + +#define MFRAME_ARG_ENCODING(CUM, TYPE, STACK, DEST) \ +({ \ + const char* type = (TYPE); \ + int align = objc_alignof_type(type); \ + int size = objc_sizeof_type(type); \ + int locn = GET_SPARC_ARG_LOCATION(CUM, type, size); \ +\ + (CUM).offsets[locn] = ROUND((CUM).offsets[locn], align); \ + if (size < sizeof(int)) \ + (CUM).offsets[locn] -= (sizeof(int) - size); \ + (TYPE) = objc_skip_typespec(type); \ + if (locn == IN_REGS) \ + { \ + sprintf((DEST), "%.*s+%d", (TYPE)-type, type, (CUM).offsets[locn]); \ + } \ + else \ + { \ + sprintf((DEST), "%.*s%d", (TYPE)-type, type, (CUM).offsets[locn]); \ + } \ + if (*(TYPE) == '+') \ + { \ + (TYPE)++; \ + } \ + while (isdigit(*(TYPE))) \ + { \ + (TYPE)++; \ + } \ + (DEST)=&(DEST)[strlen(DEST)]; \ + if (locn == ON_STACK) \ + { \ + if ((*type==_C_STRUCT_B || *type==_C_UNION_B || *type==_C_ARY_B)) \ + { \ + (STACK) = (CUM).offsets[ON_STACK] + ROUND(size, align); \ + } \ + else \ + { \ + (STACK) = (CUM).offsets[ON_STACK] + size; \ + } \ + } \ + (CUM).offsets[locn] += \ + size < sizeof(int) \ + ? ROUND(size, align) \ + : ROUND(size, sizeof(void*)); \ +}) + diff --git a/Testing/invocation_int.m b/Testing/invocation_int.m index f86dc1e83..2f761b3d3 100644 --- a/Testing/invocation_int.m +++ b/Testing/invocation_int.m @@ -1,6 +1,7 @@ #include #include #include +#include #include #define TYPE int @@ -55,12 +56,14 @@ void test6(); int main () { + id pool = [NSAutoreleasePool new]; test1(); test2(); test3(); test4(); test5(); test6(); + [pool release]; } void diff --git a/Testing/invocation_long.m b/Testing/invocation_long.m index 62adef686..c7a420b1e 100644 --- a/Testing/invocation_long.m +++ b/Testing/invocation_long.m @@ -1,6 +1,7 @@ #include #include #include +#include #include #define TYPE long @@ -55,12 +56,14 @@ void test6(); int main () { + id pool = [NSAutoreleasePool new]; test1(); test2(); test3(); test4(); test5(); test6(); + [pool release]; } void diff --git a/Testing/invocation_short.m b/Testing/invocation_short.m index 3b2534858..da1a89d94 100644 --- a/Testing/invocation_short.m +++ b/Testing/invocation_short.m @@ -1,6 +1,7 @@ #include #include #include +#include #include #define TYPE short