• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ARM_FAMILY
28 #define WEBRTC_ARCH_64_BITS
29 #define WEBRTC_ARCH_LITTLE_ENDIAN
30 #elif defined(_M_IX86) || defined(__i386__)
31 #define WEBRTC_ARCH_X86_FAMILY
32 #define WEBRTC_ARCH_X86
33 #define WEBRTC_ARCH_32_BITS
34 #define WEBRTC_ARCH_LITTLE_ENDIAN
35 #elif defined(__ARMEL__)
36 #define WEBRTC_ARCH_ARM_FAMILY
37 #define WEBRTC_ARCH_32_BITS
38 #define WEBRTC_ARCH_LITTLE_ENDIAN
39 #elif defined(__MIPSEL__)
40 #if defined(__LP64__)
41 #define WEBRTC_ARCH_MIPS64_FAMILY
42 #else
43 #define WEBRTC_ARCH_MIPS_FAMILY
44 #endif
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 #error Please add support for your architecture in typedefs.h
52 #endif
53 
54 #if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN))
55 #error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN
56 #endif
57 
58 // TODO(zhongwei.yao): WEBRTC_CPU_DETECTION is only used in one place; we should
59 // probably just remove it.
60 #if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__)) || \
61     defined(WEBRTC_DETECT_NEON)
62 #define WEBRTC_CPU_DETECTION
63 #endif
64 
65 // TODO(pbos): Use webrtc/base/basictypes.h instead to include fixed-size ints.
66 #include <stdint.h>
67 
68 // Annotate a function indicating the caller must examine the return value.
69 // Use like:
70 //   int foo() WARN_UNUSED_RESULT;
71 // To explicitly ignore a result, see |ignore_result()| in <base/macros.h>.
72 // TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and
73 // libjingle are merged.
74 #if !defined(WARN_UNUSED_RESULT)
75 #if defined(__GNUC__) || defined(__clang__)
76 #define WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
77 #else
78 #define WARN_UNUSED_RESULT
79 #endif
80 #endif  // WARN_UNUSED_RESULT
81 
82 // Put after a variable that might not be used, to prevent compiler warnings:
83 //   int result ATTRIBUTE_UNUSED = DoSomething();
84 //   assert(result == 17);
85 #ifndef ATTRIBUTE_UNUSED
86 #if defined(__GNUC__) || defined(__clang__)
87 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
88 #else
89 #define ATTRIBUTE_UNUSED
90 #endif
91 #endif
92 
93 // Macro to be used for switch-case fallthrough (required for enabling
94 // -Wimplicit-fallthrough warning on Clang).
95 #ifndef FALLTHROUGH
96 #if defined(__clang__)
97 #define FALLTHROUGH() [[clang::fallthrough]]
98 #else
99 #define FALLTHROUGH() do { } while (0)
100 #endif
101 #endif
102 
103 // Annotate a function that will not return control flow to the caller.
104 #if defined(_MSC_VER)
105 #define NO_RETURN __declspec(noreturn)
106 #elif defined(__GNUC__)
107 #define NO_RETURN __attribute__ ((__noreturn__))
108 #else
109 #define NO_RETURN
110 #endif
111 
112 #endif  // WEBRTC_TYPEDEFS_H_
113