VSF Documented
__compiler.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __USE_COMMON_COMPILER_H__
19#define __USE_COMMON_COMPILER_H__
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/*============================ INCLUDES ======================================*/
26
27#include "vsf_cfg.h"
28
29/*============================ MACROS ========================================*/
30
31#ifndef __REG_MACRO__
32#define __REG_MACRO__
33
34#define __DEF_REG \
35 union { \
36 struct {
37#define __END_DEF_REG(__NAME, __BIT_LEN) \
38 }; \
39 reg##__BIT_LEN##_t VALUE; \
40 } __NAME;
41
42#define DEF_REG __DEF_REG
43#define END_DEF_REG(__NAME, __BIT_LEN) \
44 __END_DEF_REG(__NAME, __BIT_LEN)
45
46#define DEF_REG8 DEF_REG
47#define END_DEF_REG8(__NAME) END_DEF_REG(__NAME, 8)
48#define DEF_REG16 DEF_REG
49#define END_DEF_REG16(__NAME) END_DEF_REG(__NAME, 16)
50#define DEF_REG32 DEF_REG
51#define END_DEF_REG32(__NAME) END_DEF_REG(__NAME, 32)
52
53#endif // __REG_MACRO__
54
55#ifndef __volatile__
56# define __volatile__ volatile
57#endif
58
59#undef __IS_COMPILER_SUPPORT_GNUC_EXTENSION__
60#if defined(__GNUC__) || defined(__clang__)
61# define __IS_COMPILER_SUPPORT_GNUC_EXTENSION__ 1
62#endif
63
64#ifndef __IS_COMPILER_LLVM__
65# define __IS_COMPILER_LLVM__ 0
66#endif
67
68#ifndef __IS_COMPILER_GCC__
69# define __IS_COMPILER_GCC__ 0
70#endif
71
72#ifndef __IS_COMPILER_IAR__
73# define __IS_COMPILER_IAR__ 0
74#endif
75
76#ifndef __IS_COMPILER_TCC__
77# define __IS_COMPILER_TCC__ 0
78#endif
79
80#ifndef MAX_CONSTRUCTOR_PRIORITY
81# if __IS_COMPILER_GCC__
82# define MAX_CONSTRUCTOR_PRIORITY 65535
83# elif __IS_COMPILER_LLVM__
84# define MAX_CONSTRUCTOR_PRIORITY 0xFFFFFFFF
85# endif
86#endif
87
89#if __IS_COMPILER_LLVM__
90# ifdef __APPLE__
91# define VSF_CAL_NO_INIT
92# else
93# define VSF_CAL_NO_INIT __attribute__((__section__(".bss.noinit")))
94# endif
95# define VSF_CAL_NO_RETURN __attribute__((__noreturn__))
96# define VSF_CAL_ROOT __attribute__((__used__))
97# define VSF_CAL_INLINE __inline__
98# define VSF_CAL_NO_INLINE __attribute__((__noinline__))
99# define VSF_CAL_ALWAYS_INLINE __inline__ __attribute__((__always_inline__))
100# define VSF_CAL_WEAK(...) __attribute__((__weak__))
101# ifdef __APPLE__
102# define VSF_CAL_RAMFUNC Not Supported by Apple LLVM
103# else
104# define VSF_CAL_RAMFUNC __attribute__((__section__(".textrw")))
105# endif
106# define __asm__ __asm
107# define __VSF_CAL_ALIGN(__N) __attribute__((__aligned__(__N)))
108# define __VSF_CAL_AT_ADDR(__ADDR) Not Supported by LLVM
109# ifdef __APPLE__
110# define __VSF_CAL_SECTION(__SEC)
111# else
112# define __VSF_CAL_SECTION(__SEC) __attribute__((__section__(__SEC)))
113# endif
114# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
115 __asm__(".weak " #__ALIAS); \
116 __asm__(".equ " #__ALIAS ", " #__ORIGIN)
117
118# define VSF_CAL_PACKED __attribute__((__packed__))
119//# define VSF_CAL_UNALIGNED __attribute__((__packed__))
120# undef VSF_CAL_
121# define VSF_CAL_TRANSPARENT_UNION __attribute__((__transparent_union__))
122# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
123
124# define __VSF_CAL_ISR(__VEC) void __VEC(void)
125# define __VSF_CAL_WRAPPER(__API) __wrap_ ## __API
126
127#elif __IS_COMPILER_GCC__
128# define VSF_CAL_NO_INIT __attribute__((section(".bss.noinit")))
129# define VSF_CAL_NO_RETURN __attribute__((noreturn))
130# define VSF_CAL_ROOT __attribute__((used))
131# define VSF_CAL_INLINE inline
132# define VSF_CAL_NO_INLINE __attribute__((noinline))
133# define VSF_CAL_ALWAYS_INLINE inline __attribute__((always_inline))
134# define VSF_CAL_WEAK(...) __attribute__((weak))
135# define VSF_CAL_RAMFUNC __attribute__((section(".textrw")))
136# define __asm__ __asm
137# define __VSF_CAL_ALIGN(__N) __attribute__((aligned(__N)))
138# define __VSF_CAL_AT_ADDR(__ADDR) Not Supported by GCC
139# define __VSF_CAL_SECTION(__SEC) __attribute__((section(__SEC)))
140# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
141 __attribute__((weakref(__VSF_STR(__ORIGIN))))
142
143# define VSF_CAL_PACKED __attribute__((packed))
144//# define VSF_CAL_UNALIGNED __attribute__((packed))
145# undef VSF_CAL_UNALIGNED
146# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
147# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
148
149# define __VSF_CAL_ISR(__VEC) void __VEC(void)
150# define __VSF_CAL_WRAPPER(__API) __wrap_ ## __API
151
152#elif __IS_COMPILER_TCC__
153# define VSF_CAL_NO_INIT __attribute__((section( ".bss.noinit")))
154# define VSF_CAL_NO_RETURN __attribute__((noreturn))
155# define VSF_CAL_ROOT __attribute__((used))
156# define VSF_CAL_INLINE inline
157# define VSF_CAL_NO_INLINE __attribute__((noinline))
158# define VSF_CAL_ALWAYS_INLINE inline __attribute__((always_inline))
159# define VSF_CAL_WEAK(...) __attribute__((weak))
160# define __asm__ __asm
161# define __VSF_CAL_ALIGN(__N) __attribute__((aligned (__N)))
162# define __VSF_CAL_AT_ADDR(__ADDR) Not Supported by TCC
163# define __VSF_CAL_SECTION(__SEC)
164# define __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
165 __attribute__((weakref(__VSF_STR(__ORIGIN))))
166
167# define VSF_CAL_PACKED __attribute__((packed))
168# define VSF_CAL_UNALIGNED __attribute__((packed))
169# define VSF_CAL_TRANSPARENT_UNION __attribute__((transparent_union))
170# define __VSF_CAL_ALIGN_OF(...) __alignof__(__VA_ARGS__)
171
172# define __VSF_CAL_ISR(__VEC) void __VEC(void)
173# define __VSF_CAL_WRAPPER(__API) __wrap_ ## __API
174#endif
175
176#define VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS) \
177 __VSF_CAL_WEAK_ALIAS(__ORIGIN, __ALIAS)
178#define VSF_CAL_AT_ADDR(__ADDR) __VSF_CAL_AT_ADDR(__ADDR)
179#define VSF_CAL_ALIGN(__N) __VSF_CAL_ALIGN(__N)
180
181#define VSF_CAL_SECTION(__SEC) __VSF_CAL_SECTION(__SEC)
182
183#ifdef __VSF_CAL_WRAPPER
184# define VSF_CAL_WRAPPER(__API) __VSF_CAL_WRAPPER(__API)
185#endif
186
187#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
188#define VSF_CAL_ALIGN_OF(__TYPE) __VSF_CAL_ALIGN_OF(__TYPE)
189#define VSF_CAL_ALIGN_WITH(__TYPE) VSF_CAL_ALIGN(VSF_CAL_ALIGN_OF(__TYPE))
190#define VSF_CAL_ISR(__VECT) __VSF_CAL_ISR(__VECT)
191#else
192#define VSF_CAL_ALIGN_OF(...) __VSF_CAL_ALIGN_OF(__VA_ARGS__)
193#define VSF_CAL_ALIGN_WITH(...) VSF_CAL_ALIGN(VSF_CAL_ALIGN_OF(__VA_ARGS__))
194#define VSF_CAL_ISR(...) __VSF_CAL_ISR(__VA_ARGS__)
195#endif
196
197
198/*----------------------------------------------------------------------------*
199 * Warning Mitigation *
200 *----------------------------------------------------------------------------*/
201#if defined(__clang__) //__IS_COMPILER_LLVM__
202#pragma clang diagnostic ignored "-Wmissing-declarations"
203#pragma clang diagnostic ignored "-Wdeprecated-declarations"
204#pragma clang diagnostic ignored "-Wmicrosoft-anon-tag"
205#pragma clang diagnostic ignored "-Wmissing-braces"
206#pragma clang diagnostic ignored "-Wconstant-conversion"
207#pragma clang diagnostic ignored "-Wmicrosoft-enum-forward-reference"
208#pragma clang diagnostic ignored "-Wbuiltin-requires-header"
209#pragma clang diagnostic ignored "-Winitializer-overrides"
210#pragma clang diagnostic ignored "-Wbraced-scalar-init"
211#pragma clang diagnostic ignored "-Wempty-body"
212#pragma clang diagnostic ignored "-Wgnu-empty-struct"
213#pragma clang diagnostic ignored "-Wmicrosoft-include"
214#pragma clang diagnostic ignored "-Wpragma-pack"
215#pragma clang diagnostic ignored "-Wunused-function"
216#pragma clang diagnostic ignored "-Wswitch"
217#pragma clang diagnostic ignored "-Wembedded-directive"
218#pragma clang diagnostic ignored "-Wundef"
219#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
220#pragma clang diagnostic ignored "-Wpadded"
221#pragma clang diagnostic ignored "-Wnewline-eof"
222#pragma clang diagnostic ignored "-Wduplicate-enum"
223#pragma clang diagnostic ignored "-Wextra-semi"
224#pragma clang diagnostic ignored "-Wextra-semi-stmt"
225#pragma clang diagnostic ignored "-Wzero-length-array"
226#pragma clang diagnostic ignored "-Wmissing-prototypes"
227#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
228#pragma clang diagnostic ignored "-Wnonportable-include-path"
229#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
230#pragma clang diagnostic ignored "-Wc++-compat"
231#pragma clang diagnostic ignored "-Wsign-conversion"
232#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
233#pragma clang diagnostic ignored "-Wmissing-noreturn"
234#pragma clang diagnostic ignored "-Wcast-qual"
235#pragma clang diagnostic ignored "-Wbad-function-cast"
236#pragma clang diagnostic ignored "-Wswitch-enum"
237#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
238#pragma clang diagnostic ignored "-Wmissing-field-initializers"
239#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
240#pragma clang diagnostic ignored "-Wunused-value"
241#pragma clang diagnostic ignored "-Wbuiltin-requires-header"
242#pragma clang diagnostic ignored "-Wmain-return-type"
243#pragma clang diagnostic ignored "-Wextern-c-compat"
244#pragma clang diagnostic ignored "-Wunused-label"
245#pragma clang diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
246#pragma clang diagnostic ignored "-Wself-assign"
248//#pragma clang diagnostic ignored "-Wbitfield-constant-conversion"
249//#pragma clang diagnostic ignored "-Wpointer-integer-compare"
250
251//#pragma clang diagnostic ignored "-Wno-sometimes-uninitialized"
252//#pragma clang diagnostic ignored "-Wdeprecated-declarations"
253//#pragma clang diagnostic ignored "-Wunused-variable"
254
255#elif __IS_COMPILER_GCC__
256
257#pragma GCC diagnostic ignored "-Wmissing-declarations"
258#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
259#pragma GCC diagnostic ignored "-Wmissing-braces"
260#pragma GCC diagnostic ignored "-Wempty-body"
261#pragma GCC diagnostic ignored "-Wunused-function"
262#pragma GCC diagnostic ignored "-Wswitch"
263#pragma GCC diagnostic ignored "-Wundef"
264#pragma GCC diagnostic ignored "-Wpadded"
265#pragma GCC diagnostic ignored "-Wsign-conversion"
266#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
267#pragma GCC diagnostic ignored "-Wmissing-noreturn"
268#pragma GCC diagnostic ignored "-Wcast-qual"
269#pragma GCC diagnostic ignored "-Wswitch-enum"
270#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
271#pragma GCC diagnostic ignored "-Wunused-value"
272#pragma GCC diagnostic ignored "-Wcomment"
273#pragma GCC diagnostic ignored "-Wstrict-aliasing"
274#pragma GCC diagnostic ignored "-Wnonnull-compare"
275#pragma GCC diagnostic ignored "-Woverflow"
276
277#ifndef __cplusplus
278# pragma GCC diagnostic ignored "-Wmissing-prototypes"
279# pragma GCC diagnostic ignored "-Wc++-compat"
280# pragma GCC diagnostic ignored "-Wbad-function-cast"
281# pragma GCC diagnostic ignored "-Wint-conversion"
282# pragma GCC diagnostic ignored "-Woverride-init-side-effects"
283#else
284
285#endif
286
288//#pragma GCC diagnostic ignored "-Wbitfield-constant-conversion"
289//#pragma GCC diagnostic ignored "-Wpointer-integer-compare"
290//
291//#pragma GCC diagnostic ignored "-Wno-sometimes-uninitialized"
292//#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
293//#pragma GCC diagnostic ignored "-Wunused-variable"
294
295#elif __IS_COMPILER_IAR__
296
298#pragma diag_suppress=Pa082
299
301#pragma diag_suppress=pe301
302
304#pragma diag_suppress=pe188
305
307#pragma diag_suppress=pe381
308
310#pragma diag_suppress=pa089
311
313#pragma diag_suppress=pa039
314
316#pragma diag_suppress=pe231
317
319#pragma diag_suppress=pe174
320
322#pragma diag_suppress=pe177
323
324//,Pe186,Pe111,,pe128,,,Pe1866,Pe064,Pa039
325
326#endif
327
328/*----------------------------------------------------------------------------*
329 * Warning Emphasize *
330 *----------------------------------------------------------------------------*/
331
332#if defined(__VSF_DEBUG__)
333# if defined(__clang__) //__IS_COMPILER_LLVM__
334# pragma clang diagnostic warning "-Wcast-align"
335# elif __IS_COMPILER_GCC__
336# pragma GCC diagnostic warning "-Wcast-align"
337# endif
338#endif
339
340/*----------------------------------------------------------------------------*
341 * Signal & Interrupt Definition *
342 *----------------------------------------------------------------------------*/
343
344/*----------------------------------------------------------------------------*
345 * Startup Source Code *
346 *----------------------------------------------------------------------------*/
347
348/*============================ TYPES =========================================*/
349/*============================ INCLUDES ======================================*/
350/*============================ PROTOTYPES ====================================*/
351
352extern void vsf_stdio_init(void);
353
354#ifdef __cplusplus
355}
356#endif
357
358#endif
void vsf_stdio_init(void)