aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-02-22 20:10:16 -0500
committerGitHub <noreply@github.com>2025-02-22 20:10:16 -0500
commit6769806213ab28ed629221085325d8f143e515b0 (patch)
treee621eb6aa4ab49bb72018d33c373b258f55922df /src/codegen
parentb6a1fdd3fa167878f75b4f12ac170d1a10e4e9a2 (diff)
parenteb3c7f570601a6e00cbf03f0a026b3493887a534 (diff)
downloadzig-6769806213ab28ed629221085325d8f143e515b0.tar.gz
zig-6769806213ab28ed629221085325d8f143e515b0.zip
Merge pull request #21727 from 87flowers/fmt-render2
std/zig/render: Rewrite indentation
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig6
-rw-r--r--src/codegen/c/Type.zig69
-rw-r--r--src/codegen/llvm.zig111
3 files changed, 92 insertions, 94 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 7dd2895911..5012f7e0e8 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -1990,7 +1990,7 @@ pub const DeclGen = struct {
if (dest_bits <= 64 and src_bits <= 64) {
const needs_cast = src_int_info == null or
(toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or
- dest_int_info.signedness != src_int_info.?.signedness);
+ dest_int_info.signedness != src_int_info.?.signedness);
return !needs_cast and !src_is_ptr;
} else return false;
}
@@ -2031,7 +2031,7 @@ pub const DeclGen = struct {
if (dest_bits <= 64 and src_bits <= 64) {
const needs_cast = src_int_info == null or
(toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or
- dest_int_info.signedness != src_int_info.?.signedness);
+ dest_int_info.signedness != src_int_info.?.signedness);
if (needs_cast) {
try w.writeByte('(');
@@ -4348,7 +4348,7 @@ fn airEquality(
.aligned, .array, .vector, .fwd_decl, .function => unreachable,
.aggregate => |aggregate| if (aggregate.fields.len == 2 and
(aggregate.fields.at(0, ctype_pool).name.index == .is_null or
- aggregate.fields.at(1, ctype_pool).name.index == .is_null))
+ aggregate.fields.at(1, ctype_pool).name.index == .is_null))
{
try f.writeCValueMember(writer, lhs, .{ .identifier = "is_null" });
try writer.writeAll(" || ");
diff --git a/src/codegen/c/Type.zig b/src/codegen/c/Type.zig
index 54f012e8ef..ec1bf40e0c 100644
--- a/src/codegen/c/Type.zig
+++ b/src/codegen/c/Type.zig
@@ -758,12 +758,12 @@ pub const Info = union(enum) {
fn tag(pointer_info: Pointer) Pool.Tag {
return @enumFromInt(@intFromEnum(Pool.Tag.pointer) +
@as(u2, @bitCast(packed struct(u2) {
- @"const": bool,
- @"volatile": bool,
- }{
- .@"const" = pointer_info.@"const",
- .@"volatile" = pointer_info.@"volatile",
- })));
+ @"const": bool,
+ @"volatile": bool,
+ }{
+ .@"const" = pointer_info.@"const",
+ .@"volatile" = pointer_info.@"volatile",
+ })));
}
};
@@ -887,24 +887,24 @@ pub const Info = union(enum) {
pool_adapter.eql(lhs_vector_info.elem_ctype, rhs_info.vector.elem_ctype),
.fwd_decl => |lhs_fwd_decl_info| lhs_fwd_decl_info.tag == rhs_info.fwd_decl.tag and
switch (lhs_fwd_decl_info.name) {
- .anon => |lhs_anon| rhs_info.fwd_decl.name == .anon and lhs_anon.eqlAdapted(
- lhs_pool,
- rhs_info.fwd_decl.name.anon,
- rhs_pool,
- pool_adapter,
- ),
- .index => |lhs_index| rhs_info.fwd_decl.name == .index and
- lhs_index == rhs_info.fwd_decl.name.index,
- },
+ .anon => |lhs_anon| rhs_info.fwd_decl.name == .anon and lhs_anon.eqlAdapted(
+ lhs_pool,
+ rhs_info.fwd_decl.name.anon,
+ rhs_pool,
+ pool_adapter,
+ ),
+ .index => |lhs_index| rhs_info.fwd_decl.name == .index and
+ lhs_index == rhs_info.fwd_decl.name.index,
+ },
.aggregate => |lhs_aggregate_info| lhs_aggregate_info.tag == rhs_info.aggregate.tag and
lhs_aggregate_info.@"packed" == rhs_info.aggregate.@"packed" and
switch (lhs_aggregate_info.name) {
- .anon => |lhs_anon| rhs_info.aggregate.name == .anon and
- lhs_anon.index == rhs_info.aggregate.name.anon.index and
- lhs_anon.id == rhs_info.aggregate.name.anon.id,
- .fwd_decl => |lhs_fwd_decl| rhs_info.aggregate.name == .fwd_decl and
- pool_adapter.eql(lhs_fwd_decl, rhs_info.aggregate.name.fwd_decl),
- } and lhs_aggregate_info.fields.eqlAdapted(
+ .anon => |lhs_anon| rhs_info.aggregate.name == .anon and
+ lhs_anon.index == rhs_info.aggregate.name.anon.index and
+ lhs_anon.id == rhs_info.aggregate.name.anon.id,
+ .fwd_decl => |lhs_fwd_decl| rhs_info.aggregate.name == .fwd_decl and
+ pool_adapter.eql(lhs_fwd_decl, rhs_info.aggregate.name.fwd_decl),
+ } and lhs_aggregate_info.fields.eqlAdapted(
lhs_pool,
rhs_info.aggregate.fields,
rhs_pool,
@@ -913,13 +913,12 @@ pub const Info = union(enum) {
.function => |lhs_function_info| lhs_function_info.param_ctypes.len ==
rhs_info.function.param_ctypes.len and
pool_adapter.eql(lhs_function_info.return_ctype, rhs_info.function.return_ctype) and
- for (0..lhs_function_info.param_ctypes.len) |param_index|
- {
- if (!pool_adapter.eql(
- lhs_function_info.param_ctypes.at(param_index, lhs_pool),
- rhs_info.function.param_ctypes.at(param_index, rhs_pool),
- )) break false;
- } else true,
+ for (0..lhs_function_info.param_ctypes.len) |param_index| {
+ if (!pool_adapter.eql(
+ lhs_function_info.param_ctypes.at(param_index, lhs_pool),
+ rhs_info.function.param_ctypes.at(param_index, rhs_pool),
+ )) break false;
+ } else true,
};
}
};
@@ -2301,13 +2300,13 @@ pub const Pool = struct {
const return_type = Type.fromInterned(func_info.return_type);
const return_ctype: CType =
if (!ip.isNoReturn(func_info.return_type)) try pool.fromType(
- allocator,
- scratch,
- return_type,
- pt,
- mod,
- kind.asParameter(),
- ) else .void;
+ allocator,
+ scratch,
+ return_type,
+ pt,
+ mod,
+ kind.asParameter(),
+ ) else .void;
for (0..func_info.param_types.len) |param_index| {
const param_type = Type.fromInterned(
func_info.param_types.get(ip)[param_index],
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 2767c320d1..a6dbb08a42 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -388,7 +388,7 @@ const DataLayoutBuilder = struct {
self.target.cpu.arch != .riscv64 and
self.target.cpu.arch != .loongarch64 and
!(self.target.cpu.arch == .aarch64 and
- (self.target.os.tag == .uefi or self.target.os.tag == .windows)) and
+ (self.target.os.tag == .uefi or self.target.os.tag == .windows)) and
self.target.cpu.arch != .bpfeb and self.target.cpu.arch != .bpfel) continue;
try writer.writeAll("-p");
if (info.llvm != .default) try writer.print("{d}", .{@intFromEnum(info.llvm)});
@@ -859,55 +859,54 @@ pub const Object = struct {
builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =
- if (!builder.strip)
- debug_info: {
- // We fully resolve all paths at this point to avoid lack of
- // source line info in stack traces or lack of debugging
- // information which, if relative paths were used, would be
- // very location dependent.
- // TODO: the only concern I have with this is WASI as either host or target, should
- // we leave the paths as relative then?
- // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
- // a particular directory, and then the directory path is specified elsewhere.
- // In the compiler frontend we have it stored correctly in this
- // way already, but here we throw all that sweet information
- // into the garbage can by converting into absolute paths. What
- // a terrible tragedy.
- const compile_unit_dir = blk: {
- if (comp.zcu) |zcu| m: {
- const d = try zcu.main_mod.root.joinString(arena, "");
- if (d.len == 0) break :m;
- if (std.fs.path.isAbsolute(d)) break :blk d;
- break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
- }
- break :blk try std.process.getCwdAlloc(arena);
- };
+ if (!builder.strip) debug_info: {
+ // We fully resolve all paths at this point to avoid lack of
+ // source line info in stack traces or lack of debugging
+ // information which, if relative paths were used, would be
+ // very location dependent.
+ // TODO: the only concern I have with this is WASI as either host or target, should
+ // we leave the paths as relative then?
+ // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
+ // a particular directory, and then the directory path is specified elsewhere.
+ // In the compiler frontend we have it stored correctly in this
+ // way already, but here we throw all that sweet information
+ // into the garbage can by converting into absolute paths. What
+ // a terrible tragedy.
+ const compile_unit_dir = blk: {
+ if (comp.zcu) |zcu| m: {
+ const d = try zcu.main_mod.root.joinString(arena, "");
+ if (d.len == 0) break :m;
+ if (std.fs.path.isAbsolute(d)) break :blk d;
+ break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
+ }
+ break :blk try std.process.getCwdAlloc(arena);
+ };
- const debug_file = try builder.debugFile(
- try builder.metadataString(comp.root_name),
- try builder.metadataString(compile_unit_dir),
- );
+ const debug_file = try builder.debugFile(
+ try builder.metadataString(comp.root_name),
+ try builder.metadataString(compile_unit_dir),
+ );
- const debug_enums_fwd_ref = try builder.debugForwardReference();
- const debug_globals_fwd_ref = try builder.debugForwardReference();
-
- const debug_compile_unit = try builder.debugCompileUnit(
- debug_file,
- // Don't use the version string here; LLVM misparses it when it
- // includes the git revision.
- try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
- build_options.semver.major,
- build_options.semver.minor,
- build_options.semver.patch,
- }),
- debug_enums_fwd_ref,
- debug_globals_fwd_ref,
- .{ .optimized = comp.root_mod.optimize_mode != .Debug },
- );
+ const debug_enums_fwd_ref = try builder.debugForwardReference();
+ const debug_globals_fwd_ref = try builder.debugForwardReference();
+
+ const debug_compile_unit = try builder.debugCompileUnit(
+ debug_file,
+ // Don't use the version string here; LLVM misparses it when it
+ // includes the git revision.
+ try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
+ build_options.semver.major,
+ build_options.semver.minor,
+ build_options.semver.patch,
+ }),
+ debug_enums_fwd_ref,
+ debug_globals_fwd_ref,
+ .{ .optimized = comp.root_mod.optimize_mode != .Debug },
+ );
- try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
- break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
- } else .{.none} ** 3;
+ try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
+ break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
+ } else .{.none} ** 3;
const obj = try arena.create(Object);
obj.* = .{
@@ -2759,9 +2758,9 @@ pub const Object = struct {
const full_fields: [2]Builder.Metadata =
if (layout.tag_align.compare(.gte, layout.payload_align))
- .{ debug_tag_type, debug_payload_type }
- else
- .{ debug_payload_type, debug_tag_type };
+ .{ debug_tag_type, debug_payload_type }
+ else
+ .{ debug_payload_type, debug_tag_type };
const debug_tagged_union_type = try o.builder.debugStructType(
try o.builder.metadataString(name),
@@ -4551,11 +4550,11 @@ pub const Object = struct {
// instruction is followed by a `wrap_optional`, it will return this value
// verbatim, and the result should test as non-null.
switch (zcu.getTarget().ptrBitWidth()) {
- 16 => 0xaaaa,
- 32 => 0xaaaaaaaa,
- 64 => 0xaaaaaaaa_aaaaaaaa,
- else => unreachable,
- };
+ 16 => 0xaaaa,
+ 32 => 0xaaaaaaaa,
+ 64 => 0xaaaaaaaa_aaaaaaaa,
+ else => unreachable,
+ };
const llvm_usize = try o.lowerType(Type.usize);
const llvm_ptr_ty = try o.lowerType(ptr_ty);
return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty);
@@ -9544,7 +9543,7 @@ pub const FuncGen = struct {
if (llvm_dest_ty.isStruct(&o.builder) or
((operand_ty.zigTypeTag(zcu) == .vector or inst_ty.zigTypeTag(zcu) == .vector) and
- operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
+ operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
{
// Both our operand and our result are values, not pointers,
// but LLVM won't let us bitcast struct values or vectors with padding bits.