diff options
Diffstat (limited to 'anim/src/disasm.zig')
| -rw-r--r-- | anim/src/disasm.zig | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 67b0572..3fbe4ff 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -1218,6 +1218,79 @@ pub fn plainRow(u: ui.Ui, row: Insn, y: f32) void { bareRow(u.moved(@as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv, 0), row, y); } +/// The same instruction atoms for a live debugger: one moment, without +/// indexing an animation's entire recording. Only observed operands are annotated. +pub fn liveRow(at: ui.Ui, row: Insn, y: f32, width: f32, moment: Recording.Moment, regs: zt.Regs, options: struct { + current: bool = false, + executed: bool = false, + lead: usize = 0, + touch: ?Recording.Touch = null, + branch: ?Recording.Branch = null, + heat: ui.Heat = .none, +}) void { + const base_y = rows.baseline(y); + _ = at.address(c.address, base_y, row.addr, .{ .ink = ui.rgb(theme.color.region.code_), .lead = options.lead }); + const shift = @as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv; + const u = at.moved(shift, 0); + const room = width - shift - m.side; + const pad = row.padding(); + const mn = row.mnemonic(); + if (row.line) |line| u.text(.mono, size, c.line, base_y, u.print("{d}", .{line}), t.faint); + u.text(.mono_bold, size, c.mnemonic, base_y, mn, if (pad) t.faint else theme.color.code.keyword); + var name_buf: [192]u8 = undefined; + const name = if (target(row)) |to| (moment.string(to, &name_buf) catch null) orelse "" else ""; + const annotated = options.current or options.executed; + operands(u, row, shorn(u, row), name, base_y, (if (annotated) annotationColumn() else room) - gap - c.operands, if (pad) t.faint else t.primary); + if (!annotated) return; + var x = annotationColumn(); + if (options.branch) |branch| { + const label = switch (branch.kind) { + .call => "call", + .ret => "return", + .jump => if (branch.taken) "taken" else "not taken", + .none => "", + }; + u.text(.mono, size, x, base_y, label, if (branch.taken) t.primary else t.dim); + x += u.width(.mono, size, label) + adv; + if (branch.kind == .jump and flagsRead(mn) != 0) { + _ = flags(u, x, y, regs.eflags, flagsRead(mn), if (options.current) 1 else 0); + } else { + _ = rows.chain(u, x, y, moment, branch.to, room, .{ .most = 1 }); + } + return; + } + if (options.touch) |touch| { + const label: []const u8 = if (touch.how == 1) "read" else if (touch.how == 2) "write" else "read/write"; + u.text(.mono, size, x, base_y, label, t.dim); + x += u.width(.mono, size, label) + adv; + const marks: rows.Marks = .{ .read = if (options.current and touch.how & 1 != 0) 0 else null, .read_shows = 1 }; + if (touch.len < 8) _ = rows.narrow(u, x, y, moment, touch.addr, touch.len, room, marks) else _ = rows.chain(u, x, y, moment, touch.addr, room, marks); + return; + } + if (options.executed) { + const reg = written(row) orelse return; + u.text(.mono, size, x, base_y, reg, t.dim); + _ = rows.chain(u, x + @as(f32, @floatFromInt(reg.len + 1)) * adv, y, moment, regs.named(reg).?, room, .{ .first = options.heat }); + return; + } + // Register operands at the current instruction, using their real width. + var words = std.mem.tokenizeAny(u8, row.operands(), " ,[]*+-:"); + var seen: ?[]const u8 = null; + while (words.next()) |word| { + const reg = full(word) orelse continue; + if (seen) |previous| if (std.mem.eql(u8, reg, previous)) continue; + const raw = regs.named(reg) orelse continue; + const value = number(u, if (word.len == 2 and word[1] == 'h') raw >> 8 else raw, registerSize(word) orelse 8); + const text = u.print("{s} {s}", .{ word, value }); + const w = u.width(.mono, size, text); + if (x + w > room) break; + u.text(.mono, size, x, base_y, word, t.dim); + u.text(.mono, size, x + @as(f32, @floatFromInt(word.len + 1)) * adv, base_y, value, t.primary); + x += w + 2 * adv; + seen = reg; + } +} + /// 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); |
