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__) |
andrew@webrtc.org | d30a9ea | 2014-03-27 19:48:53 | [diff] [blame] | 27 | #define WEBRTC_ARCH_64_BITS |
| 28 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 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 |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 34 | #elif defined(__ARMEL__) |
andrew@webrtc.org | d7e9041 | 2013-10-22 10:27:23 | [diff] [blame] | 35 | // TODO(ajm): We'd prefer to control platform defines here, but this is |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 36 | // currently provided by the Android makefiles. Commented to avoid duplicate |
| 37 | // definition warnings. |
| 38 | //#define WEBRTC_ARCH_ARM |
andrew@webrtc.org | d7e9041 | 2013-10-22 10:27:23 | [diff] [blame] | 39 | // TODO(ajm): Chromium uses the following two defines. Should we switch? |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 40 | //#define WEBRTC_ARCH_ARM_FAMILY |
| 41 | //#define WEBRTC_ARCH_ARMEL |
| 42 | #define WEBRTC_ARCH_32_BITS |
| 43 | #define WEBRTC_ARCH_LITTLE_ENDIAN |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 44 | #elif defined(__MIPSEL__) |
| 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@webrtc.org | e9d42e6 | 2014-02-27 04:12:34 | [diff] [blame] | 58 | #if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__)) || \ |
| 59 | (defined(WEBRTC_ARCH_ARM_V7) && !defined(WEBRTC_ARCH_ARM_NEON)) |
| 60 | #define WEBRTC_CPU_DETECTION |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 61 | #endif |
| 62 | |
| 63 | #if !defined(_MSC_VER) |
| 64 | #include <stdint.h> |
| 65 | #else |
andrew@webrtc.org | 5350e31 | 2014-03-04 20:58:13 | [diff] [blame] | 66 | // Define C99 equivalent types, since pre-2010 MSVC doesn't provide stdint.h. |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 67 | typedef signed char int8_t; |
| 68 | typedef signed short int16_t; |
| 69 | typedef signed int int32_t; |
| 70 | typedef __int64 int64_t; |
| 71 | typedef unsigned char uint8_t; |
| 72 | typedef unsigned short uint16_t; |
| 73 | typedef unsigned int uint32_t; |
| 74 | typedef unsigned __int64 uint64_t; |
| 75 | #endif |
| 76 | |
andrew@webrtc.org | 13f66d1 | 2013-03-25 21:20:38 | [diff] [blame] | 77 | // Borrowed from Chromium's base/compiler_specific.h. |
| 78 | // Annotate a virtual method indicating it must be overriding a virtual |
| 79 | // method in the parent class. |
| 80 | // Use like: |
| 81 | // virtual void foo() OVERRIDE; |
| 82 | #if defined(_MSC_VER) |
| 83 | #define OVERRIDE override |
| 84 | #elif defined(__clang__) |
pbos@webrtc.org | d7ebd68 | 2013-05-08 08:34:34 | [diff] [blame] | 85 | // Clang defaults to C++03 and warns about using override. Squelch that. |
| 86 | // Intentionally no push/pop here so all users of OVERRIDE ignore the warning |
| 87 | // too. This is like passing -Wno-c++11-extensions, except that GCC won't die |
| 88 | // (because it won't see this pragma). |
| 89 | #pragma clang diagnostic ignored "-Wc++11-extensions" |
andrew@webrtc.org | 13f66d1 | 2013-03-25 21:20:38 | [diff] [blame] | 90 | #define OVERRIDE override |
andrew@webrtc.org | aa9e768 | 2013-12-10 19:20:46 | [diff] [blame] | 91 | #elif defined(__GNUC__) && __cplusplus >= 201103 && \ |
| 92 | (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700 |
| 93 | // GCC 4.7 supports explicit virtual overrides when C++11 support is enabled. |
| 94 | #define OVERRIDE override |
andrew@webrtc.org | 13f66d1 | 2013-03-25 21:20:38 | [diff] [blame] | 95 | #else |
| 96 | #define OVERRIDE |
| 97 | #endif |
| 98 | |
andrew@webrtc.org | 221798a | 2013-10-22 12:50:00 | [diff] [blame] | 99 | // Annotate a function indicating the caller must examine the return value. |
| 100 | // Use like: |
| 101 | // int foo() WARN_UNUSED_RESULT; |
andrew@webrtc.org | 44a8ce5 | 2013-10-23 19:11:32 | [diff] [blame] | 102 | // TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and |
| 103 | // libjingle are merged. |
| 104 | #if !defined(WARN_UNUSED_RESULT) |
andrew@webrtc.org | 221798a | 2013-10-22 12:50:00 | [diff] [blame] | 105 | #if defined(__GNUC__) |
| 106 | #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| 107 | #else |
| 108 | #define WARN_UNUSED_RESULT |
| 109 | #endif |
andrew@webrtc.org | 44a8ce5 | 2013-10-23 19:11:32 | [diff] [blame] | 110 | #endif // WARN_UNUSED_RESULT |
andrew@webrtc.org | 221798a | 2013-10-22 12:50:00 | [diff] [blame] | 111 | |
kwiberg@webrtc.org | 999bcbc | 2014-08-25 06:26:04 | [diff] [blame] | 112 | // Put after a variable that might not be used, to prevent compiler warnings: |
| 113 | // int result UNUSED = DoSomething(); |
| 114 | // assert(result == 17); |
| 115 | #ifndef UNUSED |
| 116 | #ifdef __GNUC__ |
| 117 | #define UNUSED __attribute__((unused)) |
| 118 | #else |
| 119 | #define UNUSED |
| 120 | #endif |
| 121 | #endif |
| 122 | |
andrew@webrtc.org | 54ade8b | 2014-08-28 16:28:26 | [diff] [blame^] | 123 | // Annotate a function that will not return control flow to the caller. |
| 124 | #if defined(_MSC_VER) |
| 125 | #define NO_RETURN __declspec(noreturn) |
| 126 | #elif defined(__GNUC__) |
| 127 | #define NO_RETURN __attribute__((noreturn)) |
| 128 | #else |
| 129 | #define NO_RETURN |
| 130 | #endif |
| 131 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 132 | #endif // WEBRTC_TYPEDEFS_H_ |