authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-01 14:41:31+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-03 11:57:20+01:00
log023a7fefb1f468f5679ad6f10c0cf0f2946a2ab6
treedb450d95c3513609909674b25a0b6965a95eb2fa
parent43a1b88bc822ad04d51ff0fa8f5704da52ca4202
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

zig.h: Add TinyCC support where appropriate.

tcc doesn't have __has_attribute and __has_builtin, so we need to manually check for tcc in these preprocessor paths.

1 files changed, 22 insertions(+), 20 deletions(-)

lib/zig.h+22-20
......@@ -25,6 +25,14 @@ typedef char bool;
2525#endif
2626#endif
2727
28#if defined(__clang__)
29#define zig_clang
30#elif defined(__GNUC__)
31#define zig_gnuc
32#elif defined(__TINYC__)
33#define zig_tinyc
34#endif
35
2836#define zig_concat(lhs, rhs) lhs##rhs
2937#define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs)
3038
......@@ -59,12 +67,6 @@ typedef char bool;
5967#define zig_threadlocal zig_threadlocal_unavailable
6068#endif
6169
62#if defined(__clang__)
63#define zig_clang
64#elif defined(__GNUC__)
65#define zig_gnuc
66#endif
67
6870#if defined(zig_gnuc) && (defined(__i386__) || defined(__x86_64__))
6971#define zig_f128_has_miscompilations 1
7072#else
......@@ -124,13 +126,13 @@ typedef char bool;
124126
125127#if __STDC_VERSION__ >= 199901L
126128#define zig_restrict restrict
127#elif defined(__GNUC__)
129#elif defined(__GNUC__) || defined(zig_tinyc)
128130#define zig_restrict __restrict
129131#else
130132#define zig_restrict
131133#endif
132134
133#if zig_has_attribute(aligned)
135#if zig_has_attribute(aligned) || defined(zig_tinyc)
134136#define zig_under_align(alignment) __attribute__((aligned(alignment)))
135137#elif _MSC_VER
136138#define zig_under_align(alignment) __declspec(align(alignment))
......@@ -144,7 +146,7 @@ typedef char bool;
144146#define zig_align(alignment) zig_under_align(alignment)
145147#endif
146148
147#if zig_has_attribute(aligned)
149#if zig_has_attribute(aligned) || defined(zig_tinyc)
148150#define zig_align_fn(alignment) __attribute__((aligned(alignment)))
149151#elif _MSC_VER
150152#define zig_align_fn(alignment)
......@@ -152,7 +154,7 @@ typedef char bool;
152154#define zig_align_fn zig_align_fn_unavailable
153155#endif
154156
155#if zig_has_attribute(packed)
157#if zig_has_attribute(packed) || defined(zig_tinyc)
156158#define zig_packed(definition) __attribute__((packed)) definition
157159#elif _MSC_VER
158160#define zig_packed(definition) __pragma(pack(1)) definition __pragma(pack())
......@@ -160,7 +162,7 @@ typedef char bool;
160162#define zig_packed(definition) zig_packed_unavailable
161163#endif
162164
163#if zig_has_attribute(section)
165#if zig_has_attribute(section) || defined(zig_tinyc)
164166#define zig_linksection(name) __attribute__((section(name)))
165167#define zig_linksection_fn zig_linksection
166168#elif _MSC_VER
......@@ -171,7 +173,7 @@ typedef char bool;
171173#define zig_linksection_fn zig_linksection
172174#endif
173175
174#if zig_has_builtin(unreachable) || defined(zig_gnuc)
176#if zig_has_builtin(unreachable) || defined(zig_gnuc) || defined(zig_tinyc)
175177#define zig_unreachable() __builtin_unreachable()
176178#else
177179#define zig_unreachable()
......@@ -197,7 +199,7 @@ typedef char bool;
197199#endif /* __APPLE__ */
198200#endif /* _MSC_VER */
199201
200#if zig_has_attribute(alias) && !__APPLE__
202#if (zig_has_attribute(alias) || defined(zig_tinyc)) && !__APPLE__
201203#define zig_export(symbol, name) __attribute__((alias(symbol)))
202204#elif _MSC_VER
203205#define zig_export(symbol, name) ; \
......@@ -235,7 +237,7 @@ typedef char bool;
235237#define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args)
236238#define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args)
237239
238#if zig_has_attribute(weak) || defined(zig_gnuc)
240#if zig_has_attribute(weak) || defined(zig_gnuc) || defined(zig_tinyc)
239241#define zig_weak_linkage __attribute__((weak))
240242#define zig_weak_linkage_fn __attribute__((weak))
241243#elif _MSC_VER
......@@ -302,7 +304,7 @@ typedef char bool;
302304#define zig_breakpoint() zig_breakpoint_unavailable
303305#endif
304306
305#if zig_has_builtin(return_address) || defined(zig_gnuc)
307#if zig_has_builtin(return_address) || defined(zig_gnuc) || defined(zig_tinyc)
306308#define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0))
307309#elif defined(_MSC_VER)
308310#define zig_return_address() _ReturnAddress()
......@@ -310,7 +312,7 @@ typedef char bool;
310312#define zig_return_address() 0
311313#endif
312314
313#if zig_has_builtin(frame_address) || defined(zig_gnuc)
315#if zig_has_builtin(frame_address) || defined(zig_gnuc) || defined(zig_tinyc)
314316#define zig_frame_address() __builtin_frame_address(0)
315317#else
316318#define zig_frame_address() 0
......@@ -332,7 +334,7 @@ typedef char bool;
332334
333335#if __STDC_VERSION__ >= 201112L
334336#define zig_noreturn _Noreturn
335#elif zig_has_attribute(noreturn) || defined(zig_gnuc)
337#elif zig_has_attribute(noreturn) || defined(zig_gnuc) || defined(zig_tinyc)
336338#define zig_noreturn __attribute__((noreturn))
337339#elif _MSC_VER
338340#define zig_noreturn __declspec(noreturn)
......@@ -1136,7 +1138,7 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) {
11361138 static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \
11371139 return zig_popcount_u##w((uint##w##_t)val, bits); \
11381140 }
1139#if zig_has_builtin(popcount) || defined(zig_gnuc)
1141#if zig_has_builtin(popcount) || defined(zig_gnuc) || defined(zig_tinyc)
11401142#define zig_builtin_popcount(w) \
11411143 static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \
11421144 (void)bits; \
......@@ -1165,7 +1167,7 @@ zig_builtin_popcount(64)
11651167 static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \
11661168 return zig_ctz_u##w((uint##w##_t)val, bits); \
11671169 }
1168#if zig_has_builtin(ctz) || defined(zig_gnuc)
1170#if zig_has_builtin(ctz) || defined(zig_gnuc) || defined(zig_tinyc)
11691171#define zig_builtin_ctz(w) \
11701172 static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \
11711173 if (val == 0) return bits; \
......@@ -1190,7 +1192,7 @@ zig_builtin_ctz(64)
11901192 static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \
11911193 return zig_clz_u##w((uint##w##_t)val, bits); \
11921194 }
1193#if zig_has_builtin(clz) || defined(zig_gnuc)
1195#if zig_has_builtin(clz) || defined(zig_gnuc) || defined(zig_tinyc)
11941196#define zig_builtin_clz(w) \
11951197 static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \
11961198 if (val == 0) return bits; \