mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
spirv: switch on bool
This commit is contained in:
parent
364c54460f
commit
e5d5c1d423
@ -4098,11 +4098,13 @@ const DeclGen = struct {
|
|||||||
fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
|
fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
|
||||||
const mod = self.module;
|
const mod = self.module;
|
||||||
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
|
||||||
const cond = try self.resolve(pl_op.operand);
|
|
||||||
const cond_ty = self.typeOf(pl_op.operand);
|
const cond_ty = self.typeOf(pl_op.operand);
|
||||||
|
const cond = try self.resolve(pl_op.operand);
|
||||||
|
const cond_indirect = try self.convertToIndirect(cond_ty, cond);
|
||||||
const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
|
const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
|
||||||
|
|
||||||
const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) {
|
const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) {
|
||||||
|
.Bool => 1,
|
||||||
.Int => blk: {
|
.Int => blk: {
|
||||||
const bits = cond_ty.intInfo(mod).bits;
|
const bits = cond_ty.intInfo(mod).bits;
|
||||||
const backing_bits = self.backingIntBits(bits) orelse {
|
const backing_bits = self.backingIntBits(bits) orelse {
|
||||||
@ -4146,7 +4148,7 @@ const DeclGen = struct {
|
|||||||
|
|
||||||
// Emit the instruction before generating the blocks.
|
// Emit the instruction before generating the blocks.
|
||||||
try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
|
try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
|
||||||
self.func.body.writeOperand(IdRef, cond);
|
self.func.body.writeOperand(IdRef, cond_indirect);
|
||||||
self.func.body.writeOperand(IdRef, default);
|
self.func.body.writeOperand(IdRef, default);
|
||||||
|
|
||||||
// Emit each of the cases
|
// Emit each of the cases
|
||||||
@ -4167,7 +4169,7 @@ const DeclGen = struct {
|
|||||||
return self.todo("switch on runtime value???", .{});
|
return self.todo("switch on runtime value???", .{});
|
||||||
};
|
};
|
||||||
const int_val = switch (cond_ty.zigTypeTag(mod)) {
|
const int_val = switch (cond_ty.zigTypeTag(mod)) {
|
||||||
.Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
|
.Bool, .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
|
||||||
.Enum => blk: {
|
.Enum => blk: {
|
||||||
// TODO: figure out of cond_ty is correct (something with enum literals)
|
// TODO: figure out of cond_ty is correct (something with enum literals)
|
||||||
break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
|
break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
|
||||||
|
|||||||
@ -715,7 +715,6 @@ test "result location is optional inside error union" {
|
|||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const x = maybe(true) catch unreachable;
|
const x = maybe(true) catch unreachable;
|
||||||
try expect(x.? == 42);
|
try expect(x.? == 42);
|
||||||
|
|||||||
@ -72,7 +72,6 @@ test "inline switch unions" {
|
|||||||
test "inline else bool" {
|
test "inline else bool" {
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var a = true;
|
var a = true;
|
||||||
switch (a) {
|
switch (a) {
|
||||||
|
|||||||
@ -118,7 +118,6 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool {
|
|||||||
|
|
||||||
test "switching on booleans" {
|
test "switching on booleans" {
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
try testSwitchOnBools();
|
try testSwitchOnBools();
|
||||||
try comptime testSwitchOnBools();
|
try comptime testSwitchOnBools();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user