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