Home | History | Annotate | Download | only in Support
      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 #ifndef SUPPORT_DATATYPES_H
     25 #define SUPPORT_DATATYPES_H
     26 
     27 #define HAVE_INTTYPES_H 1
     28 #define HAVE_STDINT_H 1
     29 #define HAVE_UINT64_T 1
     30 #define HAVE_U_INT64_T 1
     31 
     32 #ifdef __cplusplus
     33 #include <cmath>
     34 #else
     35 #include <math.h>
     36 #endif
     37 
     38 #ifdef __cplusplus
     39 #include <cinttypes>
     40 #else
     41 #ifdef HAVE_INTTYPES_H
     42 #include <inttypes.h>
     43 #endif
     44 #endif
     45 
     46 #ifdef __cplusplus
     47 #include <cstdint>
     48 #else
     49 #ifdef HAVE_STDINT_H
     50 #include <stdint.h>
     51 #else
     52 #error "Compiler must provide an implementation of stdint.h"
     53 #endif
     54 #endif
     55 
     56 #ifndef _MSC_VER
     57 
     58 #if !defined(UINT32_MAX)
     59 # error "The standard header <cstdint> is not C++11 compliant. Must #define "\
     60         "__STDC_LIMIT_MACROS before #including Support/DataTypes.h"
     61 #endif
     62 
     63 #if !defined(UINT32_C)
     64 # error "The standard header <cstdint> is not C++11 compliant. Must #define "\
     65         "__STDC_CONSTANT_MACROS before #including Support/DataTypes.h"
     66 #endif
     67 
     68 /* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
     69 #include <sys/types.h>
     70 
     71 #ifdef _AIX
     72 // GCC is strict about defining large constants: they must have LL modifier.
     73 #undef INT64_MAX
     74 #undef INT64_MIN
     75 #endif
     76 
     77 /* Handle incorrect definition of uint64_t as u_int64_t */
     78 #ifndef HAVE_UINT64_T
     79 #ifdef HAVE_U_INT64_T
     80 typedef u_int64_t uint64_t;
     81 #else
     82 # error "Don't have a definition for uint64_t on this platform"
     83 #endif
     84 #endif
     85 
     86 #else /* _MSC_VER */
     87 #ifdef __cplusplus
     88 #include <cstdlib>
     89 #include <cstddef>
     90 #else
     91 #include <stdlib.h>
     92 #include <stddef.h>
     93 #endif
     94 #include <sys/types.h>
     95 
     96 #if defined(_WIN64)
     97 typedef signed __int64 ssize_t;
     98 #else
     99 typedef signed int ssize_t;
    100 #endif /* _WIN64 */
    101 
    102 #ifndef HAVE_INTTYPES_H
    103 #define PRId64 "I64d"
    104 #define PRIi64 "I64i"
    105 #define PRIo64 "I64o"
    106 #define PRIu64 "I64u"
    107 #define PRIx64 "I64x"
    108 #define PRIX64 "I64X"
    109 
    110 #define PRId32 "d"
    111 #define PRIi32 "i"
    112 #define PRIo32 "o"
    113 #define PRIu32 "u"
    114 #define PRIx32 "x"
    115 #define PRIX32 "X"
    116 #endif /* HAVE_INTTYPES_H */
    117 
    118 #endif /* _MSC_VER */
    119 
    120 /* Set defaults for constants which we cannot find. */
    121 #if !defined(INT64_MAX)
    122 # define INT64_MAX 9223372036854775807LL
    123 #endif
    124 #if !defined(INT64_MIN)
    125 # define INT64_MIN ((-INT64_MAX)-1)
    126 #endif
    127 #if !defined(UINT64_MAX)
    128 # define UINT64_MAX 0xffffffffffffffffULL
    129 #endif
    130 
    131 #ifndef HUGE_VALF
    132 #define HUGE_VALF (float)HUGE_VAL
    133 #endif
    134 
    135 #endif /* SUPPORT_DATATYPES_H */
    136