authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2022-12-30 02:26:06-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-02 13:56:32-07:00
log9c951cc8745256cbf94839b401abbb6afd35cae2
treee5756de84b707fa773d00bbbfa1f1f55495dc1f1
parentcac652f81be23cce8857298a8402036edf061e9d

fmt fixups


3 files changed, 10 insertions(+), 23 deletions(-)

src/codegen/c.zig+9-20
...@@ -1110,7 +1110,6 @@ pub const DeclGen = struct {...@@ -1110,7 +1110,6 @@ pub const DeclGen = struct {
1110 // MSVC throws C2078 if an array of size 65536 or greater is initialized with a string literal1110 // MSVC throws C2078 if an array of size 65536 or greater is initialized with a string literal
1111 const max_string_initializer_len = 65535;1111 const max_string_initializer_len = 65535;
11121112
1113
1114 const ai = ty.arrayInfo();1113 const ai = ty.arrayInfo();
1115 if (ai.elem_type.eql(Type.u8, dg.module)) {1114 if (ai.elem_type.eql(Type.u8, dg.module)) {
1116 if (ai.len <= max_string_initializer_len) {1115 if (ai.len <= max_string_initializer_len) {
...@@ -1134,7 +1133,7 @@ pub const DeclGen = struct {...@@ -1134,7 +1133,7 @@ pub const DeclGen = struct {
1134 if (index != 0) try writer.writeByte(',');1133 if (index != 0) try writer.writeByte(',');
1135 const elem_val = try val.elemValue(dg.module, arena_allocator, index);1134 const elem_val = try val.elemValue(dg.module, arena_allocator, index);
1136 const elem_val_u8 = if (elem_val.isUndef()) undefPattern(u8) else @intCast(u8, elem_val.toUnsignedInt(target));1135 const elem_val_u8 = if (elem_val.isUndef()) undefPattern(u8) else @intCast(u8, elem_val.toUnsignedInt(target));
1137 try writer.print("'\\x{x}'", .{ elem_val_u8 });1136 try writer.print("'\\x{x}'", .{elem_val_u8});
1138 }1137 }
1139 if (ai.sentinel) |s| {1138 if (ai.sentinel) |s| {
1140 if (index != 0) try writer.writeByte(',');1139 if (index != 0) try writer.writeByte(',');
...@@ -1350,7 +1349,7 @@ pub const DeclGen = struct {...@@ -1350,7 +1349,7 @@ pub const DeclGen = struct {
1350 try dg.renderIntCast(writer, ty, cast_context, field_ty, .FunctionArgument);1349 try dg.renderIntCast(writer, ty, cast_context, field_ty, .FunctionArgument);
1351 }1350 }
13521351
1353 if (needs_closing_paren) try writer.writeByte(')') ;1352 if (needs_closing_paren) try writer.writeByte(')');
1354 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");1353 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");
13551354
1356 bit_offset_val_pl.data += field_ty.bitSize(target);1355 bit_offset_val_pl.data += field_ty.bitSize(target);
...@@ -2254,7 +2253,7 @@ pub const DeclGen = struct {...@@ -2254,7 +2253,7 @@ pub const DeclGen = struct {
2254 if (dest_bits <= 64 and src_bits <= 64) {2253 if (dest_bits <= 64 and src_bits <= 64) {
2255 const needs_cast = src_int_info == null or2254 const needs_cast = src_int_info == null or
2256 (toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or2255 (toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or
2257 dest_int_info.signedness != src_int_info.?.signedness);2256 dest_int_info.signedness != src_int_info.?.signedness);
22582257
2259 if (needs_cast) {2258 if (needs_cast) {
2260 try w.writeByte('(');2259 try w.writeByte('(');
...@@ -2567,7 +2566,7 @@ pub const DeclGen = struct {...@@ -2567,7 +2566,7 @@ pub const DeclGen = struct {
2567 } else if (ty.isRuntimeFloat()) {2566 } else if (ty.isRuntimeFloat()) {
2568 try ty.print(writer, dg.module);2567 try ty.print(writer, dg.module);
2569 } else if (ty.isPtrAtRuntime()) {2568 } else if (ty.isPtrAtRuntime()) {
2570 try writer.print("p{d}", .{ ty.bitSize(target) });2569 try writer.print("p{d}", .{ty.bitSize(target)});
2571 } else if (ty.zigTypeTag() == .Bool) {2570 } else if (ty.zigTypeTag() == .Bool) {
2572 try writer.print("u8", .{});2571 try writer.print("u8", .{});
2573 } else return dg.fail("TODO: CBE: implement renderTypeForBuiltinFnName for type {}", .{2572 } else return dg.fail("TODO: CBE: implement renderTypeForBuiltinFnName for type {}", .{
...@@ -2633,12 +2632,7 @@ pub const DeclGen = struct {...@@ -2633,12 +2632,7 @@ pub const DeclGen = struct {
2633 const c_bits = toCIntBits(int_info.bits);2632 const c_bits = toCIntBits(int_info.bits);
2634 if (c_bits == null or c_bits.? > 128)2633 if (c_bits == null or c_bits.? > 128)
2635 return dg.fail("TODO implement integer constants larger than 128 bits", .{});2634 return dg.fail("TODO implement integer constants larger than 128 bits", .{});
2636 return std.fmt.Formatter(formatIntLiteral){ .data = .{2635 return std.fmt.Formatter(formatIntLiteral){ .data = .{ .ty = ty, .val = val, .mod = dg.module, .location = location } };
2637 .ty = ty,
2638 .val = val,
2639 .mod = dg.module,
2640 .location = location
2641 } };
2642 }2636 }
2643};2637};
26442638
...@@ -3668,9 +3662,9 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3668,9 +3662,9 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue {
3668 }3662 }
3669 try f.writeCValue(writer, operand, .FunctionArgument);3663 try f.writeCValue(writer, operand, .FunctionArgument);
3670 if (c_bits == 128) try writer.writeByte(')');3664 if (c_bits == 128) try writer.writeByte(')');
3671 try writer.print(", {})", .{ try f.fmtIntLiteral(Type.u8, shift_val) });3665 try writer.print(", {})", .{try f.fmtIntLiteral(Type.u8, shift_val)});
3672 if (c_bits == 128) try writer.writeByte(')');3666 if (c_bits == 128) try writer.writeByte(')');
3673 try writer.print(", {})", .{ try f.fmtIntLiteral(Type.u8, shift_val) });3667 try writer.print(", {})", .{try f.fmtIntLiteral(Type.u8, shift_val)});
3674 },3668 },
3675 }3669 }
36763670
...@@ -7227,12 +7221,7 @@ fn undefPattern(comptime IntType: type) IntType {...@@ -7227,12 +7221,7 @@ fn undefPattern(comptime IntType: type) IntType {
7227 return @bitCast(IntType, @as(UnsignedType, (1 << (int_info.bits | 1)) / 3));7221 return @bitCast(IntType, @as(UnsignedType, (1 << (int_info.bits | 1)) / 3));
7228}7222}
72297223
7230const FormatIntLiteralContext = struct {7224const FormatIntLiteralContext = struct { ty: Type, val: Value, mod: *Module, location: ?ValueRenderLocation = null };
7231 ty: Type,
7232 val: Value,
7233 mod: *Module,
7234 location: ?ValueRenderLocation = null
7235};
7236fn formatIntLiteral(7225fn formatIntLiteral(
7237 data: FormatIntLiteralContext,7226 data: FormatIntLiteralContext,
7238 comptime fmt: []const u8,7227 comptime fmt: []const u8,
...@@ -7324,7 +7313,7 @@ fn formatIntLiteral(...@@ -7324,7 +7313,7 @@ fn formatIntLiteral(
7324 } else {7313 } else {
7325 try writer.print("zig_as_{c}{d}(", .{ signAbbrev(int_info.signedness), c_bits });7314 try writer.print("zig_as_{c}{d}(", .{ signAbbrev(int_info.signedness), c_bits });
7326 }7315 }
7327 }7316 },
7328 }7317 }
73297318
7330 const limbs_count_64 = @divExact(64, @bitSizeOf(BigIntLimb));7319 const limbs_count_64 = @divExact(64, @bitSizeOf(BigIntLimb));
test/behavior/atomics.zig+1-1
...@@ -251,7 +251,7 @@ test "atomicrmw with ints" {...@@ -251,7 +251,7 @@ test "atomicrmw with ints" {
251 }251 }
252252
253 // TODO: Use the max atomic bit size for the target, maybe builtin?253 // TODO: Use the max atomic bit size for the target, maybe builtin?
254 const bit_values = [_]usize{ 8 } ++ if (builtin.cpu.arch == .x86_64) [_]usize{ 16, 32, 64 } else [_]usize{ };254 const bit_values = [_]usize{8} ++ if (builtin.cpu.arch == .x86_64) [_]usize{ 16, 32, 64 } else [_]usize{};
255 inline for (bit_values) |bits| {255 inline for (bit_values) |bits| {
256 try testAtomicRmwInt(.unsigned, bits);256 try testAtomicRmwInt(.unsigned, bits);
257 comptime try testAtomicRmwInt(.unsigned, bits);257 comptime try testAtomicRmwInt(.unsigned, bits);
test/behavior/math.zig-2
...@@ -377,7 +377,6 @@ fn testBinaryNot(x: u16) !void {...@@ -377,7 +377,6 @@ fn testBinaryNot(x: u16) !void {
377 try expect(~x == 0b0101010101010101);377 try expect(~x == 0b0101010101010101);
378}378}
379379
380
381test "binary not 128-bit" {380test "binary not 128-bit" {
382 try expect(comptime x: {381 try expect(comptime x: {
383 break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;382 break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa;
...@@ -667,7 +666,6 @@ test "128-bit multiplication" {...@@ -667,7 +666,6 @@ test "128-bit multiplication" {
667 var c = a * b;666 var c = a * b;
668 try expect(c == 0x63ffffffffffffff9c);667 try expect(c == 0x63ffffffffffffff9c);
669 }668 }
670
671}669}
672670
673test "@addWithOverflow" {671test "@addWithOverflow" {