1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Graph intermediate representation for multi-node compilation.
//!
//! `GraphIr` is the bridge between `GraphBuilder` (programmatic API)
//! and the rill-lang optimizer/lowerer/engine pipeline.
use crate::ir::{Ir, ParamDef};
use indexmap::IndexMap;
/// A multi-node signal processing graph in IR form.
pub struct GraphIr {
/// Number of graph input channels.
pub inputs: usize,
/// Number of graph output channels.
pub outputs: usize,
/// Named graph nodes (ordered by insertion, or topo order after build).
pub nodes: IndexMap<String, GraphNode>,
/// Signal and feedback edges between node ports.
pub edges: Vec<GraphEdge>,
/// Topological order of node names (signal edges only).
pub topo_order: Vec<String>,
}
/// A single node in the graph — a compiled built-in with its IR.
pub struct GraphNode {
/// (signal_ins, signal_outs) arity.
pub arity: (usize, usize),
/// Pre-compiled IR for this node's built-in function.
pub ir: Ir,
/// Parameter definitions exposed for automation.
pub params: Vec<ParamDef>,
/// If true, this node must remain independent (dynamic params).
pub keep: bool,
/// If true, this node should be inlined even with dynamic params.
pub inline: bool,
/// Splits the graph into left/right sub-graphs for duplex execution.
pub is_bridge: bool,
/// Named feedback buffers to read BEFORE processing (mixed into input signal).
pub feedback_read: Vec<String>,
/// Named feedback buffers to write AFTER processing (capture output).
pub feedback_write: Vec<String>,
}
/// A directed edge between two node ports.
pub struct GraphEdge {
/// Source node name.
pub from_node: String,
/// Output port index on the source node.
pub from_port: usize,
/// Destination node name.
pub to_node: String,
/// Input port index on the destination node.
pub to_port: usize,
/// Edge kind.
pub kind: EdgeKind,
}
/// Type of graph edge.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EdgeKind {
/// Forward signal flow edge — participates in topological sort.
Signal,
/// Feedback edge with implicit 1-sample delay — excluded from topo sort.
Feedback,
}