From 1f954d875846c2254e74978ecc363d078b2956b9 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 27 Aug 2022 17:23:11 +0200 Subject: [PATCH] Cell#read --- src/db/db/gsiDeclDbCell.cc | 69 +++++++++++++++++++ src/rba/unit_tests/rbaTests.cc | 5 +- .../ruby/{dbLayout.rb => dbLayoutTests1.rb} | 2 +- .../{dbLayoutTest.rb => dbLayoutTests2.rb} | 2 +- 4 files changed, 74 insertions(+), 4 deletions(-) rename testdata/ruby/{dbLayout.rb => dbLayoutTests1.rb} (99%) rename testdata/ruby/{dbLayoutTest.rb => dbLayoutTests2.rb} (99%) diff --git a/src/db/db/gsiDeclDbCell.cc b/src/db/db/gsiDeclDbCell.cc index a03c27290..af71fabda 100644 --- a/src/db/db/gsiDeclDbCell.cc +++ b/src/db/db/gsiDeclDbCell.cc @@ -38,9 +38,11 @@ #include "dbCellMapping.h" #include "dbPCellDeclaration.h" #include "dbSaveLayoutOptions.h" +#include "dbLoadLayoutOptions.h" #include "dbRecursiveShapeIterator.h" #include "dbRecursiveInstanceIterator.h" #include "dbWriter.h" +#include "dbReader.h" #include "dbHash.h" #include "tlStream.h" @@ -1683,6 +1685,39 @@ static const char *cell_name (const db::Cell *cell) } } +static std::vector +read_options (db::Cell *cell, const std::string &path, const db::LoadLayoutOptions &options) +{ + if (! cell->layout ()) { + throw tl::Exception (tl::to_string (tr ("Cell does not reside in a layout - cannot read such cells"))); + } + + db::Layout tmp (cell->layout ()->dbu ()); + + { + tl::InputStream stream (path); + db::Reader reader (stream); + reader.read (tmp, options); + } + + if (tmp.end_top_cells () - tmp.begin_top_down () != 1) { + throw tl::Exception (tl::to_string (tr ("Imported layout does not have a single top cell - cannot read such layouts into a cell"))); + } + + db::CellMapping cm; + std::vector new_cells = cm.create_single_mapping_full (*cell->layout (), cell->cell_index (), tmp, *tmp.begin_top_down ()); + cell->move_tree_shapes (tmp.cell (*tmp.begin_top_down ()), cm); + + return new_cells; +} + +static std::vector +read_simple (db::Cell *cell, const std::string &path) +{ + return read_options (cell, path, db::LoadLayoutOptions ()); +} + + static db::Point default_origin; Class decl_Cell ("db", "Cell", @@ -1761,6 +1796,40 @@ Class decl_Cell ("db", "Cell", "\n" "This method has been introduced in version 0.23.\n" ) + + gsi::method_ext ("read", &read_options, gsi::arg ("file_name"), gsi::arg ("options"), + "@brief Reads a layout file into this cell\n" + "\n" + "@param file_name The path of the file to read\n" + "@param options The reader options to use\n" + "@return The indexes of the cells created during the reading (new child cells)\n" + "\n" + "The format of the file will be determined from the file name. " + "The layout will be read into the cell, potentially creating new layers and " + "a subhierarchy of cells below this cell.\n" + "\n" + "This feature is equivalent to the following code:\n" + "\n" + "@code\n" + "def Cell.read(file_name, options)\n" + " layout = RBA::Layout::new\n" + " layout.read(file_name, options)\n" + " cm = RBA::CellMapping::new\n" + " cm.for_single_cell_full(self, layout.top_cell)\n" + " self.move_tree_shapes(layout.top_cell)\n" + "end\n" + "@/code\n" + "\n" + "See \\move_tree_shapes and \\CellMapping for more details and how to " + "implement more elaborate schemes.\n" + "\n" + "This method has been introduced in version 0.28.\n" + ) + + gsi::method_ext ("read", &read_simple, gsi::arg ("file_name"), + "@brief Reads a layout file into this cell\n" + "This version uses the default options for reading the file.\n" + "\n" + "This method has been introduced in version 0.28.\n" + ) + gsi::method_ext ("dup", &dup_cell, "@brief Creates a copy of the cell\n" "\n" diff --git a/src/rba/unit_tests/rbaTests.cc b/src/rba/unit_tests/rbaTests.cc index 300637249..fb25e8af2 100644 --- a/src/rba/unit_tests/rbaTests.cc +++ b/src/rba/unit_tests/rbaTests.cc @@ -105,10 +105,11 @@ RUBYTEST (dbInstanceTest, "dbInstanceTest.rb") RUBYTEST (dbInstElementTest, "dbInstElementTest.rb") RUBYTEST (dbLayerMapping, "dbLayerMapping.rb") RUBYTEST (dbLibrary, "dbLibrary.rb") -RUBYTEST (dbLayout, "dbLayout.rb") +RUBYTEST (dbLayoutTests1, "dbLayoutTests1.rb") +RUBYTEST (dbLayoutTests2, "dbLayoutTests2.rb") +RUBYTEST (dbCellTests, "dbCellTests.rb") RUBYTEST (dbRecursiveShapeIterator, "dbRecursiveShapeIterator.rb") RUBYTEST (dbRecursiveInstanceIterator, "dbRecursiveInstanceIterator.rb") -RUBYTEST (dbLayoutTest, "dbLayoutTest.rb") RUBYTEST (dbLayoutDiff, "dbLayoutDiff.rb") RUBYTEST (dbLayoutQuery, "dbLayoutQuery.rb") RUBYTEST (dbLayoutToNetlist, "dbLayoutToNetlist.rb") diff --git a/testdata/ruby/dbLayout.rb b/testdata/ruby/dbLayoutTests1.rb similarity index 99% rename from testdata/ruby/dbLayout.rb rename to testdata/ruby/dbLayoutTests1.rb index 92ca43de9..80cd4eb76 100644 --- a/testdata/ruby/dbLayout.rb +++ b/testdata/ruby/dbLayoutTests1.rb @@ -23,7 +23,7 @@ end load("test_prologue.rb") -class DBLayout_TestClass < TestBase +class DBLayoutTests1_TestClass < TestBase def test_1 diff --git a/testdata/ruby/dbLayoutTest.rb b/testdata/ruby/dbLayoutTests2.rb similarity index 99% rename from testdata/ruby/dbLayoutTest.rb rename to testdata/ruby/dbLayoutTests2.rb index d45f27249..1d318957b 100644 --- a/testdata/ruby/dbLayoutTest.rb +++ b/testdata/ruby/dbLayoutTests2.rb @@ -23,7 +23,7 @@ end load("test_prologue.rb") -class DBLayoutTest_TestClass < TestBase +class DBLayoutTests2_TestClass < TestBase # LayerInfo def test_1_Layout