Add code to remove devices connected only to rail terminals.

This commit is contained in:
couriersud 2017-01-14 14:29:25 +01:00
parent ef8b7ccb6b
commit bce5c521a2
3 changed files with 35 additions and 3 deletions

View File

@ -299,6 +299,20 @@ void netlist_t::register_dev(plib::owned_ptr<core_device_t> dev)
m_devices.push_back(std::move(dev));
}
void netlist_t::remove_dev(core_device_t *dev)
{
m_devices.erase(
std::remove_if(
m_devices.begin(),
m_devices.end(),
[&] (plib::owned_ptr<core_device_t> const& p)
{
return p.get() == dev;
}),
m_devices.end()
);
}
const logic_family_desc_t *netlist_t::family_from_model(const pstring &model)
{
model_map_t map;
@ -840,6 +854,19 @@ void detail::net_t::add_terminal(detail::core_terminal_t &terminal)
m_active++;
}
void detail::net_t::remove_terminal(detail::core_terminal_t &terminal)
{
if (plib::container::contains(m_core_terms, &terminal))
{
terminal.set_net(nullptr);
plib::container::remove(m_core_terms, &terminal);
}
else
netlist().log().fatal("Can not remove terminal {1} from net {2}.", terminal.name(), this->name());
if (terminal.state() != logic_t::STATE_INP_PASSIVE)
m_active--;
}
void detail::net_t::move_connections(detail::net_t &dest_net)
{
for (auto &ct : m_core_terms)

View File

@ -699,6 +699,7 @@ namespace netlist
void reset();
void add_terminal(core_terminal_t &terminal);
void remove_terminal(core_terminal_t &terminal);
bool is_logic() const NL_NOEXCEPT;
bool is_analog() const NL_NOEXCEPT;
@ -1185,6 +1186,7 @@ namespace netlist
setup_t &setup() { return *m_setup; }
void register_dev(plib::owned_ptr<core_device_t> dev);
void remove_dev(core_device_t *dev);
detail::net_t *find_net(const pstring &name);
const logic_family_desc_t *family_from_model(const pstring &model);

View File

@ -753,13 +753,16 @@ void setup_t::resolve_inputs()
log().fatal("{1}", errstr);
log().verbose("looking for two terms connected to rail nets ...\n");
log().verbose("looking for two terms connected to rail nets ...");
for (auto & t : netlist().get_device_list<devices::NETLIB_NAME(twoterm)>())
{
if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet())
{
log().warning("Found device {1} connected only to railterminals {2}/{3}\n",
log().warning("Found device {1} connected only to railterminals {2}/{3}. Will be removed",
t->name(), t->m_N.net().name(), t->m_P.net().name());
t->m_N.net().remove_terminal(t->m_N);
t->m_P.net().remove_terminal(t->m_P);
netlist().remove_dev(t);
}
}
}
@ -770,7 +773,7 @@ void setup_t::start_devices()
if (env != "")
{
log().debug("Creating dynamic logs ...\n");
log().debug("Creating dynamic logs ...");
plib::pstring_vector_t loglist(env, ":");
for (pstring ll : loglist)
{