a26070cdc9fe569869e099e0a1d293a006b700d5
[oota-llvm.git] / include / llvm / Support / DataTypes.h.cmake
1 /*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\
2 |*                                                                            *|
3 |*                     The LLVM Compiler Infrastructure                       *|
4 |*                                                                            *|
5 |* This file is distributed under the University of Illinois Open Source      *|
6 |* License. See LICENSE.TXT for details.                                      *|
7 |*                                                                            *|
8 |*===----------------------------------------------------------------------===*|
9 |*                                                                            *|
10 |* This file contains definitions to figure out the size of _HOST_ data types.*|
11 |* This file is important because different host OS's define different macros,*|
12 |* which makes portability tough.  This file exports the following            *|
13 |* definitions:                                                               *|
14 |*                                                                            *|
15 |*   [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
16 |*   [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.     *|
17 |*                                                                            *|
18 |* No library is required when using these functions.                         *|
19 |*                                                                            *|
20 |*===----------------------------------------------------------------------===*/
21
22 /* Please leave this file C-compatible. */
23
24 /* Please keep this file in sync with DataTypes.h.in */
25
26 #ifndef SUPPORT_DATATYPES_H
27 #define SUPPORT_DATATYPES_H
28
29 #cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
30 #cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
31 #cmakedefine HAVE_UINT64_T ${HAVE_UINT64_T}
32 #cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
33
34 #ifdef __cplusplus
35 #include <cmath>
36 #else
37 #include <math.h>
38 #endif
39
40 #ifndef _MSC_VER
41
42 /* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
43    being defined.  We would define it here, but in order to prevent Bad Things
44    happening when system headers or C++ STL headers include stdint.h before we
45    define it here, we define it on the g++ command line (in Makefile.rules). */
46 #if !defined(__STDC_LIMIT_MACROS)
47 # error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
48 #endif
49
50 #if !defined(__STDC_CONSTANT_MACROS)
51 # error "Must #define __STDC_CONSTANT_MACROS before " \
52         "#including Support/DataTypes.h"
53 #endif
54
55 /* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
56 #include <sys/types.h>
57
58 #ifdef HAVE_INTTYPES_H
59 #include <inttypes.h>
60 #endif
61
62 #ifdef HAVE_STDINT_H
63 #include <stdint.h>
64 #endif
65
66 #ifdef _AIX
67 #include "llvm/Support/AIXDataTypesFix.h"
68 #endif
69
70 /* Handle incorrect definition of uint64_t as u_int64_t */
71 #ifndef HAVE_UINT64_T
72 #ifdef HAVE_U_INT64_T
73 typedef u_int64_t uint64_t;
74 #else
75 # error "Don't have a definition for uint64_t on this platform"
76 #endif
77 #endif
78
79 #else /* _MSC_VER */
80 /* Visual C++ doesn't provide standard integer headers, but it does provide
81    built-in data types. */
82 #ifdef HAVE_STDINT_H
83 #include <stdint.h>
84 #endif
85 #include <stdlib.h>
86 #include <stddef.h>
87 #include <sys/types.h>
88 #ifdef __cplusplus
89 #include <cmath>
90 #else
91 #include <math.h>
92 #endif
93 typedef __int64 int64_t;
94 typedef unsigned __int64 uint64_t;
95 typedef signed int int32_t;
96 typedef unsigned int uint32_t;
97 typedef short int16_t;
98 typedef unsigned short uint16_t;
99 typedef signed char int8_t;
100 typedef unsigned char uint8_t;
101 #if defined(_WIN64)
102   typedef signed __int64 ssize_t;
103 #else
104   typedef signed int ssize_t;
105 #endif
106 #ifndef INT8_MAX
107 # define INT8_MAX 127
108 #endif
109 #ifndef INT8_MIN
110 # define INT8_MIN -128
111 #endif
112 #ifndef UINT8_MAX
113 # define UINT8_MAX 255
114 #endif
115 #ifndef INT16_MAX
116 # define INT16_MAX 32767
117 #endif
118 #ifndef INT16_MIN
119 # define INT16_MIN -32768
120 #endif
121 #ifndef UINT16_MAX
122 # define UINT16_MAX 65535
123 #endif
124 #ifndef INT32_MAX
125 # define INT32_MAX 2147483647
126 #endif
127 #ifndef INT32_MIN
128 /* MSC treats -2147483648 as -(2147483648U). */
129 # define INT32_MIN (-INT32_MAX - 1)
130 #endif
131 #ifndef UINT32_MAX
132 # define UINT32_MAX 4294967295U
133 #endif
134 /* Certain compatibility updates to VC++ introduce the `cstdint'
135  * header, which defines the INT*_C macros. On default installs they
136  * are absent. */
137 #ifndef INT8_C
138 # define INT8_C(C)   C##i8
139 #endif
140 #ifndef UINT8_C
141 # define UINT8_C(C)  C##ui8
142 #endif
143 #ifndef INT16_C
144 # define INT16_C(C)  C##i16
145 #endif
146 #ifndef UINT16_C
147 # define UINT16_C(C) C##ui16
148 #endif
149 #ifndef INT32_C
150 # define INT32_C(C)  C##i32
151 #endif
152 #ifndef UINT32_C
153 # define UINT32_C(C) C##ui32
154 #endif
155 #ifndef INT64_C
156 # define INT64_C(C)  C##i64
157 #endif
158 #ifndef UINT64_C
159 # define UINT64_C(C) C##ui64
160 #endif
161
162 #ifndef PRId64
163 # define PRId64 "I64d"
164 #endif
165 #ifndef PRIi64
166 # define PRIi64 "I64i"
167 #endif
168 #ifndef PRIo64
169 # define PRIo64 "I64o"
170 #endif
171 #ifndef PRIu64
172 # define PRIu64 "I64u"
173 #endif
174 #ifndef PRIx64
175 # define PRIx64 "I64x"
176 #endif
177 #ifndef PRIX64
178 # define PRIX64 "I64X"
179 #endif
180
181 #endif /* _MSC_VER */
182
183 /* Set defaults for constants which we cannot find. */
184 #if !defined(INT64_MAX)
185 # define INT64_MAX 9223372036854775807LL
186 #endif
187 #if !defined(INT64_MIN)
188 # define INT64_MIN ((-INT64_MAX)-1)
189 #endif
190 #if !defined(UINT64_MAX)
191 # define UINT64_MAX 0xffffffffffffffffULL
192 #endif
193
194 #if __GNUC__ > 3
195 #define END_WITH_NULL __attribute__((sentinel))
196 #else
197 #define END_WITH_NULL
198 #endif
199
200 #ifndef HUGE_VALF
201 #define HUGE_VALF (float)HUGE_VAL
202 #endif
203
204 #endif  /* SUPPORT_DATATYPES_H */