Trait libreda_db::hierarchy::traits::HierarchyBase
source · [−]pub trait HierarchyBase {
type NameType: Eq + Hash + From<String> + Into<String> + Clone + Borrow<String> + Borrow<str> + PartialOrd + Ord + Display + Debug;
type CellId: Eq + Hash + Clone + Debug + 'static;
type CellInstId: Eq + Hash + Clone + Debug + 'static;
Show 29 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;
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
Type for names of cells, instances, etc.
Required Methods
fn 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.
fn 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.
fn 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.
fn 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.
fn 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.
fn 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.
fn 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.
fn 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
.
fn 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
.
fn 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.
fn 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
fn 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.
fn 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.
fn 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.
fn 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
.
Iterate over all cells that are instantiated in this cell
.
fn 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
.
fn 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
.
Iterate over each cell that directly depends on cell
.
fn 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
.
fn 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.
fn 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.
fn num_cell_references(&self, cell: &Self::CellId) -> usize
fn num_cell_references(&self, cell: &Self::CellId) -> usize
Count all instantiations of cell
.
fn 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.
fn 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.
fn 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.