1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 // This file contains platform-specific typedefs and defines.
12 // Much of it is derived from Chromium's build/build_config.h.
13 
14 #ifndef WEBRTC_TYPEDEFS_H_
15 #define WEBRTC_TYPEDEFS_H_
16 
17 // Processor architecture detection.  For more info on what's defined, see:
18 //   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
19 //   http://www.agner.org/optimize/calling_conventions.pdf
20 //   or with gcc, run: "echo | gcc -E -dM -"
21 #if defined(_M_X64) || defined(__x86_64__)
22 #define WEBRTC_ARCH_X86_FAMILY
23 #define WEBRTC_ARCH_X86_64
24 #define WEBRTC_ARCH_64_BITS
25 #define WEBRTC_ARCH_LITTLE_ENDIAN
26 #elif defined(__aarch64__)
27 #define WEBRTC_ARCH_64_BITS
28 #define WEBRTC_ARCH_LITTLE_ENDIAN
29 #elif defined(_M_IX86) || defined(__i386__)
30 #define WEBRTC_ARCH_X86_FAMILY
31 #define WEBRTC_ARCH_X86
32 #define WEBRTC_ARCH_32_BITS
33 #define WEBRTC_ARCH_LITTLE_ENDIAN
34 #elif defined(__ARMEL__)
35 // TODO(ajm): We'd prefer to control platform defines here, but this is
36 // currently provided by the Android makefiles. Commented to avoid duplicate
37 // definition warnings.
38 //#define WEBRTC_ARCH_ARM
39 // TODO(ajm): Chromium uses the following two defines. Should we switch?
40 //#define WEBRTC_ARCH_ARM_FAMILY
41 //#define WEBRTC_ARCH_ARMEL
42 #define WEBRTC_ARCH_32_BITS
43 #define WEBRTC_ARCH_LITTLE_ENDIAN
44 #elif defined(__MIPSEL__)
45 #define WEBRTC_ARCH_32_BITS
46 #define WEBRTC_ARCH_LITTLE_ENDIAN
47 #elif defined(__pnacl__)
48 #define WEBRTC_ARCH_32_BITS
49 #define WEBRTC_ARCH_LITTLE_ENDIAN
50 #else
51 /* instead of failing, use typical unix defines... */
52 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
53 #define WEBRTC_ARCH_LITTLE_ENDIAN
54 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
55 #define WEBRTC_ARCH_BIG_ENDIAN
56 #else
57 #error __BYTE_ORDER__ is not defined
58 #endif
59 #if defined(__LP64__)
60 #define WEBRTC_ARCH_64_BITS
61 #else
62 #define WEBRTC_ARCH_32_BITS
63 #endif
64 #endif
65 
66 #if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN))
67 #error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN
68 #endif
69 
70 #if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__)) ||  \
71     (defined(WEBRTC_ARCH_ARM_V7) && !defined(WEBRTC_ARCH_ARM_NEON))
72 #define WEBRTC_CPU_DETECTION
73 #endif
74 
75 #if !defined(_MSC_VER)
76 #include <stdint.h>
77 #else
78 // Define C99 equivalent types, since pre-2010 MSVC doesn't provide stdint.h.
79 typedef signed char         int8_t;
80 typedef signed short        int16_t;
81 typedef signed int          int32_t;
82 typedef __int64             int64_t;
83 typedef unsigned char       uint8_t;
84 typedef unsigned short      uint16_t;
85 typedef unsigned int        uint32_t;
86 typedef unsigned __int64    uint64_t;
87 #endif
88 
89 // Borrowed from Chromium's base/compiler_specific.h.
90 // Annotate a virtual method indicating it must be overriding a virtual
91 // method in the parent class.
92 // Use like:
93 //   virtual void foo() OVERRIDE;
94 #if defined(_MSC_VER)
95 #define OVERRIDE override
96 #elif defined(__clang__)
97 // Clang defaults to C++03 and warns about using override. Squelch that.
98 // Intentionally no push/pop here so all users of OVERRIDE ignore the warning
99 // too. This is like passing -Wno-c++11-extensions, except that GCC won't die
100 // (because it won't see this pragma).
101 #pragma clang diagnostic ignored "-Wc++11-extensions"
102 #define OVERRIDE override
103 #elif defined(__GNUC__) && __cplusplus >= 201103 && \
104     (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700
105 // GCC 4.7 supports explicit virtual overrides when C++11 support is enabled.
106 #define OVERRIDE override
107 #else
108 #define OVERRIDE
109 #endif
110 
111 // Annotate a function indicating the caller must examine the return value.
112 // Use like:
113 //   int foo() WARN_UNUSED_RESULT;
114 // TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and
115 // libjingle are merged.
116 #if !defined(WARN_UNUSED_RESULT)
117 #if defined(__GNUC__)
118 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
119 #else
120 #define WARN_UNUSED_RESULT
121 #endif
122 #endif  // WARN_UNUSED_RESULT
123 
124 // Put after a variable that might not be used, to prevent compiler warnings:
125 //   int result ATTRIBUTE_UNUSED = DoSomething();
126 //   assert(result == 17);
127 #ifndef ATTRIBUTE_UNUSED
128 #if defined(__GNUC__) || defined(__clang__)
129 #define ATTRIBUTE_UNUSED __attribute__((unused))
130 #else
131 #define ATTRIBUTE_UNUSED
132 #endif
133 #endif
134 
135 // Macro to be used for switch-case fallthrough (required for enabling
136 // -Wimplicit-fallthrough warning on Clang).
137 #ifndef FALLTHROUGH
138 #if defined(__clang__)
139 #define FALLTHROUGH() [[clang::fallthrough]]
140 #else
141 #define FALLTHROUGH() do { } while (0)
142 #endif
143 #endif
144 
145 // Annotate a function that will not return control flow to the caller.
146 #if defined(_MSC_VER)
147 #define NO_RETURN __declspec(noreturn)
148 #elif defined(__GNUC__)
149 #define NO_RETURN __attribute__((noreturn))
150 #else
151 #define NO_RETURN
152 #endif
153 
154 #endif  // WEBRTC_TYPEDEFS_H_
155