import of gcc-2.8
[official-gcc.git] / gcc / ginclude / va-sh.h
blobf1671c7b0b6c0abc146063b895fb6cd4f03383bf
1 /* This is just like the default gvarargs.h
2 except for differences described below. */
4 /* Define __gnuc_va_list. */
6 #ifndef __GNUC_VA_LIST
7 #define __GNUC_VA_LIST
9 #ifdef __SH3E__
11 typedef long __va_greg;
12 typedef double __va_freg;
14 typedef struct {
15 __va_greg * __va_next_o; /* next available register */
16 __va_greg * __va_next_o_limit; /* past last available register */
17 __va_freg * __va_next_fp; /* next available fp register */
18 __va_freg * __va_next_fp_limit; /* last available fp register */
19 __va_greg * __va_next_stack; /* next extended word on stack */
20 } __gnuc_va_list;
22 #else /* ! SH3E */
24 typedef void *__gnuc_va_list;
26 #endif /* ! SH3E */
28 #endif /* __GNUC_VA_LIST */
30 /* If this is for internal libc use, don't define anything but
31 __gnuc_va_list. */
32 #if defined (_STDARG_H) || defined (_VARARGS_H)
34 #ifdef _STDARG_H
36 #ifdef __SH3E__
38 #define va_start(AP, LASTARG) \
39 __extension__ \
40 ({ \
41 AP.__va_next_fp = (__va_freg *) __builtin_saveregs (); \
42 AP.__va_next_fp_limit = (AP.__va_next_fp + \
43 (__builtin_args_info (1) < 8 ? 8 - __builtin_args_info (1) : 0)); \
44 AP.__va_next_o = (__va_greg *) AP.__va_next_fp_limit; \
45 AP.__va_next_o_limit = (AP.__va_next_o + \
46 (__builtin_args_info (0) < 4 ? 4 - __builtin_args_info (0) : 0)); \
47 AP.__va_next_stack = (__va_greg *) __builtin_next_arg (LASTARG); \
50 #else /* ! SH3E */
52 #define va_start(AP, LASTARG) \
53 (AP = ((__gnuc_va_list) __builtin_next_arg (LASTARG)))
55 #endif /* ! SH3E */
57 #else /* _VARARGS_H */
59 #define va_alist __builtin_va_alist
60 #define va_dcl int __builtin_va_alist;...
62 #ifdef __SH3E__
64 #define va_start(AP) \
65 __extension__ \
66 ({ \
67 AP.__va_next_fp = (__va_freg *) __builtin_saveregs (); \
68 AP.__va_next_fp_limit = (AP.__va_next_fp + \
69 (__builtin_args_info (1) < 8 ? 8 - __builtin_args_info (1) : 0)); \
70 AP.__va_next_o = (__va_greg *) AP.__va_next_fp_limit; \
71 AP.__va_next_o_limit = (AP.__va_next_o + \
72 (__builtin_args_info (0) < 4 ? 4 - __builtin_args_info (0) : 0)); \
73 AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
74 - (__builtin_args_info (0) >= 4 || __builtin_args_info (1) >= 8 ? 1 : 0); \
77 #else /* ! SH3E */
79 #define va_start(AP) AP=(char *) &__builtin_va_alist
81 #endif /* ! SH3E */
83 #endif /* _STDARG */
85 #ifndef va_end
86 void va_end (__gnuc_va_list); /* Defined in libgcc.a */
88 /* Values returned by __builtin_classify_type. */
90 enum __va_type_classes {
91 __no_type_class = -1,
92 __void_type_class,
93 __integer_type_class,
94 __char_type_class,
95 __enumeral_type_class,
96 __boolean_type_class,
97 __pointer_type_class,
98 __reference_type_class,
99 __offset_type_class,
100 __real_type_class,
101 __complex_type_class,
102 __function_type_class,
103 __method_type_class,
104 __record_type_class,
105 __union_type_class,
106 __array_type_class,
107 __string_type_class,
108 __set_type_class,
109 __file_type_class,
110 __lang_type_class
113 #endif
114 #define va_end(pvar) ((void)0)
116 #ifdef __LITTLE_ENDIAN__
117 #define __LITTLE_ENDIAN_P 1
118 #else
119 #define __LITTLE_ENDIAN_P 0
120 #endif
122 #define __SCALAR_TYPE(TYPE) \
123 ((TYPE) == __integer_type_class \
124 || (TYPE) == __char_type_class \
125 || (TYPE) == __enumeral_type_class)
127 /* RECORD_TYPE args passed using the C calling convention are
128 passed by invisible reference. ??? RECORD_TYPE args passed
129 in the stack are made to be word-aligned; for an aggregate that is
130 not word-aligned, we advance the pointer to the first non-reg slot. */
132 /* When this is a smaller-than-int integer, using
133 auto-increment in the promoted (SImode) is fastest;
134 however, there is no way to express that is C. Therefore,
135 we use an asm.
136 We want the MEM_IN_STRUCT_P bit set in the emitted RTL, therefore we
137 use unions even when it would otherwise be unnecessary. */
139 #define __va_arg_sh1(AP, TYPE) __extension__ \
140 __extension__ \
141 ({(sizeof (TYPE) == 1 \
142 ? ({union {TYPE t; char c;} __t; \
143 asm("" \
144 : "=r" (__t.c) \
145 : "0" ((((union { int i, j; } *) (AP))++)->i)); \
146 __t.t;}) \
147 : sizeof (TYPE) == 2 \
148 ? ({union {TYPE t; short s;} __t; \
149 asm("" \
150 : "=r" (__t.s) \
151 : "0" ((((union { int i, j; } *) (AP))++)->i)); \
152 __t.t;}) \
153 : sizeof (TYPE) >= 4 || __LITTLE_ENDIAN_P \
154 ? (((union { TYPE t; int i;} *) (AP))++)->t \
155 : ((union {TYPE t;TYPE u;}*) ((char *)++(int *)(AP) - sizeof (TYPE)))->t);})
157 #ifdef __SH3E__
159 #define __PASS_AS_FLOAT(TYPE_CLASS,SIZE) \
160 (TYPE_CLASS == __real_type_class && SIZE == 4)
162 #define va_arg(pvar,TYPE) \
163 __extension__ \
164 ({int __type = __builtin_classify_type (* (TYPE *) 0); \
165 void * __result_p; \
166 if (__PASS_AS_FLOAT (__type, sizeof(TYPE))) \
168 if (pvar.__va_next_fp < pvar.__va_next_fp_limit) \
170 __result_p = &pvar.__va_next_fp; \
172 else \
173 __result_p = &pvar.__va_next_stack; \
175 else \
177 if (pvar.__va_next_o + ((sizeof (TYPE) + 3) / 4) \
178 <= pvar.__va_next_o_limit) \
179 __result_p = &pvar.__va_next_o; \
180 else \
182 if (sizeof (TYPE) > 4) \
183 pvar.__va_next_o = pvar.__va_next_o_limit; \
185 __result_p = &pvar.__va_next_stack; \
188 __va_arg_sh1(*(void **)__result_p, TYPE);})
190 #else /* ! SH3E */
192 #define va_arg(AP, TYPE) __va_arg_sh1((AP), TYPE)
194 #endif /* SH3E */
196 /* Copy __gnuc_va_list into another variable of this type. */
197 #define __va_copy(dest, src) (dest) = (src)
199 #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */