mirror of
https://github.com/ziglang/zig.git
synced 2026-01-11 09:55:12 +00:00
Merge pull request #17762 from ziglang/zir-index-type-safety
make Zir.Inst.Index typed
This commit is contained in:
commit
e69fd4d696
@ -3527,21 +3527,33 @@ test "max" {
|
||||
/// Finds the smallest and largest number in a slice. O(n).
|
||||
/// Returns an anonymous struct with the fields `min` and `max`.
|
||||
/// `slice` must not be empty.
|
||||
pub fn minMax(comptime T: type, slice: []const T) struct { min: T, max: T } {
|
||||
pub fn minMax(comptime T: type, slice: []const T) struct { T, T } {
|
||||
assert(slice.len > 0);
|
||||
var minVal = slice[0];
|
||||
var maxVal = slice[0];
|
||||
var running_minimum = slice[0];
|
||||
var running_maximum = slice[0];
|
||||
for (slice[1..]) |item| {
|
||||
minVal = @min(minVal, item);
|
||||
maxVal = @max(maxVal, item);
|
||||
running_minimum = @min(running_minimum, item);
|
||||
running_maximum = @max(running_maximum, item);
|
||||
}
|
||||
return .{ .min = minVal, .max = maxVal };
|
||||
return .{ running_minimum, running_maximum };
|
||||
}
|
||||
|
||||
test "minMax" {
|
||||
try testing.expectEqual(minMax(u8, "abcdefg"), .{ .min = 'a', .max = 'g' });
|
||||
try testing.expectEqual(minMax(u8, "bcdefga"), .{ .min = 'a', .max = 'g' });
|
||||
try testing.expectEqual(minMax(u8, "a"), .{ .min = 'a', .max = 'a' });
|
||||
test minMax {
|
||||
{
|
||||
const actual_min, const actual_max = minMax(u8, "abcdefg");
|
||||
try testing.expectEqual(@as(u8, 'a'), actual_min);
|
||||
try testing.expectEqual(@as(u8, 'g'), actual_max);
|
||||
}
|
||||
{
|
||||
const actual_min, const actual_max = minMax(u8, "bcdefga");
|
||||
try testing.expectEqual(@as(u8, 'a'), actual_min);
|
||||
try testing.expectEqual(@as(u8, 'g'), actual_max);
|
||||
}
|
||||
{
|
||||
const actual_min, const actual_max = minMax(u8, "a");
|
||||
try testing.expectEqual(@as(u8, 'a'), actual_min);
|
||||
try testing.expectEqual(@as(u8, 'a'), actual_max);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the index of the smallest number in a slice. O(n).
|
||||
|
||||
357
src/AstGen.zig
357
src/AstGen.zig
File diff suppressed because it is too large
Load Diff
412
src/Autodoc.zig
412
src/Autodoc.zig
File diff suppressed because it is too large
Load Diff
@ -580,7 +580,7 @@ pub const Key = union(enum) {
|
||||
pub fn setZirIndex(s: @This(), ip: *InternPool, new_zir_index: Zir.Inst.Index) void {
|
||||
assert(s.layout != .Packed);
|
||||
const field_index = std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?;
|
||||
ip.extra.items[s.extra_index + field_index] = new_zir_index;
|
||||
ip.extra.items[s.extra_index + field_index] = @intFromEnum(new_zir_index);
|
||||
}
|
||||
|
||||
pub fn haveFieldTypes(s: @This(), ip: *const InternPool) bool {
|
||||
@ -2481,7 +2481,14 @@ pub const static_keys = [_]Key{
|
||||
};
|
||||
|
||||
/// How many items in the InternPool are statically known.
|
||||
pub const static_len: u32 = static_keys.len;
|
||||
/// This is specified with an integer literal and a corresponding comptime
|
||||
/// assert below to break an unfortunate and arguably incorrect dependency loop
|
||||
/// when compiling.
|
||||
pub const static_len = 84;
|
||||
comptime {
|
||||
//@compileLog(static_keys.len);
|
||||
assert(static_len == static_keys.len);
|
||||
}
|
||||
|
||||
pub const Tag = enum(u8) {
|
||||
/// An integer type.
|
||||
@ -3658,7 +3665,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
|
||||
.extra_index = 0,
|
||||
.namespace = .none,
|
||||
.decl = .none,
|
||||
.zir_index = @as(u32, undefined),
|
||||
.zir_index = undefined,
|
||||
.layout = .Auto,
|
||||
.field_names = .{ .start = 0, .len = 0 },
|
||||
.field_types = .{ .start = 0, .len = 0 },
|
||||
@ -3674,7 +3681,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
|
||||
.extra_index = 0,
|
||||
.namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(),
|
||||
.decl = .none,
|
||||
.zir_index = @as(u32, undefined),
|
||||
.zir_index = undefined,
|
||||
.layout = .Auto,
|
||||
.field_names = .{ .start = 0, .len = 0 },
|
||||
.field_types = .{ .start = 0, .len = 0 },
|
||||
@ -6403,6 +6410,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
|
||||
NullTerminatedString,
|
||||
OptionalNullTerminatedString,
|
||||
Tag.TypePointer.VectorIndex,
|
||||
Zir.Inst.Index,
|
||||
=> @intFromEnum(@field(extra, field.name)),
|
||||
|
||||
u32,
|
||||
@ -6477,6 +6485,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
|
||||
NullTerminatedString,
|
||||
OptionalNullTerminatedString,
|
||||
Tag.TypePointer.VectorIndex,
|
||||
Zir.Inst.Index,
|
||||
=> @enumFromInt(int32),
|
||||
|
||||
u32,
|
||||
@ -8191,7 +8200,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index {
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
return ip.extra.items[extra_index];
|
||||
return @enumFromInt(ip.extra.items[extra_index]);
|
||||
}
|
||||
|
||||
pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index {
|
||||
|
||||
@ -389,7 +389,7 @@ pub const Decl = struct {
|
||||
/// Index to ZIR `extra` array to the entry in the parent's decl structure
|
||||
/// (the part that says "for every decls_len"). The first item at this index is
|
||||
/// the contents hash, followed by line, name, etc.
|
||||
/// For anonymous decls and also the root Decl for a File, this is 0.
|
||||
/// For anonymous decls and also the root Decl for a File, this is `none`.
|
||||
zir_decl_index: Zir.OptionalExtraIndex,
|
||||
|
||||
/// Represents the "shallow" analysis status. For example, for decls that are functions,
|
||||
@ -547,7 +547,7 @@ pub const Decl = struct {
|
||||
pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index {
|
||||
assert(decl.zir_decl_index != .none);
|
||||
const zir = decl.getFileScope(mod).zir;
|
||||
return zir.extra[@intFromEnum(decl.zir_decl_index) + 6];
|
||||
return @enumFromInt(zir.extra[@intFromEnum(decl.zir_decl_index) + 6]);
|
||||
}
|
||||
|
||||
pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
|
||||
@ -1205,9 +1205,8 @@ pub const File = struct {
|
||||
if (imports_index == 0) return;
|
||||
const extra = file.zir.extraData(Zir.Inst.Imports, imports_index);
|
||||
|
||||
var import_i: u32 = 0;
|
||||
var extra_index = extra.end;
|
||||
while (import_i < extra.data.imports_len) : (import_i += 1) {
|
||||
for (0..extra.data.imports_len) |_| {
|
||||
const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
|
||||
extra_index = item.end;
|
||||
|
||||
@ -3206,8 +3205,8 @@ pub fn mapOldZirToNew(
|
||||
|
||||
// Main struct inst is always the same
|
||||
try match_stack.append(gpa, .{
|
||||
.old_inst = Zir.main_struct_inst,
|
||||
.new_inst = Zir.main_struct_inst,
|
||||
.old_inst = .main_struct_inst,
|
||||
.new_inst = .main_struct_inst,
|
||||
});
|
||||
|
||||
var old_decls = std.ArrayList(Zir.Inst.Index).init(gpa);
|
||||
@ -3622,11 +3621,10 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
};
|
||||
defer sema.deinit();
|
||||
|
||||
const main_struct_inst = Zir.main_struct_inst;
|
||||
const struct_ty = sema.getStructType(
|
||||
new_decl_index,
|
||||
new_namespace_index,
|
||||
main_struct_inst,
|
||||
.main_struct_inst,
|
||||
) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
};
|
||||
@ -3754,11 +3752,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
|
||||
defer block_scope.instructions.deinit(gpa);
|
||||
|
||||
const zir_block_index = decl.zirBlockIndex(mod);
|
||||
const inst_data = zir_datas[zir_block_index].pl_node;
|
||||
const inst_data = zir_datas[@intFromEnum(zir_block_index)].pl_node;
|
||||
const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index);
|
||||
const body = zir.extra[extra.end..][0..extra.data.body_len];
|
||||
const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;
|
||||
// We'll do some other bits with the Sema. Clear the type target index just in case they analyze any type.
|
||||
const result_ref = (try sema.analyzeBodyBreak(&block_scope, @ptrCast(body))).?.operand;
|
||||
// We'll do some other bits with the Sema. Clear the type target index just
|
||||
// in case they analyze any type.
|
||||
sema.builtin_type_target_index = .none;
|
||||
for (comptime_mutable_decls.items) |ct_decl_index| {
|
||||
const ct_decl = mod.declPtr(ct_decl_index);
|
||||
@ -6471,13 +6470,13 @@ pub fn getParamName(mod: *Module, func_index: InternPool.Index, index: u32) [:0]
|
||||
const param_body = file.zir.getParamBody(func.zir_body_inst);
|
||||
const param = param_body[index];
|
||||
|
||||
return switch (tags[param]) {
|
||||
return switch (tags[@intFromEnum(param)]) {
|
||||
.param, .param_comptime => blk: {
|
||||
const extra = file.zir.extraData(Zir.Inst.Param, data[param].pl_tok.payload_index);
|
||||
const extra = file.zir.extraData(Zir.Inst.Param, data[@intFromEnum(param)].pl_tok.payload_index);
|
||||
break :blk file.zir.nullTerminatedString(extra.data.name);
|
||||
},
|
||||
.param_anytype, .param_anytype_comptime => blk: {
|
||||
const param_data = data[param].str_tok;
|
||||
const param_data = data[@intFromEnum(param)].str_tok;
|
||||
break :blk param_data.get(file.zir);
|
||||
},
|
||||
else => unreachable,
|
||||
|
||||
732
src/Sema.zig
732
src/Sema.zig
File diff suppressed because it is too large
Load Diff
179
src/Zir.zig
179
src/Zir.zig
@ -93,13 +93,18 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
|
||||
inline for (fields) |field| {
|
||||
@field(result, field.name) = switch (field.type) {
|
||||
u32 => code.extra[i],
|
||||
Inst.Ref => @enumFromInt(code.extra[i]),
|
||||
|
||||
Inst.Ref,
|
||||
Inst.Index,
|
||||
=> @enumFromInt(code.extra[i]),
|
||||
|
||||
i32,
|
||||
Inst.Call.Flags,
|
||||
Inst.BuiltinCall.Flags,
|
||||
Inst.SwitchBlock.Bits,
|
||||
Inst.FuncFancy.Bits,
|
||||
=> @bitCast(code.extra[i]),
|
||||
|
||||
else => @compileError("bad field type"),
|
||||
};
|
||||
i += 1;
|
||||
@ -134,6 +139,10 @@ pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
|
||||
return @ptrCast(code.extra[start..][0..len]);
|
||||
}
|
||||
|
||||
pub fn bodySlice(zir: Zir, start: usize, len: usize) []Inst.Index {
|
||||
return @ptrCast(zir.extra[start..][0..len]);
|
||||
}
|
||||
|
||||
pub fn hasCompileErrors(code: Zir) bool {
|
||||
return code.extra[@intFromEnum(ExtraIndex.compile_errors)] != 0;
|
||||
}
|
||||
@ -145,10 +154,6 @@ pub fn deinit(code: *Zir, gpa: Allocator) void {
|
||||
code.* = undefined;
|
||||
}
|
||||
|
||||
/// ZIR is structured so that the outermost "main" struct of any file
|
||||
/// is always at index 0.
|
||||
pub const main_struct_inst: Inst.Index = 0;
|
||||
|
||||
/// These are untyped instructions generated from an Abstract Syntax Tree.
|
||||
/// The data here is immutable because it is possible to have multiple
|
||||
/// analyses on the same ZIR happening at the same time.
|
||||
@ -2093,7 +2098,34 @@ pub const Inst = struct {
|
||||
};
|
||||
|
||||
/// The position of a ZIR instruction within the `Zir` instructions array.
|
||||
pub const Index = u32;
|
||||
pub const Index = enum(u32) {
|
||||
/// ZIR is structured so that the outermost "main" struct of any file
|
||||
/// is always at index 0.
|
||||
main_struct_inst = 0,
|
||||
ref_start_index = InternPool.static_len,
|
||||
_,
|
||||
|
||||
pub fn toRef(i: Index) Inst.Ref {
|
||||
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
|
||||
}
|
||||
|
||||
pub fn toOptional(i: Index) OptionalIndex {
|
||||
return @enumFromInt(@intFromEnum(i));
|
||||
}
|
||||
};
|
||||
|
||||
pub const OptionalIndex = enum(u32) {
|
||||
/// ZIR is structured so that the outermost "main" struct of any file
|
||||
/// is always at index 0.
|
||||
main_struct_inst = 0,
|
||||
ref_start_index = InternPool.static_len,
|
||||
none = std.math.maxInt(u32),
|
||||
_,
|
||||
|
||||
pub fn unwrap(oi: OptionalIndex) ?Index {
|
||||
return if (oi == .none) null else @enumFromInt(@intFromEnum(oi));
|
||||
}
|
||||
};
|
||||
|
||||
/// A reference to ZIR instruction, or to an InternPool index, or neither.
|
||||
///
|
||||
@ -2196,6 +2228,21 @@ pub const Inst = struct {
|
||||
/// value and may instead be used as a sentinel to indicate null.
|
||||
none = @intFromEnum(InternPool.Index.none),
|
||||
_,
|
||||
|
||||
pub fn toIndex(inst: Ref) ?Index {
|
||||
assert(inst != .none);
|
||||
const ref_int = @intFromEnum(inst);
|
||||
if (ref_int >= @intFromEnum(Index.ref_start_index)) {
|
||||
return @enumFromInt(ref_int - @intFromEnum(Index.ref_start_index));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toIndexAllowNone(inst: Ref) ?Index {
|
||||
if (inst == .none) return null;
|
||||
return toIndex(inst);
|
||||
}
|
||||
};
|
||||
|
||||
/// All instructions have an 8-byte payload, which is contained within
|
||||
@ -3286,7 +3333,7 @@ pub const Inst = struct {
|
||||
|
||||
/// Trailing: for each `imports_len` there is an Item
|
||||
pub const Imports = struct {
|
||||
imports_len: Inst.Index,
|
||||
imports_len: u32,
|
||||
|
||||
pub const Item = struct {
|
||||
/// null terminated string index
|
||||
@ -3371,16 +3418,16 @@ pub const DeclIterator = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
|
||||
pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator {
|
||||
const tags = zir.instructions.items(.tag);
|
||||
const datas = zir.instructions.items(.data);
|
||||
switch (tags[decl_inst]) {
|
||||
switch (tags[@intFromEnum(decl_inst)]) {
|
||||
// Functions are allowed and yield no iterations.
|
||||
// There is one case matching this in the extended instruction set below.
|
||||
.func, .func_inferred, .func_fancy => return declIteratorInner(zir, 0, 0),
|
||||
|
||||
.extended => {
|
||||
const extended = datas[decl_inst].extended;
|
||||
const extended = datas[@intFromEnum(decl_inst)].extended;
|
||||
switch (extended.opcode) {
|
||||
.struct_decl => {
|
||||
const small: Inst.StructDecl.Small = @bitCast(extended.small);
|
||||
@ -3469,7 +3516,7 @@ pub fn declIteratorInner(zir: Zir, extra_index: usize, decls_len: u32) DeclItera
|
||||
/// The iterator would have to allocate memory anyway to iterate. So here we populate
|
||||
/// an ArrayList as the result.
|
||||
pub fn findDecls(zir: Zir, list: *std.ArrayList(Inst.Index), decl_sub_index: ExtraIndex) !void {
|
||||
const block_inst = zir.extra[@intFromEnum(decl_sub_index) + 6];
|
||||
const block_inst: Zir.Inst.Index = @enumFromInt(zir.extra[@intFromEnum(decl_sub_index) + 6]);
|
||||
list.clearRetainingCapacity();
|
||||
|
||||
return zir.findDeclsInner(list, block_inst);
|
||||
@ -3483,32 +3530,32 @@ fn findDeclsInner(
|
||||
const tags = zir.instructions.items(.tag);
|
||||
const datas = zir.instructions.items(.data);
|
||||
|
||||
switch (tags[inst]) {
|
||||
switch (tags[@intFromEnum(inst)]) {
|
||||
// Functions instructions are interesting and have a body.
|
||||
.func,
|
||||
.func_inferred,
|
||||
=> {
|
||||
try list.append(inst);
|
||||
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.Func, inst_data.payload_index);
|
||||
var extra_index: usize = extra.end;
|
||||
switch (extra.data.ret_body_len) {
|
||||
0 => {},
|
||||
1 => extra_index += 1,
|
||||
else => {
|
||||
const body = zir.extra[extra_index..][0..extra.data.ret_body_len];
|
||||
const body = zir.bodySlice(extra_index, extra.data.ret_body_len);
|
||||
extra_index += body.len;
|
||||
try zir.findDeclsBody(list, body);
|
||||
},
|
||||
}
|
||||
const body = zir.extra[extra_index..][0..extra.data.body_len];
|
||||
const body = zir.bodySlice(extra_index, extra.data.body_len);
|
||||
return zir.findDeclsBody(list, body);
|
||||
},
|
||||
.func_fancy => {
|
||||
try list.append(inst);
|
||||
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
|
||||
var extra_index: usize = extra.end;
|
||||
extra_index += @intFromBool(extra.data.bits.has_lib_name);
|
||||
@ -3516,7 +3563,7 @@ fn findDeclsInner(
|
||||
if (extra.data.bits.has_align_body) {
|
||||
const body_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
try zir.findDeclsBody(list, body);
|
||||
extra_index += body.len;
|
||||
} else if (extra.data.bits.has_align_ref) {
|
||||
@ -3526,7 +3573,7 @@ fn findDeclsInner(
|
||||
if (extra.data.bits.has_addrspace_body) {
|
||||
const body_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
try zir.findDeclsBody(list, body);
|
||||
extra_index += body.len;
|
||||
} else if (extra.data.bits.has_addrspace_ref) {
|
||||
@ -3536,7 +3583,7 @@ fn findDeclsInner(
|
||||
if (extra.data.bits.has_section_body) {
|
||||
const body_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
try zir.findDeclsBody(list, body);
|
||||
extra_index += body.len;
|
||||
} else if (extra.data.bits.has_section_ref) {
|
||||
@ -3546,7 +3593,7 @@ fn findDeclsInner(
|
||||
if (extra.data.bits.has_cc_body) {
|
||||
const body_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
try zir.findDeclsBody(list, body);
|
||||
extra_index += body.len;
|
||||
} else if (extra.data.bits.has_cc_ref) {
|
||||
@ -3556,7 +3603,7 @@ fn findDeclsInner(
|
||||
if (extra.data.bits.has_ret_ty_body) {
|
||||
const body_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
try zir.findDeclsBody(list, body);
|
||||
extra_index += body.len;
|
||||
} else if (extra.data.bits.has_ret_ty_ref) {
|
||||
@ -3565,11 +3612,11 @@ fn findDeclsInner(
|
||||
|
||||
extra_index += @intFromBool(extra.data.bits.has_any_noalias);
|
||||
|
||||
const body = zir.extra[extra_index..][0..extra.data.body_len];
|
||||
const body = zir.bodySlice(extra_index, extra.data.body_len);
|
||||
return zir.findDeclsBody(list, body);
|
||||
},
|
||||
.extended => {
|
||||
const extended = datas[inst].extended;
|
||||
const extended = datas[@intFromEnum(inst)].extended;
|
||||
switch (extended.opcode) {
|
||||
|
||||
// Decl instructions are interesting but have no body.
|
||||
@ -3587,23 +3634,23 @@ fn findDeclsInner(
|
||||
// Block instructions, recurse over the bodies.
|
||||
|
||||
.block, .block_comptime, .block_inline => {
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.Block, inst_data.payload_index);
|
||||
const body = zir.extra[extra.end..][0..extra.data.body_len];
|
||||
const body = zir.bodySlice(extra.end, extra.data.body_len);
|
||||
return zir.findDeclsBody(list, body);
|
||||
},
|
||||
.condbr, .condbr_inline => {
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.CondBr, inst_data.payload_index);
|
||||
const then_body = zir.extra[extra.end..][0..extra.data.then_body_len];
|
||||
const else_body = zir.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
|
||||
const then_body = zir.bodySlice(extra.end, extra.data.then_body_len);
|
||||
const else_body = zir.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
|
||||
try zir.findDeclsBody(list, then_body);
|
||||
try zir.findDeclsBody(list, else_body);
|
||||
},
|
||||
.@"try", .try_ptr => {
|
||||
const inst_data = datas[inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.Try, inst_data.payload_index);
|
||||
const body = zir.extra[extra.end..][0..extra.data.body_len];
|
||||
const body = zir.bodySlice(extra.end, extra.data.body_len);
|
||||
try zir.findDeclsBody(list, body);
|
||||
},
|
||||
.switch_block => return findDeclsSwitch(zir, list, inst),
|
||||
@ -3619,7 +3666,7 @@ fn findDeclsSwitch(
|
||||
list: *std.ArrayList(Inst.Index),
|
||||
inst: Inst.Index,
|
||||
) Allocator.Error!void {
|
||||
const inst_data = zir.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = zir.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.SwitchBlock, inst_data.payload_index);
|
||||
|
||||
var extra_index: usize = extra.end;
|
||||
@ -3634,7 +3681,7 @@ fn findDeclsSwitch(
|
||||
if (special_prong != .none) {
|
||||
const body_len: u31 = @truncate(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
try zir.findDeclsBody(list, body);
|
||||
@ -3642,20 +3689,18 @@ fn findDeclsSwitch(
|
||||
|
||||
{
|
||||
const scalar_cases_len = extra.data.bits.scalar_cases_len;
|
||||
var scalar_i: usize = 0;
|
||||
while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
|
||||
for (0..scalar_cases_len) |_| {
|
||||
extra_index += 1;
|
||||
const body_len: u31 = @truncate(zir.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
extra_index += body_len;
|
||||
|
||||
try zir.findDeclsBody(list, body);
|
||||
}
|
||||
}
|
||||
{
|
||||
var multi_i: usize = 0;
|
||||
while (multi_i < multi_cases_len) : (multi_i += 1) {
|
||||
for (0..multi_cases_len) |_| {
|
||||
const items_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const ranges_len = zir.extra[extra_index];
|
||||
@ -3672,7 +3717,7 @@ fn findDeclsSwitch(
|
||||
extra_index += 1;
|
||||
}
|
||||
|
||||
const body = zir.extra[extra_index..][0..body_len];
|
||||
const body = zir.bodySlice(extra_index, body_len);
|
||||
extra_index += body_len;
|
||||
|
||||
try zir.findDeclsBody(list, body);
|
||||
@ -3699,12 +3744,12 @@ pub const FnInfo = struct {
|
||||
total_params_len: u32,
|
||||
};
|
||||
|
||||
pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 {
|
||||
pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const Zir.Inst.Index {
|
||||
const tags = zir.instructions.items(.tag);
|
||||
const datas = zir.instructions.items(.data);
|
||||
const inst_data = datas[fn_inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
|
||||
|
||||
const param_block_index = switch (tags[fn_inst]) {
|
||||
const param_block_index = switch (tags[@intFromEnum(fn_inst)]) {
|
||||
.func, .func_inferred => blk: {
|
||||
const extra = zir.extraData(Inst.Func, inst_data.payload_index);
|
||||
break :blk extra.data.param_block;
|
||||
@ -3716,8 +3761,8 @@ pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 {
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
const param_block = zir.extraData(Inst.Block, datas[param_block_index].pl_node.payload_index);
|
||||
return zir.extra[param_block.end..][0..param_block.data.body_len];
|
||||
const param_block = zir.extraData(Inst.Block, datas[@intFromEnum(param_block_index)].pl_node.payload_index);
|
||||
return zir.bodySlice(param_block.end, param_block.data.body_len);
|
||||
}
|
||||
|
||||
pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
@ -3728,9 +3773,9 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
body: []const Inst.Index,
|
||||
ret_ty_ref: Inst.Ref,
|
||||
ret_ty_body: []const Inst.Index,
|
||||
} = switch (tags[fn_inst]) {
|
||||
} = switch (tags[@intFromEnum(fn_inst)]) {
|
||||
.func, .func_inferred => blk: {
|
||||
const inst_data = datas[fn_inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.Func, inst_data.payload_index);
|
||||
|
||||
var extra_index: usize = extra.end;
|
||||
@ -3746,12 +3791,12 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
extra_index += 1;
|
||||
},
|
||||
else => {
|
||||
ret_ty_body = zir.extra[extra_index..][0..extra.data.ret_body_len];
|
||||
ret_ty_body = zir.bodySlice(extra_index, extra.data.ret_body_len);
|
||||
extra_index += ret_ty_body.len;
|
||||
},
|
||||
}
|
||||
|
||||
const body = zir.extra[extra_index..][0..extra.data.body_len];
|
||||
const body = zir.bodySlice(extra_index, extra.data.body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
break :blk .{
|
||||
@ -3762,7 +3807,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
};
|
||||
},
|
||||
.func_fancy => blk: {
|
||||
const inst_data = datas[fn_inst].pl_node;
|
||||
const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
|
||||
const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
|
||||
|
||||
var extra_index: usize = extra.end;
|
||||
@ -3793,7 +3838,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
if (extra.data.bits.has_ret_ty_body) {
|
||||
const body_len = zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
ret_ty_body = zir.extra[extra_index..][0..body_len];
|
||||
ret_ty_body = zir.bodySlice(extra_index, body_len);
|
||||
extra_index += ret_ty_body.len;
|
||||
} else if (extra.data.bits.has_ret_ty_ref) {
|
||||
ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
|
||||
@ -3802,7 +3847,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
|
||||
extra_index += @intFromBool(extra.data.bits.has_any_noalias);
|
||||
|
||||
const body = zir.extra[extra_index..][0..extra.data.body_len];
|
||||
const body = zir.bodySlice(extra_index, extra.data.body_len);
|
||||
extra_index += body.len;
|
||||
break :blk .{
|
||||
.param_block = extra.data.param_block,
|
||||
@ -3813,14 +3858,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
assert(tags[info.param_block] == .block or
|
||||
tags[info.param_block] == .block_comptime or
|
||||
tags[info.param_block] == .block_inline);
|
||||
const param_block = zir.extraData(Inst.Block, datas[info.param_block].pl_node.payload_index);
|
||||
const param_body = zir.extra[param_block.end..][0..param_block.data.body_len];
|
||||
switch (tags[@intFromEnum(info.param_block)]) {
|
||||
.block, .block_comptime, .block_inline => {}, // OK
|
||||
else => unreachable, // assertion failure
|
||||
}
|
||||
const param_block = zir.extraData(Inst.Block, datas[@intFromEnum(info.param_block)].pl_node.payload_index);
|
||||
const param_body = zir.bodySlice(param_block.end, param_block.data.body_len);
|
||||
var total_params_len: u32 = 0;
|
||||
for (param_body) |inst| {
|
||||
switch (tags[inst]) {
|
||||
switch (tags[@intFromEnum(inst)]) {
|
||||
.param, .param_comptime, .param_anytype, .param_anytype_comptime => {
|
||||
total_params_len += 1;
|
||||
},
|
||||
@ -3836,24 +3882,3 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
|
||||
.total_params_len = total_params_len,
|
||||
};
|
||||
}
|
||||
|
||||
pub const ref_start_index: u32 = InternPool.static_len;
|
||||
|
||||
pub fn indexToRef(inst: Inst.Index) Inst.Ref {
|
||||
return @enumFromInt(ref_start_index + inst);
|
||||
}
|
||||
|
||||
pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
|
||||
assert(inst != .none);
|
||||
const ref_int = @intFromEnum(inst);
|
||||
if (ref_int >= ref_start_index) {
|
||||
return ref_int - ref_start_index;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn refToIndexAllowNone(inst: Inst.Ref) ?Inst.Index {
|
||||
if (inst == .none) return null;
|
||||
return refToIndex(inst);
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ pub fn renderAsTextToFile(
|
||||
var raw_stream = std.io.bufferedWriter(fs_file.writer());
|
||||
const stream = raw_stream.writer();
|
||||
|
||||
const main_struct_inst = Zir.main_struct_inst;
|
||||
const main_struct_inst: Zir.Inst.Index = .main_struct_inst;
|
||||
try stream.print("%{d} ", .{main_struct_inst});
|
||||
try writer.writeInstToStream(stream, main_struct_inst);
|
||||
try stream.writeAll("\n");
|
||||
@ -41,10 +41,9 @@ pub fn renderAsTextToFile(
|
||||
try stream.writeAll("Imports:\n");
|
||||
|
||||
const extra = scope_file.zir.extraData(Zir.Inst.Imports, imports_index);
|
||||
var import_i: u32 = 0;
|
||||
var extra_index = extra.end;
|
||||
|
||||
while (import_i < extra.data.imports_len) : (import_i += 1) {
|
||||
for (0..extra.data.imports_len) |_| {
|
||||
const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
|
||||
extra_index = item.end;
|
||||
|
||||
@ -197,8 +196,8 @@ const Writer = struct {
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const tags = self.code.instructions.items(.tag);
|
||||
const tag = tags[inst];
|
||||
try stream.print("= {s}(", .{@tagName(tags[inst])});
|
||||
const tag = tags[@intFromEnum(inst)];
|
||||
try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});
|
||||
switch (tag) {
|
||||
.as,
|
||||
.store,
|
||||
@ -525,7 +524,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeExtended(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const extended = self.code.instructions.items(.data)[inst].extended;
|
||||
const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended;
|
||||
try stream.print("{s}(", .{@tagName(extended.opcode)});
|
||||
switch (extended.opcode) {
|
||||
.this,
|
||||
@ -622,7 +621,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].bin;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
|
||||
try self.writeInstRef(stream, inst_data.lhs);
|
||||
try stream.writeAll(", ");
|
||||
try self.writeInstRef(stream, inst_data.rhs);
|
||||
@ -630,7 +629,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].bin;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
|
||||
try self.writeInstRef(stream, inst_data.lhs);
|
||||
try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)});
|
||||
}
|
||||
@ -640,7 +639,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].un_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
|
||||
try self.writeInstRef(stream, inst_data.operand);
|
||||
try stream.writeAll(") ");
|
||||
try self.writeSrc(stream, inst_data.src());
|
||||
@ -651,7 +650,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].un_tok;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
|
||||
try self.writeInstRef(stream, inst_data.operand);
|
||||
try stream.writeAll(") ");
|
||||
try self.writeSrc(stream, inst_data.src());
|
||||
@ -662,7 +661,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.operand);
|
||||
try stream.print(", {d}) (destructure=", .{extra.expect_len});
|
||||
@ -676,7 +675,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.ty);
|
||||
try stream.print(", {d}) ", .{extra.init_count});
|
||||
@ -688,7 +687,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.len);
|
||||
try stream.writeAll(", ");
|
||||
@ -704,7 +703,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].ptr_type;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
|
||||
const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else "";
|
||||
const str_const = if (!inst_data.flags.is_mutable) "const, " else "";
|
||||
const str_volatile = if (inst_data.flags.is_volatile) "volatile, " else "";
|
||||
@ -745,12 +744,12 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].int;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int;
|
||||
try stream.print("{d})", .{inst_data});
|
||||
}
|
||||
|
||||
fn writeIntBig(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].str;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
|
||||
const byte_count = inst_data.len * @sizeOf(std.math.big.Limb);
|
||||
const limb_bytes = self.code.string_bytes[inst_data.start..][0..byte_count];
|
||||
// limb_bytes is not aligned properly; we must allocate and copy the bytes
|
||||
@ -769,12 +768,12 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeFloat(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const number = self.code.instructions.items(.data)[inst].float;
|
||||
const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float;
|
||||
try stream.print("{d})", .{number});
|
||||
}
|
||||
|
||||
fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
|
||||
const src = inst_data.src();
|
||||
const number = extra.get();
|
||||
@ -788,13 +787,13 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].str;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
|
||||
const str = inst_data.get(self.code);
|
||||
try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)});
|
||||
}
|
||||
|
||||
fn writeSliceStart(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
try stream.writeAll(", ");
|
||||
@ -804,7 +803,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
try stream.writeAll(", ");
|
||||
@ -816,7 +815,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
try stream.writeAll(", ");
|
||||
@ -830,7 +829,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
try stream.writeAll(", ");
|
||||
@ -846,7 +845,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.union_type);
|
||||
try stream.writeAll(", ");
|
||||
@ -858,7 +857,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.elem_type);
|
||||
try stream.writeAll(", ");
|
||||
@ -885,7 +884,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.mulend1);
|
||||
try stream.writeAll(", ");
|
||||
@ -897,7 +896,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
|
||||
|
||||
try self.writeFlag(stream, "nodiscard ", extra.flags.ensure_result_used);
|
||||
@ -913,7 +912,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeFieldParentPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.parent_type);
|
||||
try stream.writeAll(", ");
|
||||
@ -938,9 +937,9 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_tok;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
|
||||
const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
|
||||
const body = self.code.extra[extra.end..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra.end, extra.data.body_len);
|
||||
try stream.print("\"{}\", ", .{
|
||||
std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)),
|
||||
});
|
||||
@ -956,7 +955,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
try stream.writeAll(", ");
|
||||
@ -966,7 +965,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
|
||||
const args = self.code.refSlice(extra.end, extra.data.operands_len);
|
||||
try stream.writeAll("{");
|
||||
@ -979,13 +978,13 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].elem_val_imm;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
|
||||
try self.writeInstRef(stream, inst_data.operand);
|
||||
try stream.print(", {d})", .{inst_data.idx});
|
||||
}
|
||||
|
||||
fn writeArrayInitElemPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, extra.ptr);
|
||||
@ -994,7 +993,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
|
||||
const decl_name = self.code.nullTerminatedString(extra.decl_name);
|
||||
|
||||
@ -1006,7 +1005,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, extra.operand);
|
||||
@ -1017,7 +1016,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, extra.ptr_ty);
|
||||
@ -1027,7 +1026,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
|
||||
var field_i: u32 = 0;
|
||||
var extra_index = extra.end;
|
||||
@ -1095,7 +1094,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, extra.elem_type);
|
||||
@ -1108,7 +1107,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, extra.ptr);
|
||||
@ -1121,7 +1120,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, extra.ptr);
|
||||
@ -1136,7 +1135,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
|
||||
var field_i: u32 = 0;
|
||||
var extra_index = extra.end;
|
||||
@ -1157,7 +1156,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.container_type);
|
||||
const field_name = self.code.nullTerminatedString(extra.name_start);
|
||||
@ -1166,7 +1165,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.container_type);
|
||||
try stream.writeAll(", ");
|
||||
@ -1193,7 +1192,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].inst_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
|
||||
try self.writeInstIndex(stream, inst_data.inst);
|
||||
try stream.writeAll(") ");
|
||||
try self.writeSrc(stream, inst_data.src());
|
||||
@ -1297,7 +1296,7 @@ const Writer = struct {
|
||||
inst: Zir.Inst.Index,
|
||||
comptime kind: enum { direct, field },
|
||||
) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const ExtraType = switch (kind) {
|
||||
.direct => Zir.Inst.Call,
|
||||
.field => Zir.Inst.FieldCall,
|
||||
@ -1331,7 +1330,7 @@ const Writer = struct {
|
||||
const arg_end = self.code.extra[extra.end + i];
|
||||
defer arg_start = arg_end;
|
||||
const arg_body = body[arg_start..arg_end];
|
||||
try self.writeBracedBody(stream, arg_body);
|
||||
try self.writeBracedBody(stream, @ptrCast(arg_body));
|
||||
|
||||
try stream.writeAll(",\n");
|
||||
}
|
||||
@ -1345,24 +1344,24 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
try self.writePlNodeBlockWithoutSrc(stream, inst);
|
||||
try self.writeSrc(stream, inst_data.src());
|
||||
}
|
||||
|
||||
fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
|
||||
const body = self.code.extra[extra.end..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra.end, extra.data.body_len);
|
||||
try self.writeBracedBody(stream, body);
|
||||
try stream.writeAll(") ");
|
||||
}
|
||||
|
||||
fn writeCondBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
|
||||
const then_body = self.code.extra[extra.end..][0..extra.data.then_body_len];
|
||||
const else_body = self.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
|
||||
const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len);
|
||||
const else_body = self.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
|
||||
try self.writeInstRef(stream, extra.data.condition);
|
||||
try stream.writeAll(", ");
|
||||
try self.writeBracedBody(stream, then_body);
|
||||
@ -1373,9 +1372,9 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index);
|
||||
const body = self.code.extra[extra.end..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra.end, extra.data.body_len);
|
||||
try self.writeInstRef(stream, extra.data.operand);
|
||||
try stream.writeAll(", ");
|
||||
try self.writeBracedBody(stream, body);
|
||||
@ -1421,7 +1420,7 @@ const Writer = struct {
|
||||
extra_index += 1;
|
||||
try self.writeInstRef(stream, backing_int_ref);
|
||||
} else {
|
||||
const body = self.code.extra[extra_index..][0..backing_int_body_len];
|
||||
const body = self.code.bodySlice(extra_index, backing_int_body_len);
|
||||
extra_index += backing_int_body_len;
|
||||
self.indent += 2;
|
||||
try self.writeBracedDecl(stream, body);
|
||||
@ -1535,7 +1534,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
if (field.type_len > 0) {
|
||||
const body = self.code.extra[extra_index..][0..field.type_len];
|
||||
const body = self.code.bodySlice(extra_index, field.type_len);
|
||||
extra_index += body.len;
|
||||
self.indent += 2;
|
||||
try self.writeBracedDecl(stream, body);
|
||||
@ -1543,7 +1542,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
if (field.align_len > 0) {
|
||||
const body = self.code.extra[extra_index..][0..field.align_len];
|
||||
const body = self.code.bodySlice(extra_index, field.align_len);
|
||||
extra_index += body.len;
|
||||
self.indent += 2;
|
||||
try stream.writeAll(" align(");
|
||||
@ -1553,7 +1552,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
if (field.init_len > 0) {
|
||||
const body = self.code.extra[extra_index..][0..field.init_len];
|
||||
const body = self.code.bodySlice(extra_index, field.init_len);
|
||||
extra_index += body.len;
|
||||
self.indent += 2;
|
||||
try stream.writeAll(" = ");
|
||||
@ -1639,7 +1638,7 @@ const Writer = struct {
|
||||
}
|
||||
try stream.writeAll(", ");
|
||||
|
||||
const body = self.code.extra[extra_index..][0..body_len];
|
||||
const body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
const prev_parent_decl_node = self.parent_decl_node;
|
||||
@ -1742,7 +1741,7 @@ const Writer = struct {
|
||||
extra_index += 1;
|
||||
const decl_name_index = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const decl_index = self.code.extra[extra_index];
|
||||
const decl_index: Zir.Inst.Index = @enumFromInt(self.code.extra[extra_index]);
|
||||
extra_index += 1;
|
||||
const doc_comment_index = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
@ -1764,7 +1763,7 @@ const Writer = struct {
|
||||
};
|
||||
|
||||
const pub_str = if (is_pub) "pub " else "";
|
||||
const hash_bytes = @as([16]u8, @bitCast(hash_u32s.*));
|
||||
const hash_bytes: [16]u8 = @bitCast(hash_u32s.*);
|
||||
if (decl_name_index == 0) {
|
||||
try stream.writeByteNTimes(' ', self.indent);
|
||||
const name = if (is_exported) "usingnamespace" else "comptime";
|
||||
@ -1810,12 +1809,12 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
if (self.recurse_decls) {
|
||||
const tag = self.code.instructions.items(.tag)[decl_index];
|
||||
const tag = self.code.instructions.items(.tag)[@intFromEnum(decl_index)];
|
||||
try stream.print(" line({d}) hash({}): %{d} = {s}(", .{
|
||||
line, std.fmt.fmtSliceHexLower(&hash_bytes), decl_index, @tagName(tag),
|
||||
});
|
||||
|
||||
const decl_block_inst_data = self.code.instructions.items(.data)[decl_index].pl_node;
|
||||
const decl_block_inst_data = self.code.instructions.items(.data)[@intFromEnum(decl_index)].pl_node;
|
||||
const sub_decl_node_off = decl_block_inst_data.src_node;
|
||||
self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off);
|
||||
try self.writePlNodeBlockWithoutSrc(stream, decl_index);
|
||||
@ -1888,7 +1887,7 @@ const Writer = struct {
|
||||
try stream.writeAll(", ");
|
||||
}
|
||||
|
||||
const body = self.code.extra[extra_index..][0..body_len];
|
||||
const body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
const prev_parent_decl_node = self.parent_decl_node;
|
||||
@ -1988,7 +1987,7 @@ const Writer = struct {
|
||||
inst: Zir.Inst.Index,
|
||||
name_strategy: Zir.Inst.NameStrategy,
|
||||
) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
|
||||
|
||||
try stream.print("{s}, ", .{@tagName(name_strategy)});
|
||||
@ -2015,7 +2014,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
|
||||
|
||||
var extra_index: usize = extra.end;
|
||||
@ -2029,7 +2028,7 @@ const Writer = struct {
|
||||
const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: {
|
||||
const tag_capture_inst = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
break :blk tag_capture_inst;
|
||||
break :blk @enumFromInt(tag_capture_inst);
|
||||
} else undefined;
|
||||
|
||||
try self.writeInstRef(stream, extra.data.operand);
|
||||
@ -2057,7 +2056,7 @@ const Writer = struct {
|
||||
};
|
||||
const inline_text = if (info.is_inline) "inline " else "";
|
||||
extra_index += 1;
|
||||
const body = self.code.extra[extra_index..][0..info.body_len];
|
||||
const body = self.code.bodySlice(extra_index, info.body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
try stream.writeAll(",\n");
|
||||
@ -2074,7 +2073,7 @@ const Writer = struct {
|
||||
extra_index += 1;
|
||||
const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index]));
|
||||
extra_index += 1;
|
||||
const body = self.code.extra[extra_index..][0..info.body_len];
|
||||
const body = self.code.bodySlice(extra_index, info.body_len);
|
||||
extra_index += info.body_len;
|
||||
|
||||
try stream.writeAll(",\n");
|
||||
@ -2131,7 +2130,7 @@ const Writer = struct {
|
||||
try self.writeInstRef(stream, item_last);
|
||||
}
|
||||
|
||||
const body = self.code.extra[extra_index..][0..info.body_len];
|
||||
const body = self.code.bodySlice(extra_index, info.body_len);
|
||||
extra_index += info.body_len;
|
||||
try stream.writeAll(" => ");
|
||||
try self.writeBracedBody(stream, body);
|
||||
@ -2145,7 +2144,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
|
||||
const name = self.code.nullTerminatedString(extra.field_name_start);
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
@ -2154,7 +2153,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.lhs);
|
||||
try stream.writeAll(", ");
|
||||
@ -2164,7 +2163,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
|
||||
try self.writeInstRef(stream, extra.dest_type);
|
||||
try stream.writeAll(", ");
|
||||
@ -2178,7 +2177,7 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const src_node = self.code.instructions.items(.data)[inst].node;
|
||||
const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
|
||||
const src = LazySrcLoc.nodeOffset(src_node);
|
||||
try stream.writeAll(") ");
|
||||
try self.writeSrc(stream, src);
|
||||
@ -2189,14 +2188,14 @@ const Writer = struct {
|
||||
stream: anytype,
|
||||
inst: Zir.Inst.Index,
|
||||
) (@TypeOf(stream).Error || error{OutOfMemory})!void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].str_tok;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
|
||||
const str = inst_data.get(self.code);
|
||||
try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)});
|
||||
try self.writeSrc(stream, inst_data.src());
|
||||
}
|
||||
|
||||
fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].str_op;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op;
|
||||
const str = inst_data.getStr(self.code);
|
||||
try self.writeInstRef(stream, inst_data.operand);
|
||||
try stream.print(", \"{}\")", .{std.zig.fmtEscapes(str)});
|
||||
@ -2208,7 +2207,7 @@ const Writer = struct {
|
||||
inst: Zir.Inst.Index,
|
||||
inferred_error_set: bool,
|
||||
) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const src = inst_data.src();
|
||||
const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index);
|
||||
|
||||
@ -2225,12 +2224,12 @@ const Writer = struct {
|
||||
extra_index += 1;
|
||||
},
|
||||
else => {
|
||||
ret_ty_body = self.code.extra[extra_index..][0..extra.data.ret_body_len];
|
||||
ret_ty_body = self.code.bodySlice(extra_index, extra.data.ret_body_len);
|
||||
extra_index += ret_ty_body.len;
|
||||
},
|
||||
}
|
||||
|
||||
const body = self.code.extra[extra_index..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra_index, extra.data.body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
var src_locs: Zir.Inst.Func.SrcLocs = undefined;
|
||||
@ -2263,7 +2262,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
|
||||
const src = inst_data.src();
|
||||
|
||||
@ -2289,7 +2288,7 @@ const Writer = struct {
|
||||
if (extra.data.bits.has_align_body) {
|
||||
const body_len = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
align_body = self.code.extra[extra_index..][0..body_len];
|
||||
align_body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += align_body.len;
|
||||
} else if (extra.data.bits.has_align_ref) {
|
||||
align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
|
||||
@ -2298,7 +2297,7 @@ const Writer = struct {
|
||||
if (extra.data.bits.has_addrspace_body) {
|
||||
const body_len = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
addrspace_body = self.code.extra[extra_index..][0..body_len];
|
||||
addrspace_body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += addrspace_body.len;
|
||||
} else if (extra.data.bits.has_addrspace_ref) {
|
||||
addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
|
||||
@ -2307,7 +2306,7 @@ const Writer = struct {
|
||||
if (extra.data.bits.has_section_body) {
|
||||
const body_len = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
section_body = self.code.extra[extra_index..][0..body_len];
|
||||
section_body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += section_body.len;
|
||||
} else if (extra.data.bits.has_section_ref) {
|
||||
section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
|
||||
@ -2316,7 +2315,7 @@ const Writer = struct {
|
||||
if (extra.data.bits.has_cc_body) {
|
||||
const body_len = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
cc_body = self.code.extra[extra_index..][0..body_len];
|
||||
cc_body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += cc_body.len;
|
||||
} else if (extra.data.bits.has_cc_ref) {
|
||||
cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
|
||||
@ -2325,7 +2324,7 @@ const Writer = struct {
|
||||
if (extra.data.bits.has_ret_ty_body) {
|
||||
const body_len = self.code.extra[extra_index];
|
||||
extra_index += 1;
|
||||
ret_ty_body = self.code.extra[extra_index..][0..body_len];
|
||||
ret_ty_body = self.code.bodySlice(extra_index, body_len);
|
||||
extra_index += ret_ty_body.len;
|
||||
} else if (extra.data.bits.has_ret_ty_ref) {
|
||||
ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
|
||||
@ -2338,7 +2337,7 @@ const Writer = struct {
|
||||
break :blk x;
|
||||
} else 0;
|
||||
|
||||
const body = self.code.extra[extra_index..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra_index, extra.data.body_len);
|
||||
extra_index += body.len;
|
||||
|
||||
var src_locs: Zir.Inst.Func.SrcLocs = undefined;
|
||||
@ -2423,7 +2422,7 @@ const Writer = struct {
|
||||
|
||||
fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
|
||||
const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
|
||||
const body = self.code.extra[extra.data.body_index..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len);
|
||||
try self.writeBracedBody(stream, body);
|
||||
try stream.writeAll(",[");
|
||||
const args = self.code.refSlice(extra.end, extended.small);
|
||||
@ -2435,16 +2434,16 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeBoolBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].bool_br;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bool_br;
|
||||
const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
|
||||
const body = self.code.extra[extra.end..][0..extra.data.body_len];
|
||||
const body = self.code.bodySlice(extra.end, extra.data.body_len);
|
||||
try self.writeInstRef(stream, inst_data.lhs);
|
||||
try stream.writeAll(", ");
|
||||
try self.writeBracedBody(stream, body);
|
||||
}
|
||||
|
||||
fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const int_type = self.code.instructions.items(.data)[inst].int_type;
|
||||
const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type;
|
||||
const prefix: u8 = switch (int_type.signedness) {
|
||||
.signed => 'i',
|
||||
.unsigned => 'u',
|
||||
@ -2454,14 +2453,14 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].save_err_ret_index;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
|
||||
|
||||
try self.writeInstRef(stream, inst_data.operand);
|
||||
try stream.writeAll(")");
|
||||
}
|
||||
|
||||
fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].restore_err_ret_index;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
|
||||
|
||||
try self.writeInstRef(stream, inst_data.block);
|
||||
try stream.writeAll(", ");
|
||||
@ -2470,7 +2469,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].@"break";
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
|
||||
const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstIndex(stream, extra.block_inst);
|
||||
@ -2480,7 +2479,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeArrayInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
|
||||
const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
|
||||
const args = self.code.refSlice(extra.end, extra.data.operands_len);
|
||||
@ -2496,7 +2495,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
|
||||
const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
|
||||
const args = self.code.refSlice(extra.end, extra.data.operands_len);
|
||||
@ -2511,7 +2510,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].pl_node;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
|
||||
|
||||
const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
|
||||
const args = self.code.refSlice(extra.end, extra.data.operands_len);
|
||||
@ -2531,7 +2530,7 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].@"unreachable";
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
|
||||
try stream.writeAll(") ");
|
||||
try self.writeSrc(stream, inst_data.src());
|
||||
}
|
||||
@ -2585,34 +2584,37 @@ const Writer = struct {
|
||||
}
|
||||
|
||||
fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].dbg_stmt;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
|
||||
try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 });
|
||||
}
|
||||
|
||||
fn writeDefer(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].@"defer";
|
||||
const body = self.code.extra[inst_data.index..][0..inst_data.len];
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";
|
||||
const body = self.code.bodySlice(inst_data.index, inst_data.len);
|
||||
try self.writeBracedBody(stream, body);
|
||||
try stream.writeByte(')');
|
||||
}
|
||||
|
||||
fn writeDeferErrCode(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
const inst_data = self.code.instructions.items(.data)[inst].defer_err_code;
|
||||
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;
|
||||
const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;
|
||||
|
||||
try self.writeInstRef(stream, Zir.indexToRef(extra.remapped_err_code));
|
||||
try self.writeInstRef(stream, extra.remapped_err_code.toRef());
|
||||
try stream.writeAll(" = ");
|
||||
try self.writeInstRef(stream, inst_data.err_code);
|
||||
try stream.writeAll(", ");
|
||||
const body = self.code.extra[extra.index..][0..extra.len];
|
||||
const body = self.code.bodySlice(extra.index, extra.len);
|
||||
try self.writeBracedBody(stream, body);
|
||||
try stream.writeByte(')');
|
||||
}
|
||||
|
||||
fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
|
||||
const i = @intFromEnum(ref);
|
||||
if (i < InternPool.static_len) return stream.print("@{}", .{@as(InternPool.Index, @enumFromInt(i))});
|
||||
return self.writeInstIndex(stream, i - InternPool.static_len);
|
||||
if (ref.toIndex()) |i| {
|
||||
return self.writeInstIndex(stream, i);
|
||||
} else {
|
||||
const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));
|
||||
return stream.print("@{}", .{val});
|
||||
}
|
||||
}
|
||||
|
||||
fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user