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