From 46dafd50ea05bfc593f392713592377cdadf10ea Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 22 Jun 2019 10:15:32 +0200 Subject: [PATCH] WIP: unit tests updated --- src/db/db/dbLayoutToNetlistWriter.cc | 2 +- src/db/db/dbLayoutVsSchematicFormatDefs.cc | 32 ++++++++++----------- src/db/db/gsiDeclDbNetlist.cc | 22 ++++++++++++++ testdata/algo/bipolar_devices_nets.gds | Bin 19116 -> 19452 bytes testdata/algo/lvs_test1_au.lvsdb | 6 ++-- testdata/algo/lvs_test1b_au.lvsdb | 6 ++-- testdata/algo/lvs_test2_au.lvsdb | 6 ++-- testdata/algo/lvs_test2b_au.lvsdb | 6 ++-- testdata/ruby/dbNetlist.rb | 4 +++ testdata/ruby/dbNetlistDeviceClasses.rb | 15 ++++++---- 10 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/db/db/dbLayoutToNetlistWriter.cc b/src/db/db/dbLayoutToNetlistWriter.cc index 4ccf62f5a..23d922208 100644 --- a/src/db/db/dbLayoutToNetlistWriter.cc +++ b/src/db/db/dbLayoutToNetlistWriter.cc @@ -577,7 +577,7 @@ void std_writer_impl::write (const db::LayoutToNetlist * /*l2n*/, const db } if (! device.name ().empty ()) { - *mp_stream << " " << Keys::name_key << "(" << tl::to_word_or_quoted_string (device.name ()) << ")"; + *mp_stream << indent << indent2 << Keys::name_key << "(" << tl::to_word_or_quoted_string (device.name ()) << ")" << endl; } for (std::vector::const_iterator i = pd.begin (); i != pd.end (); ++i) { diff --git a/src/db/db/dbLayoutVsSchematicFormatDefs.cc b/src/db/db/dbLayoutVsSchematicFormatDefs.cc index e61162fce..469f5575d 100644 --- a/src/db/db/dbLayoutVsSchematicFormatDefs.cc +++ b/src/db/db/dbLayoutVsSchematicFormatDefs.cc @@ -31,25 +31,25 @@ namespace lvs_std_format DB_PUBLIC std::string ShortKeys::lvs_magic_string (lvs_magic_string_cstr); DB_PUBLIC std::string LongKeys::lvs_magic_string (lvs_magic_string_cstr); - DB_PUBLIC std::string ShortKeys::reference_key ("reference"); - DB_PUBLIC std::string ShortKeys::layout_key ("layout"); - DB_PUBLIC std::string ShortKeys::xref_key ("xref"); + DB_PUBLIC std::string LongKeys::reference_key ("reference"); + DB_PUBLIC std::string LongKeys::layout_key ("layout"); + DB_PUBLIC std::string LongKeys::xref_key ("xref"); - DB_PUBLIC std::string ShortKeys::mismatch_key ("mismatch"); - DB_PUBLIC std::string ShortKeys::match_key ("match"); - DB_PUBLIC std::string ShortKeys::nomatch_key ("nomatch"); - DB_PUBLIC std::string ShortKeys::warning_key ("warning"); - DB_PUBLIC std::string ShortKeys::skipped_key ("skipped"); + DB_PUBLIC std::string LongKeys::mismatch_key ("mismatch"); + DB_PUBLIC std::string LongKeys::match_key ("match"); + DB_PUBLIC std::string LongKeys::nomatch_key ("nomatch"); + DB_PUBLIC std::string LongKeys::warning_key ("warning"); + DB_PUBLIC std::string LongKeys::skipped_key ("skipped"); - DB_PUBLIC std::string LongKeys::reference_key ("H"); - DB_PUBLIC std::string LongKeys::layout_key ("J"); - DB_PUBLIC std::string LongKeys::xref_key ("Z"); + DB_PUBLIC std::string ShortKeys::reference_key ("H"); + DB_PUBLIC std::string ShortKeys::layout_key ("J"); + DB_PUBLIC std::string ShortKeys::xref_key ("Z"); - DB_PUBLIC std::string LongKeys::mismatch_key ("0"); - DB_PUBLIC std::string LongKeys::match_key ("1"); - DB_PUBLIC std::string LongKeys::nomatch_key ("X"); - DB_PUBLIC std::string LongKeys::warning_key ("W"); - DB_PUBLIC std::string LongKeys::skipped_key ("S"); + DB_PUBLIC std::string ShortKeys::mismatch_key ("0"); + DB_PUBLIC std::string ShortKeys::match_key ("1"); + DB_PUBLIC std::string ShortKeys::nomatch_key ("X"); + DB_PUBLIC std::string ShortKeys::warning_key ("W"); + DB_PUBLIC std::string ShortKeys::skipped_key ("S"); } } diff --git a/src/db/db/gsiDeclDbNetlist.cc b/src/db/db/gsiDeclDbNetlist.cc index e7cb9ab40..fb8574355 100644 --- a/src/db/db/gsiDeclDbNetlist.cc +++ b/src/db/db/gsiDeclDbNetlist.cc @@ -29,6 +29,7 @@ #include "tlException.h" #include "tlInternational.h" #include "tlStream.h" +#include "tlGlobPattern.h" namespace gsi { @@ -1275,6 +1276,21 @@ static void read_netlist (db::Netlist *nl, const std::string &file, db::NetlistR reader->read (os, *nl); } +static void flatten_circuit_by_name (db::Netlist *nl, const std::string &name_pattern) +{ + std::list circuits_to_flatten; + tl::GlobPattern pat (name_pattern); + for (db::Netlist::circuit_iterator c = nl->begin_circuits (); c != nl->end_circuits (); ++c) { + if (pat.match (c->name ())) { + circuits_to_flatten.push_back (c.operator-> ()); + } + } + + for (std::list::const_iterator c = circuits_to_flatten.begin (); c != circuits_to_flatten.end (); ++c) { + nl->flatten_circuit (*c); + } +} + Class decl_dbNetlist ("db", "Netlist", gsi::method_ext ("add", &gsi::add_circuit, gsi::arg ("circuit"), "@brief Adds the circuit to the netlist\n" @@ -1290,6 +1306,12 @@ Class decl_dbNetlist ("db", "Netlist", "This method will substitute all instances (subcircuits) of the given circuit by it's " "contents. After this, the circuit is removed." ) + + gsi::method_ext ("flatten_circuit", &flatten_circuit_by_name, gsi::arg ("pattern"), + "@brief Flattens circuits matching a certain pattern\n" + "This method will substitute all instances (subcircuits) of all circuits with names matching the given name pattern. " + "The name pattern is a glob expression. For example, 'flatten_circuit(\"np*\")' will flatten all circuits witt names " + "starting with 'np'." + ) + gsi::method ("circuit_by_cell_index", (db::Circuit *(db::Netlist::*) (db::cell_index_type)) &db::Netlist::circuit_by_cell_index, gsi::arg ("cell_index"), "@brief Gets the circuit object for a given cell index.\n" "If the cell index is not valid or no circuit is registered with this index, nil is returned." diff --git a/testdata/algo/bipolar_devices_nets.gds b/testdata/algo/bipolar_devices_nets.gds index f27a728596b4e0f925c9ea35599b1ec47b7767b9..9e813195c7f05357ce5afe96011bf9c0d15578d6 100644 GIT binary patch delta 1234 zcmbu6KWGzC9LL{Xl1ojRrlB@Lcx@%LlxVMLudz0S5}TyG3fi<}kQx_v7yp11!3=K2 zp?oPWH#j+|OENf!lVovp5akfTB5?>vEGS9n^V0X8AUt$%`uy(uyZ8Hj-}gP;(|V7z zBr%AtUm;Y}gP*-RPL2^u{-}48QzI&Q>)L&1*vDA&fU%#AJ_+${GWPYQBxAkjjD348 z$@TA4lIxvGNv`+qN%nQGejv$pxuR{8EDoYk zn8r>lg6*Q^F^muAhhP+^YpKw_Pr2pf&|Bq}nlZccLqpP>^Byq( zHglp@HouHwJ6}a6pF<~qh`YtAc*)zytlUDYn8UM`9lTh*19P>C8+H|@okPpMgvs_QyarAA>l990LO~d!mx6FgD?+SZ*Bw=Kud+eEI+X z$Fa#qjE2~hO)g`Es{0fIR_DiLD1*f~1}-)>7nK0NfXR)FK@fv~Zvkt_V8(9n8s?i= zEu6uEUA%?$IyUv2^Vq~0u}aKf@5L%H*@Dw)vW23^{dck&y3 zuF2;lG&h?|van%Q?I%AKyZPS~0$+q5sV6WDCTe7h;FtD&N000-AmfipW diff --git a/testdata/algo/lvs_test1_au.lvsdb b/testdata/algo/lvs_test1_au.lvsdb index 50a44da1a..8e8112e64 100644 --- a/testdata/algo/lvs_test1_au.lvsdb +++ b/testdata/algo/lvs_test1_au.lvsdb @@ -799,7 +799,8 @@ reference( # Devices and their connections device(1 PMOS - name($1) param(L 0.25) + name($1) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) @@ -811,7 +812,8 @@ reference( terminal(B 1) ) device(2 NMOS - name($3) param(L 0.25) + name($3) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) diff --git a/testdata/algo/lvs_test1b_au.lvsdb b/testdata/algo/lvs_test1b_au.lvsdb index c52dd68bf..0c1b4a15e 100644 --- a/testdata/algo/lvs_test1b_au.lvsdb +++ b/testdata/algo/lvs_test1b_au.lvsdb @@ -799,7 +799,8 @@ reference( # Devices and their connections device(1 PMOS - name($1) param(L 0.25) + name($1) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) @@ -811,7 +812,8 @@ reference( terminal(B 1) ) device(2 NMOS - name($3) param(L 0.25) + name($3) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) diff --git a/testdata/algo/lvs_test2_au.lvsdb b/testdata/algo/lvs_test2_au.lvsdb index dbf88fd84..7510baff2 100644 --- a/testdata/algo/lvs_test2_au.lvsdb +++ b/testdata/algo/lvs_test2_au.lvsdb @@ -799,7 +799,8 @@ reference( # Devices and their connections device(1 PMOS - name($1) param(L 0.25) + name($1) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) @@ -811,7 +812,8 @@ reference( terminal(B 1) ) device(2 NMOS - name($3) param(L 0.25) + name($3) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) diff --git a/testdata/algo/lvs_test2b_au.lvsdb b/testdata/algo/lvs_test2b_au.lvsdb index e6cd63c0c..9c1707306 100644 --- a/testdata/algo/lvs_test2b_au.lvsdb +++ b/testdata/algo/lvs_test2b_au.lvsdb @@ -799,7 +799,8 @@ reference( # Devices and their connections device(1 PMOS - name($1) param(L 0.25) + name($1) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) @@ -811,7 +812,8 @@ reference( terminal(B 1) ) device(2 NMOS - name($3) param(L 0.25) + name($3) + param(L 0.25) param(W 3.5) param(AS 1.4) param(AD 1.4) diff --git a/testdata/ruby/dbNetlist.rb b/testdata/ruby/dbNetlist.rb index 03a17a85b..c5a693b6b 100644 --- a/testdata/ruby/dbNetlist.rb +++ b/testdata/ruby/dbNetlist.rb @@ -829,6 +829,7 @@ circuit NTRANS ($1=$1,$2=$2,$3=$3); end; END + nl3 = nl2.dup nl2.flatten_circuit(nl2.circuit_by_name("PTRANS")) nl2.flatten_circuit(nl2.circuit_by_name("NTRANS")) @@ -841,6 +842,9 @@ circuit INV2 (IN=IN,$2=$2,OUT=OUT,$4=$4,$5=$5); end; END + nl3.flatten_circuit("{N,P}TRANS") + assert_equal(nl3.to_s, nl2.to_s) + end end diff --git a/testdata/ruby/dbNetlistDeviceClasses.rb b/testdata/ruby/dbNetlistDeviceClasses.rb index 57da3371a..b1884e838 100644 --- a/testdata/ruby/dbNetlistDeviceClasses.rb +++ b/testdata/ruby/dbNetlistDeviceClasses.rb @@ -484,6 +484,7 @@ END d1.set_parameter(RBA::DeviceClassBJT3Transistor::PARAM_PE, 12.0) d1.set_parameter(RBA::DeviceClassBJT3Transistor::PARAM_PB, 13.0) d1.set_parameter(RBA::DeviceClassBJT3Transistor::PARAM_PC, 14.0) + d1.set_parameter(RBA::DeviceClassBJT3Transistor::PARAM_NE, 2.0) d2 = circuit.create_device(cls, "d2") d2.set_parameter("AE", 2.0) d2.set_parameter("AB", 3.0) @@ -491,6 +492,7 @@ END d2.set_parameter("PE", 13.0) d2.set_parameter("PB", 14.0) d2.set_parameter("PC", 15.0) + d2.set_parameter("NE", 3.0) pin_a = circuit.create_pin ("A") pin_b = circuit.create_pin ("B") @@ -513,8 +515,8 @@ END assert_equal(nl.to_s, <