cairo_lang_sierra_to_casm/
circuit.rs

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
use cairo_lang_sierra::extensions::circuit::{CircuitInfo, CircuitTypeConcrete, ConcreteCircuit};
use cairo_lang_sierra::extensions::core::{CoreLibfunc, CoreType, CoreTypeConcrete};
use cairo_lang_sierra::ids::ConcreteTypeId;
use cairo_lang_sierra::program_registry::ProgramRegistry;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;

use crate::compiler::CompilationError;

/// Describes a circuit in the program.
/// The information about the circuits used in the program.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct CircuitsInfo {
    pub circuits: OrderedHashMap<ConcreteTypeId, CircuitInfo>,
}

impl CircuitsInfo {
    pub fn new<'a>(
        registry: &ProgramRegistry<CoreType, CoreLibfunc>,
        type_ids: impl Iterator<Item = &'a ConcreteTypeId>,
    ) -> Result<Self, CompilationError> {
        let mut res = Self::default();
        for ty in type_ids {
            if let CoreTypeConcrete::Circuit(CircuitTypeConcrete::Circuit(ConcreteCircuit {
                circuit_info,
                ..
            })) = registry.get_type(ty).unwrap()
            {
                res.circuits.entry(ty.clone()).or_insert_with(|| circuit_info.clone());
            }
        }
        Ok(res)
    }
}