| ... | ... | @@ -46,6 +46,9 @@ host_name: []const u8 = "env", |
| 46 | 46 | /// List of all `Decl` that are currently alive. |
| 47 | 47 | /// Each index maps to the corresponding `Atom.Index`. |
| 48 | 48 | decls: std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index) = .{}, |
| 49 | /// Mapping between an `Atom` and its type index representing the Wasm |
| 50 | /// type of the function signature. |
| 51 | atom_types: std.AutoHashMapUnmanaged(Atom.Index, u32) = .{}, |
| 49 | 52 | /// List of all symbols generated by Zig code. |
| 50 | 53 | symbols: std.ArrayListUnmanaged(Symbol) = .{}, |
| 51 | 54 | /// List of symbol indexes which are free to be used. |
| ... | ... | @@ -175,15 +178,6 @@ pub const Segment = struct { |
| 175 | 178 | offset: u32, |
| 176 | 179 | }; |
| 177 | 180 | |
| 178 | | pub const FnData = struct { |
| 179 | | /// Reference to the wasm type that represents this function. |
| 180 | | type_index: u32, |
| 181 | | |
| 182 | | pub const empty: FnData = .{ |
| 183 | | .type_index = undefined, |
| 184 | | }; |
| 185 | | }; |
| 186 | | |
| 187 | 181 | pub const Export = struct { |
| 188 | 182 | sym_index: ?u32 = null, |
| 189 | 183 | }; |
| ... | ... | @@ -961,6 +955,7 @@ pub fn deinit(wasm: *Wasm) void { |
| 961 | 955 | } |
| 962 | 956 | |
| 963 | 957 | wasm.decls.deinit(gpa); |
| 958 | wasm.atom_types.deinit(gpa); |
| 964 | 959 | wasm.symbols.deinit(gpa); |
| 965 | 960 | wasm.symbols_free_list.deinit(gpa); |
| 966 | 961 | wasm.globals.deinit(gpa); |
| ... | ... | @@ -1607,7 +1602,7 @@ const Kind = union(enum) { |
| 1607 | 1602 | initialized, |
| 1608 | 1603 | synthetic, |
| 1609 | 1604 | }, |
| 1610 | | function: FnData, |
| 1605 | function: void, |
| 1611 | 1606 | |
| 1612 | 1607 | /// Returns the segment name the data kind represents. |
| 1613 | 1608 | /// Asserts `kind` has its active tag set to `data`. |
| ... | ... | @@ -1626,12 +1621,13 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void { |
| 1626 | 1621 | const atom = wasm.getAtomPtr(atom_index); |
| 1627 | 1622 | const symbol = (SymbolLoc{ .file = null, .index = atom.sym_index }).getSymbol(wasm); |
| 1628 | 1623 | const final_index: u32 = switch (kind) { |
| 1629 | | .function => |fn_data| result: { |
| 1624 | .function => result: { |
| 1630 | 1625 | const index = @intCast(u32, wasm.functions.count() + wasm.imported_functions_count); |
| 1626 | const type_index = wasm.atom_types.get(atom_index).?; |
| 1631 | 1627 | try wasm.functions.putNoClobber( |
| 1632 | 1628 | wasm.base.allocator, |
| 1633 | 1629 | .{ .file = null, .index = index }, |
| 1634 | | .{ .type_index = fn_data.type_index }, |
| 1630 | .{ .type_index = type_index }, |
| 1635 | 1631 | ); |
| 1636 | 1632 | symbol.tag = .function; |
| 1637 | 1633 | symbol.index = index; |
| ... | ... | @@ -2829,7 +2825,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod |
| 2829 | 2825 | if (decl.isExtern()) continue; |
| 2830 | 2826 | const atom_index = entry.value_ptr.*; |
| 2831 | 2827 | if (decl.ty.zigTypeTag() == .Fn) { |
| 2832 | | try wasm.parseAtom(atom_index, .{ .function = decl.fn_link.? }); |
| 2828 | try wasm.parseAtom(atom_index, .function); |
| 2833 | 2829 | } else if (decl.getVariable()) |variable| { |
| 2834 | 2830 | if (!variable.is_mutable) { |
| 2835 | 2831 | try wasm.parseAtom(atom_index, .{ .data = .read_only }); |
| ... | ... | @@ -4172,3 +4168,13 @@ pub fn putOrGetFuncType(wasm: *Wasm, func_type: std.wasm.Type) !u32 { |
| 4172 | 4168 | }); |
| 4173 | 4169 | return index; |
| 4174 | 4170 | } |
| 4171 | |
| 4172 | /// For the given `decl_index`, stores the corresponding type representing the function signature. |
| 4173 | /// Asserts declaration has an associated `Atom`. |
| 4174 | /// Returns the index into the list of types. |
| 4175 | pub fn storeDeclType(wasm: *Wasm, decl_index: Module.Decl.Index, func_type: std.wasm.Type) !u32 { |
| 4176 | const atom_index = wasm.decls.get(decl_index).?; |
| 4177 | const index = try wasm.putOrGetFuncType(func_type); |
| 4178 | try wasm.atom_types.put(wasm.base.allocator, atom_index, index); |
| 4179 | return index; |
| 4180 | } |