diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 13:22:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 13:26:44 -0300 |
| commit | 2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c (patch) | |
| tree | 140a291011e453888ed87b7a43d75f538abb9fae /anim/scenes/gallery.zig | |
| parent | 576a78b4de02c4c6566c327d85c465554d293975 (diff) | |
| download | computeranim-2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c.tar.gz computeranim-2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c.zip | |
canim: the graph of a function's blocks
From the user. A blocks lens draws a function's basic blocks as boxes
with their offsets and visit counts, loops in their lanes with the turn
count, the path's last edges gold, the pc's block gold, and the
disassembly as its view; leave and turn carry the mark along an edge,
with the compare's flags framed for the edge chosen. On the map the
graph takes the disassembly's place with its rows. The layout is a pure
function, tested on sort, reverse and libc's open (twelve blocks the run
never reached fold into six boxes). The sort scene walks one trip of its
inner loop block by block and sprints the middle on the map. Every
scene's linear rows carry a rule and a count at each block's head. The
stack's panel no longer reads registers from the file on every draw: a
frame is 20 ms where it was 57.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/scenes/gallery.zig')
| -rw-r--r-- | anim/scenes/gallery.zig | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index 693553e..48fba99 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -10,6 +10,11 @@ //! 3.6 s a step, mid-way: struck, read, projection, echo (mock 10) //! 6 s `subject` (mock 11); 8 s `none`, with the backtrace //! 10.8 s two loupes in depth, from rax and its node's `next` (mock 21) +//! 21 s the `blocks` lens: at rest (blocks reached and not yet, the trail, +//! an edge never taken), `leave` mid-way, `turn` landing, folds +//! 24 s the graph with its rows, as the map draws it (here at half size): +//! sort's (panned to its loop, the pc's block annotated) and libc's +//! `open` at its syscall (the blocks never reached folded) const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -306,6 +311,101 @@ fn rowsPage(u: ui.Ui, p: *const Pages) void { _ = canim.hexdump.reading(panel, 3 * row, 0, m, &values, &known, &.{ .{ .at = 0, .len = 1, .type = char }, .{ .at = 1, .len = 1, .type = boolean }, .{ .at = 4, .len = 4, .type = int }, .{ .at = 8, .len = 8, .reads = .pointer } }); } +/// The graph pages' names, over their drawings. +const GraphPages = struct { + box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, + + pub fn draw(_: *const GraphPages, f: *sk.Frame, at: anim.Placed) void { + const u: ui.Ui = .{ .f = f, .at = at }; + if (at.t >= 21 and at.t < 24) { + title(u, 64, 40, "graph: the blocks lens"); + for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, never taken", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks never reached" }) |p, words| note(u, p[0], p[1], words); + } else if (at.t >= 24 and at.t < 27) { + title(u, 64, 40, "graph: with its rows, as on the map (half size)"); + } + } +}; + +/// A component drawn at half its size (the map's rows as the map shows them filling a 1080p frame). +fn Half(comptime T: type) type { + return struct { + inner: T, + box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, + + pub fn draw(h: *const @This(), f: *sk.Frame, at: anim.Placed) void { + var p = at; + p.xf = p.xf.mul(.scale(0.5, 0.5)); + p.scale *= 0.5; + h.inner.draw(f, p); + } + }; +} + +/// The graph pages: sort's blocks in the lens, at rest and in `leave` and +/// `turn`, and libc's `open` folded; then the map's form of both. +fn graphPages(s: *anim.Frame, at_time: f32) [3]anim.Obj { + const graph = canim.graph; + const sort = canim.open(recordings.gallery_sort); + const hello = canim.open(recordings.gallery_hello); + const sort0 = sort.register(sort.call("sort", 0).enter, "rip"); + // Where the opening of the sort scene is: the inner loop's test, about to compare 31 with 12. + var start = sort.call("sort", 0).enter; + while (sort.next(.over, sort.next(.over, start)) < sort.call("swap", 0).enter) start = sort.next(.over, start); + // The first `jne` to the swap, and the first jump back to the test. + var jne = start; + while (!(sort.insn_branches[jne] != null and sort.insn_branches[jne].?.taken and sort.insn_branches[jne].?.to == sort0 + 0xc5)) jne += 1; + var back = jne; + while (!(sort.insn_branches[back] != null and sort.insn_branches[back].?.to == sort0 + 0x8a)) back += 1; + var syscall_at: u64 = 0; + var buf: [256]u8 = undefined; + for (hello.registers, 0..) |r, k| if (hello.strings.get(r.rip)) |name| if (std.mem.startsWith(u8, name, "libc.so.6!open+") and std.mem.eql(u8, (hello.instruction(k, r.rip, &buf) orelse continue).text, "syscall")) { + syscall_at = k; + break; + }; + const place = struct { + fn stage(s_: *anim.Frame, band: canim.Rect, disasm: canim.Rect) *canim.Stage { + var split = canim.layout.split.blocks; + split.band = band; + split.disasm = disasm; + return canim.Stage.init(s_, split); + } + }.stage; + const nowhere: canim.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; + const rest = canim.cursor(s, sort, start); + const leaving = canim.cursor(s, sort, jne); + const turning = canim.cursor(s, sort, back); + const open_at = canim.cursor(s, hello, syscall_at); + const lenses = .{ + canim.add(s, graph.Blocks{ .cursor = rest, .stage = place(s, .{ .x = 64, .y = 84, .w = 880, .h = 296 }, nowhere) }), + canim.add(s, graph.Blocks{ .cursor = leaving, .stage = place(s, .{ .x = 976, .y = 84, .w = 880, .h = 296 }, nowhere) }), + canim.add(s, graph.Blocks{ .cursor = turning, .stage = place(s, .{ .x = 64, .y = 500, .w = 880, .h = 296 }, nowhere) }), + canim.add(s, graph.Blocks{ .cursor = open_at, .stage = place(s, .{ .x = 976, .y = 500, .w = 880, .h = 296 }, nowhere) }), + }; + // Each step played so that the page shows it at `at_time`: the leave with its mark mid-way, the turn just landed. + const l = canim.theme.time.leave; + s.cursor = at_time - l.sets_off - l.mark / 2.0 - 0.05; + graph.leave(leaving, s); + s.cursor = at_time - l.sets_off - 0.30 - l.count; + graph.leave(turning, s); + // The map's form, at half size: the map's units, two columns wide each. + const maps = .{ + canim.add(s, Half(graph.Map){ .inner = .{ .cursor = canim.cursor(s, sort, jne), .stage = place(s, nowhere, .{ .x = 128, .y = 176, .w = 1792, .h = 1688 }) } }), + canim.add(s, Half(graph.Map){ .inner = .{ .cursor = canim.cursor(s, hello, syscall_at), .stage = place(s, nowhere, .{ .x = 1952, .y = 176, .w = 1792, .h = 1688 }) } }), + }; + const pages = canim.add(s, GraphPages{}); + var all: [lenses.len]anim.Animation = undefined; + inline for (lenses, 0..) |o, i| all[i] = o.fadeIn(); + s.cursor = 21; + s.play(.{pages.fadeIn()}, .{ .seconds = 0 }); + s.play(all, .{ .seconds = 0 }); + s.cursor = 24; + inline for (lenses, 0..) |o, i| all[i] = o.fadeOut(); + s.play(all, .{ .seconds = 0 }); + s.play(.{ maps[0].fadeIn(), maps[1].fadeIn() }, .{ .seconds = 0 }); + s.cursor = 27; + return .{ pages, maps[0], maps[1] }; +} + fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.gallery); const reverse = rec.call("reverse", 0); @@ -341,5 +441,12 @@ fn frame(s: *anim.Frame) void { near.open(s); s.wait(18.8 - s.cursor); deeper.open(s); + s.wait(20.6 - s.cursor); + deeper.close(s); + near.close(s); s.wait(21 - s.cursor); + // The graph's pages: the context stands aside. + inline for (panels, 0..) |o, i| all[i] = o.fadeOut(); + s.play(all, .{ .seconds = 0 }); + _ = graphPages(s, 21.8); } |
