aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2024-10-23 16:48:33 +0100
committerGitHub <noreply@github.com>2024-10-23 16:48:33 +0100
commit6bf52b0505ad7317b5f0d6fa77b7c41318b9c73b (patch)
tree22b5acedc288f3f2085fa4a170ee3d7629e8a9fe /src/codegen/c.zig
parent2d888a8e639856e8cb6e4c6f9e6a27647b464952 (diff)
parentf7d679ceae2403d4137d75d4afe32a3e8eb0cf16 (diff)
downloadzig-6bf52b0505ad7317b5f0d6fa77b7c41318b9c73b.tar.gz
zig-6bf52b0505ad7317b5f0d6fa77b7c41318b9c73b.zip
Merge pull request #21697 from mlugg/callconv
Replace `std.builtin.CallingConvention` with a tagged union, eliminating `@setAlignStack`
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 98c3c42deb..be8d2ad2a5 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1783,7 +1783,7 @@ pub const DeclGen = struct {
const fn_ctype = try dg.ctypeFromType(fn_ty, kind);
const fn_info = zcu.typeToFunc(fn_ty).?;
- if (fn_info.cc == .Naked) {
+ if (fn_info.cc == .naked) {
switch (kind) {
.forward => try w.writeAll("zig_naked_decl "),
.complete => try w.writeAll("zig_naked "),
@@ -1796,7 +1796,7 @@ pub const DeclGen = struct {
var trailing = try renderTypePrefix(dg.pass, &dg.ctype_pool, zcu, w, fn_ctype, .suffix, .{});
- if (toCallingConvention(fn_info.cc)) |call_conv| {
+ if (toCallingConvention(fn_info.cc, zcu)) |call_conv| {
try w.print("{}zig_callconv({s})", .{ trailing, call_conv });
trailing = .maybe_space;
}
@@ -7604,12 +7604,39 @@ fn writeMemoryOrder(w: anytype, order: std.builtin.AtomicOrder) !void {
return w.writeAll(toMemoryOrder(order));
}
-fn toCallingConvention(call_conv: std.builtin.CallingConvention) ?[]const u8 {
- return switch (call_conv) {
- .Stdcall => "stdcall",
- .Fastcall => "fastcall",
- .Vectorcall => "vectorcall",
- else => null,
+fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8 {
+ if (zcu.getTarget().cCallingConvention()) |ccc| {
+ if (cc.eql(ccc)) {
+ return null;
+ }
+ }
+ return switch (cc) {
+ .auto, .naked => null,
+
+ .x86_64_sysv, .x86_sysv => "sysv_abi",
+ .x86_64_win, .x86_win => "ms_abi",
+ .x86_stdcall => "stdcall",
+ .x86_fastcall => "fastcall",
+ .x86_thiscall => "thiscall",
+
+ .x86_vectorcall,
+ .x86_64_vectorcall,
+ => "vectorcall",
+
+ .x86_64_regcall_v3_sysv,
+ .x86_64_regcall_v4_win,
+ .x86_regcall_v3,
+ .x86_regcall_v4_win,
+ => "regcall",
+
+ .aarch64_vfabi => "aarch64_vector_pcs",
+ .aarch64_vfabi_sve => "aarch64_sve_pcs",
+ .arm_aapcs => "pcs(\"aapcs\")",
+ .arm_aapcs_vfp => "pcs(\"aapcs-vfp\")",
+ .riscv64_lp64_v, .riscv32_ilp32_v => "riscv_vector_cc",
+ .m68k_rtd => "m68k_rtd",
+
+ else => unreachable, // `Zcu.callconvSupported`
};
}