summaryrefslogtreecommitdiff
path: root/anim/src/Recording.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 04:45:57 -0300
committerGabriel Schneider <[email protected]>2026-11-12 07:03:05 -0300
commit4907e35bc45d12102d0e09380994814fc2e0a369 (patch)
tree7cfd90224653d73b63fbadaf2881fa0e6ba92860 /anim/src/Recording.zig
parentebdebe04a76f0302aeb24c1ac08fa9217b1a8257 (diff)
downloadcomputeranim-4907e35bc45d12102d0e09380994814fc2e0a369.tar.gz
computeranim-4907e35bc45d12102d0e09380994814fc2e0a369.zip
canim: the introduction, from the review
The introduction records the plain build (clang -O0, no instrumentation), so reverse's frame is the compiler's own push, mov and sub. The stack chapter says its convention once and keeps four free words over rsp so a push moves the pin and nothing else; reverse's rows stand under main's and are stepped, each touching its word, the call before the push, the aim drawn head first to the row it returns to. The close-up frames the bytes and the stack together with their 128 bytes marked. Nothing is named before it is shown; offsets are written in hex as the operands are; the dump folds into its tag; the map is announced before it is shown. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/Recording.zig')
-rw-r--r--anim/src/Recording.zig58
1 files changed, 56 insertions, 2 deletions
diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig
index 4bc9c1b..bcc8903 100644
--- a/anim/src/Recording.zig
+++ b/anim/src/Recording.zig
@@ -143,6 +143,11 @@ locals: []Declared = &.{},
/// The variables declared outside the stack (globals): bytes a lens draws.
globals: []Span = &.{},
strings: std.AutoHashMapUnmanaged(u64, []const u8) = .empty,
+/// What a program built without the pass does not tell of itself (the
+/// introduction's plain build): its globals' types and its named types, in
+/// the pass's notation (`types`), by name (`declare`); its locals are the
+/// debug info's (`zt.telescope.slots`), untyped.
+declared: std.StringHashMapUnmanaged(u64) = .empty,
arena: std.heap.ArenaAllocator,
const gpa = std.heap.smp_allocator;
@@ -694,7 +699,55 @@ pub fn variable(r: *const Recording, scratch: std.mem.Allocator, m: Moment, text
for (all) |v| {
if (std.mem.eql(u8, r.name(v.name), text) and (found == null or v.depth > found.?.depth)) found = v;
}
- return found;
+ return found orelse if (r.declared.count() > 0) r.plain(m, text) else null;
+}
+
+/// The live variables: the recording's, or a plain build's declared globals.
+pub fn variables(r: *const Recording, scratch: std.mem.Allocator, m: Moment) []Variable {
+ const all = m.variables(scratch) catch return &.{};
+ if (all.len > 0 or r.declared.count() == 0) return all;
+ var out: std.ArrayList(Variable) = .empty;
+ var it = r.declared.keyIterator();
+ while (it.next()) |key| if (key.*[0] != '`') if (r.plain(m, key.*)) |v| out.append(scratch, v) catch break;
+ return out.items;
+}
+
+/// Declares, for a program built without the pass, global `what`'s type
+/// (`text`, in the pass's notation), or a named type's description
+/// (`what` in backticks, as a type names it). Once each.
+/// shortcut: a scene writes them from the source, as the tracer reads no types from the debug info; upgrade when it does.
+pub fn declare(r: *Recording, what: []const u8, text: []const u8) void {
+ if (r.declared.contains(what)) return;
+ const a = r.arena.allocator();
+ const named = what[0] == '`';
+ const id = if (named) types.defId(what[1 .. what.len - 1]) else r.intern(text) catch return;
+ if (named) r.strings.put(a, id, a.dupe(u8, text) catch return) catch return;
+ r.declared.put(a, a.dupe(u8, what) catch return, id) catch {};
+}
+
+/// A plain build's variable `text` at `m`: a declared global, at the
+/// address the recording names `text+0` (a word: what a lens hangs from is
+/// a pointer); or a local of the newest frame, by the debug info. Its
+/// `name` is 0: the recording has no id for it.
+fn plain(r: *const Recording, m: Moment, text: []const u8) ?Variable {
+ if (r.declared.get(text)) |ty| {
+ var it = r.strings.iterator();
+ while (it.next()) |e| {
+ const s = e.value_ptr.*;
+ if (e.key_ptr.* >> 63 == 0 and s.len == text.len + 2 and std.mem.startsWith(u8, s, text) and std.mem.endsWith(u8, s, "+0"))
+ return .{ .addr = e.key_ptr.*, .size = 8, .name = 0, .type = ty, .tid = r.tid, .depth = 0 };
+ }
+ return null;
+ }
+ const regs = (m.regs(r.tid) catch null) orelse return null;
+ var buf: [32]zt.telescope.Slot = undefined;
+ const slots = zt.telescope.slots(m, &regs, regs.rsp, &buf) catch return null;
+ for (slots, 0..) |slot, k| if (slot.frame == 0 and slot.role == .local) {
+ const l = slot.role.local;
+ if (l.offset == 0 and std.mem.eql(u8, l.name, text))
+ return .{ .addr = regs.rsp + 8 * k, .size = l.size, .name = 0, .type = 0, .tid = r.tid, .depth = r.depths[@min(m.index, r.end())] };
+ };
+ return null;
}
/// A variable's type, as the compiler pass described it, with a named type
@@ -735,7 +788,8 @@ pub fn assigned(r: *const Recording, v: Variable, i: u64) bool {
if (c.enter > i) break;
if (c.active(i) and c.depth + 1 == v.depth) enter = c.enter;
}
- return touches(r.written(enter -| 1, i), v.addr, v.size);
+ // A plain build's local (`plain`): a store of the value its stretch of stack held assigns it too.
+ return touches(r.written(enter -| 1, i), v.addr, v.size) or (v.name == 0 and touches(r.store_spans.of(enter -| 1, i), v.addr, v.size));
}
/// Which allocation ever made holds `addr` at moment `m`: the same number