DataTypes.h.in revision 234353
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.cmake */
25
26#ifndef SUPPORT_DATATYPES_H
27#define SUPPORT_DATATYPES_H
28
29#undef HAVE_SYS_TYPES_H
30#undef HAVE_INTTYPES_H
31#undef HAVE_STDINT_H
32#undef HAVE_UINT64_T
33#undef HAVE_U_INT64_T
34
35#ifdef __cplusplus
36#include <cmath>
37#else
38#include <math.h>
39#endif
40
41#ifndef _MSC_VER
42
43/* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
44   being defined.  We would define it here, but in order to prevent Bad Things
45   happening when system headers or C++ STL headers include stdint.h before we
46   define it here, we define it on the g++ command line (in Makefile.rules). */
47#if !defined(__STDC_LIMIT_MACROS)
48# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
49#endif
50
51#if !defined(__STDC_CONSTANT_MACROS)
52# error "Must #define __STDC_CONSTANT_MACROS before " \
53        "#including Support/DataTypes.h"
54#endif
55
56/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
57#ifdef HAVE_SYS_TYPES_H
58#include <sys/types.h>
59#endif
60
61#ifdef HAVE_INTTYPES_H
62#include <inttypes.h>
63#endif
64
65#ifdef HAVE_STDINT_H
66#include <stdint.h>
67#endif
68
69#ifdef _AIX
70#include "llvm/Support/AIXDataTypesFix.h"
71#endif
72
73/* Handle incorrect definition of uint64_t as u_int64_t */
74#ifndef HAVE_UINT64_T
75#ifdef HAVE_U_INT64_T
76typedef u_int64_t uint64_t;
77#else
78# error "Don't have a definition for uint64_t on this platform"
79#endif
80#endif
81
82#ifdef _OpenBSD_
83#define INT8_MAX 127
84#define INT8_MIN -128
85#define UINT8_MAX 255
86#define INT16_MAX 32767
87#define INT16_MIN -32768
88#define UINT16_MAX 65535
89#define INT32_MAX 2147483647
90#define INT32_MIN -2147483648
91#define UINT32_MAX 4294967295U
92#endif
93
94#else /* _MSC_VER */
95/* Visual C++ doesn't provide standard integer headers, but it does provide
96   built-in data types. */
97#include <stdlib.h>
98#include <stddef.h>
99#include <sys/types.h>
100#ifdef __cplusplus
101#include <cmath>
102#else
103#include <math.h>
104#endif
105typedef __int64 int64_t;
106typedef unsigned __int64 uint64_t;
107typedef signed int int32_t;
108typedef unsigned int uint32_t;
109typedef short int16_t;
110typedef unsigned short uint16_t;
111typedef signed char int8_t;
112typedef unsigned char uint8_t;
113typedef signed int ssize_t;
114#ifndef INT8_MAX
115# define INT8_MAX 127
116#endif
117#ifndef INT8_MIN
118# define INT8_MIN -128
119#endif
120#ifndef UINT8_MAX
121# define UINT8_MAX 255
122#endif
123#ifndef INT16_MAX
124# define INT16_MAX 32767
125#endif
126#ifndef INT16_MIN
127# define INT16_MIN -32768
128#endif
129#ifndef UINT16_MAX
130# define UINT16_MAX 65535
131#endif
132#ifndef INT32_MAX
133# define INT32_MAX 2147483647
134#endif
135#ifndef INT32_MIN
136/* MSC treats -2147483648 as -(2147483648U). */
137# define INT32_MIN (-INT32_MAX - 1)
138#endif
139#ifndef UINT32_MAX
140# define UINT32_MAX 4294967295U
141#endif
142/* Certain compatibility updates to VC++ introduce the `cstdint'
143 * header, which defines the INT*_C macros. On default installs they
144 * are absent. */
145#ifndef INT8_C
146# define INT8_C(C)   C##i8
147#endif
148#ifndef UINT8_C
149# define UINT8_C(C)  C##ui8
150#endif
151#ifndef INT16_C
152# define INT16_C(C)  C##i16
153#endif
154#ifndef UINT16_C
155# define UINT16_C(C) C##ui16
156#endif
157#ifndef INT32_C
158# define INT32_C(C)  C##i32
159#endif
160#ifndef UINT32_C
161# define UINT32_C(C) C##ui32
162#endif
163#ifndef INT64_C
164# define INT64_C(C)  C##i64
165#endif
166#ifndef UINT64_C
167# define UINT64_C(C) C##ui64
168#endif
169
170#ifndef PRId64
171# define PRId64 "I64d"
172#endif
173#ifndef PRIi64
174# define PRIi64 "I64i"
175#endif
176#ifndef PRIo64
177# define PRIo64 "I64o"
178#endif
179#ifndef PRIu64
180# define PRIu64 "I64u"
181#endif
182#ifndef PRIx64
183# define PRIx64 "I64x"
184#endif
185#ifndef PRIX64
186# define PRIX64 "I64X"
187#endif
188
189#endif /* _MSC_VER */
190
191/* Set defaults for constants which we cannot find. */
192#if !defined(INT64_MAX)
193# define INT64_MAX 9223372036854775807LL
194#endif
195#if !defined(INT64_MIN)
196# define INT64_MIN ((-INT64_MAX)-1)
197#endif
198#if !defined(UINT64_MAX)
199# define UINT64_MAX 0xffffffffffffffffULL
200#endif
201
202#if __GNUC__ > 3
203#define END_WITH_NULL __attribute__((sentinel))
204#else
205#define END_WITH_NULL
206#endif
207
208#ifndef HUGE_VALF
209#define HUGE_VALF (float)HUGE_VAL
210#endif
211
212#endif  /* SUPPORT_DATATYPES_H */
213