diff options
| author | Luuk de Gram <luuk@degram.dev> | 2023-04-09 19:24:24 +0200 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2023-04-12 22:23:32 +0200 |
| commit | 3c27df6b135f998facce1aa09a9926e840671a05 (patch) | |
| tree | 4b400276a9df4f27bf574f671b2376dc3f8362cc /src/link | |
| parent | 490a411fd4e00fee65bc014fa7b1af59042d269b (diff) | |
| download | zig-3c27df6b135f998facce1aa09a9926e840671a05.tar.gz zig-3c27df6b135f998facce1aa09a9926e840671a05.zip | |
wasm: generate function to get tag name
When we lower the instruction for `@tagName` we generate a new
function if it doesn't exist yet for that decl. This function creates
an if-else chain to determine which value was provided. Each tag
generates a constant that contains its name as the value. For each
tag we generate a case where the pointer of the string is stored in
the result slice. The length of the tagname is comptime-known, therefore
will be stored in the slice directly without having it being part of
the tagname symbol. In the future this can use a jump table instead
of an if-else chain, similar to the `switch` instruction.
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Wasm.zig | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index b1fc25bf26..639b7f0776 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -577,7 +577,7 @@ pub fn getOrCreateAtomForDecl(wasm: *Wasm, decl_index: Module.Decl.Index) !Atom. } /// Creates a new empty `Atom` and returns its `Atom.Index` -fn createAtom(wasm: *Wasm) !Atom.Index { +pub fn createAtom(wasm: *Wasm) !Atom.Index { const index = @intCast(Atom.Index, wasm.managed_atoms.items.len); const atom = try wasm.managed_atoms.addOne(wasm.base.allocator); atom.* = Atom.empty; @@ -1208,7 +1208,7 @@ fn resolveLazySymbols(wasm: *Wasm) !void { // Tries to find a global symbol by its name. Returns null when not found, /// and its location when it is found. -fn findGlobalSymbol(wasm: *Wasm, name: []const u8) ?SymbolLoc { +pub fn findGlobalSymbol(wasm: *Wasm, name: []const u8) ?SymbolLoc { const offset = wasm.string_table.getOffset(name) orelse return null; return wasm.globals.get(offset); } |
