authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-04-30 12:25:13+10:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-05-07 15:55:20+10:00
loga62b5d84d834757682be9b5a0606ff8168c1d594
treee72d2fcb10666ca1225e60dce251a414b1fd82d4
parentd71a43ec2c28a53a3e1d9bcb538707eca00a6fc0

zir: add slice_length tag


5 files changed, 39 insertions(+), 0 deletions(-)

src/AstGen.zig+1
...@@ -2557,6 +2557,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2557,6 +2557,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2557 .slice_start,2557 .slice_start,
2558 .slice_end,2558 .slice_end,
2559 .slice_sentinel,2559 .slice_sentinel,
2560 .slice_length,
2560 .import,2561 .import,
2561 .switch_block,2562 .switch_block,
2562 .switch_cond,2563 .switch_cond,
src/Autodoc.zig+1
...@@ -1287,6 +1287,7 @@ fn walkInstruction(...@@ -1287,6 +1287,7 @@ fn walkInstruction(
1287 .expr = .{ .sliceIndex = slice_index },1287 .expr = .{ .sliceIndex = slice_index },
1288 };1288 };
1289 },1289 },
1290 .slice_length => @panic("TODO: implement walkInstruction for .slice_length"),
12901291
1291 // @check array_cat and array_mul1292 // @check array_cat and array_mul
1292 .add,1293 .add,
src/Sema.zig+10
...@@ -985,6 +985,7 @@ fn analyzeBodyInner(...@@ -985,6 +985,7 @@ fn analyzeBodyInner(
985 .slice_end => try sema.zirSliceEnd(block, inst),985 .slice_end => try sema.zirSliceEnd(block, inst),
986 .slice_sentinel => try sema.zirSliceSentinel(block, inst),986 .slice_sentinel => try sema.zirSliceSentinel(block, inst),
987 .slice_start => try sema.zirSliceStart(block, inst),987 .slice_start => try sema.zirSliceStart(block, inst),
988 .slice_length => try sema.zirSliceLength(block, inst),
988 .str => try sema.zirStr(block, inst),989 .str => try sema.zirStr(block, inst),
989 .switch_block => try sema.zirSwitchBlock(block, inst),990 .switch_block => try sema.zirSwitchBlock(block, inst),
990 .switch_cond => try sema.zirSwitchCond(block, inst, false),991 .switch_cond => try sema.zirSwitchCond(block, inst, false),
...@@ -9961,6 +9962,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -9961,6 +9962,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
9961 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src);9962 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src);
9962}9963}
99639964
9965fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9966 const tracy = trace(@src());
9967 defer tracy.end();
9968
9969 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9970 const src = inst_data.src();
9971 return sema.fail(block, src, "TODO: implement .slice_length", .{});
9972}
9973
9964fn zirSwitchCapture(9974fn zirSwitchCapture(
9965 sema: *Sema,9975 sema: *Sema,
9966 block: *Block,9976 block: *Block,
src/Zir.zig+14
...@@ -570,6 +570,10 @@ pub const Inst = struct {...@@ -570,6 +570,10 @@ pub const Inst = struct {
570 /// Returns a pointer to the subslice.570 /// Returns a pointer to the subslice.
571 /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceSentinel`.571 /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceSentinel`.
572 slice_sentinel,572 slice_sentinel,
573 /// Slice operation `array_ptr[start..][0..len]`. No sentinel.
574 /// Returns a pointer to the subslice.
575 /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceLength`.
576 slice_length,
573 /// Write a value to a pointer. For loading, see `load`.577 /// Write a value to a pointer. For loading, see `load`.
574 /// Source location is assumed to be same as previous instruction.578 /// Source location is assumed to be same as previous instruction.
575 /// Uses the `bin` union field.579 /// Uses the `bin` union field.
...@@ -1135,6 +1139,7 @@ pub const Inst = struct {...@@ -1135,6 +1139,7 @@ pub const Inst = struct {
1135 .slice_start,1139 .slice_start,
1136 .slice_end,1140 .slice_end,
1137 .slice_sentinel,1141 .slice_sentinel,
1142 .slice_length,
1138 .import,1143 .import,
1139 .typeof_log2_int_type,1144 .typeof_log2_int_type,
1140 .resolve_inferred_alloc,1145 .resolve_inferred_alloc,
...@@ -1430,6 +1435,7 @@ pub const Inst = struct {...@@ -1430,6 +1435,7 @@ pub const Inst = struct {
1430 .slice_start,1435 .slice_start,
1431 .slice_end,1436 .slice_end,
1432 .slice_sentinel,1437 .slice_sentinel,
1438 .slice_length,
1433 .import,1439 .import,
1434 .typeof_log2_int_type,1440 .typeof_log2_int_type,
1435 .switch_capture,1441 .switch_capture,
...@@ -1667,6 +1673,7 @@ pub const Inst = struct {...@@ -1667,6 +1673,7 @@ pub const Inst = struct {
1667 .slice_start = .pl_node,1673 .slice_start = .pl_node,
1668 .slice_end = .pl_node,1674 .slice_end = .pl_node,
1669 .slice_sentinel = .pl_node,1675 .slice_sentinel = .pl_node,
1676 .slice_length = .pl_node,
1670 .store = .bin,1677 .store = .bin,
1671 .store_node = .pl_node,1678 .store_node = .pl_node,
1672 .store_to_block_ptr = .bin,1679 .store_to_block_ptr = .bin,
...@@ -2980,6 +2987,13 @@ pub const Inst = struct {...@@ -2980,6 +2987,13 @@ pub const Inst = struct {
2980 sentinel: Ref,2987 sentinel: Ref,
2981 };2988 };
29822989
2990 pub const SliceLength = struct {
2991 lhs: Ref,
2992 start: Ref,
2993 len: Ref,
2994 start_src_node_offset: i32,
2995 };
2996
2983 /// The meaning of these operands depends on the corresponding `Tag`.2997 /// The meaning of these operands depends on the corresponding `Tag`.
2984 pub const Bin = struct {2998 pub const Bin = struct {
2985 lhs: Ref,2999 lhs: Ref,
src/print_zir.zig+13
...@@ -267,6 +267,7 @@ const Writer = struct {...@@ -267,6 +267,7 @@ const Writer = struct {
267 .slice_start => try self.writeSliceStart(stream, inst),267 .slice_start => try self.writeSliceStart(stream, inst),
268 .slice_end => try self.writeSliceEnd(stream, inst),268 .slice_end => try self.writeSliceEnd(stream, inst),
269 .slice_sentinel => try self.writeSliceSentinel(stream, inst),269 .slice_sentinel => try self.writeSliceSentinel(stream, inst),
270 .slice_length => try self.writeSliceLength(stream, inst),
270271
271 .union_init => try self.writeUnionInit(stream, inst),272 .union_init => try self.writeUnionInit(stream, inst),
272273
...@@ -756,6 +757,18 @@ const Writer = struct {...@@ -756,6 +757,18 @@ const Writer = struct {
756 try self.writeSrc(stream, inst_data.src());757 try self.writeSrc(stream, inst_data.src());
757 }758 }
758759
760 fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
761 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
762 const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
763 try self.writeInstRef(stream, extra.lhs);
764 try stream.writeAll(", ");
765 try self.writeInstRef(stream, extra.start);
766 try stream.writeAll(", ");
767 try self.writeInstRef(stream, extra.len);
768 try stream.writeAll(") ");
769 try self.writeSrc(stream, inst_data.src());
770 }
771
759 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {772 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
760 const inst_data = self.code.instructions.items(.data)[inst].pl_node;773 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
761 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;774 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;