diff options
Diffstat (limited to 'anim/src/disasm.zig')
| -rw-r--r-- | anim/src/disasm.zig | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 4324b42..282c66e 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -19,6 +19,7 @@ const Recording = @import("Recording.zig"); const ties = @import("ties.zig"); const map = @import("map.zig"); const context = @import("context.zig"); +const graph = @import("graph.zig"); const Stage = @import("stage.zig").Stage; const theme = ui.theme; const time = theme.time; @@ -40,6 +41,8 @@ pub const Insn = struct { line: ?u32 = null, /// A direct call's callee's parameter count. params: ?u8 = null, + /// A graph's row: its block's head carries the address, the row its offset. + bare: bool = false, /// Its mnemonic, with a prefix that is part of it (`rep stosq`). pub fn mnemonic(i: Insn) []const u8 { @@ -98,7 +101,8 @@ pub const Disasm = struct { u.faded(going).tagNote(box.w, names[1]); } const top = body.y + m.pad; - u.clip(.{ .x = theme.stroke.rule, .y = m.tag, .w = box.w - 2 * theme.stroke.rule, .h = box.h - m.tag - theme.stroke.rule }); + // The rows' own room: a row going out of the window passes under the padding, its block's rule too. + u.clip(.{ .x = theme.stroke.rule, .y = m.tag, .w = box.w - 2 * theme.stroke.rule, .h = box.h - m.tag - m.pad }); defer u.unclip(); // The two windows as one list, if they are of one function: the @@ -198,6 +202,8 @@ pub const Disasm = struct { // What the window holds: a jump out of it says where it goes. const window = [2]u64{ if (merged.len > 0) merged[0].addr else 0, if (merged.len > 0) merged[merged.len - 1].addr else 0 }; const echo = jumpEcho(now, base); + // The blocks (`graph`): a rule over each one's first row, its visits where the row has room. + const rules = graph.Rules.init(u.f.scratch, rec, now.marks, pc, going); for (merged, 0..) |row, j| { const y = top + (@as(f32, @floatFromInt(j)) - scroll) * m.row; const line = if (row.outside) null else row.line; @@ -215,7 +221,9 @@ pub const Disasm = struct { const is_pc = row.addr == pc[if (going >= 0.5) 1 else 0]; const was = if (is_pc) null else ran[j]; if (was) |r| lit.trail(c.mark, y, r.k); - const hangs = d.insn(lit, now, row, y, box.w, widen, line, line != last_line, current_line, lead, if (is_pc) .current else if (was) |r| .{ .ran = r } else .ahead, base, covered > 0, window, echo); + const state: State = if (is_pc) .current else if (was) |r| .{ .ran = r } else .ahead; + const hangs = d.insn(lit, now, row, y, box.w, widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); + rules.draw(lit, row.addr, y, box.w, covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); covered = @max(covered -| 1, hangs); last_line = if (above_body) null else line; if (jumped == row.addr and !is_pc) lanes[0] = y; @@ -268,7 +276,7 @@ pub const Disasm = struct { u.text(.mono, size, x, base_y, name, t.faint); return 0; } - _ = at.address(c.address, base_y, row.addr, .{ .ink = ui.rgb(code_ink), .lead = lead }); + if (!row.bare) _ = at.address(c.address, base_y, row.addr, .{ .ink = ui.rgb(code_ink), .lead = lead }); if (first_of_line) if (line) |l| { const num = u.print("{d}", .{l}); const now_line = l == current_line; @@ -290,10 +298,15 @@ pub const Disasm = struct { return if (need.drawn and !covered) d.annotation(u, now, row, y, x, room, state, base, window, echo).hangs else 0; } + /// Whether `row` has an annotation: where it has none, its block's visits may be ranged right. + pub fn noted(d: *const Disasm, u: ui.Ui, now: cursors.Now, row: Insn, y: f32, state: State, base: usize, window: [2]u64, echo: ?Echo) bool { + return d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo).drawn; + } + const Note = struct { drawn: bool = false, end: f32 = 0, hangs: usize = 0 }; /// The row that set the flags a conditional jump reads, while the jump /// runs: its chips are framed as read with it (an `echo`). - const Echo = struct { addr: u64, shows: f32 }; + pub const Echo = struct { addr: u64, shows: f32 }; /// The annotation: what it does, now, from `x`, cut where `room` ends. /// What it left behind is shown only where the step ran this @@ -781,7 +794,7 @@ fn flags(u: ui.Ui, x: f32, y: f32, eflags: u64, mask: u16, read: f32) f32 { /// While a conditional jump runs (the mark on it, its step under way), the /// row that set the flags it reads: the instruction just before it ran. -fn jumpEcho(now: cursors.Now, base: usize) ?Disasm.Echo { +pub fn jumpEcho(now: cursors.Now, base: usize) ?Disasm.Echo { if (base != 1 or now.resting()) return null; const flags_ = readsFlags(now.rec, now.stops[1]); if (flags_ == 0 or now.stops[1] == 0) return null; @@ -876,13 +889,17 @@ pub fn target(row: Insn) ?u64 { /// (faint for padding) and its operands as canim draws them, at `y` in `u` /// (the panel's origin). For the gallery's page of rows. pub fn plainRow(u: ui.Ui, row: Insn, y: f32) void { - const base_y = rows.baseline(y); - _ = u.address(c.address, base_y, row.addr, .{ .ink = ui.rgb(theme.color.region.code_) }); + _ = u.address(c.address, rows.baseline(y), row.addr, .{ .ink = ui.rgb(theme.color.region.code_) }); // A library's twelve digits move what is right of them, 12 a digit past seven. - const v = u.moved(@as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv, 0); + bareRow(u.moved(@as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv, 0), row, y); +} + +/// Its mnemonic and operands alone, at their columns (a graph's row, whose head carries the address). +pub fn bareRow(u: ui.Ui, row: Insn, y: f32) void { + const base_y = rows.baseline(y); const pad = row.padding(); - v.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); - operands(v, row, shorn(v, row), "", base_y, c.annotation - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); + operands(u, row, shorn(u, row), "", base_y, c.annotation - gap - c.operands, if (pad) t.faint else theme.color.code.plain); } /// Operands as canim draws them (design/README.md, `insn` and `width`): |
