Merge branch 'master' into gallium-sampler-view
[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 #include <stdlib.h>
35 #include <string.h>
36 #include <stddef.h>
37 #include <stdarg.h>
38
39
40 #if defined(_WIN32) && !defined(__WIN32__)
41 #define __WIN32__
42 #endif
43
44 #if defined(_MSC_VER)
45
46 /* Avoid 'expression is always true' warning */
47 #pragma warning(disable: 4296)
48
49 #endif /* _MSC_VER */
50
51
52 /*
53 * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for
54 * systems that lack it.
55 */
56 #ifndef __STDC_LIMIT_MACROS
57 #define __STDC_LIMIT_MACROS 1
58 #endif
59 #include <stdint.h>
60 #include <stdbool.h>
61
62
63 #if !defined(__HAIKU__) && !defined(__USE_MISC)
64 typedef unsigned int uint;
65 typedef unsigned short ushort;
66 #endif
67 typedef unsigned char ubyte;
68
69 typedef unsigned char boolean;
70 #ifndef TRUE
71 #define TRUE true
72 #endif
73 #ifndef FALSE
74 #define FALSE false
75 #endif
76
77
78 /* Function inlining */
79 #ifndef INLINE
80 # ifdef __cplusplus
81 # define INLINE inline
82 # elif defined(__GNUC__)
83 # define INLINE __inline__
84 # elif defined(_MSC_VER)
85 # define INLINE __inline
86 # elif defined(__ICL)
87 # define INLINE __inline
88 # elif defined(__INTEL_COMPILER)
89 # define INLINE inline
90 # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
91 # define INLINE __inline
92 # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
93 # define INLINE inline
94 # elif (__STDC_VERSION__ >= 199901L) /* C99 */
95 # define INLINE inline
96 # else
97 # define INLINE
98 # endif
99 #endif
100
101
102 /* Function visibility */
103 #ifndef PUBLIC
104 # if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
105 # define PUBLIC __attribute__((visibility("default")))
106 # else
107 # define PUBLIC
108 # endif
109 #endif
110
111
112 /* The __FUNCTION__ gcc variable is generally only used for debugging.
113 * If we're not using gcc, define __FUNCTION__ as a cpp symbol here.
114 */
115 #ifndef __FUNCTION__
116 # if !defined(__GNUC__)
117 # if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
118 (defined(__SUNPRO_C) && defined(__C99FEATURES__))
119 # define __FUNCTION__ __func__
120 # else
121 # define __FUNCTION__ "<unknown>"
122 # endif
123 # endif
124 # if defined(_MSC_VER) && _MSC_VER < 1300
125 # define __FUNCTION__ "<unknown>"
126 # endif
127 #endif
128
129
130
131 /* This should match linux gcc cdecl semantics everywhere, so that we
132 * just codegen one calling convention on all platforms.
133 */
134 #ifdef _MSC_VER
135 #define PIPE_CDECL __cdecl
136 #else
137 #define PIPE_CDECL
138 #endif
139
140
141
142 #if defined(__GNUC__)
143 #define PIPE_DEPRECATED __attribute__((__deprecated__))
144 #else
145 #define PIPE_DEPRECATED
146 #endif
147
148
149
150 /* Macros for data alignment. */
151 #if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
152
153 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */
154 #define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment)))
155
156 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */
157 #define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment)))
158
159 #if (__GNUC__ > 4 || (__GNUC__ == 4 &&__GNUC_MINOR__>1)) && !defined(PIPE_ARCH_X86_64)
160 #define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer))
161 #else
162 #define PIPE_ALIGN_STACK
163 #endif
164
165 #elif defined(_MSC_VER)
166
167 /* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */
168 #define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type
169 #define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment))
170
171 #define PIPE_ALIGN_STACK
172
173 #elif defined(SWIG)
174
175 #define PIPE_ALIGN_TYPE(_alignment, _type) _type
176 #define PIPE_ALIGN_VAR(_alignment)
177
178 #define PIPE_ALIGN_STACK
179
180 #else
181
182 #error "Unsupported compiler"
183
184 #endif
185
186
187
188 #endif /* P_COMPILER_H */