|
|
Yes, of course. My reasoning was "sizeof (char) == 1, so a char is a
unit and BITS_PER_UNIT is the bits in a char".
Based on this reasoning, here is another step. Tested on
i686-pc-linux-gnu, C/ObjC. I also built the library forcing HAVE_ABI_H
to false, and it compiles cleanly.
Ok to apply?
Paolo
2005-11-16 Paolo Bonzini <bonzini@xxxxxxx>
* sendmsg.c: Don't include GCC headers nor abi.h.
(__objc_block_forward): Assume INVISIBLE_STRUCT_RETURN.
(__objc_get_forward_imp): Assume OBJC_MAX_STRUCT_BY_VALUE undefined.
* configure.ac: If not necessary, don't use config/backwards/abi.h
and don't define HAVE_ABI_H.
* encoding.c: Include limits.h, define MAX/MIN/ROUND here. Use
CHAR_BIT instead of BITS_PER_UNIT.
[!HAVE_ABI_H]: Do not include abi.h
(objc_layout_structure): Inline default definition of
STRUCTURE_SIZE_BOUNDARY.
(objc_layout_structure_next_member): Remove commented code.
* config/backwards/abi.h: Fix comment formatting.
(gen_rtx_MEM, gen_rtx_REG, rtx, INVISIBLE_STRUCT_RETURN,
STRUCTURE_SIZE_BOUNDARY, MAX, MIN, ROUND): Remove.
(BITS_PER_UNIT): Redefine as __CHAR_BIT__.
* config.h.in: Regenerate.
* configure: Regenerate.
Index: sendmsg.c
===================================================================
--- sendmsg.c (revision 107075)
+++ sendmsg.c (working copy)
@@ -26,11 +26,10 @@ Boston, MA 02110-1301, USA. */
covered by the GNU General Public License. */
/* FIXME: This should be using libffi instead of __builtin_apply
- and friends. */
+ and friends. This is important because we currently assume
+ that all structs are returned either by value, or by reference,
+ independent of the size. */
-#include "tconfig.h"
-#include "coretypes.h"
-#include "abi.h"
#include "objc/runtime.h"
#include "objc/sarray.h"
#include "objc/encoding.h"
@@ -61,12 +60,7 @@ static void __objc_init_install_dtable (
static double __objc_double_forward (id, SEL, ...);
static id __objc_word_forward (id, SEL, ...);
typedef struct { id many[8]; } __big;
-#if INVISIBLE_STRUCT_RETURN
-static __big
-#else
-static id
-#endif
-__objc_block_forward (id, SEL, ...);
+static __big __objc_block_forward (id, SEL, ...);
static Method_t search_for_method_in_hierarchy (Class class, SEL sel);
Method_t search_for_method_in_list (MethodList_t list, SEL op);
id nil_method (id, SEL);
@@ -90,11 +84,7 @@ __objc_get_forward_imp (SEL sel)
{
const char *t = sel->sel_types;
- if (t && (*t == '[' || *t == '(' || *t == '{')
-#ifdef OBJC_MAX_STRUCT_BY_VALUE
- && objc_sizeof_type (t) > OBJC_MAX_STRUCT_BY_VALUE
-#endif
- )
+ if (t && (*t == '[' || *t == '(' || *t == '{'))
return (IMP)__objc_block_forward;
else if (t && (*t == 'f' || *t == 'd'))
return (IMP)__objc_double_forward;
@@ -570,12 +560,7 @@ __objc_double_forward (id rcv, SEL op, .
__builtin_return (res);
}
-#if INVISIBLE_STRUCT_RETURN
-static __big
-#else
-static id
-#endif
-__objc_block_forward (id rcv, SEL op, ...)
+static __big __objc_block_forward (id rcv, SEL op, ...)
{
void *args, *res;
@@ -584,11 +569,7 @@ __objc_block_forward (id rcv, SEL op, ..
if (res)
__builtin_return (res);
else
-#if INVISIBLE_STRUCT_RETURN
return (__big) {{0, 0, 0, 0, 0, 0, 0, 0}};
-#else
- return nil;
-#endif
}
Index: configure.ac
===================================================================
--- configure.ac (revision 107075)
+++ configure.ac (working copy)
@@ -84,15 +84,26 @@ AC_SUBST(OBJC_BOEHM_GC)
# target header
# ----------
-target_config_directory="config/backwards"
+case "${host}" in
+ avr*-*-* | \
+ c4x*-*-* | tic4x-*-* | \
+ m32r*-*-* | \
+ mn10300-*-* | am33_2.0-*-* | \
+ pdp11-*-* | \
+ s390-*-* | s390x-*-*)
+ ;;
-#case "${host}" in
# x86_64-*-linux-*)
# target_config_directory="config/x86_64"
# ;;
-#esac
-
+ *)
+ target_config_directory="config/backwards"
+esac
+if test x"$target_config_directory" != x; then
+ AC_DEFINE(HAVE_ABI_H, 1,
+ [Define if we need non-default ABI definitions for this target.])
+fi
AC_SUBST(target_config_directory)
Index: encoding.c
===================================================================
--- encoding.c (revision 107075)
+++ encoding.c (working copy)
@@ -28,10 +28,32 @@ Boston, MA 02110-1301, USA. */
the executable file might be covered by the GNU General Public License. */
+#include "config.h"
+
+#ifdef HAVE_ABI_H
#include "abi.h"
+#endif
+
#include "objc/objc-api.h"
#include "objc/encoding.h"
#include <stdlib.h>
+#include <limits.h>
+
+#undef MAX
+#define MAX(X, Y) \
+ ({ typeof (X) __x = (X), __y = (Y); \
+ (__x > __y ? __x : __y); })
+
+#undef MIN
+#define MIN(X, Y) \
+ ({ typeof (X) __x = (X), __y = (Y); \
+ (__x < __y ? __x : __y); })
+
+#undef ROUND
+#define ROUND(V, A) \
+ ({ typeof (V) __v = (V); typeof (A) __a = (A); \
+ __a * ((__v+__a - 1)/__a); })
+
/*
return the size of an object specified by type
@@ -138,8 +160,8 @@ objc_sizeof_type (const char *type)
;
size = atoi (type + 1);
- startByte = position / BITS_PER_UNIT;
- endByte = (position + size) / BITS_PER_UNIT;
+ startByte = position / CHAR_BIT;
+ endByte = (position + size) / CHAR_BIT;
return endByte - startByte;
}
@@ -700,9 +722,7 @@ objc_layout_structure (const char *type,
layout->type = type;
layout->prev_type = NULL;
layout->record_size = 0;
- layout->record_align = BITS_PER_UNIT;
-
- layout->record_align = MAX (layout->record_align, STRUCTURE_SIZE_BOUNDARY);
+ layout->record_align = CHAR_BIT * sizeof (struct{char a;});
}
@@ -724,7 +744,7 @@ objc_layout_structure_next_member (struc
type = objc_skip_type_qualifiers (layout->prev_type);
if (*type != _C_BFLD)
- layout->record_size += objc_sizeof_type (type) * BITS_PER_UNIT;
+ layout->record_size += objc_sizeof_type (type) * CHAR_BIT;
else {
/* Get the bitfield's type */
for (bfld_type = type + 1;
@@ -732,8 +752,8 @@ objc_layout_structure_next_member (struc
bfld_type++)
/* do nothing */;
- bfld_type_size = objc_sizeof_type (bfld_type) * BITS_PER_UNIT;
- bfld_type_align = objc_alignof_type (bfld_type) * BITS_PER_UNIT;
+ bfld_type_size = objc_sizeof_type (bfld_type) * CHAR_BIT;
+ bfld_type_align = objc_alignof_type (bfld_type) * CHAR_BIT;
bfld_field_size = atoi (objc_skip_typespec (bfld_type));
layout->record_size += bfld_field_size;
}
@@ -752,7 +772,7 @@ objc_layout_structure_next_member (struc
type = objc_skip_type_qualifiers (layout->type);
if (*type != _C_BFLD)
- desired_align = objc_alignof_type (type) * BITS_PER_UNIT;
+ desired_align = objc_alignof_type (type) * CHAR_BIT;
else
{
desired_align = 1;
@@ -762,8 +782,8 @@ objc_layout_structure_next_member (struc
bfld_type++)
/* do nothing */;
- bfld_type_size = objc_sizeof_type (bfld_type) * BITS_PER_UNIT;
- bfld_type_align = objc_alignof_type (bfld_type) * BITS_PER_UNIT;
+ bfld_type_size = objc_sizeof_type (bfld_type) * CHAR_BIT;
+ bfld_type_align = objc_alignof_type (bfld_type) * CHAR_BIT;
bfld_field_size = atoi (objc_skip_typespec (bfld_type));
}
@@ -789,25 +809,16 @@ objc_layout_structure_next_member (struc
if (bfld_field_size)
layout->record_align = MAX (layout->record_align, desired_align);
else
- desired_align = objc_alignof_type (bfld_type) * BITS_PER_UNIT;
+ desired_align = objc_alignof_type (bfld_type) * CHAR_BIT;
- /* A named bit field of declared type `int'
- forces the entire structure to have `int' alignment.
- Q1: How is encoded this thing and how to check for it?
- Q2: How to determine maximum_field_alignment at runtime? */
+ /* A named bit field of declared type `int' forces the entire structure
+ to have `int' alignment. An unnamed bit field only forces the next
+ field to have its alignment, but it is not incorrect to do the same
+ as for named bitfields (we only pick a bigger alignment than
+ requested).
-/* if (DECL_NAME (field) != 0) */
- {
- int type_align = bfld_type_align;
-#if 0
- if (maximum_field_alignment != 0)
- type_align = MIN (type_align, maximum_field_alignment);
- else if (DECL_PACKED (field))
- type_align = MIN (type_align, BITS_PER_UNIT);
-#endif
-
- layout->record_align = MAX (layout->record_align, type_align);
- }
+ FIXME: This is not true for __attribute__ ((packed)). */
+ layout->record_align = MAX (layout->record_align, bfld_type_align);
}
else
layout->record_align = MAX (layout->record_align, desired_align);
@@ -865,9 +876,9 @@ void objc_layout_finish_structure (struc
layout->type = NULL;
}
if (size)
- *size = layout->record_size / BITS_PER_UNIT;
+ *size = layout->record_size / CHAR_BIT;
if (align)
- *align = layout->record_align / BITS_PER_UNIT;
+ *align = layout->record_align / CHAR_BIT;
}
@@ -877,9 +888,9 @@ void objc_layout_structure_get_info (str
const char **type)
{
if (offset)
- *offset = layout->record_size / BITS_PER_UNIT;
+ *offset = layout->record_size / CHAR_BIT;
if (align)
- *align = layout->record_align / BITS_PER_UNIT;
+ *align = layout->record_align / CHAR_BIT;
if (type)
*type = layout->prev_type;
}
Index: config/backwards/abi.h
===================================================================
--- config/backwards/abi.h (revision 107075)
+++ config/backwards/abi.h (working copy)
@@ -34,24 +34,8 @@ Boston, MA 02110-1301, USA. */
#include "coretypes.h"
#include "tm.h"
-#undef MAX
-#define MAX(X, Y) \
- ({ typeof (X) __x = (X), __y = (Y); \
- (__x > __y ? __x : __y); })
-
-#undef MIN
-#define MIN(X, Y) \
- ({ typeof (X) __x = (X), __y = (Y); \
- (__x < __y ? __x : __y); })
-
-#undef ROUND
-#define ROUND(V, A) \
- ({ typeof (V) __v = (V); typeof (A) __a = (A); \
- __a * ((__v+__a - 1)/__a); })
-
-
/* Various hacks for objc_layout_record. These are used by the target
- * macros. */
+ macros. */
#define TREE_CODE(TYPE) *(TYPE)
#define TREE_TYPE(TREE) (TREE)
@@ -74,19 +58,18 @@ Boston, MA 02110-1301, USA. */
#define get_inner_array_type(TYPE) ((TYPE) + 1)
-/* Some ports (eg ARM) allow the structure size boundary to be
- * selected at compile-time. We override the normal definition with
- * one that has a constant value for this compilation. */
-#ifndef BITS_PER_UNIT
-#define BITS_PER_UNIT 8
-#endif
-#undef STRUCTURE_SIZE_BOUNDARY
-#define STRUCTURE_SIZE_BOUNDARY (BITS_PER_UNIT * sizeof (struct{char a;}))
+/* Some ports (eg ARM) allow the structure size boundary to be selected
+ at compile-time. We usually use CHAR_BIT, but we have to override
+ the normal definition with one that has a constant value for this
+ compilation, in case another target macro we use needs BITS_PER_UNIT.
+ */
+#undef BITS_PER_UNIT
+#define BITS_PER_UNIT __CHAR_BIT__
/* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently
- * target_flags. Define a dummy entry here to so we don't die.
- * We have to rename it because target_flags may already have been
- * declared extern. */
+ target_flags. Define a dummy entry here to so we don't die.
+ We have to rename it because target_flags may already have been
+ declared extern. */
#define target_flags not_target_flags
static int __attribute__ ((__unused__)) not_target_flags = 0;
@@ -96,10 +79,10 @@ static int __attribute__ ((__unused__))
#define ALTIVEC_VECTOR_MODE(MODE) (0)
-/* FIXME: while this file has no business including tm.h, this
- * definitely has no business defining this macro but it
- * is only way around without really rewritting this file,
- * should look after the branch of 3.4 to fix this. */
+/* FIXME: while this file has no business including tm.h, this
+ definitely has no business defining this macro but it is only
+ temporary until we convert the rs6000 port to use its own abi.h
+ file instead of the generic one. */
#define rs6000_special_round_type_align(STRUCT, COMPUTED, SPECIFIED) \
((TYPE_FIELDS (STRUCT) != 0
\
&& DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode)
\
@@ -107,15 +90,3 @@ static int __attribute__ ((__unused__))
: MAX (COMPUTED, SPECIFIED))
-/* This is how we hack STRUCT_VALUE to be 1 or 0. */
-#define gen_rtx(args...) 1
-#define gen_rtx_MEM(args...) 1
-#define gen_rtx_REG(args...) 1
-#define rtx int
-
-#if ! defined (STRUCT_VALUE) || STRUCT_VALUE == 0
-#define INVISIBLE_STRUCT_RETURN 1
-#else
-#define INVISIBLE_STRUCT_RETURN 0
-#endif
-
|
|