Skip to content

Commit

Permalink
feat(schematics): add instantiate_connected_named (#447)
Browse files Browse the repository at this point in the history
* feat(schematics): add `instantiate_connected_named`

* add instantiate named methods to sub cell builder
  • Loading branch information
rahulk29 authored Aug 10, 2024
1 parent 081f8f5 commit 6c31948
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions substrate/src/schematic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ impl<S: Schema + ?Sized> CellBuilder<S> {
self.connect(inst.io, io);
}

/// Creates an instance using [`CellBuilder::instantiate`] and immediately connects its ports.
pub fn instantiate_connected_named<B, C>(&mut self, block: B, io: C, name: impl Into<ArcStr>)
where
B: Schematic<S>,
C: IsBundle,
<B::Io as HardwareType>::Bundle: Connect<C>,
{
let inst = self.instantiate_named(block, name);
self.connect(inst.io, io);
}

/// Creates nodes for the newly-instantiated block's IOs and adds the raw instance.
fn post_instantiate<B: ExportsNestedData>(
&mut self,
Expand Down Expand Up @@ -447,6 +458,21 @@ impl<'a, S: FromSchema<S2> + ?Sized, S2: Schema + ?Sized> SubCellBuilder<'a, S,
self.post_instantiate(cell, SourceInfo::from_caller(), None)
}

/// Instantiates a block and assigns a name to the instance.
///
/// See [`CellBuilder::instantiate`] for details.
///
/// Callers must ensure that instance names are unique.
#[track_caller]
pub fn instantiate_named<B: Schematic<S2>>(
&mut self,
block: B,
name: impl Into<ArcStr>,
) -> Instance<B> {
let cell = self.ctx().generate_cross_schematic(block);
self.post_instantiate(cell, SourceInfo::from_caller(), Some(name.into()))
}

/// Instantiates a schematic view of the given block, blocking on generator for underlying
/// cell. Returns an error if the generator returned an error.
///
Expand Down Expand Up @@ -474,6 +500,17 @@ impl<'a, S: FromSchema<S2> + ?Sized, S2: Schema + ?Sized> SubCellBuilder<'a, S,
self.connect(inst.io, io);
}

/// Creates an instance using [`SubCellBuilder::instantiate`] and immediately connects its ports.
pub fn instantiate_connected_named<B, C>(&mut self, block: B, io: C, name: impl Into<ArcStr>)
where
B: Schematic<S2>,
C: IsBundle,
<B::Io as HardwareType>::Bundle: Connect<C>,
{
let inst = self.instantiate_named(block, name);
self.connect(inst.io, io);
}

/// Creates nodes for the newly-instantiated block's IOs.
fn post_instantiate<B: ExportsNestedData>(
&mut self,
Expand Down

0 comments on commit 6c31948

Please sign in to comment.