Commit 7c5a24e08c

joachimschmidt557 <joachim.schmidt557@outlook.com>
2020-10-05 10:13:56
Turn zig fmt back on in various src/ files
1 parent 9952a07
Changed files (3)
src/link/Elf.zig
@@ -27,9 +27,6 @@ const Cache = @import("../Cache.zig");
 
 const default_entry_addr = 0x8000000;
 
-// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
-// zig fmt: off
-
 pub const base_tag: File.Tag = .elf;
 
 base: File,
@@ -273,8 +270,8 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
 
 pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf {
     const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) {
-        0 ... 32 => .p32,
-        33 ... 64 => .p64,
+        0...32 => .p32,
+        33...64 => .p64,
         else => return error.UnsupportedELFArchitecture,
     };
     const self = try gpa.create(Elf);
@@ -752,40 +749,52 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
         // These are LEB encoded but since the values are all less than 127
         // we can simply append these bytes.
         const abbrev_buf = [_]u8{
-            abbrev_compile_unit,     DW.TAG_compile_unit,     DW.CHILDREN_yes, // header
-            DW.AT_stmt_list,         DW.FORM_sec_offset,      DW.AT_low_pc,
-            DW.FORM_addr,            DW.AT_high_pc,           DW.FORM_addr,
-            DW.AT_name,              DW.FORM_strp,            DW.AT_comp_dir,
-            DW.FORM_strp,            DW.AT_producer,          DW.FORM_strp,
-            DW.AT_language,          DW.FORM_data2,           0,
+            abbrev_compile_unit, DW.TAG_compile_unit, DW.CHILDREN_yes, // header
+            DW.AT_stmt_list,     DW.FORM_sec_offset,  DW.AT_low_pc,
+            DW.FORM_addr,        DW.AT_high_pc,       DW.FORM_addr,
+            DW.AT_name,          DW.FORM_strp,        DW.AT_comp_dir,
+            DW.FORM_strp,        DW.AT_producer,      DW.FORM_strp,
+            DW.AT_language,      DW.FORM_data2,       0,
             0, // table sentinel
-                                      abbrev_subprogram,       DW.TAG_subprogram,
+            abbrev_subprogram,
+            DW.TAG_subprogram,
             DW.CHILDREN_yes, // header
-                        DW.AT_low_pc,            DW.FORM_addr,
-            DW.AT_high_pc,           DW.FORM_data4,           DW.AT_type,
-            DW.FORM_ref4,            DW.AT_name,              DW.FORM_string,
-            0,                       0, // table sentinel
-                                      abbrev_subprogram_retvoid,
-            DW.TAG_subprogram,       DW.CHILDREN_yes, // header
-                        DW.AT_low_pc,
-            DW.FORM_addr,            DW.AT_high_pc,           DW.FORM_data4,
-            DW.AT_name,              DW.FORM_string,          0,
+            DW.AT_low_pc,
+            DW.FORM_addr,
+            DW.AT_high_pc,
+            DW.FORM_data4,
+            DW.AT_type,
+            DW.FORM_ref4,
+            DW.AT_name,
+            DW.FORM_string,
+            0,                         0, // table sentinel
+            abbrev_subprogram_retvoid,
+            DW.TAG_subprogram, DW.CHILDREN_yes, // header
+            DW.AT_low_pc,      DW.FORM_addr,
+            DW.AT_high_pc,     DW.FORM_data4,
+            DW.AT_name,        DW.FORM_string,
+            0,
             0, // table sentinel
-                                      abbrev_base_type,        DW.TAG_base_type,
+            abbrev_base_type,
+            DW.TAG_base_type,
             DW.CHILDREN_no, // header
-                         DW.AT_encoding,          DW.FORM_data1,
-            DW.AT_byte_size,         DW.FORM_data1,           DW.AT_name,
-            DW.FORM_string,          0,                       0, // table sentinel
-
-            abbrev_pad1,             DW.TAG_unspecified_type, DW.CHILDREN_no, // header
-            0,                       0, // table sentinel
-                                      abbrev_parameter,
+            DW.AT_encoding,
+            DW.FORM_data1,
+            DW.AT_byte_size,
+            DW.FORM_data1,
+            DW.AT_name,
+            DW.FORM_string, 0, 0, // table sentinel
+            abbrev_pad1, DW.TAG_unspecified_type, DW.CHILDREN_no, // header
+            0,                0, // table sentinel
+            abbrev_parameter,
             DW.TAG_formal_parameter, DW.CHILDREN_no, // header
-                         DW.AT_location,
-            DW.FORM_exprloc,         DW.AT_type,              DW.FORM_ref4,
-            DW.AT_name,              DW.FORM_string,          0,
+            DW.AT_location,          DW.FORM_exprloc,
+            DW.AT_type,              DW.FORM_ref4,
+            DW.AT_name,              DW.FORM_string,
+            0,
             0, // table sentinel
-                                      0,                       0,
+            0,
+            0,
             0, // section sentinel
         };
 
@@ -1021,7 +1030,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
             0, // `DW.LNS_set_prologue_end`
             0, // `DW.LNS_set_epilogue_begin`
             1, // `DW.LNS_set_isa`
-
             0, // include_directories (none except the compilation unit cwd)
         });
         // file_names[0]
@@ -1319,7 +1327,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
 
         var prev_digest_buf: [digest.len]u8 = undefined;
         const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
-            log.debug("ELF LLD new_digest={} readlink error: {}", .{digest, @errorName(err)});
+            log.debug("ELF LLD new_digest={} readlink error: {}", .{ digest, @errorName(err) });
             // Handle this as a cache miss.
             break :blk prev_digest_buf[0..0];
         };
@@ -1329,7 +1337,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
             self.base.lock = man.toOwnedLock();
             return;
         }
-        log.debug("ELF LLD prev_digest={} new_digest={}", .{prev_digest, digest});
+        log.debug("ELF LLD prev_digest={} new_digest={}", .{ prev_digest, digest });
 
         // We are about to change the output file to be different, so we invalidate the build hash now.
         directory.handle.deleteFile(id_symlink_basename) catch |err| switch (err) {
@@ -1370,7 +1378,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
     if (self.base.options.eh_frame_hdr) {
         try argv.append("--eh-frame-hdr");
     }
-    
+
     if (self.base.options.emit_relocs) {
         try argv.append("--emit-relocs");
     }
@@ -1491,9 +1499,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
 
     if (is_dyn_lib) {
         const soname = self.base.options.override_soname orelse if (self.base.options.version) |ver|
-                try std.fmt.allocPrint(arena, "lib{}.so.{}", .{self.base.options.root_name, ver.major})
-            else
-                try std.fmt.allocPrint(arena, "lib{}.so", .{self.base.options.root_name});
+            try std.fmt.allocPrint(arena, "lib{}.so.{}", .{ self.base.options.root_name, ver.major })
+        else
+            try std.fmt.allocPrint(arena, "lib{}.so", .{self.base.options.root_name});
         try argv.append("-soname");
         try argv.append(soname);
 
@@ -1616,7 +1624,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
     };
     defer stdout_context.data.deinit();
     const llvm = @import("../llvm.zig");
-    const ok = llvm.Link(.ELF, new_argv.ptr, new_argv.len, append_diagnostic,
+    const ok = llvm.Link(
+        .ELF,
+        new_argv.ptr,
+        new_argv.len,
+        append_diagnostic,
         @ptrToInt(&stdout_context),
         @ptrToInt(&stderr_context),
     );
@@ -1642,7 +1654,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
         };
         // Again failure here only means an unnecessary cache miss.
         man.writeManifest() catch |err| {
-            std.log.warn("failed to write cache manifest when linking: {}", .{ @errorName(err) });
+            std.log.warn("failed to write cache manifest when linking: {}", .{@errorName(err)});
         };
         // We hang on to this lock so that the output file path can be used without
         // other processes clobbering it.
@@ -2877,8 +2889,8 @@ fn dbgLineNeededHeaderBytes(self: Elf) u32 {
     const root_src_dir_path_len = if (self.base.options.module.?.root_pkg.root_src_directory.path) |p| p.len else 1; // "."
     return @intCast(u32, 53 + directory_entry_format_count * 2 + file_name_entry_format_count * 2 +
         directory_count * 8 + file_name_count * 8 +
-    // These are encoded as DW.FORM_string rather than DW.FORM_strp as we would like
-    // because of a workaround for readelf and gdb failing to understand DWARFv5 correctly.
+        // These are encoded as DW.FORM_string rather than DW.FORM_strp as we would like
+        // because of a workaround for readelf and gdb failing to understand DWARFv5 correctly.
         root_src_dir_path_len +
         self.base.options.module.?.root_pkg.root_src_path.len);
 }
src/codegen.zig
@@ -17,9 +17,6 @@ const DW = std.dwarf;
 const leb128 = std.debug.leb;
 const log = std.log.scoped(.codegen);
 
-// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
-// zig fmt: off
-
 /// The codegen-related data that is stored in `ir.Inst.Block` instructions.
 pub const BlockData = struct {
     relocs: std.ArrayListUnmanaged(Reloc) = undefined,
@@ -170,7 +167,6 @@ pub fn generateSymbol(
         },
         .Pointer => {
             // TODO populate .debug_info for the pointer
-
             if (typed_value.val.cast(Value.Payload.DeclRef)) |payload| {
                 const decl = payload.decl;
                 if (decl.analysis != .complete) return error.AnalysisFail;
@@ -206,7 +202,6 @@ pub fn generateSymbol(
         },
         .Int => {
             // TODO populate .debug_info for the integer
-
             const info = typed_value.ty.intInfo(bin_file.options.target);
             if (info.bits == 8 and !info.signed) {
                 const x = typed_value.val.toUnsignedInt();
@@ -399,7 +394,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
             self.free_registers &= ~(@as(FreeRegInt, 1) << free_index);
             const reg = callee_preserved_regs[free_index];
             self.registers.putAssumeCapacityNoClobber(reg, inst);
-            log.debug("alloc {} => {*}", .{reg, inst});
+            log.debug("alloc {} => {*}", .{ reg, inst });
             return reg;
         }
 
@@ -439,7 +434,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
             }
             try branch_stack.append(.{});
 
-            const src_data: struct {lbrace_src: usize, rbrace_src: usize, source: []const u8} = blk: {
+            const src_data: struct { lbrace_src: usize, rbrace_src: usize, source: []const u8 } = blk: {
                 if (module_fn.owner_decl.scope.cast(Module.Scope.Container)) |container_scope| {
                     const tree = container_scope.file_scope.contents.tree;
                     const fn_proto = tree.root_node.decls()[module_fn.owner_decl.src_index].castTag(.FnProto).?;
@@ -619,7 +614,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
 
                 const mcv = try self.genFuncInst(inst);
                 if (!inst.isUnused()) {
-                    log.debug("{*} => {}", .{inst, mcv});
+                    log.debug("{*} => {}", .{ inst, mcv });
                     const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
                     try branch.inst_table.putNoClobber(self.gpa, inst, mcv);
                 }
@@ -884,7 +879,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
             // No side effects, so if it's unreferenced, do nothing.
             if (inst.base.isUnused())
                 return MCValue.dead;
-            
+
             const operand = try self.resolveInst(inst.operand);
             const info_a = inst.operand.ty.intInfo(self.target.*);
             const info_b = inst.base.ty.intInfo(self.target.*);
@@ -1005,10 +1000,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                     if (self.registers.getEntry(toCanonicalReg(reg))) |entry| {
                         entry.value = inst;
                     }
-                    log.debug("reusing {} => {*}", .{reg, inst});
+                    log.debug("reusing {} => {*}", .{ reg, inst });
                 },
                 .stack_offset => |off| {
-                    log.debug("reusing stack offset {} => {*}", .{off, inst});
+                    log.debug("reusing stack offset {} => {*}", .{ off, inst });
                     return true;
                 },
                 else => return false,
@@ -1307,7 +1302,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
             const result = self.args[self.arg_index];
             self.arg_index += 1;
 
-            const name_with_null = inst.name[0..mem.lenZ(inst.name) + 1];
+            const name_with_null = inst.name[0 .. mem.lenZ(inst.name) + 1];
             switch (result) {
                 .register => |reg| {
                     self.registers.putAssumeCapacityNoClobber(toCanonicalReg(reg), &inst.base);
@@ -1779,7 +1774,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                     self.code.items.len += 4;
                     break :reloc reloc;
                 },
-                else => return self.fail(inst.base.src, "TODO implement condbr {}", .{ self.target.cpu.arch }),
+                else => return self.fail(inst.base.src, "TODO implement condbr {}", .{self.target.cpu.arch}),
             };
 
             // Capture the state of register and stack allocation state so that we can revert to it.
@@ -1859,7 +1854,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                         }
                     }
                 };
-                log.debug("consolidating else_entry {*} {}=>{}", .{else_entry.key, else_entry.value, canon_mcv});
+                log.debug("consolidating else_entry {*} {}=>{}", .{ else_entry.key, else_entry.value, canon_mcv });
                 // TODO make sure the destination stack offset / register does not already have something
                 // going on there.
                 try self.setRegOrMem(inst.base.src, else_entry.key.ty, canon_mcv, else_entry.value);
@@ -1883,7 +1878,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                         }
                     }
                 };
-                log.debug("consolidating then_entry {*} {}=>{}", .{then_entry.key, parent_mcv, then_entry.value});
+                log.debug("consolidating then_entry {*} {}=>{}", .{ then_entry.key, parent_mcv, then_entry.value });
                 // TODO make sure the destination stack offset / register does not already have something
                 // going on there.
                 try self.setRegOrMem(inst.base.src, then_entry.key.ty, parent_mcv, then_entry.value);
@@ -1950,7 +1945,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                 // break instruction will choose a MCValue for the block result and overwrite
                 // this field. Following break instructions will use that MCValue to put their
                 // block results.
-                .mcv = @bitCast(AnyMCValue, MCValue { .none = {} }),
+                .mcv = @bitCast(AnyMCValue, MCValue{ .none = {} }),
             };
             defer inst.codegen.relocs.deinit(self.gpa);
 
@@ -2232,7 +2227,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                                 mem.writeIntLittle(u64, &buf, x_big);
 
                                 // mov    DWORD PTR [rbp+offset+4], immediate
-                                self.code.appendSliceAssumeCapacity(&[_]u8{ 0xc7, 0x45, twos_comp + 4});
+                                self.code.appendSliceAssumeCapacity(&[_]u8{ 0xc7, 0x45, twos_comp + 4 });
                                 self.code.appendSliceAssumeCapacity(buf[4..8]);
 
                                 // mov    DWORD PTR [rbp+offset], immediate
@@ -2288,7 +2283,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
                         } else if (x <= math.maxInt(u16)) {
                             // TODO Use movw Note: Not supported on
                             // all ARM targets!
-
                             mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.mov(.al, reg, Instruction.Operand.imm(@truncate(u8, x), 0)).toU32());
                             mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.orr(.al, reg, reg, Instruction.Operand.imm(@truncate(u8, x >> 8), 12)).toU32());
                         } else if (x <= math.maxInt(u32)) {
src/glibc.zig
@@ -689,9 +689,6 @@ pub const BuiltSharedObjects = struct {
 
 const all_map_basename = "all.map";
 
-// TODO Turn back on zig fmt when https://github.com/ziglang/zig/issues/5948 is implemented.
-// zig fmt: off
-
 pub fn buildSharedObjects(comp: *Compilation) !void {
     const tracy = trace(@src());
     defer tracy.end();
@@ -827,8 +824,9 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
 
                         if (ver.patch == 0) {
                             const sym_plus_ver = try std.fmt.allocPrint(
-                                arena, "{s}_{d}_{d}",
-                                .{sym_name, ver.major, ver.minor},
+                                arena,
+                                "{s}_{d}_{d}",
+                                .{ sym_name, ver.major, ver.minor },
                             );
                             try zig_body.writer().print(
                                 \\.globl {s}
@@ -840,13 +838,19 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
                             , .{
                                 sym_plus_ver,
                                 sym_plus_ver,
-                                sym_plus_ver, sym_name, at_sign_str, ver.major, ver.minor,
+                                sym_plus_ver,
+                                sym_name,
+                                at_sign_str,
+                                ver.major,
+                                ver.minor,
                                 sym_plus_ver,
                                 sym_plus_ver,
                             });
                         } else {
-                            const sym_plus_ver = try std.fmt.allocPrint(arena, "{s}_{d}_{d}_{d}",
-                                .{sym_name, ver.major, ver.minor, ver.patch},
+                            const sym_plus_ver = try std.fmt.allocPrint(
+                                arena,
+                                "{s}_{d}_{d}_{d}",
+                                .{ sym_name, ver.major, ver.minor, ver.patch },
                             );
                             try zig_body.writer().print(
                                 \\.globl {s}
@@ -858,7 +862,12 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
                             , .{
                                 sym_plus_ver,
                                 sym_plus_ver,
-                                sym_plus_ver, sym_name, at_sign_str, ver.major, ver.minor, ver.patch,
+                                sym_plus_ver,
+                                sym_name,
+                                at_sign_str,
+                                ver.major,
+                                ver.minor,
+                                ver.patch,
                                 sym_plus_ver,
                                 sym_plus_ver,
                             });