authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-19 03:18:28+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-04-06 08:52:38+03:30
log97850149386a8ec54ffce285973d3e7010cefa00
tree34521620230eb04349d1ef2f4f5107088cca96d0
parent0f75143c621b239dd79abc32de0911a68fa7caa4

spirv: OpExtInstImport in assembler


4 files changed, 55 insertions(+), 47 deletions(-)

src/codegen/spirv.zig+17-26
...@@ -1016,7 +1016,7 @@ const DeclGen = struct {...@@ -1016,7 +1016,7 @@ const DeclGen = struct {
1016 const elem_ty = Type.fromInterned(array_type.child);1016 const elem_ty = Type.fromInterned(array_type.child);
1017 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);1017 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);
10181018
1019 const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod))));1019 const constituents = try self.gpa.alloc(IdRef, @intCast(ty.arrayLenIncludingSentinel(mod)));
1020 defer self.gpa.free(constituents);1020 defer self.gpa.free(constituents);
10211021
1022 switch (aggregate.storage) {1022 switch (aggregate.storage) {
...@@ -1736,7 +1736,6 @@ const DeclGen = struct {...@@ -1736,7 +1736,6 @@ const DeclGen = struct {
1736 .EnumLiteral,1736 .EnumLiteral,
1737 .ComptimeFloat,1737 .ComptimeFloat,
1738 .ComptimeInt,1738 .ComptimeInt,
1739 .Type,
1740 => unreachable, // Must be comptime.1739 => unreachable, // Must be comptime.
17411740
1742 else => |tag| return self.todo("Implement zig type '{}'", .{tag}),1741 else => |tag| return self.todo("Implement zig type '{}'", .{tag}),
...@@ -2323,18 +2322,10 @@ const DeclGen = struct {...@@ -2323,18 +2322,10 @@ const DeclGen = struct {
23232322
2324 .div_float,2323 .div_float,
2325 .div_float_optimized,2324 .div_float_optimized,
2326 // TODO: Check that this is the right operation.
2327 .div_trunc,2325 .div_trunc,
2328 .div_trunc_optimized,2326 .div_trunc_optimized => try self.airArithOp(inst, .OpFDiv, .OpSDiv, .OpUDiv),
2329 => try self.airArithOp(inst, .OpFDiv, .OpSDiv, .OpUDiv),2327 .rem, .rem_optimized => try self.airArithOp(inst, .OpFRem, .OpSRem, .OpSRem),
2330 // TODO: Check if this is the right operation2328 .mod, .mod_optimized => try self.airArithOp(inst, .OpFMod, .OpSMod, .OpSMod),
2331 .rem,
2332 .rem_optimized,
2333 => try self.airArithOp(inst, .OpFRem, .OpSRem, .OpSRem),
2334 // TODO: Check if this is the right operation
2335 .mod,
2336 .mod_optimized,
2337 => try self.airArithOp(inst, .OpFMod, .OpSMod, .OpSMod),
23382329
23392330
2340 .add_with_overflow => try self.airAddSubOverflow(inst, .OpIAdd, .OpULessThan, .OpSLessThan),2331 .add_with_overflow => try self.airAddSubOverflow(inst, .OpIAdd, .OpULessThan, .OpSLessThan),
...@@ -2348,7 +2339,7 @@ const DeclGen = struct {...@@ -2348,7 +2339,7 @@ const DeclGen = struct {
23482339
2349 .splat => try self.airSplat(inst),2340 .splat => try self.airSplat(inst),
2350 .reduce, .reduce_optimized => try self.airReduce(inst),2341 .reduce, .reduce_optimized => try self.airReduce(inst),
2351 .shuffle => try self.airShuffle(inst),2342 .shuffle => try self.airShuffle(inst),
23522343
2353 .ptr_add => try self.airPtrAdd(inst),2344 .ptr_add => try self.airPtrAdd(inst),
2354 .ptr_sub => try self.airPtrSub(inst),2345 .ptr_sub => try self.airPtrSub(inst),
...@@ -2742,8 +2733,8 @@ const DeclGen = struct {...@@ -2742,8 +2733,8 @@ const DeclGen = struct {
2742 else => unreachable,2733 else => unreachable,
2743 };2734 };
2744 const set_id = switch (target.os.tag) {2735 const set_id = switch (target.os.tag) {
2745 .opencl => try self.spv.importInstructionSet(.opencl),2736 .opencl => try self.spv.importInstructionSet("OpenCL.std"),
2746 .vulkan => try self.spv.importInstructionSet(.glsl),2737 .vulkan => try self.spv.importInstructionSet("GLSL.std.450"),
2747 else => unreachable,2738 else => unreachable,
2748 };2739 };
27492740
...@@ -2796,8 +2787,8 @@ const DeclGen = struct {...@@ -2796,8 +2787,8 @@ const DeclGen = struct {
2796 return self.todo("binary operations for composite integers", .{});2787 return self.todo("binary operations for composite integers", .{});
2797 },2788 },
2798 .integer, .strange_integer => switch (info.signedness) {2789 .integer, .strange_integer => switch (info.signedness) {
2799 .signed => @as(usize, 1),2790 .signed => 1,
2800 .unsigned => @as(usize, 2),2791 .unsigned => 2,
2801 },2792 },
2802 .float => 0,2793 .float => 0,
2803 .bool => unreachable,2794 .bool => unreachable,
...@@ -5357,7 +5348,7 @@ const DeclGen = struct {...@@ -5357,7 +5348,7 @@ const DeclGen = struct {
5357 const backing_bits = self.backingIntBits(bits) orelse {5348 const backing_bits = self.backingIntBits(bits) orelse {
5358 return self.todo("implement composite int switch", .{});5349 return self.todo("implement composite int switch", .{});
5359 };5350 };
5360 break :blk if (backing_bits <= 32) @as(u32, 1) else 2;5351 break :blk if (backing_bits <= 32) 1 else 2;
5361 },5352 },
5362 .Enum => blk: {5353 .Enum => blk: {
5363 const int_ty = cond_ty.intTagType(mod);5354 const int_ty = cond_ty.intTagType(mod);
...@@ -5365,7 +5356,7 @@ const DeclGen = struct {...@@ -5365,7 +5356,7 @@ const DeclGen = struct {
5365 const backing_bits = self.backingIntBits(int_info.bits) orelse {5356 const backing_bits = self.backingIntBits(int_info.bits) orelse {
5366 return self.todo("implement composite int switch", .{});5357 return self.todo("implement composite int switch", .{});
5367 };5358 };
5368 break :blk if (backing_bits <= 32) @as(u32, 1) else 2;5359 break :blk if (backing_bits <= 32) 1 else 2;
5369 },5360 },
5370 .Pointer => blk: {5361 .Pointer => blk: {
5371 cond_indirect = try self.intFromPtr(cond_indirect);5362 cond_indirect = try self.intFromPtr(cond_indirect);
...@@ -5419,7 +5410,7 @@ const DeclGen = struct {...@@ -5419,7 +5410,7 @@ const DeclGen = struct {
5419 for (0..num_cases) |case_i| {5410 for (0..num_cases) |case_i| {
5420 // SPIR-V needs a literal here, which' width depends on the case condition.5411 // SPIR-V needs a literal here, which' width depends on the case condition.
5421 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);5412 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
5422 const items = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[case.end..][0..case.data.items_len]));5413 const items: []const Air.Inst.Ref = @ptrCast(self.air.extra[case.end..][0..case.data.items_len]);
5423 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];5414 const case_body = self.air.extra[case.end + items.len ..][0..case.data.body_len];
5424 extra_index = case.end + case.data.items_len + case_body.len;5415 extra_index = case.end + case.data.items_len + case_body.len;
54255416
...@@ -5428,7 +5419,7 @@ const DeclGen = struct {...@@ -5428,7 +5419,7 @@ const DeclGen = struct {
5428 for (items) |item| {5419 for (items) |item| {
5429 const value = (try self.air.value(item, mod)) orelse unreachable;5420 const value = (try self.air.value(item, mod)) orelse unreachable;
5430 const int_val: u64 = switch (cond_ty.zigTypeTag(mod)) {5421 const int_val: u64 = switch (cond_ty.zigTypeTag(mod)) {
5431 .Bool, .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),5422 .Bool, .Int => if (cond_ty.isSignedInt(mod)) @bitCast(value.toSignedInt(mod)) else value.toUnsignedInt(mod),
5432 .Enum => blk: {5423 .Enum => blk: {
5433 // TODO: figure out of cond_ty is correct (something with enum literals)5424 // TODO: figure out of cond_ty is correct (something with enum literals)
5434 break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants5425 break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
...@@ -5550,14 +5541,14 @@ const DeclGen = struct {...@@ -5550,14 +5541,14 @@ const DeclGen = struct {
5550 const extra = self.air.extraData(Air.Asm, ty_pl.payload);5541 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
55515542
5552 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;5543 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
5553 const clobbers_len = @as(u31, @truncate(extra.data.flags));5544 const clobbers_len: u31 = @truncate(extra.data.flags);
55545545
5555 if (!is_volatile and self.liveness.isUnused(inst)) return null;5546 if (!is_volatile and self.liveness.isUnused(inst)) return null;
55565547
5557 var extra_i: usize = extra.end;5548 var extra_i: usize = extra.end;
5558 const outputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]));5549 const outputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.outputs_len]);
5559 extra_i += outputs.len;5550 extra_i += outputs.len;
5560 const inputs = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]));5551 const inputs: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra_i..][0..extra.data.inputs_len]);
5561 extra_i += inputs.len;5552 extra_i += inputs.len;
55625553
5563 if (outputs.len > 1) {5554 if (outputs.len > 1) {
...@@ -5679,7 +5670,7 @@ const DeclGen = struct {...@@ -5679,7 +5670,7 @@ const DeclGen = struct {
5679 const mod = self.module;5670 const mod = self.module;
5680 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;5671 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5681 const extra = self.air.extraData(Air.Call, pl_op.payload);5672 const extra = self.air.extraData(Air.Call, pl_op.payload);
5682 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));5673 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
5683 const callee_ty = self.typeOf(pl_op.operand);5674 const callee_ty = self.typeOf(pl_op.operand);
5684 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {5675 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
5685 .Fn => callee_ty,5676 .Fn => callee_ty,
src/codegen/spirv/Assembler.zig+26-9
...@@ -256,10 +256,15 @@ fn todo(self: *Assembler, comptime fmt: []const u8, args: anytype) Error {...@@ -256,10 +256,15 @@ fn todo(self: *Assembler, comptime fmt: []const u8, args: anytype) Error {
256/// If this function returns `error.AssembleFail`, an explanatory256/// If this function returns `error.AssembleFail`, an explanatory
257/// error message has already been emitted into `self.errors`.257/// error message has already been emitted into `self.errors`.
258fn processInstruction(self: *Assembler) !void {258fn processInstruction(self: *Assembler) !void {
259 const result = switch (self.inst.opcode) {259 const result: AsmValue = switch (self.inst.opcode) {
260 .OpEntryPoint => {260 .OpEntryPoint => {
261 return self.fail(0, "cannot export entry points via OpEntryPoint, export the kernel using callconv(.Kernel)", .{});261 return self.fail(0, "cannot export entry points via OpEntryPoint, export the kernel using callconv(.Kernel)", .{});
262 },262 },
263 .OpExtInstImport => blk: {
264 const set_name_offset = self.inst.operands.items[1].string;
265 const set_name = std.mem.sliceTo(self.inst.string_bytes.items[set_name_offset..], 0);
266 break :blk .{ .value = try self.spv.importInstructionSet(set_name) };
267 },
263 else => switch (self.inst.opcode.class()) {268 else => switch (self.inst.opcode.class()) {
264 .TypeDeclaration => try self.processTypeInstruction(),269 .TypeDeclaration => try self.processTypeInstruction(),
265 else => if (try self.processGenericInstruction()) |result|270 else => if (try self.processGenericInstruction()) |result|
...@@ -309,7 +314,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {...@@ -309,7 +314,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
309 return self.fail(0, "{} is not a valid bit count for floats (expected 16, 32 or 64)", .{bits});314 return self.fail(0, "{} is not a valid bit count for floats (expected 16, 32 or 64)", .{bits});
310 },315 },
311 }316 }
312 break :blk try self.spv.resolve(.{ .float_type = .{ .bits = @as(u16, @intCast(bits)) } });317 break :blk try self.spv.resolve(.{ .float_type = .{ .bits = @intCast(bits) } });
313 },318 },
314 .OpTypeVector => try self.spv.resolve(.{ .vector_type = .{319 .OpTypeVector => try self.spv.resolve(.{ .vector_type = .{
315 .component_type = try self.resolveTypeRef(operands[1].ref_id),320 .component_type = try self.resolveTypeRef(operands[1].ref_id),
...@@ -364,6 +369,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {...@@ -364,6 +369,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
364 .OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,369 .OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,
365 .OpVariable => switch (@as(spec.StorageClass, @enumFromInt(operands[2].value))) {370 .OpVariable => switch (@as(spec.StorageClass, @enumFromInt(operands[2].value))) {
366 .Function => &self.func.prologue,371 .Function => &self.func.prologue,
372 .UniformConstant => &self.spv.sections.types_globals_constants,
367 else => {373 else => {
368 // This is currently disabled because global variables are required to be374 // This is currently disabled because global variables are required to be
369 // emitted in the proper order, and this should be honored in inline assembly375 // emitted in the proper order, and this should be honored in inline assembly
...@@ -473,14 +479,14 @@ fn parseInstruction(self: *Assembler) !void {...@@ -473,14 +479,14 @@ fn parseInstruction(self: *Assembler) !void {
473 self.inst.string_bytes.shrinkRetainingCapacity(0);479 self.inst.string_bytes.shrinkRetainingCapacity(0);
474480
475 const lhs_result_tok = self.currentToken();481 const lhs_result_tok = self.currentToken();
476 const maybe_lhs_result = if (self.eatToken(.result_id_assign)) blk: {482 const maybe_lhs_result: ?AsmValue.Ref = if (self.eatToken(.result_id_assign)) blk: {
477 const name = self.tokenText(lhs_result_tok)[1..];483 const name = self.tokenText(lhs_result_tok)[1..];
478 const entry = try self.value_map.getOrPut(self.gpa, name);484 const entry = try self.value_map.getOrPut(self.gpa, name);
479 try self.expectToken(.equals);485 try self.expectToken(.equals);
480 if (!entry.found_existing) {486 if (!entry.found_existing) {
481 entry.value_ptr.* = .just_declared;487 entry.value_ptr.* = .just_declared;
482 }488 }
483 break :blk @as(AsmValue.Ref, @intCast(entry.index));489 break :blk @intCast(entry.index);
484 } else null;490 } else null;
485491
486 const opcode_tok = self.currentToken();492 const opcode_tok = self.currentToken();
...@@ -550,6 +556,7 @@ fn parseOperand(self: *Assembler, kind: spec.OperandKind) Error!void {...@@ -550,6 +556,7 @@ fn parseOperand(self: *Assembler, kind: spec.OperandKind) Error!void {
550 .LiteralInteger => try self.parseLiteralInteger(),556 .LiteralInteger => try self.parseLiteralInteger(),
551 .LiteralString => try self.parseString(),557 .LiteralString => try self.parseString(),
552 .LiteralContextDependentNumber => try self.parseContextDependentNumber(),558 .LiteralContextDependentNumber => try self.parseContextDependentNumber(),
559 .LiteralExtInstInteger => try self.parseLiteralExtInstInteger(),
553 .PairIdRefIdRef => try self.parsePhiSource(),560 .PairIdRefIdRef => try self.parsePhiSource(),
554 else => return self.todo("parse operand of type {s}", .{@tagName(kind)}),561 else => return self.todo("parse operand of type {s}", .{@tagName(kind)}),
555 },562 },
...@@ -641,7 +648,7 @@ fn parseRefId(self: *Assembler) !void {...@@ -641,7 +648,7 @@ fn parseRefId(self: *Assembler) !void {
641 entry.value_ptr.* = .unresolved_forward_reference;648 entry.value_ptr.* = .unresolved_forward_reference;
642 }649 }
643650
644 const index = @as(AsmValue.Ref, @intCast(entry.index));651 const index: AsmValue.Ref = @intCast(entry.index);
645 try self.inst.operands.append(self.gpa, .{ .ref_id = index });652 try self.inst.operands.append(self.gpa, .{ .ref_id = index });
646}653}
647654
...@@ -660,6 +667,16 @@ fn parseLiteralInteger(self: *Assembler) !void {...@@ -660,6 +667,16 @@ fn parseLiteralInteger(self: *Assembler) !void {
660 try self.inst.operands.append(self.gpa, .{ .literal32 = value });667 try self.inst.operands.append(self.gpa, .{ .literal32 = value });
661}668}
662669
670fn parseLiteralExtInstInteger(self: *Assembler) !void {
671 const tok = self.currentToken();
672 try self.expectToken(.value);
673 const text = self.tokenText(tok);
674 const value = std.fmt.parseInt(u32, text, 0) catch {
675 return self.fail(tok.start, "'{s}' is not a valid 32-bit integer literal", .{text});
676 };
677 try self.inst.operands.append(self.gpa, .{ .literal32 = value });
678}
679
663fn parseString(self: *Assembler) !void {680fn parseString(self: *Assembler) !void {
664 const tok = self.currentToken();681 const tok = self.currentToken();
665 try self.expectToken(.string);682 try self.expectToken(.string);
...@@ -673,7 +690,7 @@ fn parseString(self: *Assembler) !void {...@@ -673,7 +690,7 @@ fn parseString(self: *Assembler) !void {
673 else690 else
674 text[1..];691 text[1..];
675692
676 const string_offset = @as(u32, @intCast(self.inst.string_bytes.items.len));693 const string_offset: u32 = @intCast(self.inst.string_bytes.items.len);
677 try self.inst.string_bytes.ensureUnusedCapacity(self.gpa, literal.len + 1);694 try self.inst.string_bytes.ensureUnusedCapacity(self.gpa, literal.len + 1);
678 self.inst.string_bytes.appendSliceAssumeCapacity(literal);695 self.inst.string_bytes.appendSliceAssumeCapacity(literal);
679 self.inst.string_bytes.appendAssumeCapacity(0);696 self.inst.string_bytes.appendAssumeCapacity(0);
...@@ -730,9 +747,9 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness...@@ -730,9 +747,9 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness
730747
731 // Note, we store the sign-extended version here.748 // Note, we store the sign-extended version here.
732 if (width <= @bitSizeOf(spec.Word)) {749 if (width <= @bitSizeOf(spec.Word)) {
733 try self.inst.operands.append(self.gpa, .{ .literal32 = @as(u32, @truncate(@as(u128, @bitCast(int)))) });750 try self.inst.operands.append(self.gpa, .{ .literal32 = @truncate(@as(u128, @bitCast(int))) });
734 } else {751 } else {
735 try self.inst.operands.append(self.gpa, .{ .literal64 = @as(u64, @truncate(@as(u128, @bitCast(int)))) });752 try self.inst.operands.append(self.gpa, .{ .literal64 = @truncate(@as(u128, @bitCast(int))) });
736 }753 }
737 return;754 return;
738 }755 }
...@@ -753,7 +770,7 @@ fn parseContextDependentFloat(self: *Assembler, comptime width: u16) !void {...@@ -753,7 +770,7 @@ fn parseContextDependentFloat(self: *Assembler, comptime width: u16) !void {
753 return self.fail(tok.start, "'{s}' is not a valid {}-bit float literal", .{ text, width });770 return self.fail(tok.start, "'{s}' is not a valid {}-bit float literal", .{ text, width });
754 };771 };
755772
756 const float_bits = @as(Int, @bitCast(value));773 const float_bits: Int = @bitCast(value);
757 if (width <= @bitSizeOf(spec.Word)) {774 if (width <= @bitSizeOf(spec.Word)) {
758 try self.inst.operands.append(self.gpa, .{ .literal32 = float_bits });775 try self.inst.operands.append(self.gpa, .{ .literal32 = float_bits });
759 } else {776 } else {
src/codegen/spirv/Module.zig+2-2
...@@ -500,9 +500,9 @@ pub fn declPtr(self: *Module, index: Decl.Index) *Decl {...@@ -500,9 +500,9 @@ pub fn declPtr(self: *Module, index: Decl.Index) *Decl {
500500
501/// Declare ALL dependencies for a decl.501/// Declare ALL dependencies for a decl.
502pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl.Index) !void {502pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl.Index) !void {
503 const begin_dep = @as(u32, @intCast(self.decl_deps.items.len));503 const begin_dep: u32 = @intCast(self.decl_deps.items.len);
504 try self.decl_deps.appendSlice(self.gpa, deps);504 try self.decl_deps.appendSlice(self.gpa, deps);
505 const end_dep = @as(u32, @intCast(self.decl_deps.items.len));505 const end_dep: u32 = @intCast(self.decl_deps.items.len);
506506
507 const decl = self.declPtr(decl_index);507 const decl = self.declPtr(decl_index);
508 decl.begin_dep = begin_dep;508 decl.begin_dep = begin_dep;
src/codegen/spirv/Section.zig+10-10
...@@ -115,8 +115,8 @@ pub fn writeWords(section: *Section, words: []const Word) void {...@@ -115,8 +115,8 @@ pub fn writeWords(section: *Section, words: []const Word) void {
115115
116pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {116pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
117 section.writeWords(&.{117 section.writeWords(&.{
118 @as(Word, @truncate(dword)),118 @truncate(dword),
119 @as(Word, @truncate(dword >> @bitSizeOf(Word))),119 @truncate(dword >> @bitSizeOf(Word)),
120 });120 });
121}121}
122122
...@@ -196,12 +196,12 @@ fn writeString(section: *Section, str: []const u8) void {...@@ -196,12 +196,12 @@ fn writeString(section: *Section, str: []const u8) void {
196196
197fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDependentNumber) void {197fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDependentNumber) void {
198 switch (operand) {198 switch (operand) {
199 .int32 => |int| section.writeWord(@as(Word, @bitCast(int))),199 .int32 => |int| section.writeWord(@bitCast(int)),
200 .uint32 => |int| section.writeWord(@as(Word, @bitCast(int))),200 .uint32 => |int| section.writeWord(@bitCast(int)),
201 .int64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),201 .int64 => |int| section.writeDoubleWord(@bitCast(int)),
202 .uint64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),202 .uint64 => |int| section.writeDoubleWord(@bitCast(int)),
203 .float32 => |float| section.writeWord(@as(Word, @bitCast(float))),203 .float32 => |float| section.writeWord(@bitCast(float)),
204 .float64 => |float| section.writeDoubleWord(@as(DoubleWord, @bitCast(float))),204 .float64 => |float| section.writeDoubleWord(@bitCast(float)),
205 }205 }
206}206}
207207
...@@ -274,8 +274,8 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {...@@ -274,8 +274,8 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
274 spec.LiteralString => std.math.divCeil(usize, operand.len + 1, @sizeOf(Word)) catch unreachable, // Add one for zero-terminator274 spec.LiteralString => std.math.divCeil(usize, operand.len + 1, @sizeOf(Word)) catch unreachable, // Add one for zero-terminator
275275
276 spec.LiteralContextDependentNumber => switch (operand) {276 spec.LiteralContextDependentNumber => switch (operand) {
277 .int32, .uint32, .float32 => @as(usize, 1),277 .int32, .uint32, .float32 => 1,
278 .int64, .uint64, .float64 => @as(usize, 2),278 .int64, .uint64, .float64 => 2,
279 },279 },
280280
281 // TODO: Where this type is used (OpSpecConstantOp) is currently not correct in the spec281 // TODO: Where this type is used (OpSpecConstantOp) is currently not correct in the spec