andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 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 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 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 -" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 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 |
andrew@webrtc.org | 7830689 | 2014-04-01 01:19:08 | [diff] [blame] | 26 | #elif defined(__aarch64__) |
kjellander | 6de3704 | 2015-12-18 12:28:42 | [diff] [blame] | 27 | #define WEBRTC_ARCH_ARM_FAMILY |
andrew@webrtc.org | d30a9ea | 2014-03-27 19:48:53 | [diff] [blame] | 28 | #define WEBRTC_ARCH_64_BITS |
| 29 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 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 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 35 | #elif defined(__ARMEL__) |
kjellander | 6de3704 | 2015-12-18 12:28:42 | [diff] [blame] | 36 | #define WEBRTC_ARCH_ARM_FAMILY |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 37 | #define WEBRTC_ARCH_32_BITS |
| 38 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 39 | #elif defined(__MIPSEL__) |
kjellander | 6de3704 | 2015-12-18 12:28:42 | [diff] [blame] | 40 | #if defined(__LP64__) |
| 41 | #define WEBRTC_ARCH_MIPS64_FAMILY |
| 42 | #else |
| 43 | #define WEBRTC_ARCH_MIPS_FAMILY |
| 44 | #endif |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 45 | #define WEBRTC_ARCH_32_BITS |
| 46 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
andresp@webrtc.org | 1af2c14 | 2014-02-19 13:55:02 | [diff] [blame] | 47 | #elif defined(__pnacl__) |
| 48 | #define WEBRTC_ARCH_32_BITS |
| 49 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 50 | #else |
| 51 | #error Please add support for your architecture in typedefs.h |
| 52 | #endif |
| 53 | |
andrew@webrtc.org | d7e9041 | 2013-10-22 10:27:23 | [diff] [blame] | 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 | |
Andrew MacDonald | ab16802 | 2015-05-20 05:20:17 | [diff] [blame] | 58 | // TODO(zhongwei.yao): WEBRTC_CPU_DETECTION is only used in one place; we should |
| 59 | // probably just remove it. |
pasko | 43b1130 | 2016-05-17 17:56:40 | [diff] [blame] | 60 | #if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__)) |
andrew@webrtc.org | e9d42e6 | 2014-02-27 04:12:34 | [diff] [blame] | 61 | #define WEBRTC_CPU_DETECTION |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 62 | #endif |
| 63 | |
Peter Boström | 07e22e6 | 2015-10-07 10:23:21 | [diff] [blame] | 64 | // TODO(pbos): Use webrtc/base/basictypes.h instead to include fixed-size ints. |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 65 | #include <stdint.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 66 | |
andrew@webrtc.org | 221798a | 2013-10-22 12:50:00 | [diff] [blame] | 67 | // Annotate a function indicating the caller must examine the return value. |
| 68 | // Use like: |
| 69 | // int foo() WARN_UNUSED_RESULT; |
tfarina | 680196c | 2015-12-12 13:47:19 | [diff] [blame] | 70 | // To explicitly ignore a result, see |ignore_result()| in <base/macros.h>. |
andrew@webrtc.org | 44a8ce5 | 2013-10-23 19:11:32 | [diff] [blame] | 71 | // TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and |
| 72 | // libjingle are merged. |
| 73 | #if !defined(WARN_UNUSED_RESULT) |
tfarina | 680196c | 2015-12-12 13:47:19 | [diff] [blame] | 74 | #if defined(__GNUC__) || defined(__clang__) |
kjellander | 9587b40 | 2016-01-08 12:51:38 | [diff] [blame] | 75 | #define WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) |
andrew@webrtc.org | 221798a | 2013-10-22 12:50:00 | [diff] [blame] | 76 | #else |
| 77 | #define WARN_UNUSED_RESULT |
| 78 | #endif |
andrew@webrtc.org | 44a8ce5 | 2013-10-23 19:11:32 | [diff] [blame] | 79 | #endif // WARN_UNUSED_RESULT |
andrew@webrtc.org | 221798a | 2013-10-22 12:50:00 | [diff] [blame] | 80 | |
kwiberg@webrtc.org | 999bcbc | 2014-08-25 06:26:04 | [diff] [blame] | 81 | // Put after a variable that might not be used, to prevent compiler warnings: |
pbos@webrtc.org | f08b85e | 2014-11-17 13:47:38 | [diff] [blame] | 82 | // int result ATTRIBUTE_UNUSED = DoSomething(); |
kwiberg@webrtc.org | 999bcbc | 2014-08-25 06:26:04 | [diff] [blame] | 83 | // assert(result == 17); |
pbos@webrtc.org | f08b85e | 2014-11-17 13:47:38 | [diff] [blame] | 84 | #ifndef ATTRIBUTE_UNUSED |
| 85 | #if defined(__GNUC__) || defined(__clang__) |
kjellander | 9587b40 | 2016-01-08 12:51:38 | [diff] [blame] | 86 | #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
kwiberg@webrtc.org | 999bcbc | 2014-08-25 06:26:04 | [diff] [blame] | 87 | #else |
pbos@webrtc.org | f08b85e | 2014-11-17 13:47:38 | [diff] [blame] | 88 | #define ATTRIBUTE_UNUSED |
kwiberg@webrtc.org | 999bcbc | 2014-08-25 06:26:04 | [diff] [blame] | 89 | #endif |
| 90 | #endif |
| 91 | |
kjellander@webrtc.org | 2234f41 | 2015-01-28 18:37:58 | [diff] [blame] | 92 | // Macro to be used for switch-case fallthrough (required for enabling |
| 93 | // -Wimplicit-fallthrough warning on Clang). |
| 94 | #ifndef FALLTHROUGH |
| 95 | #if defined(__clang__) |
| 96 | #define FALLTHROUGH() [[clang::fallthrough]] |
| 97 | #else |
| 98 | #define FALLTHROUGH() do { } while (0) |
| 99 | #endif |
| 100 | #endif |
| 101 | |
andrew@webrtc.org | 54ade8b | 2014-08-28 16:28:26 | [diff] [blame] | 102 | // Annotate a function that will not return control flow to the caller. |
| 103 | #if defined(_MSC_VER) |
| 104 | #define NO_RETURN __declspec(noreturn) |
| 105 | #elif defined(__GNUC__) |
kjellander | 9587b40 | 2016-01-08 12:51:38 | [diff] [blame] | 106 | #define NO_RETURN __attribute__ ((__noreturn__)) |
andrew@webrtc.org | 54ade8b | 2014-08-28 16:28:26 | [diff] [blame] | 107 | #else |
| 108 | #define NO_RETURN |
| 109 | #endif |
| 110 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 111 | #endif // WEBRTC_TYPEDEFS_H_ |