authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-01-21 16:14:17-05:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-01-23 13:48:37-05:00
log77084093d8b9d162556e5ea4305ff5268ed0e6e9
treef5a9020eebe4bc3baef47654b389a0177371f413
parent4a330ab811f72a0b33026761b10030cb450c32ca

cbe: handle building for -msvc using clang and -gnu using msvc


2 files changed, 38 insertions(+), 7 deletions(-)

lib/zig.h+24-5
......@@ -1871,11 +1871,13 @@ typedef zig_i32 zig_f32;
18711871#define zig_bitSizeOf_f64 64
18721872#define zig_libc_name_f64(name) name
18731873#if _MSC_VER
1874#ifdef ZIG_TARGET_ABI_MSVC
18741875#define zig_bitSizeOf_c_longdouble 64
1876#endif
18751877#define zig_as_special_constant_f64(sign, name, arg, repr) sign zig_as_f64(zig_msvc_flt_##name, )
1876#else
1878#else /* _MSC_VER */
18771879#define zig_as_special_constant_f64(sign, name, arg, repr) zig_as_special_f64(sign, name, arg, repr)
1878#endif
1880#endif /* _MSC_VER */
18791881#if FLT_MANT_DIG == 53
18801882typedef float zig_f64;
18811883#define zig_as_f64(fp, repr) fp##f
......@@ -1977,16 +1979,32 @@ typedef zig_i128 zig_f128;
19771979#endif
19781980
19791981#define zig_has_c_longdouble 1
1982
1983#ifdef ZIG_TARGET_ABI_MSVC
1984#define zig_libc_name_c_longdouble(name) name
1985#else
19801986#define zig_libc_name_c_longdouble(name) name##l
1987#endif
1988
19811989#define zig_as_special_constant_c_longdouble(sign, name, arg, repr) zig_as_special_c_longdouble(sign, name, arg, repr)
19821990#ifdef zig_bitSizeOf_c_longdouble
1991
1992#ifdef ZIG_TARGET_ABI_MSVC
1993typedef double zig_c_longdouble;
1994#undef zig_bitSizeOf_c_longdouble
1995#define zig_bitSizeOf_c_longdouble 64
1996#define zig_as_c_longdouble(fp, repr) fp
1997#else
19831998typedef long double zig_c_longdouble;
19841999#define zig_as_c_longdouble(fp, repr) fp##l
1985#else
2000#endif
2001
2002#else /* zig_bitSizeOf_c_longdouble */
2003
19862004#undef zig_has_c_longdouble
2005#define zig_has_c_longdouble 0
19872006#define zig_bitSizeOf_c_longdouble 80
19882007#define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f80
1989#define zig_has_c_longdouble 0
19902008#define zig_repr_c_longdouble i128
19912009typedef zig_i128 zig_c_longdouble;
19922010#define zig_as_c_longdouble(fp, repr) repr
......@@ -1994,7 +2012,8 @@ typedef zig_i128 zig_c_longdouble;
19942012#define zig_as_special_c_longdouble(sign, name, arg, repr) repr
19952013#undef zig_as_special_constant_c_longdouble
19962014#define zig_as_special_constant_c_longdouble(sign, name, arg, repr) repr
1997#endif
2015
2016#endif /* zig_bitSizeOf_c_longdouble */
19982017
19992018#if !zig_has_float_builtins
20002019#define zig_float_from_repr(Type, ReprType) \
src/link/C.zig+14-2
......@@ -231,6 +231,13 @@ pub fn flush(self: *C, comp: *Compilation, prog_node: *std.Progress.Node) !void
231231 return self.flushModule(comp, prog_node);
232232}
233233
234fn abiDefine(comp: *Compilation) ?[]const u8 {
235 return switch (comp.getTarget().abi) {
236 .msvc => "#define ZIG_TARGET_ABI_MSVC\n",
237 else => null,
238 };
239}
240
234241pub fn flushModule(self: *C, comp: *Compilation, prog_node: *std.Progress.Node) !void {
235242 const tracy = trace(@src());
236243 defer tracy.end();
......@@ -248,9 +255,14 @@ pub fn flushModule(self: *C, comp: *Compilation, prog_node: *std.Progress.Node)
248255 var f: Flush = .{};
249256 defer f.deinit(gpa);
250257
251 // Covers zig.h, typedef, and asm.
252 try f.all_buffers.ensureUnusedCapacity(gpa, 2);
258 const abi_define = abiDefine(comp);
259
260 // Covers defines, zig.h, typedef, and asm.
261 var buf_count: usize = 2;
262 if (abi_define != null) buf_count += 1;
263 try f.all_buffers.ensureUnusedCapacity(gpa, buf_count);
253264
265 if (abi_define) |buf| f.appendBufAssumeCapacity(buf);
254266 f.appendBufAssumeCapacity(zig_h);
255267
256268 const typedef_index = f.all_buffers.items.len;