Whoops. I didn't mean to step on John's changes.
[oota-llvm.git] / include / Support / DataTypes.h
1 //===-- include/Support/DataTypes.h - Define fixed size types ----*- C++ -*--=//
2 //
3 // This file contains definitions to figure out the size of _HOST_ data types.
4 // This file is important because different host OS's define different macros,
5 // which makes portability tough.  This file exports the following definitions:
6 //
7 //   ENDIAN_LITTLE : is #define'd if the host is little endian
8 //   int64_t       : is a typedef for the signed 64 bit system type
9 //   uint64_t      : is a typedef for the unsigned 64 bit system type
10 //   INT64_MAX     : is a #define specifying the max value for int64_t's
11 //
12 // No library is required when using these functinons.
13 //
14 //===----------------------------------------------------------------------===//
15
16 // TODO: This file sucks.  Not only does it not work, but this stuff should be
17 // autoconfiscated anyways. Major FIXME
18
19 #ifndef LLVM_SUPPORT_DATATYPES_H
20 #define LLVM_SUPPORT_DATATYPES_H
21
22 #define __STDC_LIMIT_MACROS 1
23 #include <inttypes.h>
24
25 #ifdef __linux__
26 #  include <endian.h>
27 #  if BYTE_ORDER == LITTLE_ENDIAN
28 #    undef BIG_ENDIAN
29 #  else
30 #    undef LITTLE_ENDIAN
31 #  endif
32 #endif
33
34 #ifdef __FreeBSD__
35 #  include <machine/endian.h>
36 #  if _BYTE_ORDER == _LITTLE_ENDIAN
37 #    ifndef LITTLE_ENDIAN
38 #      define LITTLE_ENDIAN 1
39 #    endif
40 #    ifdef BIG_ENDIAN
41 #      undef BIG_ENDIAN
42 #    endif
43 #  else
44 #    ifndef BIG_ENDIAN
45 #      define BIG_ENDIAN 1
46 #    endif
47 #    ifdef LITTLE_ENDIAN
48 #      undef LITTLE_ENDIAN
49 #    endif
50 #  endif
51 #endif
52
53 #ifdef __sparc__
54 #  include <sys/types.h>
55 #  ifdef _LITTLE_ENDIAN
56 #    define LITTLE_ENDIAN 1
57 #  else
58 #    define BIG_ENDIAN 1
59 #  endif
60 #endif
61
62 //
63 // Convert the information from the header files into our own local
64 // endian macros.  We do this because various strange systems define both
65 // BIG_ENDIAN and LITTLE_ENDIAN, and we don't want to conflict with them.
66 //
67 // Don't worry; once we introduce autoconf, this will look a lot nicer.
68 // 
69 #ifdef LITTLE_ENDIAN
70 #define ENDIAN_LITTLE
71 #endif
72
73 #ifdef BIG_ENDIAN
74 #define ENDIAN_BIG
75 #endif
76
77 #if (defined(ENDIAN_LITTLE) && defined(ENDIAN_BIG))
78 #error "Cannot define both ENDIAN_LITTLE and ENDIAN_BIG!"
79 #endif
80
81 #if (!defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)) || !defined(INT64_MAX)
82 #error "include/Support/DataTypes.h could not determine endianness!"
83 #endif
84
85 #endif  /* LLVM_SUPPORT_DATATYPES_H */