Initial commit
[amiga/BoopsiListView.git] / CompilerSpecific.h
1 #ifndef COMPILERSPECIFIC_H
2 #define COMPILERSPECIFIC_H
3 /*
4 **      $VER: CompilerSpecific.h 2.3 (26.10.97)
5 **
6 **      Copyright (C) 1997 Bernardo Innocenti. All rights reserved.
7 **
8 **      Compiler specific definitions is here. You can add support
9 **      for other compilers in this header. Please return any changes
10 **      you make to me, so I can add them to my personal copy of this file.
11 **
12 **      Here is a short description of the macros defined below:
13 **
14 **      LIBCALL
15 **              Shared library entry point, with register args
16 **
17 **      HOOKCALL
18 **              Hook or boopsi dispatcher entry point with arguments
19 **              passed in registers
20 **
21 **      GLOBALCALL
22 **              Attribute for functions to be exported to other modules for
23 **              global access within the same executable file.
24 **              Usually defined to "extern", but can be overridden for special
25 **              needs, such as compiling all modules together in a single
26 **              object module to optimize code better.
27 **
28 **      XDEF
29 **              Attribute for symbols to be exported to other modules for
30 **              global access within the same executable file.
31 **              Usually defined to an empty value.
32 **
33 **      XREF
34 **              Attribute for symbols to be imported from other modules
35 **              within the same executable file.
36 **              Usually defined to "extern".
37 **
38 **      INLINE
39 **              Please put function body inline to the calling code
40 **
41 **      STDARGS
42 **              Function uses standard C conventions for arguments
43 **
44 **      ASMCALL
45 **              Function takes arguments in the specified 68K registers
46 **
47 **      REGCALL
48 **              Function takes arguments in registers choosen by the compiler
49 **
50 **      CONSTCALL
51 **              Function does not modify any global variable
52 **
53 **      FORMATCALL(archetype,string_index,first_to_check)
54 **              Function uses printf or scanf-like formatting
55 **
56 **      SAVEDS
57 **              Function needs to reload context for small data model
58 **
59 **      INTERRUPT
60 **              Function will be called from within an interrupt
61 **
62 **      NORETURN
63 **              Function does never return
64 **
65 **      ALIGNED
66 **              Variable must be aligned to longword boundaries
67 **
68 **      CHIP
69 **              Variable must be stored in CHIP RAM
70 **
71 **      REG(reg,arg)
72 **              Put argument <arg> in 68K register <reg>
73 **
74 **      min(a,b)
75 **              Return the minimum between <a> and <b>
76 **
77 **      max(a,b)
78 **              Return the maximum between <a> and <b>
79 **
80 **      abs(a)
81 **              Return the absolute value of <a>
82 **
83 **      _COMPILED_WITH
84 **              A string containing the name of the compiler
85 */
86
87 #ifdef __SASC
88         /* SAS/C 6.58 or better */
89
90         #define INLINE          static __inline
91         #define STDARGS         __stdargs
92         #define ASMCALL         __asm
93         #define REGCALL         __regcall
94         #define CONSTCALL       /* unsupported */
95         #define FORMATCALL      /* unsupported */
96         #define SAVEDS          __saveds
97         #define INTERRUPT       __interrupt
98         #define NORETURN        /* unsupported */
99         #define ALIGNED         __aligned
100         #define CHIP            __chip
101         #define REG(reg,arg) register __##reg arg
102         #define _COMPILED_WITH  "SAS/C"
103
104         /* For min(), max() and abs() */
105         #define USE_BUILTIN_MATH
106         #include <string.h>
107 #else
108 #ifdef __GNUC__
109         /* GeekGadgets GCC 2.7.2.1 or better */
110
111         #define INLINE          static inline
112         #define STDARGS         __attribute__((stkparm))
113         #define ASMCALL         /* nothing */
114         #define REGCALL         /* nothing */
115         #define CONSTCALL       __attribute__((const))
116         #define FORMATCALL(a,s,f)       __attribute__((format(a,s,f)))
117         #define SAVEDS          __attribute__((saveds))
118         #define INTERRUPT       __attribute__((interrupt))
119         #define NORETURN        __attribute__((noreturn))
120         #define ALIGNED         __attribute__((aligned(4)))
121         #define REG(reg,arg) arg __asm(#reg)
122         #define _COMPILED_WITH  "GCC"
123
124         #define min(a,b)        (((a)<(b))?(a):(b))
125         #define max(a,b)        (((a)>(b))?(a):(b))
126         #define abs(a)          (((a)>0)?(a):-(a))
127
128         /* Inline versions of some str*() and mem*() functions
129          */
130         #define _ANSI_SOURCE
131         #include <string.h>
132         #undef _ANSI_SOURCE
133
134         INLINE STDARGS size_t strlen (const char *src)
135                 { const char *tmp = src; while (*tmp) tmp++; return tmp - src; }
136
137         INLINE STDARGS int memcmp (const void *src, const void *dest, size_t n)
138         {
139                 while (n--)
140                 {
141                         if (*((char *)src) != *((char *)dest))
142                                 return (*((char *)src) - *((char *)dest));
143                         ((char *)src)++;
144                         ((char *)dest)++;
145                 }
146                 return 0;
147         }
148
149         INLINE STDARGS void * memset (void *m, int c, size_t n)
150         {
151                 void *r = m;
152                 n++;
153                 while (--n > 0)
154                         *(((unsigned char *) m)++) = (unsigned char) c;
155                 return r;
156         }
157
158         /* GCC produces code which calls these two functions
159          * to initialize and copy structures and arrays.
160          *
161          *      INLINE STDARGS void bzero (void *buf, size_t len)
162          *              { while (len--) *((char *)buf)++ = 0; }
163          *
164          *      INLINE STDARGS void bcopy (const void *src, void *dest, size_t len)
165          *              { while (len--) *((char *)dest)++ = *((const char *)src)++; }
166          */
167
168 #else
169 #ifdef __STORM__
170         /* StormC 2.00.23 or better */
171         #define INLINE          __inline
172         #define STDARGS         /* nothing */
173         #define ASMCALL         /* nothing */
174         #define REGCALL         register
175         #define CONSTCALL       /* unsupported */
176         #define FORMATCALL      /* unsupported */
177         #define SAVEDS          __saveds
178         #define INTERRUPT       __interrupt
179         #define NORETURN        /* unsupported */
180         #define ALIGNED         /* unsupported */
181         #define CHIP            __chip
182         #define REG(reg,arg) register __##reg arg
183         #define _COMPILED_WITH  "StormC"
184
185         #define min(a,b)        (((a)<(b))?(a):(b))
186         #define max(a,b)        (((a)>(b))?(a):(b))
187         #define abs(a)          (((a)>0)?(a):-(a))
188
189         #define _INLINE_INCLUDES
190         #include <string.h>
191 #else
192 #ifdef __MAXON__
193         /* Maxon C/C++ 3.0 */
194
195         #define INLINE          static inline
196         #define STDARGS         /* ? */
197         #define ASMCALL         /* ? */
198         #define REGCALL         /* ? */
199         #define CONSTCALL       /* unsupported */
200         #define FORMATCALL      /* unsupported */
201         #define SAVEDS          /* unsupported */
202         #define INTERRUPT       /* unsupported */
203         #define NORETURN        /* unsupported */
204         #define ALIGNED         /* unsupported */
205         #define REG(reg,arg)    register __##reg arg
206         #define _COMPILED_WITH  "Maxon C"
207
208         /* For min(), max() and abs() */
209         #define USE_BUILTIN_MATH
210         #include <string.h>
211
212         #error Maxon C compiler support is untested. Please check all the above definitions
213 #else
214 #ifdef _DCC
215         /* DICE C 3.15 */
216
217         #define INLINE          static __inline
218         #define STDARGS         __stdargs
219         #define ASMCALL         /* nothing */
220         #define REGCALL         /* ? */
221         #define CONSTCALL       /* unsupported */
222         #define FORMATCALL      /* unsupported */
223         #define SAVEDS          __geta4
224         #define INTERRUPT       /* unsupported */
225         #define NORETURN        /* unsupported */
226         #define ALIGNED         __aligned
227         #define REG(reg,arg)    __##reg arg
228         #define _COMPILED_WITH  "DICE"
229
230         #define min(a,b)        (((a)<(b))?(a):(b))
231         #define max(a,b)        (((a)>(b))?(a):(b))
232         #define abs(a)          (((a)>0)?(a):-(a))
233
234         #error DICE compiler support is untested. Please check all the above definitions
235 #else
236 #ifdef AZTEC_C
237         /* Aztec/Manx C */
238
239         #define INLINE          static
240         #define STDARGS         /* ? */
241         #define ASMCALL         /* ? */
242         #define REGCALL         /* ? */
243         #define CONSTCALL       /* unsupported */
244         #define FORMATCALL      /* unsupported */
245         #define SAVEDS          __geta4
246         #define INTERRUPT       /* unsupported */
247         #define NORETURN        /* unsupported */
248         #define ALIGNED         __aligned
249         #define REG(reg,arg)    __##reg arg
250         #define _COMPILED_WITH  "Manx C"
251
252         #define min(a,b)        (((a)<(b))?(a):(b))
253         #define max(a,b)        (((a)>(b))?(a):(b))
254         #define abs(a)          (((a)>0)?(a):-(a))
255
256         #error Aztec/Manx C compiler support is untested. Please check all the above definitions
257 #else
258         #error Please add compiler specific definitions for your compiler
259 #endif
260 #endif
261 #endif
262 #endif
263 #endif
264 #endif
265
266
267 /* CONST_STRPTR is a typedef made by a patched version of <exec/types.h>.
268  * Passing "const char *" parameters will only work if the OS protos are
269  * patched accordingly, otherwise you will get a lot of compiler warnings
270  * for const to volatile conversions.
271  *
272  * Using "const" where it is appropriate helps the compiler optimizing
273  * code better, so this mess is probably worth it. I wish one day the OS
274  * headers will come with support for the const keyword.
275  */
276 #ifndef _CONST_STRPTR_DEFINED
277 typedef char *CONST_STRPTR;
278 #endif
279
280
281 /* Special function attributes */
282
283 #define LIBCALL         ASMCALL SAVEDS
284 #define HOOKCALL        ASMCALL SAVEDS
285 #ifdef __cplusplus
286         #define GLOBALCALL extern "C"
287 #else
288         #define GLOBALCALL
289 #endif
290
291 /* special variable attributes */
292 #define XDEF
293 #define XREF extern
294
295
296 /* AROS Compatibility: IPTR is a type which can store a pointer
297  * as well as a long integer.
298  */
299 #ifndef IPTR
300 #define IPTR LONG
301 #endif /* IPTR */
302
303
304 #endif /* !COMPILERSPECIFIC_H */