Skip to content

Commit

Permalink
std.Target: Rename c_type_* functions to camel case
Browse files Browse the repository at this point in the history
From https://ziglang.org/documentation/master/#Names:

> If `x` is otherwise callable, then `x` should be `camelCase`.
  • Loading branch information
linusg committed Aug 11, 2024
1 parent fd434fc commit 4ef956e
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 109 deletions.
6 changes: 3 additions & 3 deletions lib/compiler/aro/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5631,15 +5631,15 @@ pub const Result = struct {
};
const a_spec = a.ty.canonicalize(.standard).specifier;
const b_spec = b.ty.canonicalize(.standard).specifier;
if (p.comp.target.c_type_bit_size(.longdouble) == 128) {
if (p.comp.target.cTypeBitSize(.longdouble) == 128) {
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
}
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[1])) return;
if (p.comp.target.c_type_bit_size(.longdouble) == 80) {
if (p.comp.target.cTypeBitSize(.longdouble) == 80) {
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
}
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[2])) return;
if (p.comp.target.c_type_bit_size(.longdouble) == 64) {
if (p.comp.target.cTypeBitSize(.longdouble) == 64) {
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
}
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[3])) return;
Expand Down
46 changes: 23 additions & 23 deletions lib/compiler/aro/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -991,19 +991,19 @@ pub fn sizeof(ty: Type, comp: *const Compilation) ?u64 {
.incomplete_array => return if (comp.langopts.emulate == .msvc) @as(?u64, 0) else null,
.func, .var_args_func, .old_style_func, .void, .bool => 1,
.char, .schar, .uchar => 1,
.short => comp.target.c_type_byte_size(.short),
.ushort => comp.target.c_type_byte_size(.ushort),
.int => comp.target.c_type_byte_size(.int),
.uint => comp.target.c_type_byte_size(.uint),
.long => comp.target.c_type_byte_size(.long),
.ulong => comp.target.c_type_byte_size(.ulong),
.long_long => comp.target.c_type_byte_size(.longlong),
.ulong_long => comp.target.c_type_byte_size(.ulonglong),
.long_double => comp.target.c_type_byte_size(.longdouble),
.short => comp.target.cTypeByteSize(.short),
.ushort => comp.target.cTypeByteSize(.ushort),
.int => comp.target.cTypeByteSize(.int),
.uint => comp.target.cTypeByteSize(.uint),
.long => comp.target.cTypeByteSize(.long),
.ulong => comp.target.cTypeByteSize(.ulong),
.long_long => comp.target.cTypeByteSize(.longlong),
.ulong_long => comp.target.cTypeByteSize(.ulonglong),
.long_double => comp.target.cTypeByteSize(.longdouble),
.int128, .uint128 => 16,
.fp16, .float16 => 2,
.float => comp.target.c_type_byte_size(.float),
.double => comp.target.c_type_byte_size(.double),
.float => comp.target.cTypeByteSize(.float),
.double => comp.target.cTypeByteSize(.double),
.float80 => 16,
.float128 => 16,
.bit_int => {
Expand Down Expand Up @@ -1049,7 +1049,7 @@ pub fn bitSizeof(ty: Type, comp: *const Compilation) ?u64 {
.typeof_expr => ty.data.expr.ty.bitSizeof(comp),
.attributed => ty.data.attributed.base.bitSizeof(comp),
.bit_int => return ty.data.int.bits,
.long_double => comp.target.c_type_bit_size(.longdouble),
.long_double => comp.target.cTypeBitSize(.longdouble),
.float80 => return 80,
else => 8 * (ty.sizeof(comp) orelse return null),
};
Expand Down Expand Up @@ -1104,24 +1104,24 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {
=> return ty.makeReal().alignof(comp),
// zig fmt: on

.short => comp.target.c_type_alignment(.short),
.ushort => comp.target.c_type_alignment(.ushort),
.int => comp.target.c_type_alignment(.int),
.uint => comp.target.c_type_alignment(.uint),
.short => comp.target.cTypeAlignment(.short),
.ushort => comp.target.cTypeAlignment(.ushort),
.int => comp.target.cTypeAlignment(.int),
.uint => comp.target.cTypeAlignment(.uint),

.long => comp.target.c_type_alignment(.long),
.ulong => comp.target.c_type_alignment(.ulong),
.long_long => comp.target.c_type_alignment(.longlong),
.ulong_long => comp.target.c_type_alignment(.ulonglong),
.long => comp.target.cTypeAlignment(.long),
.ulong => comp.target.cTypeAlignment(.ulong),
.long_long => comp.target.cTypeAlignment(.longlong),
.ulong_long => comp.target.cTypeAlignment(.ulonglong),

.bit_int => @min(
std.math.ceilPowerOfTwoPromote(u16, (ty.data.int.bits + 7) / 8),
16, // comp.target.maxIntAlignment(), please use your own logic for this value as it is implementation-defined
),

.float => comp.target.c_type_alignment(.float),
.double => comp.target.c_type_alignment(.double),
.long_double => comp.target.c_type_alignment(.longdouble),
.float => comp.target.cTypeAlignment(.float),
.double => comp.target.cTypeAlignment(.double),
.long_double => comp.target.cTypeAlignment(.longdouble),

.int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.isGnu()) 8 else 16,
.fp16, .float16 => 2,
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/aro/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub const FPSemantics = enum {
/// Only intended for generating float.h macros for the preprocessor
pub fn forType(ty: std.Target.CType, target: std.Target) FPSemantics {
std.debug.assert(ty == .float or ty == .double or ty == .longdouble);
return switch (target.c_type_bit_size(ty)) {
return switch (target.cTypeBitSize(ty)) {
32 => .IEEESingle,
64 => .IEEEDouble,
80 => .x87ExtendedDouble,
Expand Down Expand Up @@ -350,7 +350,7 @@ pub const FPSemantics = enum {
};

pub fn isLP64(target: std.Target) bool {
return target.c_type_bit_size(.int) == 32 and target.ptrBitWidth() == 64;
return target.cTypeBitSize(.int) == 32 and target.ptrBitWidth() == 64;
}

pub fn isKnownWindowsMSVCEnvironment(target: std.Target) bool {
Expand Down
18 changes: 9 additions & 9 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ pub const CType = enum {
longdouble,
};

pub fn c_type_byte_size(t: Target, c_type: CType) u16 {
pub fn cTypeByteSize(t: Target, c_type: CType) u16 {
return switch (c_type) {
.char,
.short,
Expand All @@ -2022,20 +2022,20 @@ pub fn c_type_byte_size(t: Target, c_type: CType) u16 {
.ulonglong,
.float,
.double,
=> @divExact(c_type_bit_size(t, c_type), 8),
=> @divExact(cTypeBitSize(t, c_type), 8),

.longdouble => switch (c_type_bit_size(t, c_type)) {
.longdouble => switch (cTypeBitSize(t, c_type)) {
16 => 2,
32 => 4,
64 => 8,
80 => @intCast(std.mem.alignForward(usize, 10, c_type_alignment(t, .longdouble))),
80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, .longdouble))),
128 => 16,
else => unreachable,
},
};
}

pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
switch (target.os.tag) {
.freestanding, .other => switch (target.cpu.arch) {
.msp430 => switch (c_type) {
Expand Down Expand Up @@ -2331,7 +2331,7 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
}
}

pub fn c_type_alignment(target: Target, c_type: CType) u16 {
pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
// Overrides for unusual alignments
switch (target.cpu.arch) {
.avr => return 1,
Expand All @@ -2351,7 +2351,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {

// Next-power-of-two-aligned, up to a maximum.
return @min(
std.math.ceilPowerOfTwoAssert(u16, (c_type_bit_size(target, c_type) + 7) / 8),
std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
@as(u16, switch (target.cpu.arch) {
.arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
.netbsd => switch (target.abi) {
Expand Down Expand Up @@ -2423,7 +2423,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 {
);
}

pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {
pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
// Overrides for unusual alignments
switch (target.cpu.arch) {
.arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
Expand Down Expand Up @@ -2476,7 +2476,7 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {

// Next-power-of-two-aligned, up to a maximum.
return @min(
std.math.ceilPowerOfTwoAssert(u16, (c_type_bit_size(target, c_type) + 7) / 8),
std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
@as(u16, switch (target.cpu.arch) {
.msp430 => 2,

Expand Down
8 changes: 4 additions & 4 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30943,7 +30943,7 @@ fn coerceVarArgParam(
.Array => return sema.fail(block, inst_src, "arrays must be passed by reference to variadic function", .{}),
.Float => float: {
const target = zcu.getTarget();
const double_bits = target.c_type_bit_size(.double);
const double_bits = target.cTypeBitSize(.double);
const inst_bits = uncasted_ty.floatBits(target);
if (inst_bits >= double_bits) break :float inst;
switch (double_bits) {
Expand All @@ -30956,21 +30956,21 @@ fn coerceVarArgParam(
if (!try sema.validateExternType(uncasted_ty, .param_ty)) break :int inst;
const target = zcu.getTarget();
const uncasted_info = uncasted_ty.intInfo(zcu);
if (uncasted_info.bits <= target.c_type_bit_size(switch (uncasted_info.signedness) {
if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
.signed => .int,
.unsigned => .uint,
})) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
.signed => Type.c_int,
.unsigned => Type.c_uint,
}, inst, inst_src);
if (uncasted_info.bits <= target.c_type_bit_size(switch (uncasted_info.signedness) {
if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
.signed => .long,
.unsigned => .ulong,
})) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
.signed => Type.c_long,
.unsigned => Type.c_ulong,
}, inst, inst_src);
if (uncasted_info.bits <= target.c_type_bit_size(switch (uncasted_info.signedness) {
if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
.signed => .longlong,
.unsigned => .ulonglong,
})) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
Expand Down
72 changes: 36 additions & 36 deletions src/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1005,15 +1005,15 @@ pub fn abiAlignmentAdvanced(

.f16 => return .{ .scalar = .@"2" },
.f32 => return .{ .scalar = cTypeAlign(target, .float) },
.f64 => switch (target.c_type_bit_size(.double)) {
.f64 => switch (target.cTypeBitSize(.double)) {
64 => return .{ .scalar = cTypeAlign(target, .double) },
else => return .{ .scalar = .@"8" },
},
.f80 => switch (target.c_type_bit_size(.longdouble)) {
.f80 => switch (target.cTypeBitSize(.longdouble)) {
80 => return .{ .scalar = cTypeAlign(target, .longdouble) },
else => return .{ .scalar = Type.u80.abiAlignment(pt) },
},
.f128 => switch (target.c_type_bit_size(.longdouble)) {
.f128 => switch (target.cTypeBitSize(.longdouble)) {
128 => return .{ .scalar = cTypeAlign(target, .longdouble) },
else => return .{ .scalar = .@"16" },
},
Expand Down Expand Up @@ -1366,25 +1366,25 @@ pub fn abiSizeAdvanced(
.f32 => return .{ .scalar = 4 },
.f64 => return .{ .scalar = 8 },
.f128 => return .{ .scalar = 16 },
.f80 => switch (target.c_type_bit_size(.longdouble)) {
80 => return .{ .scalar = target.c_type_byte_size(.longdouble) },
.f80 => switch (target.cTypeBitSize(.longdouble)) {
80 => return .{ .scalar = target.cTypeByteSize(.longdouble) },
else => return .{ .scalar = Type.u80.abiSize(pt) },
},

.usize,
.isize,
=> return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },

.c_char => return .{ .scalar = target.c_type_byte_size(.char) },
.c_short => return .{ .scalar = target.c_type_byte_size(.short) },
.c_ushort => return .{ .scalar = target.c_type_byte_size(.ushort) },
.c_int => return .{ .scalar = target.c_type_byte_size(.int) },
.c_uint => return .{ .scalar = target.c_type_byte_size(.uint) },
.c_long => return .{ .scalar = target.c_type_byte_size(.long) },
.c_ulong => return .{ .scalar = target.c_type_byte_size(.ulong) },
.c_longlong => return .{ .scalar = target.c_type_byte_size(.longlong) },
.c_ulonglong => return .{ .scalar = target.c_type_byte_size(.ulonglong) },
.c_longdouble => return .{ .scalar = target.c_type_byte_size(.longdouble) },
.c_char => return .{ .scalar = target.cTypeByteSize(.char) },
.c_short => return .{ .scalar = target.cTypeByteSize(.short) },
.c_ushort => return .{ .scalar = target.cTypeByteSize(.ushort) },
.c_int => return .{ .scalar = target.cTypeByteSize(.int) },
.c_uint => return .{ .scalar = target.cTypeByteSize(.uint) },
.c_long => return .{ .scalar = target.cTypeByteSize(.long) },
.c_ulong => return .{ .scalar = target.cTypeByteSize(.ulong) },
.c_longlong => return .{ .scalar = target.cTypeByteSize(.longlong) },
.c_ulonglong => return .{ .scalar = target.cTypeByteSize(.ulonglong) },
.c_longdouble => return .{ .scalar = target.cTypeByteSize(.longdouble) },

.anyopaque,
.void,
Expand Down Expand Up @@ -1724,16 +1724,16 @@ pub fn bitSizeAdvanced(
.isize,
=> return target.ptrBitWidth(),

.c_char => return target.c_type_bit_size(.char),
.c_short => return target.c_type_bit_size(.short),
.c_ushort => return target.c_type_bit_size(.ushort),
.c_int => return target.c_type_bit_size(.int),
.c_uint => return target.c_type_bit_size(.uint),
.c_long => return target.c_type_bit_size(.long),
.c_ulong => return target.c_type_bit_size(.ulong),
.c_longlong => return target.c_type_bit_size(.longlong),
.c_ulonglong => return target.c_type_bit_size(.ulonglong),
.c_longdouble => return target.c_type_bit_size(.longdouble),
.c_char => return target.cTypeBitSize(.char),
.c_short => return target.cTypeBitSize(.short),
.c_ushort => return target.cTypeBitSize(.ushort),
.c_int => return target.cTypeBitSize(.int),
.c_uint => return target.cTypeBitSize(.uint),
.c_long => return target.cTypeBitSize(.long),
.c_ulong => return target.cTypeBitSize(.ulong),
.c_longlong => return target.cTypeBitSize(.longlong),
.c_ulonglong => return target.cTypeBitSize(.ulonglong),
.c_longdouble => return target.cTypeBitSize(.longdouble),

.bool => return 1,
.void => return 0,
Expand Down Expand Up @@ -2310,15 +2310,15 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
},
.usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
.isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
.c_char_type => return .{ .signedness = mod.getTarget().charSignedness(), .bits = target.c_type_bit_size(.char) },
.c_short_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.short) },
.c_ushort_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ushort) },
.c_int_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.int) },
.c_uint_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.uint) },
.c_long_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.long) },
.c_ulong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulong) },
.c_longlong_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.longlong) },
.c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
.c_char_type => return .{ .signedness = mod.getTarget().charSignedness(), .bits = target.cTypeBitSize(.char) },
.c_short_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.short) },
.c_ushort_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ushort) },
.c_int_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.int) },
.c_uint_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.uint) },
.c_long_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.long) },
.c_ulong_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ulong) },
.c_longlong_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.longlong) },
.c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ulonglong) },
else => switch (ip.indexToKey(ty.toIntern())) {
.int_type => |int_type| return int_type,
.struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntTypeUnordered(ip)),
Expand Down Expand Up @@ -2427,7 +2427,7 @@ pub fn floatBits(ty: Type, target: Target) u16 {
.f64_type => 64,
.f80_type => 80,
.f128_type, .comptime_float_type => 128,
.c_longdouble_type => target.c_type_bit_size(.longdouble),
.c_longdouble_type => target.cTypeBitSize(.longdouble),

else => unreachable,
};
Expand Down Expand Up @@ -4025,5 +4025,5 @@ pub fn smallestUnsignedBits(max: u64) u16 {
pub const packed_struct_layout_version = 2;

fn cTypeAlign(target: Target, c_type: Target.CType) Alignment {
return Alignment.fromByteUnits(target.c_type_alignment(c_type));
return Alignment.fromByteUnits(target.cTypeAlignment(c_type));
}
2 changes: 1 addition & 1 deletion src/arch/riscv64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8304,7 +8304,7 @@ fn promoteVarArg(func: *Func, ty: Type) Type {
switch (ty.floatBits(func.target.*)) {
32, 64 => return Type.f64,
else => |float_bits| {
assert(float_bits == func.target.c_type_bit_size(.longdouble));
assert(float_bits == func.target.cTypeBitSize(.longdouble));
return Type.c_longdouble;
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19374,7 +19374,7 @@ fn promoteVarArg(self: *Self, ty: Type) Type {
switch (ty.floatBits(self.target.*)) {
32, 64 => return Type.f64,
else => |float_bits| {
assert(float_bits == self.target.c_type_bit_size(.longdouble));
assert(float_bits == self.target.cTypeBitSize(.longdouble));
return Type.c_longdouble;
},
}
Expand Down
Loading

0 comments on commit 4ef956e

Please sign in to comment.