From 62f0ea3b97edc615fe6fb173e5b29dd6736db53b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 14 Apr 2024 21:04:02 +0200 Subject: [PATCH] Fixing issue #1683 (Spice reader accepts circuits without definition but pins get shorted) --- src/db/db/dbNetlistSpiceReader.cc | 7 +++++-- src/db/unit_tests/dbNetlistReaderTests.cc | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/db/db/dbNetlistSpiceReader.cc b/src/db/db/dbNetlistSpiceReader.cc index 7f92bcf8b..88632b71a 100644 --- a/src/db/db/dbNetlistSpiceReader.cc +++ b/src/db/db/dbNetlistSpiceReader.cc @@ -1203,7 +1203,10 @@ SpiceNetlistBuilder::process_element (tl::Extractor &ex, const std::string &pref cc_nc->set_anonymous (true); cc = cc_nc; std::vector pins; - pins.resize (nn.size ()); + pins.reserve (nn.size ()); + for (size_t i = 0; i < nn.size (); ++i) { + pins.push_back (tl::to_string (i + 1)); + } cc_nc->set_pins (pins); } } @@ -1218,7 +1221,7 @@ SpiceNetlistBuilder::process_element (tl::Extractor &ex, const std::string &pref } if (cc->pin_count () != nn.size ()) { - error (tl::sprintf (tl::to_string (tr ("Pin count mismatch between circuit definition and circuit call: %d expected, got %d")), int (cc->pin_count ()), int (nets.size ()))); + error (tl::sprintf (tl::to_string (tr ("Pin count mismatch between circuit definition and circuit call: %d expected, got %d (definition maybe implicit somewhere before)")), int (cc->pin_count ()), int (nets.size ()))); } db::Circuit *c = build_circuit (cc, pv); diff --git a/src/db/unit_tests/dbNetlistReaderTests.cc b/src/db/unit_tests/dbNetlistReaderTests.cc index fdb68e873..85aee7ada 100644 --- a/src/db/unit_tests/dbNetlistReaderTests.cc +++ b/src/db/unit_tests/dbNetlistReaderTests.cc @@ -858,6 +858,28 @@ TEST(22_endl) ); } +// issue #1683 +TEST(23_endl) +{ + db::Netlist nl; + + std::string path = tl::combine_path (tl::combine_path (tl::testdata (), "algo"), "nreader23.cir"); + + db::NetlistSpiceReader reader; + tl::InputStream is (path); + reader.read (is, nl); + + EXPECT_EQ (nl.to_string (), + "circuit .TOP ();\n" + " device PFET M1 (S=VDD,G=I,D=O,B=VDD) (L=100,W=100,AS=0,AD=0,PS=0,PD=0);\n" + " device NFET M2 (S=VSS,G=I,D=O,B=VSS) (L=100,W=100,AS=0,AD=0,PS=0,PD=0);\n" + " subcircuit DOESNOTEXIST DUMMY ('1'=O,'2'=I);\n" + "end;\n" + "circuit DOESNOTEXIST ('1'='1','2'='2');\n" + "end;\n" + ); +} + TEST(100_ExpressionParser) { std::map vars;