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-2024 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.4.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 //Types
48 typedef char char_t;
49 typedef signed int int_t;
50 typedef unsigned int uint_t;
51 
52 #if !defined(R_TYPEDEFS_H) && !defined(USE_CHIBIOS_2)
53  typedef int bool_t;
54 #endif
55 
56 //ARM compiler?
57 #if defined(__CC_ARM)
58  #undef PRIu8
59  #undef PRIu16
60  #define PRIu8 "u"
61  #define PRIu16 "u"
62  #define PRIuSIZE "u"
63  #define PRIXSIZE "X"
64  #define PRIuTIME "lu"
65 //Microchip XC32 compiler?
66 #elif defined(__XC32)
67  #if defined(__C32_LEGACY_LIBC__)
68  #define PRIuSIZE "lu"
69  #define PRIXSIZE "lX"
70  #define PRIuTIME "lu"
71  #else
72  #define PRIuSIZE "u"
73  #define PRIXSIZE "X"
74  #define PRIuTIME "u"
75  #endif
76 //NXP MCUXpresso compiler?
77 #elif defined(__MCUXPRESSO)
78  #undef PRIu64
79  #define PRIu64 "llu"
80  #define PRIuSIZE "u"
81  #define PRIXSIZE "X"
82  #define PRIuTIME "lu"
83 //NXP CodeWarrior compiler?
84 #elif defined(__CWCC__)
85  #define PRIu8 "u"
86  #define PRIu16 "u"
87  #define PRIu32 "u"
88  #define PRIx8 "x"
89  #define PRIx16 "x"
90  #define PRIx32 "x"
91  #define PRIX8 "X"
92  #define PRIX16 "X"
93  #define PRIX32 "X"
94  #define PRIuSIZE "u"
95  #define PRIXSIZE "X"
96  #define PRIuTIME "u"
97 //Espressif ESP-IDF compiler?
98 #elif defined(IDF_VER)
99  #undef PRIu8
100  #undef PRIu16
101  #undef PRIx8
102  #undef PRIx16
103  #undef PRIX8
104  #undef PRIX16
105  #define PRIu8 "u"
106  #define PRIu16 "u"
107  #define PRIx8 "x"
108  #define PRIx16 "x"
109  #define PRIX8 "X"
110  #define PRIX16 "X"
111  #define PRIuSIZE "u"
112  #define PRIXSIZE "X"
113  #define PRIuTIME "lu"
114 //Linux/FreeBSD GCC compiler
115 #elif defined(__linux__) || defined(__FreeBSD__)
116  #define PRIuSIZE "zu"
117  #define PRIXSIZE "zX"
118  #define PRIuTIME "lu"
119 //Win32 compiler?
120 #elif defined(_WIN32)
121  #define PRIuSIZE "Iu"
122  #define PRIXSIZE "IX"
123  #define PRIuTIME "lu"
124 //GCC compiler (with newlib-nano runtime library)?
125 #elif defined(__GNUC__) && defined(_NANO_FORMATTED_IO) && (_NANO_FORMATTED_IO != 0)
126  #undef PRIu8
127  #undef PRIu16
128  #undef PRIx8
129  #undef PRIx16
130  #undef PRIX8
131  #undef PRIX16
132  #define PRIu8 "u"
133  #define PRIu16 "u"
134  #define PRIx8 "x"
135  #define PRIx16 "x"
136  #define PRIX8 "X"
137  #define PRIX16 "X"
138  #define PRIuSIZE "u"
139  #define PRIXSIZE "X"
140  #define PRIuTIME "u"
141 //GCC compiler (with newlib-standard runtime library)?
142 #else
143  #define PRIuSIZE "u"
144  #define PRIXSIZE "X"
145  #define PRIuTIME "lu"
146 #endif
147 
148 //ARM compiler V6?
149 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
150  int vsnprintf(char *dest, size_t size, const char *format, va_list ap);
151  char *strtok_r(char *s, const char *delim, char **last);
152 //GCC compiler (for PowerPC architecture)?
153 #elif defined(__GNUC__) && defined(__PPC_EABI__)
154  typedef uint32_t time_t;
155  int strcasecmp(const char *s1, const char *s2);
156  int strncasecmp(const char *s1, const char *s2, size_t n);
157  char *strtok_r(char *s, const char *delim, char **last);
158 //GCC compiler?
159 #elif defined(__GNUC__)
160  int strcasecmp(const char *s1, const char *s2);
161  int strncasecmp(const char *s1, const char *s2, size_t n);
162  char *strtok_r(char *s, const char *delim, char **last);
163 //Tasking compiler?
164 #elif defined(__TASKING__)
165  char *strtok_r(char *s, const char *delim, char **last);
166 //Microchip XC32 compiler?
167 #elif defined(__XC32)
168  #define sprintf _sprintf
169  int sprintf(char * str, const char * format, ...);
170  int strcasecmp(const char *s1, const char *s2);
171  int strncasecmp(const char *s1, const char *s2, size_t n);
172  char *strtok_r(char *s, const char *delim, char **last);
173 //NXP CodeWarrior compiler?
174 #elif defined(__CWCC__)
175  typedef uint32_t time_t;
176  int strcasecmp(const char *s1, const char *s2);
177  int strncasecmp(const char *s1, const char *s2, size_t n);
178  char *strtok_r(char *s, const char *delim, char **last);
179 //Renesas CC-RX compiler?
180 #elif defined(__CCRX__)
181  int strcasecmp(const char *s1, const char *s2);
182  int strncasecmp(const char *s1, const char *s2, size_t n);
183  char *strtok_r(char *s, const char *delim, char **last);
184 //TI ARM compiler?
185 #elif defined(__TI_ARM__)
186  int strcasecmp(const char *s1, const char *s2);
187  int strncasecmp(const char *s1, const char *s2, size_t n);
188  char *strtok_r(char *s, const char *delim, char **last);
189 #endif
190 
191 //ARM compiler V6?
192 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
193  #undef __packed_struct
194  #define __packed_struct struct __attribute__((packed))
195  #undef __packed_union
196  #define __packed_union union __attribute__((packed))
197 //GCC compiler?
198 #elif defined(__GNUC__)
199  #undef __packed_struct
200  #define __packed_struct struct __attribute__((__packed__))
201  #undef __packed_union
202  #define __packed_union union __attribute__((__packed__))
203 //ARM compiler?
204 #elif defined(__CC_ARM)
205  #pragma anon_unions
206  #undef __packed_struct
207  #define __packed_struct __packed struct
208  #undef __packed_union
209  #define __packed_union __packed union
210 //IAR compiler?
211 #elif defined(__IAR_SYSTEMS_ICC__)
212  #undef __packed_struct
213  #define __packed_struct __packed struct
214  #undef __packed_union
215  #define __packed_union __packed union
216 //Tasking compiler?
217 #elif defined(__TASKING__)
218  #undef __packed_struct
219  #define __packed_struct struct __packed__
220  #undef __packed_union
221  #define __packed_union union __packed__
222 //NXP CodeWarrior compiler?
223 #elif defined(__CWCC__)
224  #undef __packed_struct
225  #define __packed_struct struct
226  #undef __packed_union
227  #define __packed_union union
228 //Renesas CC-RX compiler?
229 #elif defined(__CCRX__)
230  #undef __packed_struct
231  #define __packed_struct struct
232  #undef __packed_union
233  #define __packed_union union
234 //TI ARM compiler?
235 #elif defined(__TI_ARM__)
236  #undef __packed_struct
237  #define __packed_struct struct __attribute__((__packed__))
238  #undef __packed_union
239  #define __packed_union union __attribute__((__packed__))
240 //Win32 compiler?
241 #elif defined(_WIN32)
242  #undef interface
243  #undef __packed_struct
244  #define __packed_struct struct
245  #undef __packed_union
246  #define __packed_union union
247 #endif
248 
249 #ifndef __weak_func
250  //ARM compiler V6?
251  #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
252  #define __weak_func __attribute__((weak))
253  //GCC compiler?
254  #elif defined(__GNUC__)
255  #define __weak_func __attribute__((weak))
256  //ARM compiler?
257  #elif defined(__CC_ARM)
258  #define __weak_func __weak
259  //IAR compiler?
260  #elif defined(__IAR_SYSTEMS_ICC__)
261  #define __weak_func __weak
262  //Tasking compiler?
263  #elif defined(__TASKING__)
264  #define __weak_func __attribute__((weak))
265  //NXP CodeWarrior compiler?
266  #elif defined(__CWCC__)
267  #define __weak_func
268  //Renesas CC-RX compiler?
269  #elif defined(__CCRX__)
270  #define __weak_func
271  //TI ARM compiler?
272  #elif defined(__TI_ARM__)
273  #define __weak_func __attribute__((weak))
274  //Win32 compiler?
275  #elif defined(_WIN32)
276  #define __weak_func
277  #endif
278 #endif
279 
280 //C++ guard
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 #endif
signed int int_t
Definition: compiler_port.h:49
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
int bool_t
Definition: compiler_port.h:53
uint8_t n
uint16_t last
Definition: ipv4_frag.h:105
uint8_t s
Definition: ndp.h:345
#define strtok_r(str, delim, p)
#define strncasecmp
#define strcasecmp