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.zig57
1 files changed, 52 insertions, 5 deletions
diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig
index f61c721..67b0572 100644
--- a/anim/src/disasm.zig
+++ b/anim/src/disasm.zig
@@ -85,6 +85,8 @@ pub const Disasm = struct {
/// A `pair`'s stopped run, 0 to 1: the call at the pc never returned. Its
/// row reads so, the plaque goes, the tag says `stopped`.
stopped: ?anim.Value = null,
+ /// 0 to 1: how much the pc's mark shows (the introduction's code arrives before its mark, II4).
+ mark_in: ?anim.Value = null,
pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void {
const box = d.stage.box(placed, .disasm);
@@ -154,6 +156,7 @@ pub const Disasm = struct {
mark_y = top + (j - scroll) * m.row;
}
if (to.rows.len == 0) mark_shows = 0;
+ if (d.mark_in) |v| mark_shows *= std.math.clamp(placed.value(v), 0, 1);
// Which moment the current mark stands for, and the three steps before it.
const base: usize = if (going >= 0.5) 0 else 1;
@@ -411,16 +414,41 @@ pub const Disasm = struct {
.call => {
// Through memory or a register: where it went, and where that was read.
if (target(row) == null) return a.went(b.to, touches[0], moment);
- // Once it has run: the call in C's form and its result.
+ // Once it has run: the call in C's form and its result (struck with rax while the step that stepped over it plays).
if (state == .ran) if (returned(rec, row, moment, now.stops[base])) |back| {
+ if (now.plan.result >= 0 and state.ran.at == now.stops[1]) return a.returning(row, b.to, moment, rec.register(back, "rax"), now.register(cursors.rax_index, 0));
return a.said(a.cForm(row, b.to, moment, rec.register(back, "rax"), a.room - a.x), t.primary);
};
+ // A call stepped over (`Plan.result`, design/motion.md "A call stepped over"): its
+ // callee and its arguments hanging under it, framed as read from 18 f; then, as rax
+ // strikes, its C form and its result, struck with it, the hanging rows going (6 f).
+ if (now.plan.result >= 0 and state == .current and !now.resting()) if (returned(rec, row, moment, now.stops[0])) |back| {
+ const k = std.math.clamp((now.time - now.plan.at[0]) / (6.0 / 60.0), 0, 1);
+ var note: Note = .{};
+ if (k < 1) {
+ const before: Say = .{ .u = u.faded(1 - k), .rec = rec, .y = y, .x = x, .room = room };
+ note = before.callee(b.to, moment);
+ note.hangs = before.arguments(row, b.to, moment);
+ const framed = std.math.clamp((now.time - 18.0 / 60.0) / (6.0 / 60.0), 0, 1) * (1 - k);
+ for (carriers[0..note.hangs], 1..) |reg, j| {
+ const v = rec.register(moment, reg);
+ const shown = ui.Value.of(v, rows.regionOf(rec.moment(moment), v) != .none);
+ u.read(.{ .x = x + 4 * adv, .y = y + @as(f32, @floatFromInt(j)) * m.row, .w = shown.width(), .h = m.row }, framed);
+ }
+ }
+ if (k > 0) {
+ const struck: Say = .{ .u = u.faded(k), .rec = rec, .y = y, .x = x, .room = room };
+ note = struck.returning(row, b.to, moment, rec.register(back, "rax"), now.register(cursors.rax_index, 0));
+ }
+ return note;
+ };
// `tied`: a call to the program's own function in C's form (a PLT stub's callee by name,
// its arguments under it), then its move of rsp, struck with rsp: `fib(4) ยท rsp -8`.
if (now.annotation == .tied and state == .current) {
const stub = pltName(u, rec, target(row).?).len > 0;
var note = if (stub) a.callee(b.to, moment) else a.said(a.cForm(row, b.to, moment, null, a.room - a.x - 10 * adv), t.primary);
- note.end = a.move(note.end + adv, -8, a.rspHeat(now, base), null, true);
+ // (The introduction walks no call: the one it shows is stepped over, rsp as it was after it.)
+ if (!now.introduction) note.end = a.move(note.end + adv, -8, a.rspHeat(now, base), null, true);
if (stub) note.hangs = a.arguments(row, b.to, moment);
return note;
}
@@ -548,8 +576,13 @@ pub const Disasm = struct {
const at = value_at orelse return .{};
const value = rec.register(at, reg);
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(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 };
+ // `tied`: its first value (the registers' row has its chain, struck in the same frame);
+ // in the introduction struck with its register (a part's bytes are struck so: `reg` `parts`).
+ var marks: rows.Marks = .{ .most = if (now.annotation == .tied) 1 else 6 };
+ if (now.introduction and state == .current) if (context.index(reg)) |ri| {
+ marks.first = now.register(ri, ties.strikeDelay(now, ri));
+ };
+ return .{ .drawn = true, .end = rows.chain(new.u, x + @as(f32, @floatFromInt(reg.len + 1)) * adv, y, rec.moment(at), value, room, marks).end };
}
};
@@ -738,6 +771,14 @@ const Say = struct {
return .{ .drawn = true, .end = rows.chain(u, x, a.y, shown, v, a.room, .{ .first = if (marks.changed == 1) marks.changed_heat else .none }).end };
}
+ /// A call that has run, in C's form with its result struck as `heat` says (rax's: an echo).
+ fn returning(a: Say, row: Insn, to: u64, moment: u64, value: u64, heat: ui.Heat) Disasm.Note {
+ const back = resultText(a.u, a.rec, moment, value);
+ var end = a.word(a.x, a.cForm(row, to, moment, null, a.room - a.x - @as(f32, @floatFromInt(back.len + 3)) * adv), t.primary);
+ end = a.word(end, " = ", t.primary);
+ return .{ .drawn = true, .end = a.struck(end, back, heat) };
+ }
+
/// A direct call's callee, bright.
fn callee(a: Say, to: u64, moment: u64) Disasm.Note {
return .{ .drawn = true, .end = a.word(a.x, a.functionName(to, moment), t.bright) };
@@ -791,7 +832,7 @@ const Say = struct {
}
if (shown < count) out = u.print("{s}{s}\u{2026}", .{ out, if (shown > 0) ", " else "" });
out = u.print("{s})", .{out});
- if (result) |r| out = u.print("{s} = {d}", .{ out, @as(i64, @bitCast(r)) });
+ if (result) |r| out = u.print("{s} = {s}", .{ out, resultText(u, a.rec, moment, r) });
if (shown == 0 or @as(f32, @floatFromInt(std.unicode.utf8CountCodepoints(out) catch out.len)) * adv <= width) return out;
}
}
@@ -994,6 +1035,12 @@ fn returned(rec: *const Recording, row: Insn, moment: u64, until: u64) ?u64 {
return null;
}
+/// A call's result as a caller reads it: an address in hex, as the chains write it; else signed, in decimal.
+fn resultText(u: ui.Ui, rec: *const Recording, moment: u64, r: u64) []const u8 {
+ if (rows.regionOf(rec.moment(moment), r) != .none) return u.print("{x}", .{r});
+ return u.print("{d}", .{@as(i64, @bitCast(r))});
+}
+
/// The slot a `jmp` or `call` through `[rip + X]` reads.
fn ripSlot(row: Insn) ?u64 {
const ops = row.operands();