Fixing issue #1683 (Spice reader accepts circuits without definition but pins get shorted)

This commit is contained in:
Matthias Koefferlein 2024-04-14 21:04:02 +02:00
parent 6a876d2cd6
commit 62f0ea3b97
2 changed files with 27 additions and 2 deletions

View File

@ -1203,7 +1203,10 @@ SpiceNetlistBuilder::process_element (tl::Extractor &ex, const std::string &pref
cc_nc->set_anonymous (true);
cc = cc_nc;
std::vector<std::string> 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);

View File

@ -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<std::string, tl::Variant> vars;