aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2022-03-22 21:20:36 +0100
committerLuuk de Gram <luuk@degram.dev>2022-03-23 21:40:32 +0100
commit49051c065120781b6ff78172c447b6307bd01e39 (patch)
tree37efe02f2da2419f37fec7ce152313229cab6950 /src/Module.zig
parentb872539a13ac46abe57a59bafdf5392812468482 (diff)
downloadzig-49051c065120781b6ff78172c447b6307bd01e39.tar.gz
zig-49051c065120781b6ff78172c447b6307bd01e39.zip
wasm: Implement `@errorName`
This implements the `error_name` instruction, which is emit for runtime `@errorName` callsites. The implementation works by creating 2 symbols and corresponding atoms. The initial symbol contains a table which each element consisting of a slice where the ptr field points towards the error name, and the len field contains the error name length without the sentinel. The secondary symbol contains a list of all error names from the global error set. During the error_name instruction, we first get a pointer to the first symbol. Then based on the operand we perform pointer arithmetic, to get the correct index into this table. e.g. error index 2 = ptr + (2 * ptr size). The result of this will be stored in a local and then returned as instruction result. During `flush()` we populate the error names table by looping over the global error set and creating a relocation for each error name. This relocation is appended to the table symbol. Then finally, this name is written to the names list itself. Finally, both symbols' atom are allocated within the rest of the binary. When no error name is referenced, the `error_name_symbol` is never set, and therefore no error name table will be emit into the final binary.
Diffstat (limited to 'src/Module.zig')
0 files changed, 0 insertions, 0 deletions