Various netlist fixes:

- minor include cleanup
- fix a memory hole (caused by assign operators)
- more C++.
This commit is contained in:
couriersud 2016-08-06 04:36:13 +02:00
parent 4cf6ac6cfd
commit 20a584b348
13 changed files with 98 additions and 92 deletions

View File

@ -803,37 +803,6 @@ analog_net_t::analog_net_t(netlist_t &nl, const pstring &aname, detail::core_ter
{
}
bool analog_net_t::already_processed(std::vector<list_t> &groups)
{
if (isRailNet())
return true;
for (auto & grp : groups)
{
if (plib::container::contains(grp, this))
return true;
}
return false;
}
void analog_net_t::process_net(std::vector<list_t> &groups)
{
if (num_cons() == 0)
return;
/* add the net */
groups.back().push_back(this);
for (auto &p : m_core_terms)
{
if (p->is_type(terminal_t::TERMINAL))
{
terminal_t *pt = static_cast<terminal_t *>(p);
analog_net_t *other_net = &pt->m_otherterm->net();
if (!other_net->already_processed(groups))
other_net->process_net(groups);
}
}
}
// ----------------------------------------------------------------------------------------
// core_terminal_t
// ----------------------------------------------------------------------------------------

View File

@ -17,6 +17,7 @@
#include "nl_lists.h"
#include "nl_time.h"
#include "plib/palloc.h"
#include "plib/pdynlib.h"
#include "plib/pstate.h"
#include "plib/pfmtlog.h"
@ -694,8 +695,6 @@ namespace netlist
void rebuild_list(); /* rebuild m_list after a load */
void move_connections(net_t *new_net);
std::vector<core_terminal_t *> m_core_terms; // save post-start m_list ...
protected:
@ -707,6 +706,8 @@ namespace netlist
state_var_u8 m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */
private:
void move_connections(net_t *new_net);
plib::linkedlist_t<core_terminal_t> m_list_active;
core_terminal_t * m_railterminal;
@ -750,7 +751,7 @@ namespace netlist
/* internal state support
* FIXME: get rid of this and implement export/import in MAME
*/
netlist_sig_t &Q_state_ptr() { return m_cur_Q; }
netlist_sig_t &Q_state_ptr() { return m_cur_Q; }
protected:
private:
@ -772,12 +773,9 @@ namespace netlist
nl_double &Q_Analog_state_ptr() { return m_cur_Analog; }
//FIXME: needed by current solver code
devices::matrix_solver_t *solver() { return m_solver; }
devices::matrix_solver_t *solver() const { return m_solver; }
void set_solver(devices::matrix_solver_t *solver) { m_solver = solver; }
bool already_processed(std::vector<list_t> &groups);
void process_net(std::vector<list_t> &groups);
private:
devices::matrix_solver_t *m_solver;
};

View File

@ -12,6 +12,7 @@
#include <type_traits>
#include "nl_config.h"
#include "plib/palloc.h"
#include "plib/plists.h"
#include "plib/putil.h"
#include "nl_base.h"

View File

@ -678,8 +678,8 @@ void setup_t::resolve_inputs()
int tries = 100;
while (m_links.size() > 0 && tries > 0) // FIXME: convert into constant
{
auto li = m_links.begin();
while (li != m_links.end())
for (auto li = m_links.begin(); li != m_links.end(); )
{
const pstring t1s = li->first;
const pstring t2s = li->second;
@ -703,18 +703,20 @@ void setup_t::resolve_inputs()
log().verbose("deleting empty nets ...");
// delete empty nets ... and save m_list ...
// delete empty nets
for (auto net = netlist().m_nets.begin(); net != netlist().m_nets.end();)
{
if (net->get()->num_cons() == 0)
{
log().verbose("Deleting net {1} ...", net->get()->name());
net = netlist().m_nets.erase(net);
}
else
++net;
}
netlist().m_nets.erase(
std::remove_if(netlist().m_nets.begin(), netlist().m_nets.end(),
[](plib::owned_ptr<detail::net_t> &x)
{
if (x->num_cons() == 0)
{
x->netlist().log().verbose("Deleting net {1} ...", x->name());
return true;
}
else
return false;
}), netlist().m_nets.end());
pstring errstr("");

View File

@ -14,7 +14,6 @@
#include <vector>
#include "plib/pstring.h"
#include "plib/palloc.h"
#include "plib/pfmtlog.h"
#include "plib/pstream.h"
#include "plib/putil.h"

View File

@ -64,7 +64,9 @@ mempool::~mempool()
for (auto & b : m_blocks)
{
if (b.m_num_alloc != 0)
fprintf(stderr, "Found block with dangling allocations\n");
{
fprintf(stderr, "Found block with %d dangling allocations\n", (int) b.m_num_alloc);
}
delete b.data;
}
m_blocks.clear();
@ -122,8 +124,8 @@ void mempool::free(void *ptr)
fprintf(stderr, "Argh .. double free\n");
else
{
b->m_free = m_min_alloc;
b->cur_ptr = b->data;
//b->m_free = m_min_alloc;
//b->cur_ptr = b->data;
}
b->m_num_alloc--;
}

View File

@ -117,14 +117,19 @@ public:
{ }
owned_ptr(const owned_ptr &r) = delete;
owned_ptr & operator =(owned_ptr &r) = delete;
owned_ptr & operator =(owned_ptr &&r)
template<typename DC>
owned_ptr & operator =(owned_ptr<DC> &&r)
{
if (m_is_owned && (m_ptr != nullptr))
delete m_ptr;
m_is_owned = r.m_is_owned;
m_ptr = r.m_ptr;
r.m_is_owned = false;
r.m_ptr = nullptr;
return *this;
}
owned_ptr(owned_ptr &&r)
{
m_is_owned = r.m_is_owned;
@ -143,7 +148,7 @@ public:
~owned_ptr()
{
if (m_is_owned && m_ptr != nullptr)
if (m_is_owned && (m_ptr != nullptr))
delete m_ptr;
m_is_owned = false;
m_ptr = nullptr;
@ -164,25 +169,16 @@ public:
a.m_ptr = new SC(std::forward<Args>(args)...);
return std::move(a);
}
void release()
SC * release()
{
SC *tmp = m_ptr;
m_is_owned = false;
m_ptr = nullptr;
return tmp;
}
bool is_owned() const { return m_is_owned; }
#if 1
template<typename DC>
owned_ptr & operator =(owned_ptr<DC> &&r)
{
m_is_owned = r.m_is_owned;
m_ptr = r.m_ptr;
r.m_is_owned = false;
r.m_ptr = nullptr;
return *this;
}
#endif
SC * operator ->() const { return m_ptr; }
SC & operator *() const { return *m_ptr; }
SC * get() const { return m_ptr; }

View File

@ -15,7 +15,6 @@
#include <type_traits>
#include <cmath>
#include "palloc.h"
#include "pstring.h"
namespace plib {

View File

@ -8,6 +8,7 @@
#include <cstdarg>
#include "pparser.h"
#include "plib/palloc.h"
namespace plib {
// ----------------------------------------------------------------------------------------

View File

@ -6,6 +6,7 @@
*/
#include "pstate.h"
#include "palloc.h"
namespace plib {
state_manager_t::state_manager_t()

View File

@ -12,7 +12,6 @@
#include "pconfig.h"
#include "pstring.h"
#include "palloc.h"
#include "pfmtlog.h"
namespace plib {

View File

@ -157,9 +157,6 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets)
if (net_proxy_output == nullptr)
{
//net_proxy_output = palloc(analog_output_t(*this,
// this->name() + "." + plib::pfmt("m{1}")(m_inps.size())));
auto net_proxy_output_u = plib::make_unique<proxied_analog_output_t>(*this, this->name() + "." + plib::pfmt("m{1}")(m_inps.size()));
net_proxy_output = net_proxy_output_u.get();
m_inps.push_back(std::move(net_proxy_output_u));
@ -691,9 +688,61 @@ std::unique_ptr<matrix_solver_t> NETLIB_NAME(solver)::create_solver(unsigned siz
}
}
struct net_splitter
{
bool already_processed(analog_net_t *n)
{
if (n->isRailNet())
return true;
for (auto & grp : groups)
if (plib::container::contains(grp, n))
return true;
return false;
}
void process_net(analog_net_t *n)
{
if (n->num_cons() == 0)
return;
/* add the net */
groups.back().push_back(n);
for (auto &p : n->m_core_terms)
{
if (p->is_type(terminal_t::TERMINAL))
{
terminal_t *pt = static_cast<terminal_t *>(p);
analog_net_t *other_net = &pt->m_otherterm->net();
if (!already_processed(other_net))
process_net(other_net);
}
}
}
void run(netlist_t &netlist)
{
for (auto & net : netlist.m_nets)
{
netlist.log().debug("processing {1}\n", net->name());
if (!net->isRailNet() && net->num_cons() > 0)
{
netlist.log().debug(" ==> not a rail net\n");
/* Must be an analog net */
analog_net_t *n = static_cast<analog_net_t *>(net.get());
if (!already_processed(n))
{
groups.push_back(analog_net_t::list_t());
process_net(n);
}
}
}
}
std::vector<analog_net_t::list_t> groups;
};
void NETLIB_NAME(solver)::post_start()
{
std::vector<analog_net_t::list_t> groups;
const bool use_specific = true;
m_params.m_pivot = m_pivot();
@ -729,25 +778,14 @@ void NETLIB_NAME(solver)::post_start()
netlist().log().verbose("Scanning net groups ...");
// determine net groups
for (auto & net : netlist().m_nets)
{
netlist().log().debug("processing {1}\n", net->name());
if (!net->isRailNet())
{
netlist().log().debug(" ==> not a rail net\n");
/* Must be an analog net */
analog_net_t *n = static_cast<analog_net_t *>(net.get());
if (!n->already_processed(groups))
{
groups.push_back(analog_net_t::list_t());
n->process_net(groups);
}
}
}
net_splitter splitter;
splitter.run(netlist());
// setup the solvers
netlist().log().verbose("Found {1} net groups in {2} nets\n", groups.size(), netlist().m_nets.size());
for (auto & grp : groups)
netlist().log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), netlist().m_nets.size());
for (auto & grp : splitter.groups)
{
std::unique_ptr<matrix_solver_t> ms;
unsigned net_count = static_cast<unsigned>(grp.size());

View File

@ -9,6 +9,7 @@
#include <cstdio>
#include <cmath>
#include "nl_convert.h"
#include "plib/palloc.h"
/*-------------------------------------------------