rune_ssa/
phi.rs

1use crate::internal::commas;
2use crate::Assign;
3use std::fmt;
4
5/// The definition of an input to a block.
6///
7/// These are essentially phi nodes, and makes sure that there's a local
8/// variable declaration available.
9#[derive(Debug, Clone)]
10pub struct Phi {
11    /// The blocks which defines the variable.
12    dependencies: Vec<Assign>,
13}
14
15impl Phi {
16    /// Construct a new phi node.
17    pub(crate) fn new() -> Self {
18        Self {
19            dependencies: Vec::new(),
20        }
21    }
22
23    /// Extend with the given iterator.
24    pub(crate) fn extend<I>(&mut self, iter: I)
25    where
26        I: IntoIterator<Item = Assign>,
27    {
28        self.dependencies.extend(iter);
29    }
30}
31
32impl fmt::Display for Phi {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        if self.dependencies.is_empty() {
35            write!(f, "φ(?)")?;
36        } else {
37            write!(f, "φ({})", commas(&self.dependencies))?;
38        }
39
40        Ok(())
41    }
42}