diff options
| author | Luuk de Gram <luuk@degram.dev> | 2023-02-03 16:46:55 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-02-03 22:55:46 +0100 |
| commit | c9b957c937ef457083f1a00c1343239086ef8796 (patch) | |
| tree | e7d974f5bcc87fbf70f1fa88d59feee50baf37fb /src/link | |
| parent | 60935decd318498529a016eeb1379d943a7e830d (diff) | |
| download | zig-c9b957c937ef457083f1a00c1343239086ef8796.tar.gz zig-c9b957c937ef457083f1a00c1343239086ef8796.zip | |
link: remove `FnData` and make it self-owned
This finishes the work started in #14502 where atoms are owned by the
linker themselves. This now makes debug atoms fully owned by dwarf,
and no information is left stored on the decl.
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Wasm.zig | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 17391b017a..9d20412788 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -46,6 +46,9 @@ host_name: []const u8 = "env", /// List of all `Decl` that are currently alive. /// Each index maps to the corresponding `Atom.Index`. decls: std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index) = .{}, +/// Mapping between an `Atom` and its type index representing the Wasm +/// type of the function signature. +atom_types: std.AutoHashMapUnmanaged(Atom.Index, u32) = .{}, /// List of all symbols generated by Zig code. symbols: std.ArrayListUnmanaged(Symbol) = .{}, /// List of symbol indexes which are free to be used. @@ -175,15 +178,6 @@ pub const Segment = struct { offset: u32, }; -pub const FnData = struct { - /// Reference to the wasm type that represents this function. - type_index: u32, - - pub const empty: FnData = .{ - .type_index = undefined, - }; -}; - pub const Export = struct { sym_index: ?u32 = null, }; @@ -961,6 +955,7 @@ pub fn deinit(wasm: *Wasm) void { } wasm.decls.deinit(gpa); + wasm.atom_types.deinit(gpa); wasm.symbols.deinit(gpa); wasm.symbols_free_list.deinit(gpa); wasm.globals.deinit(gpa); @@ -1607,7 +1602,7 @@ const Kind = union(enum) { initialized, synthetic, }, - function: FnData, + function: void, /// Returns the segment name the data kind represents. /// Asserts `kind` has its active tag set to `data`. @@ -1626,12 +1621,13 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void { const atom = wasm.getAtomPtr(atom_index); const symbol = (SymbolLoc{ .file = null, .index = atom.sym_index }).getSymbol(wasm); const final_index: u32 = switch (kind) { - .function => |fn_data| result: { + .function => result: { const index = @intCast(u32, wasm.functions.count() + wasm.imported_functions_count); + const type_index = wasm.atom_types.get(atom_index).?; try wasm.functions.putNoClobber( wasm.base.allocator, .{ .file = null, .index = index }, - .{ .type_index = fn_data.type_index }, + .{ .type_index = type_index }, ); symbol.tag = .function; symbol.index = index; @@ -2829,7 +2825,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod if (decl.isExtern()) continue; const atom_index = entry.value_ptr.*; if (decl.ty.zigTypeTag() == .Fn) { - try wasm.parseAtom(atom_index, .{ .function = decl.fn_link.? }); + try wasm.parseAtom(atom_index, .function); } else if (decl.getVariable()) |variable| { if (!variable.is_mutable) { try wasm.parseAtom(atom_index, .{ .data = .read_only }); @@ -4172,3 +4168,13 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 { }); return index; } + +/// For the given `decl_index`, stores the corresponding type representing the function signature. +/// Asserts declaration has an associated `Atom`. +/// Returns the index into the list of types. +pub fn storeDeclType(wasm: *Wasm, decl_index: Module.Decl.Index, func_type: std.wasm.Type) !u32 { + const atom_index = wasm.decls.get(decl_index).?; + const index = try wasm.putOrGetFuncType(func_type); + try wasm.atom_types.put(wasm.base.allocator, atom_index, index); + return index; +} |
