Skip to content

Commit

Permalink
feat(layouts): support exporting layouts with multiple top cells (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulk29 authored Jun 12, 2024
1 parent fc40421 commit 991e467
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
23 changes: 22 additions & 1 deletion substrate/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,28 @@ impl<PDK: Pdk> PdkContext<PDK> {
let layer_ctx = self.layer_ctx.read().unwrap();
let db_units = PDK::LAYOUT_DB_UNITS.to_f64().unwrap();
GdsExporter::with_units(
cell.raw.clone(),
vec![cell.raw.clone()],
&layer_ctx,
GdsUnits::new(db_units / 1e-6, db_units),
)
.export()
.map_err(LayoutError::from)?
.save(path)
.map_err(GdsExportError::from)
.map_err(LayoutError::from)?;
Ok(())
}

/// Writes a set of layout cells to a GDS file.
pub fn write_layout_all(
&self,
cells: impl IntoIterator<Item = Arc<RawCell>>,
path: impl AsRef<Path>,
) -> Result<()> {
let layer_ctx = self.layer_ctx.read().unwrap();
let db_units = PDK::LAYOUT_DB_UNITS.to_f64().unwrap();
GdsExporter::with_units(
cells.into_iter().collect::<Vec<_>>(),
&layer_ctx,
GdsUnits::new(db_units / 1e-6, db_units),
)
Expand Down
14 changes: 8 additions & 6 deletions substrate/src/layout/gds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ new_key_type! {
///
/// Takes a [`RawCell`] and converts it to a [`gds::GdsLibrary`].
pub struct GdsExporter<'a> {
cell: Arc<RawCell>,
cells: Vec<Arc<RawCell>>,
layers: &'a LayerContext,
cell_db: Names<CellId>,
gds: gds::GdsLibrary,
Expand All @@ -56,9 +56,9 @@ impl<'a> GdsExporter<'a> {
///
/// Requires the cell to be exported and a [`LayerContext`] for mapping Substrate layers to GDS
/// layers.
pub fn new(cell: Arc<RawCell>, layers: &'a LayerContext) -> Self {
pub fn new(cells: Vec<Arc<RawCell>>, layers: &'a LayerContext) -> Self {
Self {
cell,
cells,
layers,
cell_db: Default::default(),
gds: gds::GdsLibrary::new("TOP"),
Expand All @@ -69,9 +69,9 @@ impl<'a> GdsExporter<'a> {
///
/// Requires the cell to be exported and a [`LayerContext`] for mapping Substrate layers to GDS
/// layers.
pub fn with_units(cell: Arc<RawCell>, layers: &'a LayerContext, units: GdsUnits) -> Self {
pub fn with_units(cells: Vec<Arc<RawCell>>, layers: &'a LayerContext, units: GdsUnits) -> Self {
Self {
cell,
cells,
layers,
cell_db: Default::default(),
gds: gds::GdsLibrary::with_units("TOP", units),
Expand All @@ -80,7 +80,9 @@ impl<'a> GdsExporter<'a> {

/// Exports the contents of `self` as a [`gds::GdsLibrary`].
pub fn export(mut self) -> GdsExportResult<gds::GdsLibrary> {
self.cell.clone().export(&mut self)?;
for cell in self.cells.clone() {
cell.clone().export(&mut self)?;
}
Ok(self.gds)
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<T: ExportsLayoutData> Cell<T> {
}

/// The raw layout geometry contained by this cell.
pub fn raw(&self) -> &RawCell {
pub fn raw(&self) -> &Arc<RawCell> {
&self.raw
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,29 @@ fn cell_builder_supports_bbox() {
assert_eq!(cell.bbox(), Some(Rect::from_sides(-10, -1110, 2200, 210)));
}

#[test]
fn export_multi_top_layout() {
let test_name = "export_multi_top_layout";

let block1 = BufferNxM::new(5, 10, 6);
let block2 = BufferNxM::new(5, 10, 6);
let block3 = BufferNxM::new(8, 12, 4);

let ctx = PdkContext::new(ExamplePdkA);
let block1 = ctx.generate_layout(block1);
let block2 = ctx.generate_layout(block2);
let block3 = ctx.generate_layout(block3);
ctx.write_layout_all(
[
block1.cell().raw().clone(),
block2.cell().raw().clone(),
block3.cell().raw().clone(),
],
get_path(test_name, "layout.gds"),
)
.expect("failed to write layout");
}

#[test]
fn grid_tiler_works_with_various_spans() {
let test_name = "grid_tiler_works_with_various_spans";
Expand Down

0 comments on commit 991e467

Please sign in to comment.