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