disas/libvixl: Fix fall-through annotation for GCC >= 7
[qemu/ar7.git] / disas / libvixl / vixl / globals.h
blob7099aa599fb5a9be2e8596116f0f07eb40098306
1 // Copyright 2015, ARM Limited
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // * Neither the name of ARM Limited nor the names of its contributors may be
13 // used to endorse or promote products derived from this software without
14 // specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef VIXL_GLOBALS_H
28 #define VIXL_GLOBALS_H
30 // Get standard C99 macros for integer types.
31 #ifndef __STDC_CONSTANT_MACROS
32 #define __STDC_CONSTANT_MACROS
33 #endif
35 #ifndef __STDC_LIMIT_MACROS
36 #define __STDC_LIMIT_MACROS
37 #endif
39 #ifndef __STDC_FORMAT_MACROS
40 #define __STDC_FORMAT_MACROS
41 #endif
43 #include <stdint.h>
44 #include <inttypes.h>
46 #include <assert.h>
47 #include <stdarg.h>
48 #include <stdio.h>
49 #include <stdint.h>
50 #include <stdlib.h>
51 #include <stddef.h>
52 #include "vixl/platform.h"
55 typedef uint8_t byte;
57 // Type for half-precision (16 bit) floating point numbers.
58 typedef uint16_t float16;
60 const int KBytes = 1024;
61 const int MBytes = 1024 * KBytes;
63 #define VIXL_ABORT() \
64 do { printf("in %s, line %i", __FILE__, __LINE__); abort(); } while (false)
65 #ifdef VIXL_DEBUG
66 #define VIXL_ASSERT(condition) assert(condition)
67 #define VIXL_CHECK(condition) VIXL_ASSERT(condition)
68 #define VIXL_UNIMPLEMENTED() \
69 do { fprintf(stderr, "UNIMPLEMENTED\t"); VIXL_ABORT(); } while (false)
70 #define VIXL_UNREACHABLE() \
71 do { fprintf(stderr, "UNREACHABLE\t"); VIXL_ABORT(); } while (false)
72 #else
73 #define VIXL_ASSERT(condition) ((void) 0)
74 #define VIXL_CHECK(condition) assert(condition)
75 #define VIXL_UNIMPLEMENTED() ((void) 0)
76 #define VIXL_UNREACHABLE() ((void) 0)
77 #endif
78 // This is not as powerful as template based assertions, but it is simple.
79 // It assumes that the descriptions are unique. If this starts being a problem,
80 // we can switch to a different implemention.
81 #define VIXL_CONCAT(a, b) a##b
82 #define VIXL_STATIC_ASSERT_LINE(line, condition) \
83 typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \
84 __attribute__((unused))
85 #define VIXL_STATIC_ASSERT(condition) \
86 VIXL_STATIC_ASSERT_LINE(__LINE__, condition)
88 template <typename T1>
89 inline void USE(T1) {}
91 template <typename T1, typename T2>
92 inline void USE(T1, T2) {}
94 template <typename T1, typename T2, typename T3>
95 inline void USE(T1, T2, T3) {}
97 template <typename T1, typename T2, typename T3, typename T4>
98 inline void USE(T1, T2, T3, T4) {}
100 #define VIXL_ALIGNMENT_EXCEPTION() \
101 do { fprintf(stderr, "ALIGNMENT EXCEPTION\t"); VIXL_ABORT(); } while (0)
103 // The clang::fallthrough attribute is used along with the Wimplicit-fallthrough
104 // argument to annotate intentional fall-through between switch labels.
105 // For more information please refer to:
106 // http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
107 #ifndef __has_warning
108 #define __has_warning(x) 0
109 #endif
111 // Fallthrough annotation for Clang and C++11(201103L).
112 #if __has_warning("-Wimplicit-fallthrough") && __cplusplus >= 201103L
113 #define VIXL_FALLTHROUGH() [[clang::fallthrough]] //NOLINT
114 // Fallthrough annotation for GCC >= 7.
115 #elif __GNUC__ >= 7
116 #define VIXL_FALLTHROUGH() __attribute__((fallthrough))
117 #else
118 #define VIXL_FALLTHROUGH() do {} while (0)
119 #endif
121 #if __cplusplus >= 201103L
122 #define VIXL_NO_RETURN [[noreturn]] //NOLINT
123 #else
124 #define VIXL_NO_RETURN __attribute__((noreturn))
125 #endif
127 // Some functions might only be marked as "noreturn" for the DEBUG build. This
128 // macro should be used for such cases (for more details see what
129 // VIXL_UNREACHABLE expands to).
130 #ifdef VIXL_DEBUG
131 #define VIXL_DEBUG_NO_RETURN VIXL_NO_RETURN
132 #else
133 #define VIXL_DEBUG_NO_RETURN
134 #endif
136 #ifdef VIXL_INCLUDE_SIMULATOR
137 #ifndef VIXL_GENERATE_SIMULATOR_INSTRUCTIONS_VALUE
138 #define VIXL_GENERATE_SIMULATOR_INSTRUCTIONS_VALUE 1
139 #endif
140 #else
141 #ifndef VIXL_GENERATE_SIMULATOR_INSTRUCTIONS_VALUE
142 #define VIXL_GENERATE_SIMULATOR_INSTRUCTIONS_VALUE 0
143 #endif
144 #if VIXL_GENERATE_SIMULATOR_INSTRUCTIONS_VALUE
145 #warning "Generating Simulator instructions without Simulator support."
146 #endif
147 #endif
149 #ifdef USE_SIMULATOR
150 #error "Please see the release notes for USE_SIMULATOR."
151 #endif
153 #endif // VIXL_GLOBALS_H