std.Target: rename defaultCCallingConvention and Cpu.Arch.fromCallconv
This commit is contained in:
@@ -1612,7 +1612,7 @@ pub const Cpu = struct {
|
||||
|
||||
/// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies.
|
||||
/// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
|
||||
pub fn fromCallconv(cc: std.builtin.CallingConvention.Tag) []const Arch {
|
||||
pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch {
|
||||
return switch (cc) {
|
||||
.auto,
|
||||
.@"async",
|
||||
@@ -3032,7 +3032,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn defaultCCallingConvention(target: Target) ?std.builtin.CallingConvention {
|
||||
pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
|
||||
return switch (target.cpu.arch) {
|
||||
.x86_64 => switch (target.os.tag) {
|
||||
.windows, .uefi => .{ .x86_64_win = .{} },
|
||||
|
||||
@@ -171,7 +171,7 @@ pub const CallingConvention = union(enum(u8)) {
|
||||
|
||||
/// This is an alias for the default C calling convention for this target.
|
||||
/// Functions marked as `extern` or `export` are given this calling convention by default.
|
||||
pub const c = builtin.target.defaultCCallingConvention().?;
|
||||
pub const c = builtin.target.cCallingConvention().?;
|
||||
|
||||
pub const winapi: CallingConvention = switch (builtin.target.cpu.arch) {
|
||||
.x86_64 => .{ .x86_64_win = .{} },
|
||||
@@ -482,7 +482,7 @@ pub const CallingConvention = union(enum(u8)) {
|
||||
/// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
|
||||
/// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
|
||||
pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
|
||||
return std.Target.Cpu.Arch.fromCallconv(cc);
|
||||
return std.Target.Cpu.Arch.fromCallingConvention(cc);
|
||||
}
|
||||
|
||||
pub fn eql(a: CallingConvention, b: CallingConvention) bool {
|
||||
|
||||
@@ -9499,11 +9499,11 @@ fn zirFunc(
|
||||
break :exported zir_decl.flags.is_export;
|
||||
};
|
||||
if (fn_is_exported) {
|
||||
break :cc target.defaultCCallingConvention() orelse {
|
||||
break :cc target.cCallingConvention() orelse {
|
||||
// This target has no default C calling convention. We sometimes trigger a similar
|
||||
// error by trying to evaluate `std.builtin.CallingConvention.c`, so for consistency,
|
||||
// let's eval that now and just get the transitive error. (It's guaranteed to error
|
||||
// because it does the exact `defaultCCallingConvention` call we just did.)
|
||||
// because it does the exact `cCallingConvention` call we just did.)
|
||||
const cc_type = try sema.getBuiltinType("CallingConvention");
|
||||
_ = try sema.namespaceLookupVal(
|
||||
block,
|
||||
@@ -9717,7 +9717,7 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:
|
||||
_ = options;
|
||||
var first = true;
|
||||
for (calling_conventions_supporting_var_args) |cc_inner| {
|
||||
for (std.Target.Cpu.Arch.fromCallconv(cc_inner)) |supported_arch| {
|
||||
for (std.Target.Cpu.Arch.fromCallingConvention(cc_inner)) |supported_arch| {
|
||||
if (supported_arch == ctx.arch) break;
|
||||
} else continue; // callconv not supported by this arch
|
||||
if (!first) {
|
||||
|
||||
@@ -391,7 +391,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
|
||||
}
|
||||
try writer.writeAll(") ");
|
||||
if (fn_info.cc != .auto) print_cc: {
|
||||
if (zcu.getTarget().defaultCCallingConvention()) |ccc| {
|
||||
if (zcu.getTarget().cCallingConvention()) |ccc| {
|
||||
if (fn_info.cc.eql(ccc)) {
|
||||
try writer.writeAll("callconv(.c) ");
|
||||
break :print_cc;
|
||||
|
||||
@@ -3562,7 +3562,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
|
||||
|
||||
.stage2_llvm => @import("codegen/llvm.zig").toLlvmCallConv(cc, target) != null,
|
||||
.stage2_c => ok: {
|
||||
if (target.defaultCCallingConvention()) |default_c| {
|
||||
if (target.cCallingConvention()) |default_c| {
|
||||
if (cc.eql(default_c)) {
|
||||
break :ok true;
|
||||
}
|
||||
|
||||
@@ -4895,7 +4895,7 @@ fn genCall(
|
||||
.lib => |lib| try pt.funcType(.{
|
||||
.param_types = lib.param_types,
|
||||
.return_type = lib.return_type,
|
||||
.cc = func.target.defaultCCallingConvention().?,
|
||||
.cc = func.target.cCallingConvention().?,
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
@@ -12384,7 +12384,7 @@ fn genCall(self: *Self, info: union(enum) {
|
||||
.lib => |lib| try pt.funcType(.{
|
||||
.param_types = lib.param_types,
|
||||
.return_type = lib.return_type,
|
||||
.cc = self.target.defaultCCallingConvention().?,
|
||||
.cc = self.target.cCallingConvention().?,
|
||||
}),
|
||||
};
|
||||
const fn_info = zcu.typeToFunc(fn_ty).?;
|
||||
|
||||
@@ -7612,7 +7612,7 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8
|
||||
.x86_vectorcall, .x86_64_vectorcall => "vectorcall",
|
||||
else => {
|
||||
// `Zcu.callconvSupported` means this must be the C callconv.
|
||||
assert(cc.eql(zcu.getTarget().defaultCCallingConvention().?));
|
||||
assert(cc.eql(zcu.getTarget().cCallingConvention().?));
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -11616,7 +11616,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?Ca
|
||||
};
|
||||
}
|
||||
fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Target) ?Builder.CallConv {
|
||||
if (target.defaultCCallingConvention()) |default_c| {
|
||||
if (target.cCallingConvention()) |default_c| {
|
||||
if (cc_tag == default_c) {
|
||||
return .ccc;
|
||||
}
|
||||
@@ -11668,7 +11668,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ
|
||||
.nvptx_kernel => .ptx_kernel,
|
||||
|
||||
// All the calling conventions which LLVM does not have a general representation for.
|
||||
// Note that these are often still supported through the `defaultCCallingConvention` path above via `ccc`.
|
||||
// Note that these are often still supported through the `cCallingConvention` path above via `ccc`.
|
||||
.x86_sysv,
|
||||
.x86_win,
|
||||
.x86_thiscall_mingw,
|
||||
|
||||
@@ -1484,7 +1484,7 @@ pub fn updateExports(
|
||||
const exported_nav = ip.getNav(exported_nav_index);
|
||||
const exported_ty = exported_nav.typeOf(ip);
|
||||
if (!ip.isFunctionType(exported_ty)) continue;
|
||||
const c_cc = target.defaultCCallingConvention().?;
|
||||
const c_cc = target.cCallingConvention().?;
|
||||
const winapi_cc: std.builtin.CallingConvention = switch (target.cpu.arch) {
|
||||
.x86 => .{ .x86_stdcall = .{} },
|
||||
else => c_cc,
|
||||
|
||||
@@ -3399,7 +3399,7 @@ fn updateType(
|
||||
try wip_nav.abbrevCode(if (is_nullary) .nullary_func_type else .func_type);
|
||||
try wip_nav.strp(name);
|
||||
const cc: DW.CC = cc: {
|
||||
if (zcu.getTarget().defaultCCallingConvention()) |cc| {
|
||||
if (zcu.getTarget().cCallingConvention()) |cc| {
|
||||
if (@as(std.builtin.CallingConvention.Tag, cc) == func_type.cc) {
|
||||
break :cc .normal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user