DataTypes.h.in revision 263508
117706Sjulian/*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\
235123Sjb|*                                                                            *|
317706Sjulian|*                     The LLVM Compiler Infrastructure                       *|
417706Sjulian|*                                                                            *|
517706Sjulian|* This file is distributed under the University of Illinois Open Source      *|
617706Sjulian|* License. See LICENSE.TXT for details.                                      *|
717706Sjulian|*                                                                            *|
817706Sjulian|*===----------------------------------------------------------------------===*|
917706Sjulian|*                                                                            *|
1017706Sjulian|* This file contains definitions to figure out the size of _HOST_ data types.*|
1117706Sjulian|* This file is important because different host OS's define different macros,*|
1217706Sjulian|* which makes portability tough.  This file exports the following            *|
13173127Simp|* definitions:                                                               *|
1417706Sjulian|*                                                                            *|
1517706Sjulian|*   [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
1617706Sjulian|*   [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.     *|
1717706Sjulian|*                                                                            *|
1817706Sjulian|* No library is required when using these functions.                         *|
1917706Sjulian|*                                                                            *|
2017706Sjulian|*===----------------------------------------------------------------------===*/
2117706Sjulian
2217706Sjulian/* Please leave this file C-compatible. */
2317706Sjulian
2417706Sjulian/* Please keep this file in sync with DataTypes.h.cmake */
2517706Sjulian
2617706Sjulian#ifndef SUPPORT_DATATYPES_H
2717706Sjulian#define SUPPORT_DATATYPES_H
2817706Sjulian
2974462Salfred#undef HAVE_INTTYPES_H
3017706Sjulian#undef HAVE_STDINT_H
3117706Sjulian#undef HAVE_UINT64_T
3217706Sjulian#undef HAVE_U_INT64_T
3317706Sjulian
3417706Sjulian#ifdef __cplusplus
3544965Sjb#include <cmath>
3644965Sjb#else
3793032Simp#include <math.h>
3844965Sjb#endif
3944965Sjb
4017706Sjulian#ifndef _MSC_VER
4117706Sjulian
4217706Sjulian/* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
4393032Simp   being defined.  We would define it here, but in order to prevent Bad Things
44108898Sfjoe   happening when system headers or C++ STL headers include stdint.h before we
4597206Sdeischen   define it here, we define it on the g++ command line (in Makefile.rules). */
4693032Simp#if !defined(__STDC_LIMIT_MACROS)
4797206Sdeischen# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
4897206Sdeischen#endif
49105727Sfjoe
5093032Simp#if !defined(__STDC_CONSTANT_MACROS)
5197206Sdeischen# error "Must #define __STDC_CONSTANT_MACROS before " \
5293032Simp        "#including Support/DataTypes.h"
53105727Sfjoe#endif
5493032Simp
5593032Simp/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
5693032Simp#include <sys/types.h>
57150902Sdavidxu
5817706Sjulian#ifdef HAVE_INTTYPES_H
5917706Sjulian#include <inttypes.h>
6017706Sjulian#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
73typedef 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#include <stdlib.h>
83#include <stddef.h>
84#include <sys/types.h>
85#ifdef __cplusplus
86#include <cmath>
87#else
88#include <math.h>
89#endif
90typedef __int64 int64_t;
91typedef unsigned __int64 uint64_t;
92typedef signed int int32_t;
93typedef unsigned int uint32_t;
94typedef short int16_t;
95typedef unsigned short uint16_t;
96typedef signed char int8_t;
97typedef unsigned char uint8_t;
98#if defined(_WIN64)
99  typedef signed __int64 ssize_t;
100#else
101  typedef signed int ssize_t;
102#endif
103
104#ifndef INT8_MAX
105# define INT8_MAX 127
106#endif
107#ifndef INT8_MIN
108# define INT8_MIN -128
109#endif
110#ifndef UINT8_MAX
111# define UINT8_MAX 255
112#endif
113#ifndef INT16_MAX
114# define INT16_MAX 32767
115#endif
116#ifndef INT16_MIN
117# define INT16_MIN -32768
118#endif
119#ifndef UINT16_MAX
120# define UINT16_MAX 65535
121#endif
122#ifndef INT32_MAX
123# define INT32_MAX 2147483647
124#endif
125#ifndef INT32_MIN
126/* MSC treats -2147483648 as -(2147483648U). */
127# define INT32_MIN (-INT32_MAX - 1)
128#endif
129#ifndef UINT32_MAX
130# define UINT32_MAX 4294967295U
131#endif
132/* Certain compatibility updates to VC++ introduce the `cstdint'
133 * header, which defines the INT*_C macros. On default installs they
134 * are absent. */
135#ifndef INT8_C
136# define INT8_C(C)   C##i8
137#endif
138#ifndef UINT8_C
139# define UINT8_C(C)  C##ui8
140#endif
141#ifndef INT16_C
142# define INT16_C(C)  C##i16
143#endif
144#ifndef UINT16_C
145# define UINT16_C(C) C##ui16
146#endif
147#ifndef INT32_C
148# define INT32_C(C)  C##i32
149#endif
150#ifndef UINT32_C
151# define UINT32_C(C) C##ui32
152#endif
153#ifndef INT64_C
154# define INT64_C(C)  C##i64
155#endif
156#ifndef UINT64_C
157# define UINT64_C(C) C##ui64
158#endif
159
160#ifndef PRId64
161# define PRId64 "I64d"
162#endif
163#ifndef PRIi64
164# define PRIi64 "I64i"
165#endif
166#ifndef PRIo64
167# define PRIo64 "I64o"
168#endif
169#ifndef PRIu64
170# define PRIu64 "I64u"
171#endif
172#ifndef PRIx64
173# define PRIx64 "I64x"
174#endif
175#ifndef PRIX64
176# define PRIX64 "I64X"
177#endif
178
179#endif /* _MSC_VER */
180
181/* Set defaults for constants which we cannot find. */
182#if !defined(INT64_MAX)
183# define INT64_MAX 9223372036854775807LL
184#endif
185#if !defined(INT64_MIN)
186# define INT64_MIN ((-INT64_MAX)-1)
187#endif
188#if !defined(UINT64_MAX)
189# define UINT64_MAX 0xffffffffffffffffULL
190#endif
191
192#if __GNUC__ > 3
193#define END_WITH_NULL __attribute__((sentinel))
194#else
195#define END_WITH_NULL
196#endif
197
198#ifndef HUGE_VALF
199#define HUGE_VALF (float)HUGE_VAL
200#endif
201
202#endif  /* SUPPORT_DATATYPES_H */
203