From 2c5924c59a148335e5025b72a5ba98d765ed771d Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreplay.github.com> Date: Tue, 2 May 2023 22:04:15 +1000 Subject: [PATCH] autodoc: fix support for slice_length ZIR instruction --- lib/docs/main.js | 19 ++++++++++++++++++- src/Autodoc.zig | 14 +++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/docs/main.js b/lib/docs/main.js index 9b650643e9..f803fddb81 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -1093,6 +1093,23 @@ const NAV_MODES = { payloadHtml += decl + "[" + start + ".." + end + sentinel + "]"; return payloadHtml; } + case "sliceLength": { + let payloadHtml = ""; + const lhsExpr = zigAnalysis.exprs[expr.sliceLength.lhs]; + const startExpr = zigAnalysis.exprs[expr.sliceLength.start]; + const lenExpr = zigAnalysis.exprs[expr.sliceLength.len]; + let decl = exprName(lhsExpr, opts); + let start = exprName(startExpr, opts); + let len = exprName(lenExpr, opts); + let sentinel = ""; + if (expr.sliceLength["sentinel"]) { + const sentinelExpr = zigAnalysis.exprs[expr.sliceLength.sentinel]; + let sentinel_ = exprName(sentinelExpr, options); + sentinel += " :" + sentinel_; + } + payloadHtml += decl + "[" + start + "..][0.." + len + sentinel + "]"; + return payloadHtml; + } case "sliceIndex": { const sliceIndex = zigAnalysis.exprs[expr.sliceIndex]; return exprName(sliceIndex, opts, opts); @@ -4850,4 +4867,4 @@ function RadixTree() { // BUT! -// We want to be able to search "Hash", for example! \ No newline at end of file +// We want to be able to search "Hash", for example! diff --git a/src/Autodoc.zig b/src/Autodoc.zig index eba53b7e17..1dfe036fd6 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -755,6 +755,7 @@ const DocData = struct { string: []const u8, // direct value sliceIndex: usize, slice: Slice, + sliceLength: SliceLength, cmpxchgIndex: usize, cmpxchg: Cmpxchg, builtin: Builtin, @@ -791,6 +792,12 @@ const DocData = struct { end: ?usize = null, sentinel: ?usize = null, // index in `exprs` }; + const SliceLength = struct { + lhs: usize, + start: usize, + len: usize, + sentinel: ?usize = null, + }; const Cmpxchg = struct { name: []const u8, type: usize, @@ -1337,7 +1344,12 @@ fn walkInstruction( try self.exprs.append(self.arena, sentinel.expr); break :sentinel_index index; } else null; - self.exprs.items[slice_index] = .{ .slice = .{ .lhs = lhs_index, .start = start_index, .end = len_index, .sentinel = sentinel_index } }; + self.exprs.items[slice_index] = .{ .sliceLength = .{ + .lhs = lhs_index, + .start = start_index, + .len = len_index, + .sentinel = sentinel_index, + } }; return DocData.WalkResult{ .typeRef = self.decls.items[lhs.expr.declRef.Analyzed].value.typeRef,