authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-01 18:24:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-02 00:46:27-05:00
log665eba93c1733f83614c443c19cd9a5f1be910df
tree79d9456c5841e54705591f1d37b66727fe4ee2d5
parente6e459e9e36fcd84edca548d8c722fc1f81c07a4

CBE: eliminate zig_void

C void is perfectly fine.

3 files changed, 48 insertions(+), 35 deletions(-)

lib/zig.h-2
......@@ -189,8 +189,6 @@
189189
190190#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T))
191191
192typedef void zig_void;
193
194192#if defined(__cplusplus)
195193typedef bool zig_bool;
196194#define zig_false false
src/codegen/c.zig+37-22
......@@ -1802,33 +1802,24 @@ pub const DeclGen = struct {
18021802 const target = dg.module.getTarget();
18031803
18041804 switch (t.zigTypeTag()) {
1805 .NoReturn, .Void, .Bool, .Int, .Float, .ErrorSet => |tag| {
1806 const is_named = switch (tag) {
1807 .Int => t.isNamedInt(),
1808 .ErrorSet => false,
1809 else => true,
1810 };
1811 if (is_named) {
1805 .Void => {
1806 try w.writeAll("void");
1807 },
1808 .NoReturn, .Bool, .Float => {
1809 try w.writeAll("zig_");
1810 try t.print(w, dg.module);
1811 },
1812 .Int => {
1813 if (t.isNamedInt()) {
18121814 try w.writeAll("zig_");
18131815 try t.print(w, dg.module);
18141816 } else {
1815 const int_info = t.intInfo(target);
1816 if (toCIntBits(int_info.bits)) |c_bits|
1817 return w.print("zig_{c}{d}", .{ signAbbrev(int_info.signedness), c_bits })
1818 else if (loweredArrayInfo(t, target)) |array_info| {
1819 assert(array_info.sentinel == null);
1820 var array_pl = Type.Payload.Array{
1821 .base = .{ .tag = .array },
1822 .data = .{ .len = array_info.len, .elem_type = array_info.elem_type },
1823 };
1824 const array_ty = Type.initPayload(&array_pl.base);
1825
1826 return dg.renderType(w, array_ty, kind);
1827 } else return dg.fail("C backend: Unable to lower unnamed integer type {}", .{
1828 t.fmt(dg.module),
1829 });
1817 return renderTypeUnnamed(dg, w, t, kind);
18301818 }
18311819 },
1820 .ErrorSet => {
1821 return renderTypeUnnamed(dg, w, t, kind);
1822 },
18321823 .Pointer => {
18331824 const ptr_info = t.ptrInfo().data;
18341825 if (ptr_info.size == .Slice) {
......@@ -2015,6 +2006,30 @@ pub const DeclGen = struct {
20152006 }
20162007 }
20172008
2009 fn renderTypeUnnamed(
2010 dg: *DeclGen,
2011 w: anytype,
2012 t: Type,
2013 kind: TypedefKind,
2014 ) error{ OutOfMemory, AnalysisFail }!void {
2015 const target = dg.module.getTarget();
2016 const int_info = t.intInfo(target);
2017 if (toCIntBits(int_info.bits)) |c_bits|
2018 return w.print("zig_{c}{d}", .{ signAbbrev(int_info.signedness), c_bits })
2019 else if (loweredArrayInfo(t, target)) |array_info| {
2020 assert(array_info.sentinel == null);
2021 var array_pl = Type.Payload.Array{
2022 .base = .{ .tag = .array },
2023 .data = .{ .len = array_info.len, .elem_type = array_info.elem_type },
2024 };
2025 const array_ty = Type.initPayload(&array_pl.base);
2026
2027 return dg.renderType(w, array_ty, kind);
2028 } else return dg.fail("C backend: Unable to lower unnamed integer type {}", .{
2029 t.fmt(dg.module),
2030 });
2031 }
2032
20182033 /// Renders a type in C typecast format.
20192034 ///
20202035 /// This is guaranteed to be valid in a typecast expression, but not
test/stage2/cbe.zig+11-11
......@@ -951,7 +951,7 @@ pub fn addCases(ctx: *TestContext) !void {
951951 ctx.h("simple header", linux_x64,
952952 \\export fn start() void{}
953953 ,
954 \\zig_extern zig_void start(zig_void);
954 \\zig_extern void start(void);
955955 \\
956956 );
957957 ctx.h("header with single param function", linux_x64,
......@@ -959,7 +959,7 @@ pub fn addCases(ctx: *TestContext) !void {
959959 \\ _ = a;
960960 \\}
961961 ,
962 \\zig_extern zig_void start(zig_u8 const a0);
962 \\zig_extern void start(zig_u8 const a0);
963963 \\
964964 );
965965 ctx.h("header with multiple param function", linux_x64,
......@@ -967,25 +967,25 @@ pub fn addCases(ctx: *TestContext) !void {
967967 \\ _ = a; _ = b; _ = c;
968968 \\}
969969 ,
970 \\zig_extern zig_void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2);
970 \\zig_extern void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2);
971971 \\
972972 );
973973 ctx.h("header with u32 param function", linux_x64,
974974 \\export fn start(a: u32) void{ _ = a; }
975975 ,
976 \\zig_extern zig_void start(zig_u32 const a0);
976 \\zig_extern void start(zig_u32 const a0);
977977 \\
978978 );
979979 ctx.h("header with usize param function", linux_x64,
980980 \\export fn start(a: usize) void{ _ = a; }
981981 ,
982 \\zig_extern zig_void start(zig_usize const a0);
982 \\zig_extern void start(zig_usize const a0);
983983 \\
984984 );
985985 ctx.h("header with bool param function", linux_x64,
986986 \\export fn start(a: bool) void{_ = a;}
987987 ,
988 \\zig_extern zig_void start(zig_bool const a0);
988 \\zig_extern void start(zig_bool const a0);
989989 \\
990990 );
991991 ctx.h("header with noreturn function", linux_x64,
......@@ -993,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void {
993993 \\ unreachable;
994994 \\}
995995 ,
996 \\zig_extern zig_noreturn start(zig_void);
996 \\zig_extern zig_noreturn start(void);
997997 \\
998998 );
999999 ctx.h("header with multiple functions", linux_x64,
......@@ -1001,15 +1001,15 @@ pub fn addCases(ctx: *TestContext) !void {
10011001 \\export fn b() void{}
10021002 \\export fn c() void{}
10031003 ,
1004 \\zig_extern zig_void a(zig_void);
1005 \\zig_extern zig_void b(zig_void);
1006 \\zig_extern zig_void c(zig_void);
1004 \\zig_extern void a(void);
1005 \\zig_extern void b(void);
1006 \\zig_extern void c(void);
10071007 \\
10081008 );
10091009 ctx.h("header with multiple includes", linux_x64,
10101010 \\export fn start(a: u32, b: usize) void{ _ = a; _ = b; }
10111011 ,
1012 \\zig_extern zig_void start(zig_u32 const a0, zig_usize const a1);
1012 \\zig_extern void start(zig_u32 const a0, zig_usize const a1);
10131013 \\
10141014 );
10151015}