authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-04-12 06:37:55+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-04-12 22:23:36+02:00
log5c451b6e63e52c82bde247b0b5db658409c6db30
tree07f70efa9d97c403dd93fb2aa26cdace3cf78b52
parent370401cf60f70d6b3a2b3f40253f601b0cb8589d
signature Commit is signed but in an unrecognized format.

wasm: make tagName null-terminated


1 files changed, 19 insertions(+), 4 deletions(-)

src/arch/wasm/CodeGen.zig+19-4
......@@ -6457,13 +6457,28 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
64576457 // for each tag name, create an unnamed const,
64586458 // and then get a pointer to its value.
64596459 var name_ty_payload: Type.Payload.Len = .{
6460 .base = .{ .tag = .array_u8 },
6460 .base = .{ .tag = .array_u8_sentinel_0 },
64616461 .data = @intCast(u64, tag_name.len),
64626462 };
64636463 const name_ty = Type.initPayload(&name_ty_payload.base);
6464 var name_val_payload: Value.Payload.Bytes = .{
6465 .base = .{ .tag = .bytes },
6466 .data = tag_name,
6464 const string_bytes = &module.string_literal_bytes;
6465 try string_bytes.ensureUnusedCapacity(module.gpa, tag_name.len);
6466 const gop = try module.string_literal_table.getOrPutContextAdapted(module.gpa, tag_name, Module.StringLiteralAdapter{
6467 .bytes = string_bytes,
6468 }, Module.StringLiteralContext{
6469 .bytes = string_bytes,
6470 });
6471 if (!gop.found_existing) {
6472 gop.key_ptr.* = .{
6473 .index = @intCast(u32, string_bytes.items.len),
6474 .len = @intCast(u32, tag_name.len),
6475 };
6476 string_bytes.appendSliceAssumeCapacity(tag_name);
6477 gop.value_ptr.* = .none;
6478 }
6479 var name_val_payload: Value.Payload.StrLit = .{
6480 .base = .{ .tag = .str_lit },
6481 .data = gop.key_ptr.*,
64676482 };
64686483 const name_val = Value.initPayload(&name_val_payload.base);
64696484 const tag_sym_index = try func.bin_file.lowerUnnamedConst(