mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
spirv: lower ptrtoint & ignore dbg_inline instructions
This commit is contained in:
parent
f8de4db873
commit
6fca3f8b72
@ -1724,6 +1724,7 @@ pub const DeclGen = struct {
|
||||
|
||||
.bitcast => try self.airBitcast(inst),
|
||||
.intcast, .trunc => try self.airIntcast(inst),
|
||||
.ptrtoint => try self.airPtrToInt(inst),
|
||||
.int_to_float => try self.airIntToFloat(inst),
|
||||
.float_to_int => try self.airFloatToInt(inst),
|
||||
.not => try self.airNot(inst),
|
||||
@ -1786,10 +1787,12 @@ pub const DeclGen = struct {
|
||||
.call_never_tail => try self.airCall(inst, .never_tail),
|
||||
.call_never_inline => try self.airCall(inst, .never_inline),
|
||||
|
||||
.dbg_var_ptr => return,
|
||||
.dbg_var_val => return,
|
||||
.dbg_block_begin => return,
|
||||
.dbg_block_end => return,
|
||||
.dbg_inline_begin => return,
|
||||
.dbg_inline_end => return,
|
||||
.dbg_var_ptr => return,
|
||||
.dbg_var_val => return,
|
||||
.dbg_block_begin => return,
|
||||
.dbg_block_end => return,
|
||||
// zig fmt: on
|
||||
|
||||
else => |tag| return self.todo("implement AIR tag {s}", .{@tagName(tag)}),
|
||||
@ -2131,6 +2134,22 @@ pub const DeclGen = struct {
|
||||
return result_id;
|
||||
}
|
||||
|
||||
fn airPtrToInt(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||
if (self.liveness.isUnused(inst)) return null;
|
||||
|
||||
const un_op = self.air.instructions.items(.data)[inst].un_op;
|
||||
const operand_id = try self.resolve(un_op);
|
||||
const result_type_id = try self.resolveTypeId(Type.usize);
|
||||
|
||||
const result_id = self.spv.allocId();
|
||||
try self.func.body.emit(self.spv.gpa, .OpConvertPtrToU, .{
|
||||
.id_result_type = result_type_id,
|
||||
.id_result = result_id,
|
||||
.pointer = operand_id,
|
||||
});
|
||||
return result_id;
|
||||
}
|
||||
|
||||
fn airIntToFloat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||
if (self.liveness.isUnused(inst)) return null;
|
||||
|
||||
|
||||
@ -1285,14 +1285,10 @@ test "implicit cast *[0]T to E![]const u8" {
|
||||
|
||||
var global_array: [4]u8 = undefined;
|
||||
test "cast from array reference to fn: comptime fn ptr" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
const f = @ptrCast(*align(1) const fn () callconv(.C) void, &global_array);
|
||||
try expect(@ptrToInt(f) == @ptrToInt(&global_array));
|
||||
}
|
||||
test "cast from array reference to fn: runtime fn ptr" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
var f = @ptrCast(*align(1) const fn () callconv(.C) void, &global_array);
|
||||
try expect(@ptrToInt(f) == @ptrToInt(&global_array));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user