Trait libreda_db::hierarchy::traits::HierarchyBase
source · pub trait HierarchyBase: HierarchyIds {
type NameType: Eq + Hash + From<String> + Into<String> + Clone + Borrow<String> + Borrow<str> + PartialOrd + Ord + Display + Debug;
Show 29 methods
// Required methods
fn cell_by_name(&self, name: &str) -> Option<Self::CellId>;
fn cell_instance_by_name(
&self,
parent_cell: &Self::CellId,
name: &str
) -> Option<Self::CellInstId>;
fn cell_name(&self, cell: &Self::CellId) -> Self::NameType;
fn cell_instance_name(
&self,
cell_inst: &Self::CellInstId
) -> Option<Self::NameType>;
fn parent_cell(&self, cell_instance: &Self::CellInstId) -> Self::CellId;
fn template_cell(&self, cell_instance: &Self::CellInstId) -> Self::CellId;
fn for_each_cell<F>(&self, f: F)
where F: FnMut(Self::CellId);
fn for_each_cell_instance<F>(&self, cell: &Self::CellId, f: F)
where F: FnMut(Self::CellInstId);
fn for_each_cell_dependency<F>(&self, cell: &Self::CellId, f: F)
where F: FnMut(Self::CellId);
fn for_each_dependent_cell<F>(&self, cell: &Self::CellId, f: F)
where F: FnMut(Self::CellId);
fn for_each_cell_reference<F>(&self, cell: &Self::CellId, f: F)
where F: FnMut(Self::CellInstId);
fn num_child_instances(&self, cell: &Self::CellId) -> usize;
fn num_cells(&self) -> usize;
// Provided methods
fn each_cell_vec(&self) -> Vec<Self::CellId> { ... }
fn each_cell(&self) -> Box<dyn Iterator<Item = Self::CellId> + '_> { ... }
fn each_cell_instance_vec(
&self,
cell: &Self::CellId
) -> Vec<Self::CellInstId> { ... }
fn each_cell_instance(
&self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellInstId> + '_> { ... }
fn each_cell_dependency_vec(&self, cell: &Self::CellId) -> Vec<Self::CellId> { ... }
fn each_cell_dependency<'a>(
&'a self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellId> + 'a> { ... }
fn num_cell_dependencies(&self, cell: &Self::CellId) -> usize { ... }
fn each_dependent_cell_vec(&self, cell: &Self::CellId) -> Vec<Self::CellId> { ... }
fn each_dependent_cell<'a>(
&'a self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellId> + 'a> { ... }
fn num_dependent_cells(&self, cell: &Self::CellId) -> usize { ... }
fn each_cell_reference_vec(
&self,
cell: &Self::CellId
) -> Vec<Self::CellInstId> { ... }
fn each_cell_reference(
&self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellInstId> + '_> { ... }
fn num_cell_references(&self, cell: &Self::CellId) -> usize { ... }
fn get_chip_property(&self, key: &Self::NameType) -> Option<PropertyValue> { ... }
fn get_cell_property(
&self,
cell: &Self::CellId,
key: &Self::NameType
) -> Option<PropertyValue> { ... }
fn get_cell_instance_property(
&self,
inst: &Self::CellInstId,
key: &Self::NameType
) -> Option<PropertyValue> { ... }
}
Expand description
Most basic trait for the hierarchical flyweight pattern which is used to efficiently represent chip layouts and netlists.
Component relations
A netlist consists of cells which are templates for cell instances. Each cell may contain such instances of other cells.
The following diagram illustrates how this composition graph can be traversed using the functions
defined by HierarchyBase
.
each_cell_dependency
+---------------------------+
| |
+ v
+----------------+ each_dependent_cell +------------------+
|Circuit (Top) |<----------------------+|Circuit (Sub) |
+----------------+ +------------------+
|+ ^| | ^ + |
||each_instance || | | | |
|| || | | | |
|| |parent | | | |
|| || | | | |
||+-----------+ || | | | |
+--> |>|Inst1 (Sub)|-+| | | | |
| ||+-----------+ | | | | |
| || | | | | |
| || | +-|---|------------+
| || | | |
| ||+-----------+ | template | |
+--> |>|Inst2 (Sub)|+----------------------------+ |
| | +-----------+ | |
| | | |
| | | |
| +----------------+ |
| |
| each_reference |
+----------------------------------------------------+
Example
Basic hierchy operations:
use libreda_db::chip::Chip;
use libreda_db::traits::{HierarchyBase, HierarchyEdit};
// Create a simple hierarchical structure.
let mut chip = Chip::new();
let top_cell = chip.create_cell("MyTopCell".into());
let sub_cell = chip.create_cell("MySubCell".into());
// Create an instance of `sub_cell` inside `top_cell`.
let inst = chip.create_cell_instance(&top_cell, &sub_cell, Some("inst1".into()));
// Get all cells.
assert_eq!(chip.each_cell().count(), 2);
// Iterate over child instances.
assert_eq!(chip.each_cell_instance(&top_cell).next().as_ref(), Some(&inst));
// Get the template of an instance.
assert_eq!(&chip.template_cell(&inst), &sub_cell);
// Get the parent of an instance.
assert_eq!(&chip.parent_cell(&inst), &top_cell);
Required Associated Types§
Required Methods§
sourcefn cell_by_name(&self, name: &str) -> Option<Self::CellId>
fn cell_by_name(&self, name: &str) -> Option<Self::CellId>
Find a cell by its name.
Return the cell with the given name. Returns None
if the cell does not exist.
sourcefn cell_instance_by_name(
&self,
parent_cell: &Self::CellId,
name: &str
) -> Option<Self::CellInstId>
fn cell_instance_by_name( &self, parent_cell: &Self::CellId, name: &str ) -> Option<Self::CellInstId>
Find a cell instance by its name.
Returns None
if the name does not exist.
sourcefn cell_instance_name(
&self,
cell_inst: &Self::CellInstId
) -> Option<Self::NameType>
fn cell_instance_name( &self, cell_inst: &Self::CellInstId ) -> Option<Self::NameType>
Get the name of the cell instance.
sourcefn parent_cell(&self, cell_instance: &Self::CellInstId) -> Self::CellId
fn parent_cell(&self, cell_instance: &Self::CellInstId) -> Self::CellId
Get the ID of the parent cell of this instance.
sourcefn template_cell(&self, cell_instance: &Self::CellInstId) -> Self::CellId
fn template_cell(&self, cell_instance: &Self::CellInstId) -> Self::CellId
Get the ID of the template cell of this instance.
sourcefn for_each_cell<F>(&self, f: F)where
F: FnMut(Self::CellId),
fn for_each_cell<F>(&self, f: F)where F: FnMut(Self::CellId),
Call a function on each cell of the netlist.
sourcefn for_each_cell_instance<F>(&self, cell: &Self::CellId, f: F)where
F: FnMut(Self::CellInstId),
fn for_each_cell_instance<F>(&self, cell: &Self::CellId, f: F)where F: FnMut(Self::CellInstId),
Call a function on each instance in this cell.
sourcefn for_each_cell_dependency<F>(&self, cell: &Self::CellId, f: F)where
F: FnMut(Self::CellId),
fn for_each_cell_dependency<F>(&self, cell: &Self::CellId, f: F)where F: FnMut(Self::CellId),
Call a function for each cell that is a child of this cell
.
sourcefn for_each_dependent_cell<F>(&self, cell: &Self::CellId, f: F)where
F: FnMut(Self::CellId),
fn for_each_dependent_cell<F>(&self, cell: &Self::CellId, f: F)where F: FnMut(Self::CellId),
Call a function for each cell that directly depends on cell
.
sourcefn for_each_cell_reference<F>(&self, cell: &Self::CellId, f: F)where
F: FnMut(Self::CellInstId),
fn for_each_cell_reference<F>(&self, cell: &Self::CellId, f: F)where F: FnMut(Self::CellInstId),
Iterate over all instances of this cell
, i.e. instances that use this cell as
a template.
sourcefn num_child_instances(&self, cell: &Self::CellId) -> usize
fn num_child_instances(&self, cell: &Self::CellId) -> usize
Get the number of cell instances inside the cell
.
Provided Methods§
sourcefn each_cell_vec(&self) -> Vec<Self::CellId>
fn each_cell_vec(&self) -> Vec<Self::CellId>
Get a Vec
of all cell IDs in this netlist.
sourcefn each_cell_instance_vec(&self, cell: &Self::CellId) -> Vec<Self::CellInstId>
fn each_cell_instance_vec(&self, cell: &Self::CellId) -> Vec<Self::CellInstId>
Get a Vec
of the IDs of all instances in this cell.
sourcefn each_cell_instance(
&self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellInstId> + '_>
fn each_cell_instance( &self, cell: &Self::CellId ) -> Box<dyn Iterator<Item = Self::CellInstId> + '_>
Iterate over all instances in a cell.
sourcefn each_cell_dependency_vec(&self, cell: &Self::CellId) -> Vec<Self::CellId>
fn each_cell_dependency_vec(&self, cell: &Self::CellId) -> Vec<Self::CellId>
Get a Vec
of each cell that is a child of this cell
.
sourcefn each_cell_dependency<'a>(
&'a self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellId> + 'a>
fn each_cell_dependency<'a>( &'a self, cell: &Self::CellId ) -> Box<dyn Iterator<Item = Self::CellId> + 'a>
Iterate over all cells that are instantiated in this cell
.
sourcefn num_cell_dependencies(&self, cell: &Self::CellId) -> usize
fn num_cell_dependencies(&self, cell: &Self::CellId) -> usize
Count all cells that are dependencies of cell
.
sourcefn each_dependent_cell_vec(&self, cell: &Self::CellId) -> Vec<Self::CellId>
fn each_dependent_cell_vec(&self, cell: &Self::CellId) -> Vec<Self::CellId>
Get a Vec
of each cell that directly depends on cell
.
sourcefn each_dependent_cell<'a>(
&'a self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellId> + 'a>
fn each_dependent_cell<'a>( &'a self, cell: &Self::CellId ) -> Box<dyn Iterator<Item = Self::CellId> + 'a>
Iterate over each cell that directly depends on cell
.
sourcefn num_dependent_cells(&self, cell: &Self::CellId) -> usize
fn num_dependent_cells(&self, cell: &Self::CellId) -> usize
Count all cells that are directly dependent on cell
, i.e. contain an instance of cell
.
sourcefn each_cell_reference_vec(&self, cell: &Self::CellId) -> Vec<Self::CellInstId>
fn each_cell_reference_vec(&self, cell: &Self::CellId) -> Vec<Self::CellInstId>
Get a Vec
with all cell instances referencing this cell.
sourcefn each_cell_reference(
&self,
cell: &Self::CellId
) -> Box<dyn Iterator<Item = Self::CellInstId> + '_>
fn each_cell_reference( &self, cell: &Self::CellId ) -> Box<dyn Iterator<Item = Self::CellInstId> + '_>
Iterate over all instances of this cell
, i.e. instances that use this cell as
a template.
sourcefn num_cell_references(&self, cell: &Self::CellId) -> usize
fn num_cell_references(&self, cell: &Self::CellId) -> usize
Count all instantiations of cell
.
sourcefn get_chip_property(&self, key: &Self::NameType) -> Option<PropertyValue>
fn get_chip_property(&self, key: &Self::NameType) -> Option<PropertyValue>
Get a property of the top-level chip data structure.
sourcefn get_cell_property(
&self,
cell: &Self::CellId,
key: &Self::NameType
) -> Option<PropertyValue>
fn get_cell_property( &self, cell: &Self::CellId, key: &Self::NameType ) -> Option<PropertyValue>
Get a property of a cell.
sourcefn get_cell_instance_property(
&self,
inst: &Self::CellInstId,
key: &Self::NameType
) -> Option<PropertyValue>
fn get_cell_instance_property( &self, inst: &Self::CellInstId, key: &Self::NameType ) -> Option<PropertyValue>
Get a property of a cell instance.