···135135 } else if (n->kind == TOBI_IR_WHILE) {
136136 if (n->child_len > 1) {
137137 dot_block(sb, n->child[1], id, "while-body", next);
138138- /*
139139- * The body is package-bounded in AML, so a back edge to the
140140- * loop header is justified even when the body internals are only
141141- * partially understood.
142142- */
143138 tobi_sb_printf(sb, " n%zu -> n%zu [label=\"back\"];\n", (*next) - 1u, id);
144139 }
145140 }
···5252 size_t child_cap;
5353} tobi_ir;
54545555-/** Allocate a new IR node with source offset and length. */
5655tobi_ir *tobi_ir_new(tobi_ir_kind kind, size_t off, size_t len);
57565858-/** Recursively free an IR tree. */
5957void tobi_ir_free(tobi_ir *node);
60586161-/** Append child to parent, transferring ownership. */
6259void tobi_ir_add(tobi_ir *parent, tobi_ir *child);
63606464-/** Set node name by copying s. */
6561void tobi_ir_set_name(tobi_ir *node, const char *s);
66626767-/** Set resolved namespace path by copying s. */
6863void tobi_ir_set_path(tobi_ir *node, const char *s);
69647070-/** Set string payload by copying s. */
7165void tobi_ir_set_str(tobi_ir *node, const char *s);
72667373-/** Return a stable textual name for an IR kind. */
7467const char *tobi_ir_kind_name(tobi_ir_kind kind);
75687676-/** Return first direct child of kind or NULL when absent. */
7769tobi_ir *tobi_ir_find_child(tobi_ir *node, tobi_ir_kind kind);
78707979-/** Count direct children with a specific kind. */
8071size_t tobi_ir_count_kind(const tobi_ir *node, tobi_ir_kind kind);
81728273#endif
···3344#include <stddef.h>
5566-/** Allocate n bytes or terminate the process on allocation failure. */
76void *tobi_xmalloc(size_t n);
8799-/** Allocate zeroed storage for count elements of size bytes or terminate. */
108void *tobi_xcalloc(size_t count, size_t size);
1191212-/** Resize an allocation or terminate the process on allocation failure. */
1310void *tobi_xrealloc(void *ptr, size_t n);
14111515-/** Duplicate a NUL-terminated string or terminate on allocation failure. */
1612char *tobi_xstrdup(const char *s);
17131818-/** Duplicate exactly n bytes from a string and add a NUL terminator. */
1914char *tobi_xstrndup(const char *s, size_t n);
20152116#endif
···2424 const char *operands;
2525} tobi_op_desc;
26262727-/** Return metadata for an AML opcode byte or NULL when unsupported. */
2827const tobi_op *tobi_op_find(uint8_t op);
29283030-/** Return metadata for an AML extended opcode following ExtOpPrefix. */
3129const tobi_op *tobi_op_find_ext(uint8_t ext);
32303333-/** Return metadata for a complete opcode code; extended opcodes use 0x5b00|ext. */
3431const tobi_op *tobi_op_find_code(uint16_t code);
35323636-/** Return a compact operand descriptor string for an opcode, or NULL. */
3733const char *tobi_op_operands(uint16_t code);
38343935#endif