source: EcnlProtoTool/trunk/asp3_dcre/mbed/platform/mbed_toolchain.h@ 439

Last change on this file since 439 was 439, checked in by coas-nagasima, 4 years ago

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 11.0 KB
Line 
1
2/** \addtogroup platform */
3/** @{*/
4/**
5 * \defgroup platform_toolchain Toolchain functions
6 * @{
7 */
8
9/* mbed Microcontroller Library
10 * Copyright (c) 2006-2013 ARM Limited
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 */
24#ifndef MBED_TOOLCHAIN_H
25#define MBED_TOOLCHAIN_H
26
27#include "mbed_preprocessor.h"
28
29
30// Warning for unsupported compilers
31#if !defined(__GNUC__) /* GCC */ \
32 && !defined(__CC_ARM) /* ARMCC */ \
33 && !defined(__clang__) /* LLVM/Clang */ \
34 && !defined(__ICCARM__) /* IAR */
35#warning "This compiler is not yet supported."
36#endif
37
38
39// Attributes
40
41/** MBED_PACKED
42 * Pack a structure, preventing any padding from being added between fields.
43 *
44 * @code
45 * #include "mbed_toolchain.h"
46 *
47 * MBED_PACKED(struct) foo {
48 * char x;
49 * int y;
50 * };
51 * @endcode
52 */
53#ifndef MBED_PACKED
54#if defined(__ICCARM__)
55#define MBED_PACKED(struct) __packed struct
56#else
57#define MBED_PACKED(struct) struct __attribute__((packed))
58#endif
59#endif
60
61/** MBED_ALIGN(N)
62 * Declare a variable to be aligned on an N-byte boundary.
63 *
64 * @note
65 * IAR does not support alignment greater than word size on the stack
66 *
67 * @code
68 * #include "mbed_toolchain.h"
69 *
70 * MBED_ALIGN(16) char a;
71 * @endcode
72 */
73#ifndef MBED_ALIGN
74#if defined(__ICCARM__)
75#define MBED_ALIGN(N) _Pragma(MBED_STRINGIFY(data_alignment=N))
76#else
77#define MBED_ALIGN(N) __attribute__((aligned(N)))
78#endif
79#endif
80
81/** MBED_UNUSED
82 * Declare a function argument to be unused, suppressing compiler warnings
83 *
84 * @code
85 * #include "mbed_toolchain.h"
86 *
87 * void foo(MBED_UNUSED int arg) {
88 *
89 * }
90 * @endcode
91 */
92#ifndef MBED_UNUSED
93#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
94#define MBED_UNUSED __attribute__((__unused__))
95#else
96#define MBED_UNUSED
97#endif
98#endif
99
100/** MBED_USED
101 * Inform the compiler that a static variable is to be retained in the object file, even if it is unreferenced.
102 *
103 * @code
104 * #include "mbed_toolchain.h"
105 *
106 * MBED_USED int foo;
107 *
108 * @endcode
109 */
110#ifndef MBED_USED
111#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
112#define MBED_USED __attribute__((used))
113#elif defined(__ICCARM__)
114#define MBED_USED __root
115#else
116#define MBED_USED
117#endif
118#endif
119
120/** MBED_WEAK
121 * Mark a function as being weak.
122 *
123 * @note
124 * Functions should only be marked as weak in the source file. The header file
125 * should contain a regular function declaration to insure the function is emitted.
126 * A function marked weak will not be emitted if an alternative non-weak
127 * implementation is defined.
128 *
129 * @note
130 * Weak functions are not friendly to making code re-usable, as they can only
131 * be overridden once (and if they are multiply overridden the linker will emit
132 * no warning). You should not normally use weak symbols as part of the API to
133 * re-usable modules.
134 *
135 * @code
136 * #include "mbed_toolchain.h"
137 *
138 * MBED_WEAK void foo() {
139 * // a weak implementation of foo that can be overriden by a definition
140 * // without __weak
141 * }
142 * @endcode
143 */
144#ifndef MBED_WEAK
145#if defined(__ICCARM__)
146#define MBED_WEAK __weak
147#else
148#define MBED_WEAK __attribute__((weak))
149#endif
150#endif
151
152/** MBED_PURE
153 * Hint to the compiler that a function depends only on parameters
154 *
155 * @code
156 * #include "mbed_toolchain.h"
157 *
158 * MBED_PURE int foo(int arg){
159 * // no access to global variables
160 * }
161 * @endcode
162 */
163#ifndef MBED_PURE
164#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
165#define MBED_PURE __attribute__((const))
166#else
167#define MBED_PURE
168#endif
169#endif
170
171/** MBED_NOINLINE
172 * Declare a function that must not be inlined.
173 *
174 * @code
175 * #include "mbed_toolchain.h"
176 *
177 * MBED_NOINLINE void foo() {
178 *
179 * }
180 * @endcode
181 */
182#ifndef MBED_NOINLINE
183#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
184#define MBED_NOINLINE __attribute__((noinline))
185#elif defined(__ICCARM__)
186#define MBED_NOINLINE _Pragma("inline=never")
187#else
188#define MBED_NOINLINE
189#endif
190#endif
191
192/** MBED_FORCEINLINE
193 * Declare a function that must always be inlined. Failure to inline
194 * such a function will result in an error.
195 *
196 * @code
197 * #include "mbed_toolchain.h"
198 *
199 * MBED_FORCEINLINE void foo() {
200 *
201 * }
202 * @endcode
203 */
204#ifndef MBED_FORCEINLINE
205#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
206#define MBED_FORCEINLINE static inline __attribute__((always_inline))
207#elif defined(__ICCARM__)
208#define MBED_FORCEINLINE _Pragma("inline=forced") static
209#else
210#define MBED_FORCEINLINE static inline
211#endif
212#endif
213
214/** MBED_NORETURN
215 * Declare a function that will never return.
216 *
217 * @code
218 * #include "mbed_toolchain.h"
219 *
220 * MBED_NORETURN void foo() {
221 * // must never return
222 * while (1) {}
223 * }
224 * @endcode
225 */
226#ifndef MBED_NORETURN
227#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
228#define MBED_NORETURN __attribute__((noreturn))
229#elif defined(__ICCARM__)
230#define MBED_NORETURN __noreturn
231#else
232#define MBED_NORETURN
233#endif
234#endif
235
236/** MBED_UNREACHABLE
237 * An unreachable statement. If the statement is reached,
238 * behaviour is undefined. Useful in situations where the compiler
239 * cannot deduce the unreachability of code.
240 *
241 * @code
242 * #include "mbed_toolchain.h"
243 *
244 * void foo(int arg) {
245 * switch (arg) {
246 * case 1: return 1;
247 * case 2: return 2;
248 * ...
249 * }
250 * MBED_UNREACHABLE;
251 * }
252 * @endcode
253 */
254#ifndef MBED_UNREACHABLE
255#if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM)
256#define MBED_UNREACHABLE __builtin_unreachable()
257#else
258#define MBED_UNREACHABLE while (1)
259#endif
260#endif
261
262/** MBED_DEPRECATED("message string")
263 * Mark a function declaration as deprecated, if it used then a warning will be
264 * issued by the compiler possibly including the provided message. Note that not
265 * all compilers are able to display the message.
266 *
267 * @code
268 * #include "mbed_toolchain.h"
269 *
270 * MBED_DEPRECATED("don't foo any more, bar instead")
271 * void foo(int arg);
272 * @endcode
273 */
274#ifndef MBED_DEPRECATED
275#if defined(__CC_ARM)
276#define MBED_DEPRECATED(M) __attribute__((deprecated))
277#elif defined(__GNUC__) || defined(__clang__)
278#define MBED_DEPRECATED(M) __attribute__((deprecated(M)))
279#else
280#define MBED_DEPRECATED(M)
281#endif
282#endif
283
284/** MBED_DEPRECATED_SINCE("version", "message string")
285 * Mark a function declaration as deprecated, noting that the declaration was
286 * deprecated on the specified version. If the function is used then a warning
287 * will be issued by the compiler possibly including the provided message.
288 * Note that not all compilers are able to display this message.
289 *
290 * @code
291 * #include "mbed_toolchain.h"
292 *
293 * MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead")
294 * void foo(int arg);
295 * @endcode
296 */
297#define MBED_DEPRECATED_SINCE(D, M) MBED_DEPRECATED(M " [since " D "]")
298
299/** MBED_CALLER_ADDR()
300 * Returns the caller of the current function.
301 *
302 * @note
303 * This macro is only implemented for GCC and ARMCC.
304 *
305 * @code
306 * #include "mbed_toolchain.h"
307 *
308 * printf("This function was called from %p", MBED_CALLER_ADDR());
309 * @endcode
310 *
311 * @return Address of the calling function
312 */
313#ifndef MBED_CALLER_ADDR
314#if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM)
315#define MBED_CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0))
316#elif defined(__CC_ARM)
317#define MBED_CALLER_ADDR() __builtin_return_address(0)
318#else
319#define MBED_CALLER_ADDR() (NULL)
320#endif
321#endif
322
323#ifndef MBED_SECTION
324#if (defined(__GNUC__) || defined(__clang__)) || defined(__CC_ARM)
325#define MBED_SECTION(name) __attribute__ ((section (name)))
326#elif defined(__ICCARM__)
327#define MBED_SECTION(name) _Pragma(MBED_STRINGIFY(location=name))
328#else
329#error "Missing MBED_SECTION directive"
330#endif
331#endif
332
333/**
334 * Macro expanding to a string literal of the enclosing function name.
335 *
336 * The string returned takes into account language specificity and yield human
337 * readable content.
338 *
339 * As an example, if the macro is used within a C++ function then the string
340 * literal containing the function name will contain the complete signature of
341 * the function - including template parameters - and namespace qualifications.
342 */
343#ifndef MBED_PRETTY_FUNCTION
344#define MBED_PRETTY_FUNCTION __PRETTY_FUNCTION__
345#endif
346
347#ifndef MBED_PRINTF
348#if defined(__GNUC__) || defined(__CC_ARM)
349#define MBED_PRINTF(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx, first_param_idx)))
350#else
351#define MBED_PRINTF(format_idx, first_param_idx)
352#endif
353#endif
354
355#ifndef MBED_PRINTF_METHOD
356#if defined(__GNUC__) || defined(__CC_ARM)
357#define MBED_PRINTF_METHOD(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx+1, first_param_idx+1)))
358#else
359#define MBED_PRINTF_METHOD(format_idx, first_param_idx)
360#endif
361#endif
362
363#ifndef MBED_SCANF
364#if defined(__GNUC__) || defined(__CC_ARM)
365#define MBED_SCANF(format_idx, first_param_idx) __attribute__ ((__format__(__scanf__, format_idx, first_param_idx)))
366#else
367#define MBED_SCANF(format_idx, first_param_idx)
368#endif
369#endif
370
371#ifndef MBED_SCANF_METHOD
372#if defined(__GNUC__) || defined(__CC_ARM)
373#define MBED_SCANF_METHOD(format_idx, first_param_idx) __attribute__ ((__format__(__scanf__, format_idx+1, first_param_idx+1)))
374#else
375#define MBED_SCANF_METHOD(format_idx, first_param_idx)
376#endif
377#endif
378
379// Macro containing the filename part of the value of __FILE__. Defined as
380// string literal.
381#ifndef MBED_FILENAME
382#if defined(__CC_ARM)
383#define MBED_FILENAME __MODULE__
384#elif defined(__GNUC__)
385#define MBED_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__)
386#elif defined(__ICCARM__)
387#define MBED_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
388#else
389#define MBED_FILENAME __FILE__
390#endif
391#endif // #ifndef MBED_FILENAME
392
393// FILEHANDLE declaration
394#if defined(TOOLCHAIN_ARM)
395#include <rt_sys.h>
396#endif
397
398#ifndef FILEHANDLE
399typedef int FILEHANDLE;
400#endif
401
402// Backwards compatibility
403#ifndef WEAK
404#define WEAK MBED_WEAK
405#endif
406
407#ifndef PACKED
408#define PACKED MBED_PACKED()
409#endif
410
411#ifndef EXTERN
412#define EXTERN extern
413#endif
414
415/** MBED_NONSECURE_ENTRY
416 * Declare a function that can be called from non-secure world or secure world
417 *
418 * @code
419 * #include "mbed_toolchain.h"
420 *
421 * MBED_NONSECURE_ENTRY void foo() {
422 *
423 * }
424 * @endcode
425 */
426#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3L)
427#if defined (__ICCARM__)
428#define MBED_NONSECURE_ENTRY __cmse_nonsecure_entry
429#else
430#define MBED_NONSECURE_ENTRY __attribute__((cmse_nonsecure_entry))
431#endif
432#else
433#define MBED_NONSECURE_ENTRY
434#endif
435
436#endif
437
438/** @}*/
439/** @}*/
Note: See TracBrowser for help on using the repository browser.