| ... | ... | @@ -85,11 +85,13 @@ pub fn init(zig_object: *ZigObject, wasm_file: *Wasm) !void { |
| 85 | 85 | |
| 86 | 86 | fn createStackPointer(zig_object: *ZigObject, wasm_file: *Wasm) !void { |
| 87 | 87 | const gpa = wasm_file.base.comp.gpa; |
| 88 | | const sym_index = try zig_object.getGlobalSymbol(gpa, "__stack_pointer", .global); |
| 89 | | zig_object.symbols.items[sym_index].index = zig_object.imported_globals_count; |
| 88 | const sym_index = try zig_object.getGlobalSymbol(gpa, "__stack_pointer"); |
| 89 | const sym = zig_object.symbol(sym_index); |
| 90 | sym.index = zig_object.imported_globals_count; |
| 91 | sym.tag = .global; |
| 90 | 92 | const is_wasm32 = wasm_file.base.comp.root_mod.resolved_target.result.cpu.arch == .wasm32; |
| 91 | 93 | try zig_object.imports.putNoClobber(gpa, sym_index, .{ |
| 92 | | .name = zig_object.symbols.items[sym_index].name, |
| 94 | .name = sym.name, |
| 93 | 95 | .module_name = try zig_object.string_table.insert(gpa, wasm_file.host_name), |
| 94 | 96 | .kind = .{ .global = .{ .valtype = if (is_wasm32) .i32 else .i64, .mutable = true } }, |
| 95 | 97 | }); |
| ... | ... | @@ -97,6 +99,10 @@ fn createStackPointer(zig_object: *ZigObject, wasm_file: *Wasm) !void { |
| 97 | 99 | zig_object.stack_pointer_sym = sym_index; |
| 98 | 100 | } |
| 99 | 101 | |
| 102 | fn symbol(zig_object: *const ZigObject, index: u32) *Symbol { |
| 103 | return &zig_object.symbols.items[index]; |
| 104 | } |
| 105 | |
| 100 | 106 | /// Frees and invalidates all memory of the incrementally compiled Zig module. |
| 101 | 107 | /// It is illegal behavior to access the `ZigObject` after calling `deinit`. |
| 102 | 108 | pub fn deinit(zig_object: *ZigObject, gpa: std.mem.Allocator) void { |
| ... | ... | @@ -146,7 +152,7 @@ pub fn deinit(zig_object: *ZigObject, gpa: std.mem.Allocator) void { |
| 146 | 152 | /// Will re-use slots when a symbol was freed at an earlier stage. |
| 147 | 153 | pub fn allocateSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator) !u32 { |
| 148 | 154 | try zig_object.symbols.ensureUnusedCapacity(gpa, 1); |
| 149 | | const symbol: Symbol = .{ |
| 155 | const sym: Symbol = .{ |
| 150 | 156 | .name = std.math.maxInt(u32), // will be set after updateDecl as well as during atom creation for decls |
| 151 | 157 | .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), |
| 152 | 158 | .tag = .undefined, // will be set after updateDecl |
| ... | ... | @@ -154,17 +160,22 @@ pub fn allocateSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator) !u32 { |
| 154 | 160 | .virtual_address = std.math.maxInt(u32), // will be set during atom allocation |
| 155 | 161 | }; |
| 156 | 162 | if (zig_object.symbols_free_list.popOrNull()) |index| { |
| 157 | | zig_object.symbols.items[index] = symbol; |
| 163 | zig_object.symbols.items[index] = sym; |
| 158 | 164 | return index; |
| 159 | 165 | } |
| 160 | 166 | const index = @as(u32, @intCast(zig_object.symbols.items.len)); |
| 161 | | zig_object.symbols.appendAssumeCapacity(symbol); |
| 167 | zig_object.symbols.appendAssumeCapacity(sym); |
| 162 | 168 | return index; |
| 163 | 169 | } |
| 164 | 170 | |
| 165 | 171 | // Generate code for the Decl, storing it in memory to be later written to |
| 166 | 172 | // the file on flush(). |
| 167 | | pub fn updateDecl(zig_object: *ZigObject, wasm_file: *Wasm, mod: *Module, decl_index: InternPool.DeclIndex) !void { |
| 173 | pub fn updateDecl( |
| 174 | zig_object: *ZigObject, |
| 175 | wasm_file: *Wasm, |
| 176 | mod: *Module, |
| 177 | decl_index: InternPool.DeclIndex, |
| 178 | ) !void { |
| 168 | 179 | const decl = mod.declPtr(decl_index); |
| 169 | 180 | if (decl.val.getFunction(mod)) |_| { |
| 170 | 181 | return; |
| ... | ... | @@ -173,7 +184,7 @@ pub fn updateDecl(zig_object: *ZigObject, wasm_file: *Wasm, mod: *Module, decl_i |
| 173 | 184 | } |
| 174 | 185 | |
| 175 | 186 | const gpa = wasm_file.base.comp.gpa; |
| 176 | | const atom_index = try zig_object.getOrCreateAtomForDecl(decl_index); |
| 187 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); |
| 177 | 188 | const atom = wasm_file.getAtomPtr(atom_index); |
| 178 | 189 | atom.clear(); |
| 179 | 190 | |
| ... | ... | @@ -181,7 +192,7 @@ pub fn updateDecl(zig_object: *ZigObject, wasm_file: *Wasm, mod: *Module, decl_i |
| 181 | 192 | const variable = decl.getOwnedVariable(mod).?; |
| 182 | 193 | const name = mod.intern_pool.stringToSlice(decl.name); |
| 183 | 194 | const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); |
| 184 | | return wasm_file.addOrUpdateImport(name, atom.sym_index, lib_name, null); |
| 195 | return zig_object.addOrUpdateImport(wasm_file, name, atom.sym_index, lib_name, null); |
| 185 | 196 | } |
| 186 | 197 | const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; |
| 187 | 198 | |
| ... | ... | @@ -206,15 +217,22 @@ pub fn updateDecl(zig_object: *ZigObject, wasm_file: *Wasm, mod: *Module, decl_i |
| 206 | 217 | }, |
| 207 | 218 | }; |
| 208 | 219 | |
| 209 | | return wasm_file.finishUpdateDecl(decl_index, code, .data); |
| 220 | return zig_object.finishUpdateDecl(wasm_file, decl_index, code, .data); |
| 210 | 221 | } |
| 211 | 222 | |
| 212 | | pub fn updateFunc(zig_object: *ZigObject, wasm_file: *Wasm, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void { |
| 223 | pub fn updateFunc( |
| 224 | zig_object: *ZigObject, |
| 225 | wasm_file: *Wasm, |
| 226 | mod: *Module, |
| 227 | func_index: InternPool.Index, |
| 228 | air: Air, |
| 229 | liveness: Liveness, |
| 230 | ) !void { |
| 213 | 231 | const gpa = wasm_file.base.comp.gpa; |
| 214 | 232 | const func = mod.funcInfo(func_index); |
| 215 | 233 | const decl_index = func.owner_decl; |
| 216 | 234 | const decl = mod.declPtr(decl_index); |
| 217 | | const atom_index = try zig_object.getOrCreateAtomForDecl(decl_index); |
| 235 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); |
| 218 | 236 | const atom = wasm_file.getAtomPtr(atom_index); |
| 219 | 237 | atom.clear(); |
| 220 | 238 | |
| ... | ... | @@ -242,16 +260,22 @@ pub fn updateFunc(zig_object: *ZigObject, wasm_file: *Wasm, mod: *Module, func_i |
| 242 | 260 | return zig_object.finishUpdateDecl(wasm_file, decl_index, code, .function); |
| 243 | 261 | } |
| 244 | 262 | |
| 245 | | fn finishUpdateDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool.DeclIndex, code: []const u8, symbol_tag: Symbol.Tag) !void { |
| 263 | fn finishUpdateDecl( |
| 264 | zig_object: *ZigObject, |
| 265 | wasm_file: *Wasm, |
| 266 | decl_index: InternPool.DeclIndex, |
| 267 | code: []const u8, |
| 268 | symbol_tag: Symbol.Tag, |
| 269 | ) !void { |
| 246 | 270 | const gpa = wasm_file.base.comp.gpa; |
| 247 | 271 | const mod = wasm_file.base.comp.module.?; |
| 248 | 272 | const decl = mod.declPtr(decl_index); |
| 249 | 273 | const atom_index = zig_object.decls.get(decl_index).?; |
| 250 | 274 | const atom = wasm_file.getAtomPtr(atom_index); |
| 251 | | const symbol = &zig_object.symbols.items[atom.sym_index]; |
| 275 | const sym = zig_object.symbol(atom.getSymbolIndex().?); |
| 252 | 276 | const full_name = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod)); |
| 253 | | symbol.name = try zig_object.string_table.insert(gpa, full_name); |
| 254 | | symbol.tag = symbol_tag; |
| 277 | sym.name = try zig_object.string_table.insert(gpa, full_name); |
| 278 | sym.tag = symbol_tag; |
| 255 | 279 | try atom.code.appendSlice(gpa, code); |
| 256 | 280 | try wasm_file.resolved_symbols.put(gpa, atom.symbolLoc(), {}); |
| 257 | 281 | |
| ... | ... | @@ -267,14 +291,13 @@ pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_ind |
| 267 | 291 | const gpa = wasm_file.base.comp.gpa; |
| 268 | 292 | const gop = try zig_object.decls.getOrPut(gpa, decl_index); |
| 269 | 293 | if (!gop.found_existing) { |
| 270 | | const atom_index = try wasm_file.createAtom(); |
| 271 | | gop.value_ptr.* = atom_index; |
| 272 | | const atom = wasm_file.getAtom(atom_index); |
| 273 | | const symbol = atom.symbolLoc().getSymbol(wasm_file); |
| 294 | const sym_index = try zig_object.allocateSymbol(gpa); |
| 295 | gop.value_ptr.* = try wasm_file.createAtom(sym_index); |
| 274 | 296 | const mod = wasm_file.base.comp.module.?; |
| 275 | 297 | const decl = mod.declPtr(decl_index); |
| 276 | 298 | const full_name = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod)); |
| 277 | | symbol.name = try wasm_file.string_table.insert(gpa, full_name); |
| 299 | const sym = zig_object.symbol(sym_index); |
| 300 | sym.name = try zig_object.string_table.insert(gpa, full_name); |
| 278 | 301 | } |
| 279 | 302 | return gop.value_ptr.*; |
| 280 | 303 | } |
| ... | ... | @@ -297,7 +320,7 @@ pub fn lowerAnonDecl( |
| 297 | 320 | @intFromEnum(decl_val), |
| 298 | 321 | }) catch unreachable; |
| 299 | 322 | |
| 300 | | switch (try zig_object.lowerConst(name, tv, src_loc)) { |
| 323 | switch (try zig_object.lowerConst(wasm_file, name, tv, src_loc)) { |
| 301 | 324 | .ok => |atom_index| zig_object.anon_decls.values()[gop.index] = atom_index, |
| 302 | 325 | .fail => |em| return .{ .fail = em }, |
| 303 | 326 | } |
| ... | ... | @@ -323,7 +346,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, tv: TypedValu |
| 323 | 346 | std.debug.assert(tv.ty.zigTypeTag(mod) != .Fn); // cannot create local symbols for functions |
| 324 | 347 | const decl = mod.declPtr(decl_index); |
| 325 | 348 | |
| 326 | | const parent_atom_index = try zig_object.getOrCreateAtomForDecl(decl_index); |
| 349 | const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); |
| 327 | 350 | const parent_atom = wasm_file.getAtom(parent_atom_index); |
| 328 | 351 | const local_index = parent_atom.locals.items.len; |
| 329 | 352 | const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod)); |
| ... | ... | @@ -332,7 +355,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, tv: TypedValu |
| 332 | 355 | }); |
| 333 | 356 | defer gpa.free(name); |
| 334 | 357 | |
| 335 | | switch (try zig_object.lowerConst(name, tv, decl.srcLoc(mod))) { |
| 358 | switch (try zig_object.lowerConst(wasm_file, name, tv, decl.srcLoc(mod))) { |
| 336 | 359 | .ok => |atom_index| { |
| 337 | 360 | try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index); |
| 338 | 361 | return wasm_file.getAtom(atom_index).getSymbolIndex().?; |
| ... | ... | @@ -355,14 +378,15 @@ fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, tv: Ty |
| 355 | 378 | const mod = wasm_file.base.comp.module.?; |
| 356 | 379 | |
| 357 | 380 | // Create and initialize a new local symbol and atom |
| 358 | | const atom_index = try wasm_file.createAtom(); |
| 381 | const sym_index = try zig_object.allocateSymbol(gpa); |
| 382 | const atom_index = try wasm_file.createAtom(sym_index); |
| 359 | 383 | var value_bytes = std.ArrayList(u8).init(gpa); |
| 360 | 384 | defer value_bytes.deinit(); |
| 361 | 385 | |
| 362 | 386 | const code = code: { |
| 363 | 387 | const atom = wasm_file.getAtomPtr(atom_index); |
| 364 | 388 | atom.alignment = tv.ty.abiAlignment(mod); |
| 365 | | zig_object.symbols.items[atom.sym_index] = .{ |
| 389 | zig_object.symbols.items[sym_index] = .{ |
| 366 | 390 | .name = try zig_object.string_table.insert(gpa, name), |
| 367 | 391 | .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), |
| 368 | 392 | .tag = .data, |
| ... | ... | @@ -399,14 +423,14 @@ fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, tv: Ty |
| 399 | 423 | /// |
| 400 | 424 | /// When the symbol does not yet exist, it will create a new one instead. |
| 401 | 425 | pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm) !u32 { |
| 402 | | if (zig_object.error_table_symbol) |symbol| { |
| 403 | | return symbol; |
| 426 | if (zig_object.error_table_symbol) |sym| { |
| 427 | return sym; |
| 404 | 428 | } |
| 405 | 429 | |
| 406 | 430 | // no error was referenced yet, so create a new symbol and atom for it |
| 407 | 431 | // and then return said symbol's index. The final table will be populated |
| 408 | 432 | // during `flush` when we know all possible error names. |
| 409 | | const gpa = wasm_file.base.gpa; |
| 433 | const gpa = wasm_file.base.comp.gpa; |
| 410 | 434 | const sym_index = try zig_object.allocateSymbol(gpa); |
| 411 | 435 | const atom_index = try wasm_file.createAtom(sym_index); |
| 412 | 436 | const atom = wasm_file.getAtomPtr(atom_index); |
| ... | ... | @@ -415,15 +439,16 @@ pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm) !u32 { |
| 415 | 439 | atom.alignment = slice_ty.abiAlignment(mod); |
| 416 | 440 | |
| 417 | 441 | const sym_name = try zig_object.string_table.insert(gpa, "__zig_err_name_table"); |
| 418 | | const symbol = &zig_object.symbols.items[sym_index]; |
| 419 | | symbol.* = .{ |
| 442 | const sym = zig_object.symbol(sym_index); |
| 443 | sym.* = .{ |
| 420 | 444 | .name = sym_name, |
| 421 | 445 | .tag = .data, |
| 422 | 446 | .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), |
| 423 | 447 | .index = 0, |
| 424 | 448 | .virtual_address = undefined, |
| 425 | 449 | }; |
| 426 | | symbol.mark(); |
| 450 | // TODO: can we remove this? |
| 451 | // sym.mark(); |
| 427 | 452 | |
| 428 | 453 | log.debug("Error name table was created with symbol index: ({d})", .{sym_index}); |
| 429 | 454 | zig_object.error_table_symbol = sym_index; |
| ... | ... | @@ -528,13 +553,13 @@ pub fn addOrUpdateImport( |
| 528 | 553 | defer if (mangle_name) gpa.free(full_name); |
| 529 | 554 | |
| 530 | 555 | const decl_name_index = try zig_object.string_table.insert(gpa, full_name); |
| 531 | | const symbol: *Symbol = &zig_object.symbols.items[symbol_index]; |
| 532 | | symbol.setUndefined(true); |
| 533 | | symbol.setGlobal(true); |
| 534 | | symbol.name = decl_name_index; |
| 556 | const sym: *Symbol = &zig_object.symbols.items[symbol_index]; |
| 557 | sym.setUndefined(true); |
| 558 | sym.setGlobal(true); |
| 559 | sym.name = decl_name_index; |
| 535 | 560 | if (mangle_name) { |
| 536 | 561 | // we specified a specific name for the symbol that does not match the import name |
| 537 | | symbol.setFlag(.WASM_SYM_EXPLICIT_NAME); |
| 562 | sym.setFlag(.WASM_SYM_EXPLICIT_NAME); |
| 538 | 563 | } |
| 539 | 564 | |
| 540 | 565 | if (type_index) |ty_index| { |
| ... | ... | @@ -557,22 +582,22 @@ pub fn addOrUpdateImport( |
| 557 | 582 | /// such as an exported or imported symbol. |
| 558 | 583 | /// If the symbol does not yet exist, creates a new one symbol instead |
| 559 | 584 | /// and then returns the index to it. |
| 560 | | pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []const u8, tag: Symbol.Tag) !u32 { |
| 585 | pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []const u8) !u32 { |
| 561 | 586 | const name_index = try zig_object.string_table.insert(gpa, name); |
| 562 | 587 | const gop = try zig_object.global_syms.getOrPut(gpa, name_index); |
| 563 | 588 | if (gop.found_existing) { |
| 564 | 589 | return gop.value_ptr.*; |
| 565 | 590 | } |
| 566 | 591 | |
| 567 | | var symbol: Symbol = .{ |
| 592 | var sym: Symbol = .{ |
| 568 | 593 | .name = name_index, |
| 569 | 594 | .flags = 0, |
| 570 | 595 | .index = undefined, // index to type will be set after merging symbols |
| 571 | | .tag = tag, |
| 596 | .tag = .function, |
| 572 | 597 | .virtual_address = std.math.maxInt(u32), |
| 573 | 598 | }; |
| 574 | | symbol.setGlobal(true); |
| 575 | | symbol.setUndefined(true); |
| 599 | sym.setGlobal(true); |
| 600 | sym.setUndefined(true); |
| 576 | 601 | |
| 577 | 602 | const sym_index = if (zig_object.symbols_free_list.popOrNull()) |index| index else blk: { |
| 578 | 603 | const index: u32 = @intCast(zig_object.symbols.items.len); |
| ... | ... | @@ -580,7 +605,7 @@ pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []c |
| 580 | 605 | zig_object.symbols.items.len += 1; |
| 581 | 606 | break :blk index; |
| 582 | 607 | }; |
| 583 | | zig_object.symbols.items[sym_index] = symbol; |
| 608 | zig_object.symbols.items[sym_index] = sym; |
| 584 | 609 | gop.value_ptr.* = sym_index; |
| 585 | 610 | return sym_index; |
| 586 | 611 | } |
| ... | ... | @@ -675,8 +700,8 @@ pub fn deleteDeclExport( |
| 675 | 700 | const atom_index = zig_object.decls.get(decl_index) orelse return; |
| 676 | 701 | const sym_index = wasm_file.getAtom(atom_index).sym_index; |
| 677 | 702 | const loc: Wasm.SymbolLoc = .{ .file = null, .index = sym_index }; |
| 678 | | const symbol = loc.getSymbol(wasm_file); |
| 679 | | std.debug.assert(zig_object.global_syms.remove(symbol.name)); |
| 703 | const sym = loc.getSymbol(wasm_file); |
| 704 | std.debug.assert(zig_object.global_syms.remove(sym.name)); |
| 680 | 705 | } |
| 681 | 706 | |
| 682 | 707 | pub fn updateExports( |
| ... | ... | @@ -694,7 +719,7 @@ pub fn updateExports( |
| 694 | 719 | }, |
| 695 | 720 | }; |
| 696 | 721 | const decl = mod.declPtr(decl_index); |
| 697 | | const atom_index = try zig_object.getOrCreateAtomForDecl(decl_index); |
| 722 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); |
| 698 | 723 | const atom = wasm_file.getAtom(atom_index); |
| 699 | 724 | const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*; |
| 700 | 725 | const gpa = mod.gpa; |
| ... | ... | @@ -722,24 +747,24 @@ pub fn updateExports( |
| 722 | 747 | }, |
| 723 | 748 | .decl_index => |i| i, |
| 724 | 749 | }; |
| 725 | | const exported_atom_index = try zig_object.getOrCreateAtomForDecl(exported_decl_index); |
| 750 | const exported_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, exported_decl_index); |
| 726 | 751 | const exported_atom = wasm_file.getAtom(exported_atom_index); |
| 727 | 752 | // const export_name = try zig_object.string_table.put(gpa, mod.intern_pool.stringToSlice(exp.opts.name)); |
| 728 | 753 | const sym_loc = exported_atom.symbolLoc(); |
| 729 | | const symbol = sym_loc.getSymbol(wasm_file); |
| 730 | | symbol.setGlobal(true); |
| 731 | | symbol.setUndefined(false); |
| 732 | | symbol.index = atom_sym.index; |
| 733 | | symbol.tag = atom_sym.tag; |
| 734 | | symbol.name = atom_sym.name; |
| 754 | const sym = sym_loc.getSymbol(wasm_file); |
| 755 | sym.setGlobal(true); |
| 756 | sym.setUndefined(false); |
| 757 | sym.index = atom_sym.index; |
| 758 | sym.tag = atom_sym.tag; |
| 759 | sym.name = atom_sym.name; |
| 735 | 760 | |
| 736 | 761 | switch (exp.opts.linkage) { |
| 737 | 762 | .Internal => { |
| 738 | | symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); |
| 739 | | symbol.setFlag(.WASM_SYM_BINDING_WEAK); |
| 763 | sym.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); |
| 764 | sym.setFlag(.WASM_SYM_BINDING_WEAK); |
| 740 | 765 | }, |
| 741 | 766 | .Weak => { |
| 742 | | symbol.setFlag(.WASM_SYM_BINDING_WEAK); |
| 767 | sym.setFlag(.WASM_SYM_BINDING_WEAK); |
| 743 | 768 | }, |
| 744 | 769 | .Strong => {}, // symbols are strong by default |
| 745 | 770 | .LinkOnce => { |
| ... | ... | @@ -840,7 +865,7 @@ pub fn freeDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool |
| 840 | 865 | } |
| 841 | 866 | } |
| 842 | 867 | |
| 843 | | pub fn getTypeIndex(zig_object: *const ZigObject, func_type: std.wasm.Type) ?u32 { |
| 868 | fn getTypeIndex(zig_object: *const ZigObject, func_type: std.wasm.Type) ?u32 { |
| 844 | 869 | var index: u32 = 0; |
| 845 | 870 | while (index < zig_object.func_types.items.len) : (index += 1) { |
| 846 | 871 | if (zig_object.func_types.items[index].eql(func_type)) return index; |
| ... | ... | @@ -1115,6 +1140,16 @@ fn allocateDebugAtoms(zig_object: *ZigObject) !void { |
| 1115 | 1140 | try allocAtom(zig_object, &zig_object.debug_pubtypes_index, zig_object.debug_pubtypes_atom.?); |
| 1116 | 1141 | } |
| 1117 | 1142 | |
| 1143 | /// For the given `decl_index`, stores the corresponding type representing the function signature. |
| 1144 | /// Asserts declaration has an associated `Atom`. |
| 1145 | /// Returns the index into the list of types. |
| 1146 | pub fn storeDeclType(zig_object: *ZigObject, gpa: std.mem.Allocator, decl_index: InternPool.DeclIndex, func_type: std.wasm.Type) !u32 { |
| 1147 | const atom_index = zig_object.decls.get(decl_index).?; |
| 1148 | const index = try zig_object.putOrGetFuncType(gpa, func_type); |
| 1149 | try zig_object.atom_types.put(gpa, atom_index, index); |
| 1150 | return index; |
| 1151 | } |
| 1152 | |
| 1118 | 1153 | const build_options = @import("build_options"); |
| 1119 | 1154 | const builtin = @import("builtin"); |
| 1120 | 1155 | const codegen = @import("../../codegen.zig"); |