compiler_port.h
Go to the documentation of this file.
1 /**
2  * @file compiler_port.h
3  * @brief Compiler specific definitions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.5.0
27  **/
28 
29 #ifndef _COMPILER_PORT_H
30 #define _COMPILER_PORT_H
31 
32 //Dependencies
33 #include <stddef.h>
34 #include <stdint.h>
35 #include <inttypes.h>
36 
37 //ARM compiler V6?
38 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
39  #include <stdarg.h>
40 #endif
41 
42 //C++ guard
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 //TI C2000-CGT compiler?
48 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
49  typedef char char_t;
50  typedef int32_t int_t;
51  typedef uint32_t uint_t;
52  typedef int16_t int8_t;
53  typedef uint16_t uint8_t;
54 #else
55  typedef char char_t;
56  typedef signed int int_t;
57  typedef unsigned int uint_t;
58 #endif
59 
60 #if !defined(R_TYPEDEFS_H) && !defined(USE_CHIBIOS_2)
61  typedef int bool_t;
62 #endif
63 
64 //ARM compiler?
65 #if defined(__CC_ARM)
66  #undef PRIu8
67  #undef PRIu16
68  #define PRIu8 "u"
69  #define PRIu16 "u"
70  #define PRIuSIZE "u"
71  #define PRIXSIZE "X"
72  #define PRIuTIME "lu"
73 //Microchip XC32 compiler?
74 #elif defined(__XC32)
75  #if defined(__C32_LEGACY_LIBC__)
76  #define PRIuSIZE "lu"
77  #define PRIXSIZE "lX"
78  #define PRIuTIME "lu"
79  #else
80  #define PRIuSIZE "u"
81  #define PRIXSIZE "X"
82  #define PRIuTIME "u"
83  #endif
84 //NXP MCUXpresso compiler?
85 #elif defined(__MCUXPRESSO)
86  #undef PRIu64
87  #define PRIu64 "llu"
88  #define PRIuSIZE "u"
89  #define PRIXSIZE "X"
90  #define PRIuTIME "lu"
91 //NXP CodeWarrior compiler?
92 #elif defined(__CWCC__)
93  #define PRIu8 "u"
94  #define PRIu16 "u"
95  #define PRIu32 "u"
96  #define PRIx8 "x"
97  #define PRIx16 "x"
98  #define PRIx32 "x"
99  #define PRIX8 "X"
100  #define PRIX16 "X"
101  #define PRIX32 "X"
102  #define PRIuSIZE "u"
103  #define PRIXSIZE "X"
104  #define PRIuTIME "u"
105 //Espressif ESP-IDF compiler?
106 #elif defined(IDF_VER)
107  #undef PRIu8
108  #undef PRIu16
109  #undef PRIx8
110  #undef PRIx16
111  #undef PRIX8
112  #undef PRIX16
113  #define PRIu8 "u"
114  #define PRIu16 "u"
115  #define PRIx8 "x"
116  #define PRIx16 "x"
117  #define PRIX8 "X"
118  #define PRIX16 "X"
119  #define PRIuSIZE "u"
120  #define PRIXSIZE "X"
121  #define PRIuTIME "lu"
122 //TI C2000-CGT compiler?
123 #elif defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
124  #undef PRIu8
125  #undef PRIX8
126  #define PRIu8 PRIu16
127  #define PRIX8 PRIX16
128  #define PRIuSIZE "u"
129  #define PRIXSIZE "X"
130  #define PRIuTIME "lu"
131 //Linux/FreeBSD GCC compiler
132 #elif defined(__linux__) || defined(__FreeBSD__)
133  #define PRIuSIZE "zu"
134  #define PRIXSIZE "zX"
135  #define PRIuTIME "lu"
136 //Win32 compiler?
137 #elif defined(_WIN32)
138  #define PRIuSIZE "Iu"
139  #define PRIXSIZE "IX"
140  #define PRIuTIME "lu"
141 //GCC compiler (with newlib-nano runtime library)?
142 #elif defined(__GNUC__) && defined(_NANO_FORMATTED_IO) && (_NANO_FORMATTED_IO != 0)
143  #undef PRIu8
144  #undef PRIu16
145  #undef PRIx8
146  #undef PRIx16
147  #undef PRIX8
148  #undef PRIX16
149  #define PRIu8 "u"
150  #define PRIu16 "u"
151  #define PRIx8 "x"
152  #define PRIx16 "x"
153  #define PRIX8 "X"
154  #define PRIX16 "X"
155  #define PRIuSIZE "u"
156  #define PRIXSIZE "X"
157  #define PRIuTIME "u"
158 //GCC compiler (with newlib-standard runtime library)?
159 #else
160  #define PRIuSIZE "u"
161  #define PRIXSIZE "X"
162  #define PRIuTIME "lu"
163 #endif
164 
165 //ARM compiler V6?
166 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
167  int vsnprintf(char *dest, size_t size, const char *format, va_list ap);
168  char *strtok_r(char *s, const char *delim, char **last);
169 //GCC compiler (for PowerPC architecture)?
170 #elif defined(__GNUC__) && defined(__PPC_EABI__)
171  typedef uint32_t time_t;
172  int strcasecmp(const char *s1, const char *s2);
173  int strncasecmp(const char *s1, const char *s2, size_t n);
174  char *strtok_r(char *s, const char *delim, char **last);
175 //GCC compiler?
176 #elif defined(__GNUC__)
177  int strcasecmp(const char *s1, const char *s2);
178  int strncasecmp(const char *s1, const char *s2, size_t n);
179  char *strtok_r(char *s, const char *delim, char **last);
180 //Tasking compiler?
181 #elif defined(__TASKING__)
182  char *strtok_r(char *s, const char *delim, char **last);
183 //Microchip XC32 compiler?
184 #elif defined(__XC32)
185  #define sprintf _sprintf
186  int sprintf(char *str, const char *format, ...);
187  int strcasecmp(const char *s1, const char *s2);
188  int strncasecmp(const char *s1, const char *s2, size_t n);
189  char *strtok_r(char *s, const char *delim, char **last);
190 //NXP CodeWarrior compiler?
191 #elif defined(__CWCC__)
192  typedef uint32_t time_t;
193  int strcasecmp(const char *s1, const char *s2);
194  int strncasecmp(const char *s1, const char *s2, size_t n);
195  char *strtok_r(char *s, const char *delim, char **last);
196 //Renesas CC-RX compiler?
197 #elif defined(__CCRX__)
198  int strcasecmp(const char *s1, const char *s2);
199  int strncasecmp(const char *s1, const char *s2, size_t n);
200  char *strtok_r(char *s, const char *delim, char **last);
201 //TI CGT compiler?
202 #elif defined(__TI_COMPILER_VERSION__)
203  int strcasecmp(const char *s1, const char *s2);
204  int strncasecmp(const char *s1, const char *s2, size_t n);
205  char *strtok_r(char *s, const char *delim, char **last);
206 #endif
207 
208 //ARM compiler V6?
209 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
210  #undef __packed_struct
211  #define __packed_struct struct __attribute__((packed))
212  #undef __packed_union
213  #define __packed_union union __attribute__((packed))
214 //GCC compiler?
215 #elif defined(__GNUC__)
216  #undef __packed_struct
217  #define __packed_struct struct __attribute__((__packed__))
218  #undef __packed_union
219  #define __packed_union union __attribute__((__packed__))
220 //ARM compiler?
221 #elif defined(__CC_ARM)
222  #pragma anon_unions
223  #undef __packed_struct
224  #define __packed_struct __packed struct
225  #undef __packed_union
226  #define __packed_union __packed union
227 //IAR compiler?
228 #elif defined(__IAR_SYSTEMS_ICC__)
229  #undef __packed_struct
230  #define __packed_struct __packed struct
231  #undef __packed_union
232  #define __packed_union __packed union
233 //Tasking compiler?
234 #elif defined(__TASKING__)
235  #undef __packed_struct
236  #define __packed_struct struct __packed__
237  #undef __packed_union
238  #define __packed_union union __packed__
239 //NXP CodeWarrior compiler?
240 #elif defined(__CWCC__)
241  #undef __packed_struct
242  #define __packed_struct struct
243  #undef __packed_union
244  #define __packed_union union
245 //Renesas CC-RX compiler?
246 #elif defined(__CCRX__)
247  #undef __packed_struct
248  #define __packed_struct struct
249  #undef __packed_union
250  #define __packed_union union
251 //TI CGT compiler?
252 #elif defined(__TI_COMPILER_VERSION__)
253  #undef __packed_struct
254  #define __packed_struct struct __attribute__((__packed__))
255  #undef __packed_union
256  #define __packed_union union __attribute__((__packed__))
257 //Win32 compiler?
258 #elif defined(_WIN32)
259  #undef interface
260  #undef __packed_struct
261  #define __packed_struct struct
262  #undef __packed_union
263  #define __packed_union union
264 #endif
265 
266 #ifndef __weak_func
267  //ARM compiler V6?
268  #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
269  #define __weak_func __attribute__((weak))
270  //GCC compiler?
271  #elif defined(__GNUC__)
272  #define __weak_func __attribute__((weak))
273  //ARM compiler?
274  #elif defined(__CC_ARM)
275  #define __weak_func __weak
276  //IAR compiler?
277  #elif defined(__IAR_SYSTEMS_ICC__)
278  #define __weak_func __weak
279  //Tasking compiler?
280  #elif defined(__TASKING__)
281  #define __weak_func __attribute__((weak))
282  //NXP CodeWarrior compiler?
283  #elif defined(__CWCC__)
284  #define __weak_func
285  //Renesas CC-RX compiler?
286  #elif defined(__CCRX__)
287  #define __weak_func
288  //TI CGT compiler?
289  #elif defined(__TI_COMPILER_VERSION__)
290  #define __weak_func __attribute__((weak))
291  //Win32 compiler?
292  #elif defined(_WIN32)
293  #define __weak_func
294  #endif
295 #endif
296 
297 //C++ guard
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif
int bool_t
Definition: compiler_port.h:61
signed int int_t
Definition: compiler_port.h:56
#define strncasecmp
uint16_t last
Definition: ipv4_frag.h:105
#define strtok_r(str, delim, p)
char char_t
Definition: compiler_port.h:55
uint8_t n
#define strcasecmp
uint8_t s
Definition: igmp_common.h:234
unsigned int uint_t
Definition: compiler_port.h:57