]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_compiler.h
Core(M): Add support for LLVM/Clang
[cmsis] / CMSIS / Core / Include / cmsis_compiler.h
1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V5.4.0
5  * @date     27. June 2023
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * 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, WITHOUT
20  * 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
25 #ifndef __CMSIS_COMPILER_H
26 #define __CMSIS_COMPILER_H
27
28 #include <stdint.h>
29
30 /*
31  * Arm Compiler 4/5
32  */
33 #if   defined ( __CC_ARM )
34   #include "cmsis_armcc.h"
35
36
37 /*
38  * Arm Compiler 6.6 LTM (armclang)
39  */
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
41   #include "cmsis_armclang_ltm.h"
42
43   /*
44  * Arm Compiler above 6.10.1 (armclang)
45  */
46 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
47   #include "cmsis_armclang.h"
48
49 /*
50  * TI Arm Clang Compiler (tiarmclang)
51  */
52 #elif defined (__ti__)
53   #include "cmsis_tiarmclang.h"
54
55
56 /*
57  * LLVM/Clang Compiler
58  */
59 #elif defined ( __clang__ )
60   #include "cmsis_clang.h"
61
62
63 /*
64  * GNU Compiler
65  */
66 #elif defined ( __GNUC__ )
67   #include "cmsis_gcc.h"
68
69
70 /*
71  * IAR Compiler
72  */
73 #elif defined ( __ICCARM__ )
74   #include <cmsis_iccarm.h>
75
76
77 /*
78  * TI Arm Compiler (armcl)
79  */
80 #elif defined ( __TI_ARM__ )
81   #include <cmsis_ccs.h>
82
83   #ifndef   __ASM
84     #define __ASM                                  __asm
85   #endif
86   #ifndef   __INLINE
87     #define __INLINE                               inline
88   #endif
89   #ifndef   __STATIC_INLINE
90     #define __STATIC_INLINE                        static inline
91   #endif
92   #ifndef   __STATIC_FORCEINLINE
93     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
94   #endif
95   #ifndef   __NO_RETURN
96     #define __NO_RETURN                            __attribute__((noreturn))
97   #endif
98   #ifndef   __USED
99     #define __USED                                 __attribute__((used))
100   #endif
101   #ifndef   __WEAK
102     #define __WEAK                                 __attribute__((weak))
103   #endif
104   #ifndef   __PACKED
105     #define __PACKED                               __attribute__((packed))
106   #endif
107   #ifndef   __PACKED_STRUCT
108     #define __PACKED_STRUCT                        struct __attribute__((packed))
109   #endif
110   #ifndef   __PACKED_UNION
111     #define __PACKED_UNION                         union __attribute__((packed))
112   #endif
113   #ifndef   __UNALIGNED_UINT32        /* deprecated */
114     struct __attribute__((packed)) T_UINT32 { uint32_t v; };
115     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
116   #endif
117   #ifndef   __UNALIGNED_UINT16_WRITE
118     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
119     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
120   #endif
121   #ifndef   __UNALIGNED_UINT16_READ
122     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
123     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
124   #endif
125   #ifndef   __UNALIGNED_UINT32_WRITE
126     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
127     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
128   #endif
129   #ifndef   __UNALIGNED_UINT32_READ
130     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
131     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
132   #endif
133   #ifndef   __ALIGNED
134     #define __ALIGNED(x)                           __attribute__((aligned(x)))
135   #endif
136   #ifndef   __RESTRICT
137     #define __RESTRICT                             __restrict
138   #endif
139   #ifndef   __COMPILER_BARRIER
140     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
141     #define __COMPILER_BARRIER()                   (void)0
142   #endif
143   #ifndef __NO_INIT
144     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
145   #endif
146   #ifndef __ALIAS
147     #define __ALIAS(x)                             __attribute__ ((alias(x)))
148   #endif
149
150 /*
151  * TASKING Compiler
152  */
153 #elif defined ( __TASKING__ )
154   /*
155    * The CMSIS functions have been implemented as intrinsics in the compiler.
156    * Please use "carm -?i" to get an up to date list of all intrinsics,
157    * Including the CMSIS ones.
158    */
159
160   #ifndef   __ASM
161     #define __ASM                                  __asm
162   #endif
163   #ifndef   __INLINE
164     #define __INLINE                               inline
165   #endif
166   #ifndef   __STATIC_INLINE
167     #define __STATIC_INLINE                        static inline
168   #endif
169   #ifndef   __STATIC_FORCEINLINE
170     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
171   #endif
172   #ifndef   __NO_RETURN
173     #define __NO_RETURN                            __attribute__((noreturn))
174   #endif
175   #ifndef   __USED
176     #define __USED                                 __attribute__((used))
177   #endif
178   #ifndef   __WEAK
179     #define __WEAK                                 __attribute__((weak))
180   #endif
181   #ifndef   __PACKED
182     #define __PACKED                               __packed__
183   #endif
184   #ifndef   __PACKED_STRUCT
185     #define __PACKED_STRUCT                        struct __packed__
186   #endif
187   #ifndef   __PACKED_UNION
188     #define __PACKED_UNION                         union __packed__
189   #endif
190   #ifndef   __UNALIGNED_UINT32        /* deprecated */
191     struct __packed__ T_UINT32 { uint32_t v; };
192     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
193   #endif
194   #ifndef   __UNALIGNED_UINT16_WRITE
195     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
196     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
197   #endif
198   #ifndef   __UNALIGNED_UINT16_READ
199     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
200     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
201   #endif
202   #ifndef   __UNALIGNED_UINT32_WRITE
203     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
204     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
205   #endif
206   #ifndef   __UNALIGNED_UINT32_READ
207     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
208     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
209   #endif
210   #ifndef   __ALIGNED
211     #define __ALIGNED(x)              __align(x)
212   #endif
213   #ifndef   __RESTRICT
214     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
215     #define __RESTRICT
216   #endif
217   #ifndef   __COMPILER_BARRIER
218     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
219     #define __COMPILER_BARRIER()                   (void)0
220   #endif
221   #ifndef __NO_INIT
222     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
223   #endif
224   #ifndef __ALIAS
225     #define __ALIAS(x)                             __attribute__ ((alias(x)))
226   #endif
227
228 /*
229  * COSMIC Compiler
230  */
231 #elif defined ( __CSMC__ )
232    #include <cmsis_csm.h>
233
234  #ifndef   __ASM
235     #define __ASM                                  _asm
236   #endif
237   #ifndef   __INLINE
238     #define __INLINE                               inline
239   #endif
240   #ifndef   __STATIC_INLINE
241     #define __STATIC_INLINE                        static inline
242   #endif
243   #ifndef   __STATIC_FORCEINLINE
244     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
245   #endif
246   #ifndef   __NO_RETURN
247     // NO RETURN is automatically detected hence no warning here
248     #define __NO_RETURN
249   #endif
250   #ifndef   __USED
251     #warning No compiler specific solution for __USED. __USED is ignored.
252     #define __USED
253   #endif
254   #ifndef   __WEAK
255     #define __WEAK                                 __weak
256   #endif
257   #ifndef   __PACKED
258     #define __PACKED                               @packed
259   #endif
260   #ifndef   __PACKED_STRUCT
261     #define __PACKED_STRUCT                        @packed struct
262   #endif
263   #ifndef   __PACKED_UNION
264     #define __PACKED_UNION                         @packed union
265   #endif
266   #ifndef   __UNALIGNED_UINT32        /* deprecated */
267     @packed struct T_UINT32 { uint32_t v; };
268     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
269   #endif
270   #ifndef   __UNALIGNED_UINT16_WRITE
271     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
272     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
273   #endif
274   #ifndef   __UNALIGNED_UINT16_READ
275     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
276     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
277   #endif
278   #ifndef   __UNALIGNED_UINT32_WRITE
279     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
280     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
281   #endif
282   #ifndef   __UNALIGNED_UINT32_READ
283     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
284     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
285   #endif
286   #ifndef   __ALIGNED
287     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
288     #define __ALIGNED(x)
289   #endif
290   #ifndef   __RESTRICT
291     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
292     #define __RESTRICT
293   #endif
294   #ifndef   __COMPILER_BARRIER
295     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
296     #define __COMPILER_BARRIER()                   (void)0
297   #endif
298   #ifndef __NO_INIT
299     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
300   #endif
301   #ifndef __ALIAS
302     #define __ALIAS(x)                             __attribute__ ((alias(x)))
303   #endif
304
305 #else
306   #error Unknown compiler.
307 #endif
308
309
310 #endif /* __CMSIS_COMPILER_H */
311