| ... | ... | @@ -603,7 +603,14 @@ fn parseObjectFile(wasm: *Wasm, path: []const u8) !bool { |
| 603 | 603 | pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom.Index { |
| 604 | 604 | const gop = try wasm.decls.getOrPut(wasm.base.allocator, decl_index); |
| 605 | 605 | if (!gop.found_existing) { |
| 606 | | gop.value_ptr.* = try wasm.createAtom(); |
| 606 | const atom_index = try wasm.createAtom(); |
| 607 | gop.value_ptr.* = atom_index; |
| 608 | const atom = wasm.getAtom(atom_index); |
| 609 | const symbol = atom.symbolLoc().getSymbol(wasm); |
| 610 | const mod = wasm.base.options.module.?; |
| 611 | const decl = mod.declPtr(decl_index); |
| 612 | const full_name = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod)); |
| 613 | symbol.name = try wasm.string_table.put(wasm.base.allocator, full_name); |
| 607 | 614 | } |
| 608 | 615 | return gop.value_ptr.*; |
| 609 | 616 | } |
| ... | ... | @@ -1338,11 +1345,11 @@ pub fn deinit(wasm: *Wasm) void { |
| 1338 | 1345 | pub fn allocateSymbol(wasm: *Wasm) !u32 { |
| 1339 | 1346 | try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); |
| 1340 | 1347 | var symbol: Symbol = .{ |
| 1341 | | .name = undefined, // will be set after updateDecl |
| 1348 | .name = std.math.maxInt(u32), // will be set after updateDecl as well as during atom creation for decls |
| 1342 | 1349 | .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), |
| 1343 | | .tag = undefined, // will be set after updateDecl |
| 1344 | | .index = undefined, // will be set after updateDecl |
| 1345 | | .virtual_address = undefined, // will be set during atom allocation |
| 1350 | .tag = .undefined, // will be set after updateDecl |
| 1351 | .index = std.math.maxInt(u32), // will be set during atom parsing |
| 1352 | .virtual_address = std.math.maxInt(u32), // will be set during atom allocation |
| 1346 | 1353 | }; |
| 1347 | 1354 | if (wasm.symbols_free_list.popOrNull()) |index| { |
| 1348 | 1355 | wasm.symbols.items[index] = symbol; |
| ... | ... | @@ -1414,7 +1421,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air: |
| 1414 | 1421 | // &decl_state.?, |
| 1415 | 1422 | // ); |
| 1416 | 1423 | // } |
| 1417 | | return wasm.finishUpdateDecl(decl_index, code); |
| 1424 | return wasm.finishUpdateDecl(decl_index, code, .function); |
| 1418 | 1425 | } |
| 1419 | 1426 | |
| 1420 | 1427 | // Generate code for the Decl, storing it in memory to be later written to |
| ... | ... | @@ -1468,7 +1475,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi |
| 1468 | 1475 | }, |
| 1469 | 1476 | }; |
| 1470 | 1477 | |
| 1471 | | return wasm.finishUpdateDecl(decl_index, code); |
| 1478 | return wasm.finishUpdateDecl(decl_index, code, .data); |
| 1472 | 1479 | } |
| 1473 | 1480 | |
| 1474 | 1481 | pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !void { |
| ... | ... | @@ -1485,7 +1492,7 @@ pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.I |
| 1485 | 1492 | } |
| 1486 | 1493 | } |
| 1487 | 1494 | |
| 1488 | | fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8) !void { |
| 1495 | fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8, symbol_tag: Symbol.Tag) !void { |
| 1489 | 1496 | const mod = wasm.base.options.module.?; |
| 1490 | 1497 | const decl = mod.declPtr(decl_index); |
| 1491 | 1498 | const atom_index = wasm.decls.get(decl_index).?; |
| ... | ... | @@ -1493,6 +1500,7 @@ fn finishUpdateDecl(wasm: *Wasm, decl_index: Module.Decl.Index, code: []const u8 |
| 1493 | 1500 | const symbol = &wasm.symbols.items[atom.sym_index]; |
| 1494 | 1501 | const full_name = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod)); |
| 1495 | 1502 | symbol.name = try wasm.string_table.put(wasm.base.allocator, full_name); |
| 1503 | symbol.tag = symbol_tag; |
| 1496 | 1504 | try atom.code.appendSlice(wasm.base.allocator, code); |
| 1497 | 1505 | try wasm.resolved_symbols.put(wasm.base.allocator, atom.symbolLoc(), {}); |
| 1498 | 1506 | |