| ... | ... | @@ -503,7 +503,7 @@ pub fn updateFunc(self: *Wasm, module: *Module, func: *Module.Fn, air: Air, live |
| 503 | 503 | const decl = func.owner_decl; |
| 504 | 504 | assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes() |
| 505 | 505 | |
| 506 | | decl.link.wasm.clear(); |
| 506 | decl.link.wasm.clear(self.base.allocator); |
| 507 | 507 | |
| 508 | 508 | var codegen_: CodeGen = .{ |
| 509 | 509 | .gpa = self.base.allocator, |
| ... | ... | @@ -544,7 +544,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void { |
| 544 | 544 | |
| 545 | 545 | assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes() |
| 546 | 546 | |
| 547 | | decl.link.wasm.clear(); |
| 547 | decl.link.wasm.clear(self.base.allocator); |
| 548 | 548 | |
| 549 | 549 | if (decl.isExtern()) { |
| 550 | 550 | return self.addOrUpdateImport(decl); |
| ... | ... | @@ -607,7 +607,9 @@ pub fn lowerUnnamedConst(self: *Wasm, decl: *Module.Decl, tv: TypedValue) !u32 { |
| 607 | 607 | |
| 608 | 608 | // Create and initialize a new local symbol and atom |
| 609 | 609 | const local_index = decl.link.wasm.locals.items.len; |
| 610 | | const name = try std.fmt.allocPrintZ(self.base.allocator, "__unnamed_{s}_{d}", .{ decl.name, local_index }); |
| 610 | const fqdn = try decl.getFullyQualifiedName(self.base.allocator); |
| 611 | defer self.base.allocator.free(fqdn); |
| 612 | const name = try std.fmt.allocPrintZ(self.base.allocator, "__unnamed_{s}_{d}", .{ fqdn, local_index }); |
| 611 | 613 | defer self.base.allocator.free(name); |
| 612 | 614 | var symbol: Symbol = .{ |
| 613 | 615 | .name = try self.string_table.put(self.base.allocator, name), |
| ... | ... | @@ -636,27 +638,25 @@ pub fn lowerUnnamedConst(self: *Wasm, decl: *Module.Decl, tv: TypedValue) !u32 { |
| 636 | 638 | defer value_bytes.deinit(); |
| 637 | 639 | |
| 638 | 640 | const module = self.base.options.module.?; |
| 639 | | var decl_gen: CodeGen.DeclGen = .{ |
| 640 | | .bin_file = self, |
| 641 | | .decl = decl, |
| 642 | | .err_msg = undefined, |
| 643 | | .gpa = self.base.allocator, |
| 644 | | .module = module, |
| 645 | | .code = &value_bytes, |
| 646 | | .symbol_index = atom.sym_index, |
| 647 | | }; |
| 648 | | |
| 649 | | const result = decl_gen.genTypedValue(tv.ty, tv.val) catch |err| switch (err) { |
| 650 | | error.CodegenFail => { |
| 651 | | decl.analysis = .codegen_failure; |
| 652 | | try module.failed_decls.put(module.gpa, decl, decl_gen.err_msg); |
| 653 | | return error.AnalysisFail; |
| 641 | const result = try codegen.generateSymbol( |
| 642 | &self.base, |
| 643 | decl.srcLoc(), |
| 644 | tv, |
| 645 | &value_bytes, |
| 646 | .none, |
| 647 | .{ |
| 648 | .parent_atom_index = atom.sym_index, |
| 649 | .addend = null, |
| 654 | 650 | }, |
| 655 | | else => |e| return e, |
| 656 | | }; |
| 651 | ); |
| 657 | 652 | const code = switch (result) { |
| 653 | .externally_managed => |x| x, |
| 658 | 654 | .appended => value_bytes.items, |
| 659 | | .externally_managed => |data| data, |
| 655 | .fail => |em| { |
| 656 | decl.analysis = .codegen_failure; |
| 657 | try module.failed_decls.put(module.gpa, decl, em); |
| 658 | return error.AnalysisFail; |
| 659 | }, |
| 660 | 660 | }; |
| 661 | 661 | |
| 662 | 662 | atom.size = @intCast(u32, code.len); |
| ... | ... | @@ -989,6 +989,7 @@ fn allocateAtoms(self: *Wasm) !void { |
| 989 | 989 | atom.size, |
| 990 | 990 | }); |
| 991 | 991 | offset += atom.size; |
| 992 | self.symbol_atom.putAssumeCapacity(atom.symbolLoc(), atom); // Update atom pointers |
| 992 | 993 | atom = atom.next orelse break; |
| 993 | 994 | } |
| 994 | 995 | } |