From c0df70706695a67089d4e691d3d3a0f77b90298f Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 3 Jun 2025 16:25:16 +0100 Subject: wasm: get self-hosted compiling, and supporting `separate_thread` My original goal here was just to get the self-hosted Wasm backend compiling again after the pipeline change, but it turned out that from there it was pretty simple to entirely eliminate the shared state between `codegen.wasm` and `link.Wasm`. As such, this commit not only fixes the backend, but makes it the second backend (after CBE) to support the new 1:N:1 threading model. --- src/codegen.zig | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index ea57aaf89c..5a8f17735a 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -123,6 +123,7 @@ pub const AnyMir = union { .stage2_riscv64, .stage2_sparc64, .stage2_x86_64, + .stage2_wasm, .stage2_c, => |backend_ct| @field(mir, tag(backend_ct)).deinit(gpa), } @@ -153,6 +154,7 @@ pub fn generateFunction( .stage2_riscv64, .stage2_sparc64, .stage2_x86_64, + .stage2_wasm, .stage2_c, => |backend| { dev.check(devFeatureForBackend(backend)); @@ -784,7 +786,6 @@ fn lowerUavRef( const comp = lf.comp; const target = &comp.root_mod.resolved_target.result; const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8); - const is_obj = comp.config.output_mode == .Obj; const uav_val = uav.val; const uav_ty = Type.fromInterned(ip.typeOf(uav_val)); const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; @@ -804,21 +805,7 @@ fn lowerUavRef( dev.check(link.File.Tag.wasm.devFeature()); const wasm = lf.cast(.wasm).?; assert(reloc_parent == .none); - if (is_obj) { - try wasm.out_relocs.append(gpa, .{ - .offset = @intCast(code.items.len), - .pointee = .{ .symbol_index = try wasm.uavSymbolIndex(uav.val) }, - .tag = if (ptr_width_bytes == 4) .memory_addr_i32 else .memory_addr_i64, - .addend = @intCast(offset), - }); - } else { - try wasm.uav_fixups.ensureUnusedCapacity(gpa, 1); - wasm.uav_fixups.appendAssumeCapacity(.{ - .uavs_exe_index = try wasm.refUavExe(uav.val, uav.orig_ty), - .offset = @intCast(code.items.len), - .addend = @intCast(offset), - }); - } + try wasm.addUavReloc(code.items.len, uav.val, uav.orig_ty, @intCast(offset)); code.appendNTimesAssumeCapacity(0, ptr_width_bytes); return; }, -- cgit v1.2.3