diff options
| author | Luuk de Gram <luuk@degram.dev> | 2023-04-12 06:37:55 +0200 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2023-04-12 22:23:36 +0200 |
| commit | 5c451b6e63e52c82bde247b0b5db658409c6db30 (patch) | |
| tree | 07f70efa9d97c403dd93fb2aa26cdace3cf78b52 /src/arch/wasm/CodeGen.zig | |
| parent | 370401cf60f70d6b3a2b3f40253f601b0cb8589d (diff) | |
| download | zig-5c451b6e63e52c82bde247b0b5db658409c6db30.tar.gz zig-5c451b6e63e52c82bde247b0b5db658409c6db30.zip | |
wasm: make tagName null-terminated
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 4a61f2d846..83af640b82 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -6457,13 +6457,28 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { // for each tag name, create an unnamed const, // and then get a pointer to its value. var name_ty_payload: Type.Payload.Len = .{ - .base = .{ .tag = .array_u8 }, + .base = .{ .tag = .array_u8_sentinel_0 }, .data = @intCast(u64, tag_name.len), }; const name_ty = Type.initPayload(&name_ty_payload.base); - var name_val_payload: Value.Payload.Bytes = .{ - .base = .{ .tag = .bytes }, - .data = tag_name, + const string_bytes = &module.string_literal_bytes; + try string_bytes.ensureUnusedCapacity(module.gpa, tag_name.len); + const gop = try module.string_literal_table.getOrPutContextAdapted(module.gpa, tag_name, Module.StringLiteralAdapter{ + .bytes = string_bytes, + }, Module.StringLiteralContext{ + .bytes = string_bytes, + }); + if (!gop.found_existing) { + gop.key_ptr.* = .{ + .index = @intCast(u32, string_bytes.items.len), + .len = @intCast(u32, tag_name.len), + }; + string_bytes.appendSliceAssumeCapacity(tag_name); + gop.value_ptr.* = .none; + } + var name_val_payload: Value.Payload.StrLit = .{ + .base = .{ .tag = .str_lit }, + .data = gop.key_ptr.*, }; const name_val = Value.initPayload(&name_val_payload.base); const tag_sym_index = try func.bin_file.lowerUnnamedConst( |
