84956a2ba411e3ee0178f5da0738cd1f8c6cd2c5
[mesa.git] / src / gallium / include / pipe / p_compiler.h
1 /**************************************************************************
2 *
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef P_COMPILER_H
29 #define P_COMPILER_H
30
31
32 #include "p_config.h"
33
34 #ifndef XFree86Server
35 #include <stdlib.h>
36 #include <string.h>
37 #else
38 #include "xf86_ansic.h"
39 #include "xf86_libc.h"
40 #endif
41 #include <stddef.h>
42 #include <stdarg.h>
43
44
45 #if defined(_WIN32) && !defined(__WIN32__)
46 #define __WIN32__
47 #endif
48
49 #if defined(_MSC_VER)
50
51 /* Avoid 'expression is always true' warning */
52 #pragma warning(disable: 4296)
53
54 #endif /* _MSC_VER */
55
56
57 /*
58 * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for
59 * systems that lack it.
60 */
61 #ifndef __STDC_LIMIT_MACROS
62 #define __STDC_LIMIT_MACROS 1
63 #endif
64 #include <stdint.h>
65 #include <stdbool.h>
66
67
68 #if !defined(__HAIKU__) && !defined(__USE_MISC)
69 typedef unsigned int uint;
70 typedef unsigned short ushort;
71 #endif
72 typedef unsigned char ubyte;
73
74 typedef unsigned char boolean;
75 #ifndef TRUE
76 #define TRUE true
77 #endif
78 #ifndef FALSE
79 #define FALSE false
80 #endif
81
82
83 /* Function inlining */
84 #ifndef INLINE
85 # ifdef __cplusplus
86 # define INLINE inline
87 # elif defined(__GNUC__)
88 # define INLINE __inline__
89 # elif defined(_MSC_VER)
90 # define INLINE __inline
91 # elif defined(__ICL)
92 # define INLINE __inline
93 # elif defined(__INTEL_COMPILER)
94 # define INLINE inline
95 # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
96 # define INLINE __inline
97 # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
98 # define INLINE inline
99 # elif (__STDC_VERSION__ >= 199901L) /* C99 */
100 # define INLINE inline
101 # else
102 # define INLINE
103 # endif
104 #endif
105
106
107 /* Function visibility */
108 #ifndef PUBLIC
109 # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303) \
110 || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
111 # define PUBLIC __attribute__((visibility("default")))
112 # else
113 # define PUBLIC
114 # endif
115 #endif
116
117
118 /* The __FUNCTION__ gcc variable is generally only used for debugging.
119 * If we're not using gcc, define __FUNCTION__ as a cpp symbol here.
120 */
121 #ifndef __FUNCTION__
122 # if (!defined(__GNUC__) || (__GNUC__ < 2))
123 # if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
124 (defined(__SUNPRO_C) && defined(__C99FEATURES__))
125 # define __FUNCTION__ __func__
126 # else
127 # define __FUNCTION__ "<unknown>"
128 # endif
129 # endif
130 # if defined(_MSC_VER) && _MSC_VER < 1300
131 # define __FUNCTION__ "<unknown>"
132 # endif
133 #endif
134
135
136
137 /* This should match linux gcc cdecl semantics everywhere, so that we
138 * just codegen one calling convention on all platforms.
139 */
140 #ifdef _MSC_VER
141 #define PIPE_CDECL __cdecl
142 #else
143 #define PIPE_CDECL
144 #endif
145
146
147
148 /* Macros for data alignment. */
149 #if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
150
151 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */
152 #define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment)))
153
154 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */
155 #define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment)))
156
157 #if (__GNUC__ > 4 || (__GNUC__ == 4 &&__GNUC_MINOR__>1)) && !defined(PIPE_ARCH_X86_64)
158 #define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer))
159 #else
160 #define PIPE_ALIGN_STACK
161 #endif
162
163 #elif defined(_MSC_VER)
164
165 /* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */
166 #define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type
167 #define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment))
168
169 #define PIPE_ALIGN_STACK
170
171 #elif defined(SWIG)
172
173 #define PIPE_ALIGN_TYPE(_alignment, _type) _type
174 #define PIPE_ALIGN_VAR(_alignment)
175
176 #define PIPE_ALIGN_STACK
177
178 #else
179
180 #error "Unsupported compiler"
181
182 #endif
183
184
185
186 #endif /* P_COMPILER_H */