dcf7bfc07ea0fbf9c309939b85e2a9b91ebede17
[oota-llvm.git] / include / llvm / Support / DataTypes.h.in
1 //===-- include/Support/DataTypes.h - Define fixed size types ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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 definitions:
13 //
14 //   [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types
15 //   [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.
16 //
17 // No library is required when using these functinons.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef SUPPORT_DATATYPES_H
22 #define SUPPORT_DATATYPES_H
23
24 #undef HAVE_SYS_TYPES_H
25 #undef HAVE_INTTYPES_H
26 #undef HAVE_STDINT_H
27 #undef HAVE_UINT64_T
28 #undef HAVE_U_INT64_T
29
30 #ifndef _MSC_VER
31
32 // Note that this header's correct operation depends on __STDC_LIMIT_MACROS
33 // being defined.  We would define it here, but in order to prevent Bad Things
34 // happening when system headers or C++ STL headers include stdint.h before
35 // we define it here, we define it on the g++ command line (in Makefile.rules).
36 #if !defined(__STDC_LIMIT_MACROS)
37 # error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
38 #endif
39
40 // Note that <inttypes.h> includes <stdint.h>, if this is a C99 system.
41 #ifdef HAVE_SYS_TYPES_H
42 #include <sys/types.h>
43 #endif
44
45 #ifdef HAVE_INTTYPES_H
46 #include <inttypes.h>
47 #endif
48
49 #ifdef HAVE_STDINT_H
50 #include <stdint.h>
51 #endif
52
53 #ifdef __cplusplus
54 #include <cmath>
55 #else
56 #include <math.h>
57 #endif
58
59 #ifdef _AIX
60 #include "llvm/Support/AIXDataTypesFix.h"
61 #endif
62
63 // Handle incorrect definition of uint64_t as u_int64_t
64 #ifndef HAVE_UINT64_T
65 #ifdef HAVE_U_INT64_T
66 typedef u_int64_t uint64_t;
67 #else
68 # error "Don't have a definition for uint64_t on this platform"
69 #endif
70 #endif
71
72 #ifdef _OpenBSD_
73 #define INT8_MAX 127
74 #define INT8_MIN -128
75 #define UINT8_MAX 255
76 #define INT16_MAX 32767
77 #define INT16_MIN -32768
78 #define UINT16_MAX 65535
79 #define INT32_MAX 2147483647
80 #define INT32_MIN -2147483648
81 #define UINT32_MAX 4294967295U
82 #endif
83
84 #else /* _MSC_VER */
85 // Visual C++ doesn't provide standard integer headers, but it does provide
86 // built-in data types.
87 #include <stdlib.h>
88 #include <stddef.h>
89 #include <sys/types.h>
90 typedef __int64 int64_t;
91 typedef unsigned __int64 uint64_t;
92 typedef signed int int32_t;
93 typedef unsigned int uint32_t;
94 typedef short int16_t;
95 typedef unsigned short uint16_t;
96 typedef signed char int8_t;
97 typedef unsigned char uint8_t;
98 typedef signed int ssize_t;
99 #define INT8_MAX 127
100 #define INT8_MIN -128
101 #define UINT8_MAX 255
102 #define INT16_MAX 32767
103 #define INT16_MIN -32768
104 #define UINT16_MAX 65535
105 #define INT32_MAX 2147483647
106 #define INT32_MIN -2147483648
107 #define UINT32_MAX 4294967295U
108 #endif /* _MSC_VER */
109
110 /* Set defaults for constants which we cannot find. */
111 #if !defined(INT64_MAX)
112 # define INT64_MAX 9223372036854775807LL
113 #endif
114 #if !defined(INT64_MIN)
115 # define INT64_MIN ((-INT64_MAX)-1)
116 #endif
117 #if !defined(UINT64_MAX)
118 # define UINT64_MAX 0xffffffffffffffffULL
119 #endif
120
121 #if __GNUC__ > 3
122 #define END_WITH_NULL __attribute__((sentinel))
123 #else
124 #define END_WITH_NULL
125 #endif
126
127 #ifndef HUGE_VALF
128 #define HUGE_VALF (float)HUGE_VAL
129 #endif
130
131 #endif  /* SUPPORT_DATATYPES_H */