diff --git a/src/db/db/dbNetlistSpiceReader.cc b/src/db/db/dbNetlistSpiceReader.cc index af72199e5..269a85bb5 100644 --- a/src/db/db/dbNetlistSpiceReader.cc +++ b/src/db/db/dbNetlistSpiceReader.cc @@ -419,7 +419,10 @@ bool NetlistSpiceReader::read_card () while (! ex.at_end ()) { std::string n = read_name (ex); - m_global_nets.push_back (n); + if (m_global_net_names.find (n) == m_global_net_names.end ()) { + m_global_nets.push_back (n); + m_global_net_names.insert (n); + } } } else if (ex.test_without_case ("subckt")) { diff --git a/src/db/db/dbNetlistSpiceReader.h b/src/db/db/dbNetlistSpiceReader.h index fd1de5e26..088400258 100644 --- a/src/db/db/dbNetlistSpiceReader.h +++ b/src/db/db/dbNetlistSpiceReader.h @@ -131,6 +131,7 @@ private: std::string m_stored_line; std::map m_captured; std::vector m_global_nets; + std::set m_global_net_names; std::set m_circuits_read; void push_stream (const std::string &path); diff --git a/src/db/unit_tests/dbNetlistReaderTests.cc b/src/db/unit_tests/dbNetlistReaderTests.cc index 8c6f29de0..75ff3bf80 100644 --- a/src/db/unit_tests/dbNetlistReaderTests.cc +++ b/src/db/unit_tests/dbNetlistReaderTests.cc @@ -422,3 +422,24 @@ TEST(11_ErrorOnCircuitRedefinition) EXPECT_EQ (tl::replaced (msg, path, "?"), "Redefinition of circuit SUBCKT in ?, line 20"); } +TEST(12_IgnoreDuplicateGlobals) +{ + db::Netlist nl; + + std::string path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "nreader12.cir"); + + db::NetlistSpiceReader reader; + tl::InputStream is (path); + reader.read (is, nl); + + EXPECT_EQ (nl.to_string (), + "circuit .TOP ();\n" + " device RES $1 (A=VDD,B=GND) (R=1000,L=0,W=0,A=0,P=0);\n" + " subcircuit FILLER_CAP '0' (VDD=VDD,GND=GND);\n" + "end;\n" + "circuit FILLER_CAP (VDD=VDD,GND=GND);\n" + " device NMOS '0' (S=GND,G=VDD,D=GND,B=GND) (L=10,W=10,AS=0,AD=0,PS=0,PD=0);\n" + "end;\n" + ); +} + diff --git a/testdata/algo/nreader12.cir b/testdata/algo/nreader12.cir new file mode 100644 index 000000000..86a72691d --- /dev/null +++ b/testdata/algo/nreader12.cir @@ -0,0 +1,14 @@ + +.global vdd gnd + +X0 FILLER_CAP +R$1 vdd gnd 1k + +* should be ignored: +.global vdd +.global gnd + +.subckt FILLER_CAP +M0 gnd vdd gnd gnd NMOS W=10u L=10u +.ends FILLER_CAP +