all: zig fmt and rename "@XToY" to "@YFromX"

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
This commit is contained in:
Eric Joldasov
2023-06-15 13:14:16 +06:00
committed by Andrew Kelley
parent a6c8ee5231
commit 50339f595a
665 changed files with 6204 additions and 5889 deletions

View File

@@ -462,7 +462,7 @@ pub const Function = struct {
=> |owner_decl| try std.fmt.allocPrint(arena, "zig_{s}_{}__{d}", .{
@tagName(key),
fmtIdent(mod.intern_pool.stringToSlice(mod.declPtr(owner_decl).name)),
@enumToInt(owner_decl),
@intFromEnum(owner_decl),
}),
},
.data = switch (key) {
@@ -1865,7 +1865,7 @@ pub const DeclGen = struct {
};
try writer.print("{}__{d}", .{
fmtIdent(name_stream.getWritten()),
@enumToInt(decl_index),
@intFromEnum(decl_index),
});
}
}
@@ -1991,7 +1991,7 @@ fn renderTypeName(
@tagName(tag)["fwd_".len..],
attributes,
fmtIdent(mod.intern_pool.stringToSlice(mod.declPtr(owner_decl).name)),
@enumToInt(owner_decl),
@intFromEnum(owner_decl),
});
},
}
@@ -2100,7 +2100,7 @@ fn renderTypePrefix(
.fwd_anon_struct,
.fwd_anon_union,
=> if (decl.unwrap()) |decl_index|
try w.print("anon__{d}_{d}", .{ @enumToInt(decl_index), idx })
try w.print("anon__{d}_{d}", .{ @intFromEnum(decl_index), idx })
else
try renderTypeName(mod, w, idx, cty, ""),
@@ -2514,7 +2514,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
const name = mod.intern_pool.stringToSlice(name_ip);
const tag_val = try mod.enumValueFieldIndex(enum_ty, index);
const int_val = try tag_val.enumToInt(enum_ty, mod);
const int_val = try tag_val.intFromEnum(enum_ty, mod);
const name_ty = try mod.arrayType(.{
.len = name.len,
@@ -4701,7 +4701,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
// On the final iteration we do not need to fix any state. This is because, like in the `else`
// branch of a `cond_br`, our parent has to do it for this entire body anyway.
const last_case_i = switch_br.data.cases_len - @boolToInt(switch_br.data.else_body_len == 0);
const last_case_i = switch_br.data.cases_len - @intFromBool(switch_br.data.else_body_len == 0);
var extra_index: usize = switch_br.end;
for (0..switch_br.data.cases_len) |case_i| {
@@ -6894,7 +6894,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
const int_val = try tag_val.enumToInt(tag_ty, mod);
const int_val = try tag_val.intFromEnum(tag_ty, mod);
const a = try Assignment.start(f, writer, tag_ty);
try f.writeCValueMember(writer, local, .{ .identifier = "tag" });
@@ -6924,7 +6924,7 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
.data => {
try writer.writeAll("zig_prefetch(");
try f.writeCValue(writer, ptr, .FunctionArgument);
try writer.print(", {d}, {d});\n", .{ @enumToInt(prefetch.rw), prefetch.locality });
try writer.print(", {d}, {d});\n", .{ @intFromEnum(prefetch.rw), prefetch.locality });
},
// The available prefetch intrinsics do not accept a cache argument; only
// address, rw, and locality.

View File

@@ -129,15 +129,15 @@ pub const CType = extern union {
varargs_function,
pub const last_no_payload_tag = Tag.zig_c_longdouble;
pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
pub const no_payload_count = @intFromEnum(last_no_payload_tag) + 1;
pub fn hasPayload(self: Tag) bool {
return @enumToInt(self) >= no_payload_count;
return @intFromEnum(self) >= no_payload_count;
}
pub fn toIndex(self: Tag) Index {
assert(!self.hasPayload());
return @intCast(Index, @enumToInt(self));
return @intCast(Index, @intFromEnum(self));
}
pub fn Type(comptime self: Tag) type {
@@ -334,7 +334,7 @@ pub const CType = extern union {
map: Map = .{},
pub fn indexToCType(self: Set, index: Index) CType {
if (index < Tag.no_payload_count) return initTag(@intToEnum(Tag, index));
if (index < Tag.no_payload_count) return initTag(@enumFromInt(Tag, index));
return self.map.keys()[index - Tag.no_payload_count];
}
@@ -370,7 +370,7 @@ pub const CType = extern union {
pub fn cTypeToIndex(self: *Promoted, cty: CType) Allocator.Error!Index {
const t = cty.tag();
if (@enumToInt(t) < Tag.no_payload_count) return @intCast(Index, @enumToInt(t));
if (@intFromEnum(t) < Tag.no_payload_count) return @intCast(Index, @intFromEnum(t));
const gop = try self.set.map.getOrPutContext(self.gpa(), cty, .{ .store = &self.set });
if (!gop.found_existing) gop.key_ptr.* = cty;

View File

@@ -949,7 +949,7 @@ pub const Object = struct {
mod.comp.bin_file.options.error_return_tracing;
const err_ret_trace = if (err_return_tracing)
llvm_func.getParam(@boolToInt(ret_ptr != null))
llvm_func.getParam(@intFromBool(ret_ptr != null))
else
null;
@@ -960,7 +960,7 @@ pub const Object = struct {
defer args.deinit();
{
var llvm_arg_i = @as(c_uint, @boolToInt(ret_ptr != null)) + @boolToInt(err_return_tracing);
var llvm_arg_i = @as(c_uint, @intFromBool(ret_ptr != null)) + @intFromBool(err_return_tracing);
var it = iterateParamTypes(&dg, fn_info);
while (it.next()) |lowering| switch (lowering) {
.no_bits => continue,
@@ -2570,7 +2570,7 @@ pub const DeclGen = struct {
mod.comp.bin_file.options.error_return_tracing;
if (err_return_tracing) {
dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull");
dg.addArgAttr(llvm_fn, @intFromBool(sret), "nonnull");
}
switch (fn_info.cc) {
@@ -2604,8 +2604,8 @@ pub const DeclGen = struct {
// because functions with bodies are handled in `updateFunc`.
if (is_extern) {
var it = iterateParamTypes(dg, fn_info);
it.llvm_index += @boolToInt(sret);
it.llvm_index += @boolToInt(err_return_tracing);
it.llvm_index += @intFromBool(sret);
it.llvm_index += @intFromBool(err_return_tracing);
while (it.next()) |lowering| switch (lowering) {
.byval => {
const param_index = it.zig_index - 1;
@@ -2812,7 +2812,7 @@ pub const DeclGen = struct {
const elem_ty = t.childType(mod);
if (std.debug.runtime_safety) assert((try elem_ty.onePossibleValue(mod)) == null);
const elem_llvm_ty = try dg.lowerType(elem_ty);
const total_len = t.arrayLen(mod) + @boolToInt(t.sentinel(mod) != null);
const total_len = t.arrayLen(mod) + @intFromBool(t.sentinel(mod) != null);
return elem_llvm_ty.arrayType(@intCast(c_uint, total_len));
},
.Vector => {
@@ -3307,7 +3307,7 @@ pub const DeclGen = struct {
}
},
.enum_tag => {
const int_val = try tv.enumToInt(mod);
const int_val = try tv.intFromEnum(mod);
var bigint_space: Value.BigIntSpace = undefined;
const bigint = int_val.toBigInt(&bigint_space, mod);
@@ -3476,7 +3476,7 @@ pub const DeclGen = struct {
const elem_ty = tv.ty.childType(mod);
const sentinel = tv.ty.sentinel(mod);
const len = @intCast(usize, tv.ty.arrayLen(mod));
const len_including_sent = len + @boolToInt(sentinel != null);
const len_including_sent = len + @intFromBool(sentinel != null);
const gpa = dg.gpa;
const llvm_elems = try gpa.alloc(*llvm.Value, len_including_sent);
defer gpa.free(llvm_elems);
@@ -3923,7 +3923,7 @@ pub const DeclGen = struct {
const llvm_pl_index = if (layout.tag_size == 0)
0
else
@boolToInt(layout.tag_align >= layout.payload_align);
@intFromBool(layout.tag_align >= layout.payload_align);
const indices: [2]*llvm.Value = .{
llvm_u32.constInt(0, .False),
llvm_u32.constInt(llvm_pl_index, .False),
@@ -3959,7 +3959,7 @@ pub const DeclGen = struct {
};
return parent_llvm_ty.constInBoundsGEP(parent_llvm_ptr, &indices, indices.len);
} else {
const llvm_index = llvm_u32.constInt(@boolToInt(parent_ty.hasRuntimeBitsIgnoreComptime(mod)), .False);
const llvm_index = llvm_u32.constInt(@intFromBool(parent_ty.hasRuntimeBitsIgnoreComptime(mod)), .False);
const indices: [1]*llvm.Value = .{llvm_index};
return parent_llvm_ty.constInBoundsGEP(parent_llvm_ptr, &indices, indices.len);
}
@@ -4762,8 +4762,8 @@ pub const FuncGen = struct {
if (callee_ty.zigTypeTag(mod) == .Pointer) {
// Add argument attributes for function pointer calls.
it = iterateParamTypes(self.dg, fn_info);
it.llvm_index += @boolToInt(sret);
it.llvm_index += @boolToInt(err_return_tracing);
it.llvm_index += @intFromBool(sret);
it.llvm_index += @intFromBool(err_return_tracing);
while (it.next()) |lowering| switch (lowering) {
.byval => {
const param_index = it.zig_index - 1;
@@ -5857,7 +5857,7 @@ pub const FuncGen = struct {
.Union => {
const union_llvm_ty = try self.dg.lowerType(struct_ty);
const layout = struct_ty.unionGetLayout(mod);
const payload_index = @boolToInt(layout.tag_align >= layout.payload_align);
const payload_index = @intFromBool(layout.tag_align >= layout.payload_align);
const field_ptr = self.builder.buildStructGEP(union_llvm_ty, struct_llvm_val, payload_index, "");
const llvm_field_ty = try self.dg.lowerType(field_ty);
if (isByRef(field_ty, mod)) {
@@ -8444,7 +8444,7 @@ pub const FuncGen = struct {
return null;
}
const un_llvm_ty = try self.dg.lowerType(un_ty);
const tag_index = @boolToInt(layout.tag_align < layout.payload_align);
const tag_index = @intFromBool(layout.tag_align < layout.payload_align);
const tag_field_ptr = self.builder.buildStructGEP(un_llvm_ty, union_ptr, tag_index, "");
// TODO alignment on this store
_ = self.builder.buildStore(new_tag, tag_field_ptr);
@@ -8463,14 +8463,14 @@ pub const FuncGen = struct {
if (layout.payload_size == 0) {
return self.builder.buildLoad(llvm_un_ty, union_handle, "");
}
const tag_index = @boolToInt(layout.tag_align < layout.payload_align);
const tag_index = @intFromBool(layout.tag_align < layout.payload_align);
const tag_field_ptr = self.builder.buildStructGEP(llvm_un_ty, union_handle, tag_index, "");
return self.builder.buildLoad(llvm_un_ty.structGetTypeAtIndex(tag_index), tag_field_ptr, "");
} else {
if (layout.payload_size == 0) {
return union_handle;
}
const tag_index = @boolToInt(layout.tag_align < layout.payload_align);
const tag_index = @intFromBool(layout.tag_align < layout.payload_align);
return self.builder.buildExtractValue(union_handle, tag_index, "");
}
}
@@ -9206,7 +9206,7 @@ pub const FuncGen = struct {
const union_field_name = union_obj.fields.keys()[extra.field_index];
const enum_field_index = tag_ty.enumFieldIndex(union_field_name, mod).?;
const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
const tag_int_val = try tag_val.enumToInt(tag_ty, mod);
const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);
break :blk tag_int_val.toUnsignedInt(mod);
};
if (layout.payload_size == 0) {
@@ -9288,7 +9288,7 @@ pub const FuncGen = struct {
{
const indices: [3]*llvm.Value = .{
index_type.constNull(),
index_type.constInt(@boolToInt(layout.tag_align >= layout.payload_align), .False),
index_type.constInt(@intFromBool(layout.tag_align >= layout.payload_align), .False),
index_type.constNull(),
};
const len: c_uint = if (field_size == layout.payload_size) 2 else 3;
@@ -9298,7 +9298,7 @@ pub const FuncGen = struct {
{
const indices: [2]*llvm.Value = .{
index_type.constNull(),
index_type.constInt(@boolToInt(layout.tag_align < layout.payload_align), .False),
index_type.constInt(@intFromBool(layout.tag_align < layout.payload_align), .False),
};
const field_ptr = self.builder.buildInBoundsGEP(llvm_union_ty, result_ptr, &indices, indices.len, "");
const tag_llvm_ty = try self.dg.lowerType(union_obj.tag_ty);
@@ -9313,15 +9313,15 @@ pub const FuncGen = struct {
fn airPrefetch(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
const prefetch = self.air.instructions.items(.data)[inst].prefetch;
comptime assert(@enumToInt(std.builtin.PrefetchOptions.Rw.read) == 0);
comptime assert(@enumToInt(std.builtin.PrefetchOptions.Rw.write) == 1);
comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.read) == 0);
comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.write) == 1);
// TODO these two asserts should be able to be comptime because the type is a u2
assert(prefetch.locality >= 0);
assert(prefetch.locality <= 3);
comptime assert(@enumToInt(std.builtin.PrefetchOptions.Cache.instruction) == 0);
comptime assert(@enumToInt(std.builtin.PrefetchOptions.Cache.data) == 1);
comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Cache.instruction) == 0);
comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Cache.data) == 1);
// LLVM fails during codegen of instruction cache prefetchs for these architectures.
// This is an LLVM bug as the prefetch intrinsic should be a noop if not supported
@@ -9368,9 +9368,9 @@ pub const FuncGen = struct {
const params = [_]*llvm.Value{
ptr,
llvm_u32.constInt(@enumToInt(prefetch.rw), .False),
llvm_u32.constInt(@intFromEnum(prefetch.rw), .False),
llvm_u32.constInt(prefetch.locality, .False),
llvm_u32.constInt(@enumToInt(prefetch.cache), .False),
llvm_u32.constInt(@intFromEnum(prefetch.cache), .False),
};
_ = self.builder.buildCall(fn_val.globalGetValueType(), fn_val, &params, params.len, .C, .Auto, "");
return null;
@@ -9596,7 +9596,7 @@ pub const FuncGen = struct {
// the index to the element at index `1` to get a pointer to the end of
// the struct.
const llvm_u32 = self.context.intType(32);
const llvm_index = llvm_u32.constInt(@boolToInt(struct_ty.hasRuntimeBitsIgnoreComptime(mod)), .False);
const llvm_index = llvm_u32.constInt(@intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(mod)), .False);
const indices: [1]*llvm.Value = .{llvm_index};
return self.builder.buildInBoundsGEP(struct_llvm_ty, struct_ptr, &indices, indices.len, "");
}
@@ -9605,7 +9605,7 @@ pub const FuncGen = struct {
.Union => {
const layout = struct_ty.unionGetLayout(mod);
if (layout.payload_size == 0 or struct_ty.containerLayout(mod) == .Packed) return struct_ptr;
const payload_index = @boolToInt(layout.tag_align >= layout.payload_align);
const payload_index = @intFromBool(layout.tag_align >= layout.payload_align);
const union_llvm_ty = try self.dg.lowerType(struct_ty);
const union_field_ptr = self.builder.buildStructGEP(union_llvm_ty, struct_ptr, payload_index, "");
return union_field_ptr;
@@ -9658,7 +9658,7 @@ pub const FuncGen = struct {
assert(info.vector_index != .runtime);
if (info.vector_index != .none) {
const index_u32 = self.context.intType(32).constInt(@enumToInt(info.vector_index), .False);
const index_u32 = self.context.intType(32).constInt(@intFromEnum(info.vector_index), .False);
const vec_elem_ty = try self.dg.lowerType(info.pointee_type);
const vec_ty = vec_elem_ty.vectorType(info.host_size);
@@ -9734,7 +9734,7 @@ pub const FuncGen = struct {
assert(info.vector_index != .runtime);
if (info.vector_index != .none) {
const index_u32 = self.context.intType(32).constInt(@enumToInt(info.vector_index), .False);
const index_u32 = self.context.intType(32).constInt(@intFromEnum(info.vector_index), .False);
const vec_elem_ty = try self.dg.lowerType(elem_ty);
const vec_ty = vec_elem_ty.vectorType(info.host_size);
@@ -11025,29 +11025,29 @@ const AnnotatedDITypePtr = enum(usize) {
_,
fn initFwd(di_type: *llvm.DIType) AnnotatedDITypePtr {
const addr = @ptrToInt(di_type);
const addr = @intFromPtr(di_type);
assert(@truncate(u1, addr) == 0);
return @intToEnum(AnnotatedDITypePtr, addr | 1);
return @enumFromInt(AnnotatedDITypePtr, addr | 1);
}
fn initFull(di_type: *llvm.DIType) AnnotatedDITypePtr {
const addr = @ptrToInt(di_type);
return @intToEnum(AnnotatedDITypePtr, addr);
const addr = @intFromPtr(di_type);
return @enumFromInt(AnnotatedDITypePtr, addr);
}
fn init(di_type: *llvm.DIType, resolve: Object.DebugResolveStatus) AnnotatedDITypePtr {
const addr = @ptrToInt(di_type);
const bit = @boolToInt(resolve == .fwd);
return @intToEnum(AnnotatedDITypePtr, addr | bit);
const addr = @intFromPtr(di_type);
const bit = @intFromBool(resolve == .fwd);
return @enumFromInt(AnnotatedDITypePtr, addr | bit);
}
fn toDIType(self: AnnotatedDITypePtr) *llvm.DIType {
const fixed_addr = @enumToInt(self) & ~@as(usize, 1);
return @intToPtr(*llvm.DIType, fixed_addr);
const fixed_addr = @intFromEnum(self) & ~@as(usize, 1);
return @ptrFromInt(*llvm.DIType, fixed_addr);
}
fn isFwdOnly(self: AnnotatedDITypePtr) bool {
return @truncate(u1, @enumToInt(self)) != 0;
return @truncate(u1, @intFromEnum(self)) != 0;
}
};
@@ -11118,11 +11118,11 @@ fn buildAllocaInner(
}
fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u1 {
return @boolToInt(Type.anyerror.abiAlignment(mod) > payload_ty.abiAlignment(mod));
return @intFromBool(Type.anyerror.abiAlignment(mod) > payload_ty.abiAlignment(mod));
}
fn errUnionErrorOffset(payload_ty: Type, mod: *Module) u1 {
return @boolToInt(Type.anyerror.abiAlignment(mod) <= payload_ty.abiAlignment(mod));
return @intFromBool(Type.anyerror.abiAlignment(mod) <= payload_ty.abiAlignment(mod));
}
/// Returns true for asm constraint (e.g. "=*m", "=r") if it accepts a memory location

View File

@@ -8,7 +8,7 @@ pub const Bool = enum(c_int) {
_,
pub fn fromBool(b: bool) Bool {
return @intToEnum(Bool, @boolToInt(b));
return @enumFromInt(Bool, @intFromBool(b));
}
pub fn toBool(b: Bool) bool {

View File

@@ -387,7 +387,7 @@ pub const DeclGen = struct {
switch (repr) {
.indirect => {
const int_ty_ref = try self.intType(.unsigned, 1);
return self.spv.constInt(int_ty_ref, @boolToInt(value));
return self.spv.constInt(int_ty_ref, @intFromBool(value));
},
.direct => {
const bool_ty_ref = try self.resolveType(Type.bool, .direct);
@@ -532,7 +532,7 @@ pub const DeclGen = struct {
}
fn addConstBool(self: *@This(), value: bool) !void {
try self.addByte(@boolToInt(value)); // TODO: Keep in sync with something?
try self.addByte(@intFromBool(value)); // TODO: Keep in sync with something?
}
fn addInt(self: *@This(), ty: Type, val: Value) !void {
@@ -697,7 +697,7 @@ pub const DeclGen = struct {
try self.addUndef(padding);
},
.enum_tag => {
const int_val = try val.enumToInt(ty, mod);
const int_val = try val.intFromEnum(ty, mod);
const int_ty = ty.intTagType(mod);
@@ -873,7 +873,7 @@ pub const DeclGen = struct {
assert(storage_class != .Generic and storage_class != .Function);
const var_id = self.spv.allocId();
log.debug("lowerIndirectConstant: id = {}, index = {}, ty = {}, val = {}", .{ var_id.id, @enumToInt(spv_decl_index), ty.fmt(self.module), val.fmtDebug() });
log.debug("lowerIndirectConstant: id = {}, index = {}, ty = {}, val = {}", .{ var_id.id, @intFromEnum(spv_decl_index), ty.fmt(self.module), val.fmtDebug() });
const section = &self.spv.globals.section;
@@ -1010,7 +1010,7 @@ pub const DeclGen = struct {
false,
alignment,
);
log.debug("indirect constant: index = {}", .{@enumToInt(spv_decl_index)});
log.debug("indirect constant: index = {}", .{@intFromEnum(spv_decl_index)});
try self.func.decl_deps.put(self.spv.gpa, spv_decl_index, {});
try self.func.body.emit(self.spv.gpa, .OpLoad, .{
@@ -1578,7 +1578,7 @@ pub const DeclGen = struct {
}
}
fn boolToInt(self: *DeclGen, result_ty_ref: CacheRef, condition_id: IdRef) !IdRef {
fn intFromBool(self: *DeclGen, result_ty_ref: CacheRef, condition_id: IdRef) !IdRef {
const zero_id = try self.spv.constInt(result_ty_ref, 0);
const one_id = try self.spv.constInt(result_ty_ref, 1);
const result_id = self.spv.allocId();
@@ -1621,7 +1621,7 @@ pub const DeclGen = struct {
return switch (ty.zigTypeTag(mod)) {
.Bool => blk: {
const indirect_bool_ty_ref = try self.resolveType(ty, .indirect);
break :blk self.boolToInt(indirect_bool_ty_ref, operand_id);
break :blk self.intFromBool(indirect_bool_ty_ref, operand_id);
},
else => operand_id,
};
@@ -2011,7 +2011,7 @@ pub const DeclGen = struct {
// Construct the struct that Zig wants as result.
// The value should already be the correct type.
const ov_id = try self.boolToInt(ov_ty_ref, overflowed_id);
const ov_id = try self.intFromBool(ov_ty_ref, overflowed_id);
const result_ty_ref = try self.resolveType(result_ty, .direct);
return try self.constructStruct(result_ty_ref, &.{
value_id,
@@ -2515,7 +2515,7 @@ pub const DeclGen = struct {
if (layout.payload_size == 0) return union_handle;
const tag_ty = un_ty.unionTagTypeSafety().?;
const tag_index = @boolToInt(layout.tag_align < layout.payload_align);
const tag_index = @intFromBool(layout.tag_align < layout.payload_align);
return try self.extractField(tag_ty, union_handle, tag_index);
}
@@ -3105,7 +3105,7 @@ pub const DeclGen = struct {
.Int => if (cond_ty.isSignedInt(mod)) @bitCast(u64, value.toSignedInt(mod)) else value.toUnsignedInt(mod),
.Enum => blk: {
// TODO: figure out of cond_ty is correct (something with enum literals)
break :blk (try value.enumToInt(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
},
else => unreachable,
};

View File

@@ -306,7 +306,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
},
.OpTypePointer => try self.spv.ptrType(
try self.resolveTypeRef(operands[2].ref_id),
@intToEnum(spec.StorageClass, operands[1].value),
@enumFromInt(spec.StorageClass, operands[1].value),
),
.OpTypeFunction => blk: {
const param_operands = operands[2..];
@@ -340,7 +340,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
else => switch (self.inst.opcode) {
.OpEntryPoint => unreachable,
.OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,
.OpVariable => switch (@intToEnum(spec.StorageClass, operands[2].value)) {
.OpVariable => switch (@enumFromInt(spec.StorageClass, operands[2].value)) {
.Function => &self.func.prologue,
else => {
// This is currently disabled because global variables are required to be
@@ -391,7 +391,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
}
const actual_word_count = section.instructions.items.len - first_word;
section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @enumToInt(self.inst.opcode);
section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @intFromEnum(self.inst.opcode);
if (maybe_result_id) |result| {
return AsmValue{ .value = result };
@@ -695,7 +695,7 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness
.unsigned => 0,
.signed => -(@as(i128, 1) << (@intCast(u7, width) - 1)),
};
const max = (@as(i128, 1) << (@intCast(u7, width) - @boolToInt(signedness == .signed))) - 1;
const max = (@as(i128, 1) << (@intCast(u7, width) - @intFromBool(signedness == .signed))) - 1;
if (int < min or int > max) {
break :invalid;
}

View File

@@ -411,7 +411,7 @@ pub const Key = union(enum) {
pub fn eql(ctx: @This(), a: Key, b_void: void, b_index: usize) bool {
_ = b_void;
return ctx.self.lookup(@intToEnum(Ref, b_index)).eql(a);
return ctx.self.lookup(@enumFromInt(Ref, b_index)).eql(a);
}
pub fn hash(ctx: @This(), a: Key) u32 {
@@ -445,7 +445,7 @@ pub fn materialize(self: *const Self, spv: *Module) !Section {
var section = Section{};
errdefer section.deinit(spv.gpa);
for (self.items.items(.result_id), 0..) |result_id, index| {
try self.emit(spv, result_id, @intToEnum(Ref, index), &section);
try self.emit(spv, result_id, @enumFromInt(Ref, index), &section);
}
return section;
}
@@ -603,14 +603,14 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
const adapter: Key.Adapter = .{ .self = self };
const entry = try self.map.getOrPutAdapted(spv.gpa, key, adapter);
if (entry.found_existing) {
return @intToEnum(Ref, entry.index);
return @enumFromInt(Ref, entry.index);
}
const result_id = spv.allocId();
const item: Item = switch (key) {
inline .void_type, .bool_type => .{
.tag = .type_simple,
.result_id = result_id,
.data = @enumToInt(key.toSimpleType()),
.data = @intFromEnum(key.toSimpleType()),
},
.int_type => |int| blk: {
const t: Tag = switch (int.signedness) {
@@ -654,17 +654,17 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
.Generic => Item{
.tag = .type_ptr_generic,
.result_id = result_id,
.data = @enumToInt(ptr.child_type),
.data = @intFromEnum(ptr.child_type),
},
.CrossWorkgroup => Item{
.tag = .type_ptr_crosswgp,
.result_id = result_id,
.data = @enumToInt(ptr.child_type),
.data = @intFromEnum(ptr.child_type),
},
.Function => Item{
.tag = .type_ptr_function,
.result_id = result_id,
.data = @enumToInt(ptr.child_type),
.data = @intFromEnum(ptr.child_type),
},
else => |storage_class| Item{
.tag = .type_ptr_simple,
@@ -770,12 +770,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
.undef => |undef| .{
.tag = .undef,
.result_id = result_id,
.data = @enumToInt(undef.ty),
.data = @intFromEnum(undef.ty),
},
.null => |null_info| .{
.tag = .null,
.result_id = result_id,
.data = @enumToInt(null_info.ty),
.data = @intFromEnum(null_info.ty),
},
.bool => |bool_info| .{
.tag = switch (bool_info.value) {
@@ -783,21 +783,21 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
false => Tag.bool_false,
},
.result_id = result_id,
.data = @enumToInt(bool_info.ty),
.data = @intFromEnum(bool_info.ty),
},
};
try self.items.append(spv.gpa, item);
return @intToEnum(Ref, entry.index);
return @enumFromInt(Ref, entry.index);
}
/// Turn a Ref back into a Key.
/// The Key is valid until the next call to resolve().
pub fn lookup(self: *const Self, ref: Ref) Key {
const item = self.items.get(@enumToInt(ref));
const item = self.items.get(@intFromEnum(ref));
const data = item.data;
return switch (item.tag) {
.type_simple => switch (@intToEnum(Tag.SimpleType, data)) {
.type_simple => switch (@enumFromInt(Tag.SimpleType, data)) {
.void => .void_type,
.bool => .bool_type,
},
@@ -826,19 +826,19 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
.type_ptr_generic => .{
.ptr_type = .{
.storage_class = .Generic,
.child_type = @intToEnum(Ref, data),
.child_type = @enumFromInt(Ref, data),
},
},
.type_ptr_crosswgp => .{
.ptr_type = .{
.storage_class = .CrossWorkgroup,
.child_type = @intToEnum(Ref, data),
.child_type = @enumFromInt(Ref, data),
},
},
.type_ptr_function => .{
.ptr_type = .{
.storage_class = .Function,
.child_type = @intToEnum(Ref, data),
.child_type = @enumFromInt(Ref, data),
},
},
.type_ptr_simple => {
@@ -923,17 +923,17 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
} };
},
.undef => .{ .undef = .{
.ty = @intToEnum(Ref, data),
.ty = @enumFromInt(Ref, data),
} },
.null => .{ .null = .{
.ty = @intToEnum(Ref, data),
.ty = @enumFromInt(Ref, data),
} },
.bool_true => .{ .bool = .{
.ty = @intToEnum(Ref, data),
.ty = @enumFromInt(Ref, data),
.value = true,
} },
.bool_false => .{ .bool = .{
.ty = @intToEnum(Ref, data),
.ty = @enumFromInt(Ref, data),
.value = false,
} },
};
@@ -942,14 +942,14 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
/// Look op the result-id that corresponds to a particular
/// ref.
pub fn resultId(self: Self, ref: Ref) IdResult {
return self.items.items(.result_id)[@enumToInt(ref)];
return self.items.items(.result_id)[@intFromEnum(ref)];
}
/// Get the ref for a key that has already been added to the cache.
fn get(self: *const Self, key: Key) Ref {
const adapter: Key.Adapter = .{ .self = self };
const index = self.map.getIndexAdapted(key, adapter).?;
return @intToEnum(Ref, index);
return @enumFromInt(Ref, index);
}
fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
@@ -965,9 +965,9 @@ fn addExtraAssumeCapacity(self: *Self, extra: anytype) !u32 {
const word = switch (field.type) {
u32 => field_val,
i32 => @bitCast(u32, field_val),
Ref => @enumToInt(field_val),
StorageClass => @enumToInt(field_val),
String => @enumToInt(field_val),
Ref => @intFromEnum(field_val),
StorageClass => @intFromEnum(field_val),
String => @intFromEnum(field_val),
else => @compileError("Invalid type: " ++ @typeName(field.type)),
};
self.extra.appendAssumeCapacity(word);
@@ -987,9 +987,9 @@ fn extraDataTrail(self: Self, comptime T: type, offset: u32) struct { data: T, t
@field(result, field.name) = switch (field.type) {
u32 => word,
i32 => @bitCast(i32, word),
Ref => @intToEnum(Ref, word),
StorageClass => @intToEnum(StorageClass, word),
String => @intToEnum(String, word),
Ref => @enumFromInt(Ref, word),
StorageClass => @enumFromInt(StorageClass, word),
String => @enumFromInt(String, word),
else => @compileError("Invalid type: " ++ @typeName(field.type)),
};
}
@@ -1035,12 +1035,12 @@ pub fn addString(self: *Self, spv: *Module, str: []const u8) !String {
entry.value_ptr.* = @intCast(u32, offset);
}
return @intToEnum(String, entry.index);
return @enumFromInt(String, entry.index);
}
pub fn getString(self: *const Self, ref: String) ?[]const u8 {
return switch (ref) {
.none => null,
else => std.mem.sliceTo(self.string_bytes.items[self.strings.values()[@enumToInt(ref)]..], 0),
else => std.mem.sliceTo(self.string_bytes.items[self.strings.values()[@intFromEnum(ref)]..], 0),
};
}

View File

@@ -246,10 +246,10 @@ fn orderGlobalsInto(
const global = self.globalPtr(decl_index).?;
const insts = self.globals.section.instructions.items[global.begin_inst..global.end_inst];
seen.set(@enumToInt(decl_index));
seen.set(@intFromEnum(decl_index));
for (deps) |dep| {
if (!seen.isSet(@enumToInt(dep))) {
if (!seen.isSet(@intFromEnum(dep))) {
try self.orderGlobalsInto(dep, section, seen);
}
}
@@ -267,7 +267,7 @@ fn orderGlobals(self: *Module) !Section {
errdefer ordered_globals.deinit(self.gpa);
for (globals) |decl_index| {
if (!seen.isSet(@enumToInt(decl_index))) {
if (!seen.isSet(@intFromEnum(decl_index))) {
try self.orderGlobalsInto(decl_index, &ordered_globals, &seen);
}
}
@@ -284,14 +284,14 @@ fn addEntryPointDeps(
const decl = self.declPtr(decl_index);
const deps = self.decl_deps.items[decl.begin_dep..decl.end_dep];
seen.set(@enumToInt(decl_index));
seen.set(@intFromEnum(decl_index));
if (self.globalPtr(decl_index)) |global| {
try interface.append(global.result_id);
}
for (deps) |dep| {
if (!seen.isSet(@enumToInt(dep))) {
if (!seen.isSet(@intFromEnum(dep))) {
try self.addEntryPointDeps(dep, seen, interface);
}
}
@@ -516,7 +516,7 @@ pub fn allocDecl(self: *Module, kind: DeclKind) !Decl.Index {
.begin_dep = undefined,
.end_dep = undefined,
});
const index = @intToEnum(Decl.Index, @intCast(u32, self.decls.items.len - 1));
const index = @enumFromInt(Decl.Index, @intCast(u32, self.decls.items.len - 1));
switch (kind) {
.func => {},
// If the decl represents a global, also allocate a global node.
@@ -531,7 +531,7 @@ pub fn allocDecl(self: *Module, kind: DeclKind) !Decl.Index {
}
pub fn declPtr(self: *Module, index: Decl.Index) *Decl {
return &self.decls.items[@enumToInt(index)];
return &self.decls.items[@intFromEnum(index)];
}
pub fn globalPtr(self: *Module, index: Decl.Index) ?*Global {

View File

@@ -50,7 +50,7 @@ pub fn emitRaw(
) !void {
const word_count = 1 + operand_words;
try section.instructions.ensureUnusedCapacity(allocator, word_count);
section.writeWord((@intCast(Word, word_count << 16)) | @enumToInt(opcode));
section.writeWord((@intCast(Word, word_count << 16)) | @intFromEnum(opcode));
}
pub fn emit(
@@ -61,7 +61,7 @@ pub fn emit(
) !void {
const word_count = instructionSize(opcode, operands);
try section.instructions.ensureUnusedCapacity(allocator, word_count);
section.writeWord(@intCast(Word, word_count << 16) | @enumToInt(opcode));
section.writeWord(@intCast(Word, word_count << 16) | @intFromEnum(opcode));
section.writeOperands(opcode.Operands(), operands);
}
@@ -126,14 +126,14 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
// TODO: Where this type is used (OpSpecConstantOp) is currently not correct in the spec json,
// so it most likely needs to be altered into something that can actually describe the entire
// instruction in which it is used.
spec.LiteralSpecConstantOpInteger => section.writeWord(@enumToInt(operand.opcode)),
spec.LiteralSpecConstantOpInteger => section.writeWord(@intFromEnum(operand.opcode)),
spec.PairLiteralIntegerIdRef => section.writeWords(&.{ operand.value, operand.label.id }),
spec.PairIdRefLiteralInteger => section.writeWords(&.{ operand.target.id, operand.member }),
spec.PairIdRefIdRef => section.writeWords(&.{ operand[0].id, operand[1].id }),
else => switch (@typeInfo(Operand)) {
.Enum => section.writeWord(@enumToInt(operand)),
.Enum => section.writeWord(@intFromEnum(operand)),
.Optional => |info| if (operand) |child| {
section.writeOperand(info.child, child);
},
@@ -217,7 +217,7 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
fn writeExtendedUnion(section: *Section, comptime Operand: type, operand: Operand) void {
const tag = std.meta.activeTag(operand);
section.writeWord(@enumToInt(tag));
section.writeWord(@intFromEnum(tag));
inline for (@typeInfo(Operand).Union.fields) |field| {
if (@field(Operand, field.name) == tag) {
@@ -327,7 +327,7 @@ test "SPIR-V Section emit() - no operands" {
try section.emit(std.testing.allocator, .OpNop, {});
try testing.expect(section.instructions.items[0] == (@as(Word, 1) << 16) | @enumToInt(Opcode.OpNop));
try testing.expect(section.instructions.items[0] == (@as(Word, 1) << 16) | @intFromEnum(Opcode.OpNop));
}
test "SPIR-V Section emit() - simple" {
@@ -340,7 +340,7 @@ test "SPIR-V Section emit() - simple" {
});
try testing.expectEqualSlices(Word, &.{
(@as(Word, 3) << 16) | @enumToInt(Opcode.OpUndef),
(@as(Word, 3) << 16) | @intFromEnum(Opcode.OpUndef),
0,
1,
}, section.instructions.items);
@@ -358,8 +358,8 @@ test "SPIR-V Section emit() - string" {
});
try testing.expectEqualSlices(Word, &.{
(@as(Word, 10) << 16) | @enumToInt(Opcode.OpSource),
@enumToInt(spec.SourceLanguage.Unknown),
(@as(Word, 10) << 16) | @intFromEnum(Opcode.OpSource),
@intFromEnum(spec.SourceLanguage.Unknown),
123,
456,
std.mem.bytesToValue(Word, "pub "),
@@ -389,7 +389,7 @@ test "SPIR-V Section emit() - extended mask" {
});
try testing.expectEqualSlices(Word, &.{
(@as(Word, 5) << 16) | @enumToInt(Opcode.OpLoopMerge),
(@as(Word, 5) << 16) | @intFromEnum(Opcode.OpLoopMerge),
10,
20,
@bitCast(Word, spec.LoopControl{ .Unroll = true, .DependencyLength = true }),
@@ -409,9 +409,9 @@ test "SPIR-V Section emit() - extended union" {
});
try testing.expectEqualSlices(Word, &.{
(@as(Word, 6) << 16) | @enumToInt(Opcode.OpExecutionMode),
(@as(Word, 6) << 16) | @intFromEnum(Opcode.OpExecutionMode),
888,
@enumToInt(spec.ExecutionMode.LocalSize),
@intFromEnum(spec.ExecutionMode.LocalSize),
4,
8,
16,