Commit 4ca9b4c44a

Jakub Konka <kubkon@jakubkonka.com>
2022-03-26 14:33:31
dwarf: move DbgInfoTypeRelocsTable into Dwarf module
1 parent 1a80315
Changed files (4)
src/link/Dwarf.zig
@@ -82,6 +82,22 @@ pub const SrcFn = struct {
 
 pub const PtrWidth = enum { p32, p64 };
 
+pub const DbgInfoTypeRelocsTable = std.ArrayHashMapUnmanaged(
+    Type,
+    DbgInfoTypeReloc,
+    Type.HashContext32,
+    true,
+);
+
+pub const DbgInfoTypeReloc = struct {
+    /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
+    /// This is where the .debug_info tag for the type is.
+    off: u32,
+    /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
+    /// List of DW.AT.type / DW.FORM.ref4 that points to the type.
+    relocs: std.ArrayListUnmanaged(u32),
+};
+
 pub const abbrev_compile_unit = 1;
 pub const abbrev_subprogram = 2;
 pub const abbrev_subprogram_retvoid = 3;
@@ -138,7 +154,7 @@ pub fn deinit(self: *Dwarf) void {
 pub const DeclDebugBuffers = struct {
     dbg_line_buffer: std.ArrayList(u8),
     dbg_info_buffer: std.ArrayList(u8),
-    dbg_info_type_relocs: File.DbgInfoTypeRelocsTable,
+    dbg_info_type_relocs: DbgInfoTypeRelocsTable,
 };
 
 pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {
@@ -153,7 +169,7 @@ pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {
     const gpa = self.allocator;
     var dbg_line_buffer = std.ArrayList(u8).init(gpa);
     var dbg_info_buffer = std.ArrayList(u8).init(gpa);
-    var dbg_info_type_relocs: File.DbgInfoTypeRelocsTable = .{};
+    var dbg_info_type_relocs: DbgInfoTypeRelocsTable = .{};
 
     assert(decl.has_tv);
 
@@ -890,7 +906,7 @@ fn addDbgInfoType(
     module: *Module,
     ty: Type,
     dbg_info_buffer: *std.ArrayList(u8),
-    dbg_info_type_relocs: *File.DbgInfoTypeRelocsTable,
+    dbg_info_type_relocs: *DbgInfoTypeRelocsTable,
     nested_ref4_relocs: *std.ArrayList(u32),
 ) error{OutOfMemory}!void {
     const target = self.target;
src/link/Elf.zig
@@ -2232,7 +2232,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void {
     }
 }
 
-fn deinitRelocs(gpa: Allocator, table: *File.DbgInfoTypeRelocsTable) void {
+fn deinitRelocs(gpa: Allocator, table: *link.File.Dwarf.DbgInfoTypeRelocsTable) void {
     for (table.values()) |*value| {
         value.relocs.deinit(gpa);
     }
src/codegen.zig
@@ -1,26 +1,25 @@
 const std = @import("std");
+const build_options = @import("build_options");
 const builtin = @import("builtin");
+const assert = std.debug.assert;
+const leb128 = std.leb;
+const link = @import("link.zig");
+const log = std.log.scoped(.codegen);
 const mem = std.mem;
 const math = std.math;
-const assert = std.debug.assert;
+const trace = @import("tracy.zig").trace;
+
 const Air = @import("Air.zig");
-const Zir = @import("Zir.zig");
-const Liveness = @import("Liveness.zig");
-const Type = @import("type.zig").Type;
-const Value = @import("value.zig").Value;
-const TypedValue = @import("TypedValue.zig");
-const link = @import("link.zig");
-const Module = @import("Module.zig");
+const Allocator = mem.Allocator;
 const Compilation = @import("Compilation.zig");
 const ErrorMsg = Module.ErrorMsg;
+const Liveness = @import("Liveness.zig");
+const Module = @import("Module.zig");
 const Target = std.Target;
-const Allocator = mem.Allocator;
-const trace = @import("tracy.zig").trace;
-const DW = std.dwarf;
-const leb128 = std.leb;
-const log = std.log.scoped(.codegen);
-const build_options = @import("build_options");
-const RegisterManager = @import("register_manager.zig").RegisterManager;
+const Type = @import("type.zig").Type;
+const TypedValue = @import("TypedValue.zig");
+const Value = @import("value.zig").Value;
+const Zir = @import("Zir.zig");
 
 pub const FnResult = union(enum) {
     /// The `code` parameter passed to `generateSymbol` has the value appended.
@@ -46,7 +45,7 @@ pub const DebugInfoOutput = union(enum) {
     dwarf: struct {
         dbg_line: *std.ArrayList(u8),
         dbg_info: *std.ArrayList(u8),
-        dbg_info_type_relocs: *link.File.DbgInfoTypeRelocsTable,
+        dbg_info_type_relocs: *link.File.Dwarf.DbgInfoTypeRelocsTable,
     },
     /// the plan9 debuginfo output is a bytecode with 4 opcodes
     /// assume all numbers/variables are bytes
src/link.zig
@@ -1,22 +1,22 @@
 const std = @import("std");
+const build_options = @import("build_options");
 const builtin = @import("builtin");
-const mem = std.mem;
-const Allocator = std.mem.Allocator;
+const assert = std.debug.assert;
 const fs = std.fs;
+const mem = std.mem;
 const log = std.log.scoped(.link);
-const assert = std.debug.assert;
+const trace = @import("tracy.zig").trace;
+const wasi_libc = @import("wasi_libc.zig");
 
+const Air = @import("Air.zig");
+const Allocator = std.mem.Allocator;
+const Cache = @import("Cache.zig");
 const Compilation = @import("Compilation.zig");
+const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
+const Liveness = @import("Liveness.zig");
 const Module = @import("Module.zig");
-const trace = @import("tracy.zig").trace;
 const Package = @import("Package.zig");
 const Type = @import("type.zig").Type;
-const Cache = @import("Cache.zig");
-const build_options = @import("build_options");
-const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
-const wasi_libc = @import("wasi_libc.zig");
-const Air = @import("Air.zig");
-const Liveness = @import("Liveness.zig");
 const TypedValue = @import("TypedValue.zig");
 
 pub const SystemLib = struct {
@@ -245,24 +245,6 @@ pub const File = struct {
         nvptx: void,
     };
 
-    /// For DWARF .debug_info.
-    pub const DbgInfoTypeRelocsTable = std.ArrayHashMapUnmanaged(
-        Type,
-        DbgInfoTypeReloc,
-        Type.HashContext32,
-        true,
-    );
-
-    /// For DWARF .debug_info.
-    pub const DbgInfoTypeReloc = struct {
-        /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
-        /// This is where the .debug_info tag for the type is.
-        off: u32,
-        /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
-        /// List of DW.AT.type / DW.FORM.ref4 that points to the type.
-        relocs: std.ArrayListUnmanaged(u32),
-    };
-
     /// Attempts incremental linking, if the file already exists. If
     /// incremental linking fails, falls back to truncating the file and
     /// rewriting it. A malicious file is detected as incremental link failure