| 151 | } |
| 152 | |
| 153 | export function buildProgram(input: ProgramInput): WireProgram | null { |
| 154 | if (input.root === null) return null; |
| 155 | const state: Reading = { truncated: 0, items: 0, read: new Set([input.root]) }; |
| 156 | const root = blockFor(input, input.root, [input.root], state); |
| 157 | return root.length === 0 ? null : { root, truncated: state.truncated }; |
| 158 | } |
| 159 | |
| 160 | /** One function's body, in the code's order. */ |
| 161 | function blockFor(input: ProgramInput, fn: string, path: readonly string[], state: Reading): WireBlock { |