summaryrefslogtreecommitdiff
path: root/anim/src/disasm.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/disasm.zig')
-rw-r--r--anim/src/disasm.zig105
1 files changed, 66 insertions, 39 deletions
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig
index 085982d..6c9e2dc 100644
--- a/anim/src/disasm.zig
+++ b/anim/src/disasm.zig
@@ -75,13 +75,15 @@ pub const Disasm = struct {
focus: bool = false,
/// On the map its box is as long as what it shows (not where it is a strip's column alone).
measures: bool = true,
+ /// Its window this many rows whatever its box (a `pair`'s stopped run: the box shortens over its lower rows).
+ rows: ?usize = null,
pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void {
const box = d.stage.box(placed, .disasm);
const u = context.at(f, placed, box);
const now = d.cursor.now(placed);
const rec = d.cursor.rec;
- const room = theme.layout.rowsIn(box.h);
+ const room = d.rows orelse theme.layout.rowsIn(box.h);
// The mark: it moves last, with the source's and rip.
const going = now.advancing();
const from = listing(u, rec, now.marks[0], room);
@@ -127,7 +129,7 @@ pub const Disasm = struct {
fade = if (ui.mapping) 1 else @abs(2 * going - 1);
}
}
- const scroll = std.math.lerp(offsets[0], offsets[1], cursors.glide(going));
+ const scroll = std.math.lerp(offsets[0], offsets[1], cursors.glidePixels(going, now.plan.travel, @abs(offsets[1] - offsets[0]) * m.row * u.at.scale));
const lit = if (fade < 1) u.faded(fade) else u;
// Where the pc's plaque is: it slides from the row it was on to the
@@ -144,7 +146,6 @@ pub const Disasm = struct {
const base: usize = if (going >= 0.5) 0 else 1;
// The line the source panel is on, in the file it shows: rows of that file carry their numbers.
const current = rec.shown[now.marks[if (going >= 0.5) 1 else 0]];
- const current_line = current.line;
// The addresses' shared digits, of the window the mark is in: they
// change with the advance, not before it.
const lead = blk: {
@@ -170,17 +171,21 @@ pub const Disasm = struct {
// `ran`: what the last three steps ran (every instruction, where the
// recording is by instruction), the newest step's mark on each row,
// and the moment it last ran at for its annotation.
- const ran = u.f.scratch.alloc(?Ran, merged.len) catch return;
- @memset(ran, null);
- for (0..3) |k| {
- const first = now.stops[@min(base + 1 + k, now.stops.len - 1)];
- const last = now.stops[base + k];
- var at = last;
- // shortcut: a step through more than 4096 moments marks its last 4096.
- while (at > first and last - at < 4096) {
- at -= 1;
- const j = rowOf(merged, rec.register(at, "rip")) orelse continue;
- if (ran[j] == null) ran[j] = .{ .k = k, .at = at };
+ // As before the advance and as after it (`base` 1 and 0): the row crossfades between them.
+ var rans: [2][]?Ran = undefined;
+ for (&rans, [2]usize{ 1, 0 }) |*ran, b| {
+ ran.* = u.f.scratch.alloc(?Ran, merged.len) catch return;
+ @memset(ran.*, null);
+ for (0..3) |k| {
+ const first = now.stops[@min(b + 1 + k, now.stops.len - 1)];
+ const last = now.stops[b + k];
+ var at = last;
+ // shortcut: a step through more than 4096 moments marks its last 4096.
+ while (at > first and last - at < 4096) {
+ at -= 1;
+ const j = rowOf(merged, rec.register(at, "rip")) orelse continue;
+ if (ran.*[j] == null) ran.*[j] = .{ .k = k, .at = at };
+ }
}
}
// The jump that brought control here: the instruction just before
@@ -227,11 +232,31 @@ pub const Disasm = struct {
map.row(.disasm, row.addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row });
ties.anchor(u, .{ .row = row.addr }, .{ .x = 0, .y = y, .w = box.w, .h = m.row });
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 state: State = if (is_pc) .current else if (was) |r| .{ .ran = r } else .ahead;
- const hangs = d.insn(lit, now, row, y, map.content(box.w), widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo);
- rules.draw(lit, row.addr, y, map.content(box.w), covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo));
+ // The row as before the advance and as after it (its state, its trail, its
+ // line number): where they differ, the one crossfades to the other over the
+ // advance's middle, never in a frame.
+ const across: f32 = if (now.resting()) 1 else std.math.clamp((going - 0.25) * 2, 0, 1);
+ var hangs: usize = 0;
+ for ([2]usize{ 1, 0 }) |b| {
+ const cur_s = rec.shown[now.marks[1 - b]];
+ const line_s = if (row.outside or row.src != cur_s.src) null else row.line;
+ const pc_s = row.addr == pc[1 - b];
+ const was_s = if (pc_s) null else rans[1 - b][j];
+ const state: State = if (pc_s) .current else if (was_s) |r| .{ .ran = r } else .ahead;
+ const main = b == base;
+ const o = 1 - b;
+ const cur_o = rec.shown[now.marks[1 - o]];
+ const line_o = if (row.outside or row.src != cur_o.src) null else row.line;
+ const pc_o = row.addr == pc[1 - o];
+ const same = pc_s == pc_o and std.meta.eql(line_s, line_o) and cur_s.line == cur_o.line and std.meta.eql(was_s, if (pc_o) null else rans[1 - o][j]);
+ const alpha: f32 = if (same) (if (main) 1 else 0) else if (b == 0) across else 1 - across;
+ if (alpha <= 0) continue;
+ const v = lit.faded(alpha);
+ if (was_s) |r| v.trail(c.mark, y, r.k);
+ const h = d.insn(v, now, row, y, map.content(box.w), widen, line_s, line_s != last_line, cur_s.line, lead, state, b, covered > 0, window, echo);
+ if (main) hangs = h;
+ rules.draw(v, row.addr, y, map.content(box.w), covered == 0 and !row.outside and !d.noted(v, now, row, y, state, b, 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;
@@ -292,7 +317,7 @@ pub const Disasm = struct {
if (!ui.mapping and now.annotation == .tied and now.walking() and (now.plan.touch >= 0 or now.plan.carry >= 0)) if (touchPc(rec, now)) |pc| if (pc == row.addr) {
const a = at.at.xf.apply(.{ w + theme.strip.cost, y });
const b = at.at.xf.apply(.{ w + theme.strip.cost, y + m.row });
- ties.touch_row = .{ a[0], a[1], b[0], b[1] };
+ ties.of(at.f).touch_row = .{ a[0], a[1], b[0], b[1] };
};
if (first_of_line) if (line) |l| {
const num = u.print("{d}", .{l});
@@ -407,37 +432,36 @@ pub const Disasm = struct {
}
// `tied`: an instruction that moves rsp or rbp says the move first.
if (now.annotation == .tied) if (a.stackMove(now, row, moment, after, state, base)) |note| return note;
+ // What it left behind is shown once it has run; in the step that
+ // makes it, it fades in from the CPU's strike (12 f), never in a frame.
+ const appears: f32 = if (state == .current and after != null) now.moving(.cpu, 0, theme.time.quick) else 1;
+ const value_at: ?u64 = switch (state) {
+ .ran => after,
+ .current => if (after != null and appears > 0) after.? else null,
+ .ahead, .waiting => null,
+ };
+ const new = Say{ .u = u.faded(appears), .rec = rec, .y = y, .x = x, .room = room };
// A compare: the two values, then (once it has run) the flags it leaves.
if (std.mem.eql(u8, mn, "cmp") or std.mem.eql(u8, mn, "test")) {
const left = a.compared(row, moment, touches[0]);
var end = a.word(x, left[0], t.primary);
end = a.word(end, " : ", t.faint);
end = a.word(end, left[1], t.primary);
- const left_at: ?u64 = switch (state) {
- .ran => after,
- .current => if (after != null and now.landed(.cpu, 0)) after else null,
- .ahead, .waiting => null,
- };
- if (left_at) |l| {
+ if (value_at) |l| {
var buf: [256]u8 = undefined;
const next = rec.instruction(moment, row.addr + row.len, &buf);
var mask = if (next) |n| flagsRead((Insn{ .addr = 0, .len = 0, .text = n.text }).mnemonic()) else 0;
if (mask == 0) mask = flag_bits.cf | flag_bits.zf | flag_bits.sf | flag_bits.of;
- end = flags(u, end + 2 * adv, y, rec.register(l, "eflags"), mask, if (echo) |e| if (e.addr == row.addr) e.shows else 0 else 0);
+ end = flags(new.u, end + 2 * adv, y, rec.register(l, "eflags"), mask, if (echo) |e| if (e.addr == row.addr) e.shows else 0 else 0);
}
return .{ .drawn = true, .end = end };
}
// The rest is what it left behind, or where it reads: by what it is.
- const value_at: ?u64 = switch (state) {
- .ran => after,
- .current => if (after != null and now.landed(.cpu, 0)) after.? else null,
- .ahead, .waiting => null,
- };
// A place the C library's layout names: the canary.
if (std.mem.indexOf(u8, row.text, "fs:[0x28]") != null) {
const end = a.word(x, if (x + 35 * adv <= room) "the stack's canary" else "canary", t.dim);
const word_ = if (touches[0]) |touch| Recording.word(rec.moment(value_at orelse moment), touch.addr, 8) catch null else null;
- if (word_) |v| return .{ .drawn = true, .end = a.word(end + adv, u.print("{x}", .{v}), t.primary) };
+ if (word_) |v| return .{ .drawn = true, .end = (if (value_at != null) new else a).word(end + adv, u.print("{x}", .{v}), t.primary) };
u.unknown(.{ .x = end + adv, .y = y, .w = 24, .h = m.row });
return .{ .drawn = true, .end = end + adv + 24 };
}
@@ -445,8 +469,8 @@ pub const Disasm = struct {
if (std.mem.eql(u8, mn, "lea")) {
const at = value_at orelse return .{};
const reg = written(row) orelse return .{};
- const end = a.word(x, "=", t.faint);
- return .{ .drawn = true, .end = rows.chain(u, end + adv, y, rec.moment(at), rec.register(at, reg), room, .{}).end };
+ const end = new.word(x, "=", t.faint);
+ return .{ .drawn = true, .end = rows.chain(new.u, end + adv, y, rec.moment(at), rec.register(at, reg), room, .{}).end };
}
// A `rep`: how many times, how wide each, and where it goes.
if (std.mem.startsWith(u8, mn, "rep")) {
@@ -494,9 +518,9 @@ pub const Disasm = struct {
const reg = written(row) orelse return .{};
const at = value_at orelse return .{};
const value = rec.register(at, reg);
- u.text(.mono, size, x, base_y, reg, t.dim);
+ new.u.text(.mono, size, x, base_y, reg, t.dim);
// `tied`: its first value (the registers' row has its chain, struck in the same frame).
- return .{ .drawn = true, .end = rows.chain(u, x + @as(f32, @floatFromInt(reg.len + 1)) * adv, y, rec.moment(at), value, room, .{ .most = if (now.annotation == .tied) 1 else 6 }).end };
+ return .{ .drawn = true, .end = rows.chain(new.u, x + @as(f32, @floatFromInt(reg.len + 1)) * adv, y, rec.moment(at), value, room, .{ .most = if (now.annotation == .tied) 1 else 6 }).end };
}
};
@@ -607,12 +631,15 @@ const Say = struct {
var end = a.word(a.x, "rbp = rsp", t.primary);
// Its value once rbp has landed, struck with it.
const lands = ties.strikeDelay(now, cursors.bp_index);
+ // In from rbp's strike (12 f), never in a frame.
+ const shows: f32 = if (state == .current and after != null) now.moving(.cpu, -lands, theme.time.quick) else 1;
const value_at: ?u64 = switch (state) {
.ran => after,
- .current => if (after != null and now.landed(.cpu, lands)) after.? else null,
+ .current => if (after != null and shows > 0) after.? else null,
.ahead, .waiting => null,
};
- if (value_at) |v| end = a.struck(end + adv, a.u.print("{x}", .{a.rec.register(v, "rbp")}), if (state == .current and base == 1) now.heat(now.registerAge(cursors.bp_index), null, now.since(.cpu, lands)) else .none);
+ const b: Say = .{ .u = a.u.faded(shows), .rec = a.rec, .y = a.y, .x = a.x, .room = a.room };
+ if (value_at) |v| end = b.struck(end + adv, a.u.print("{x}", .{a.rec.register(v, "rbp")}), if (state == .current and base == 1) now.heat(now.registerAge(cursors.bp_index), null, now.since(.cpu, lands)) else .none);
return .{ .drawn = true, .end = end };
} else return null;
var role: ?Role = null;