mirror of
https://github.com/holub/mame
synced 2025-07-01 16:19:38 +03:00
Various netlist fixes:
- minor include cleanup - fix a memory hole (caused by assign operators) - more C++.
This commit is contained in:
parent
4cf6ac6cfd
commit
20a584b348
@ -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
|
// core_terminal_t
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "nl_lists.h"
|
#include "nl_lists.h"
|
||||||
#include "nl_time.h"
|
#include "nl_time.h"
|
||||||
|
#include "plib/palloc.h"
|
||||||
#include "plib/pdynlib.h"
|
#include "plib/pdynlib.h"
|
||||||
#include "plib/pstate.h"
|
#include "plib/pstate.h"
|
||||||
#include "plib/pfmtlog.h"
|
#include "plib/pfmtlog.h"
|
||||||
@ -694,8 +695,6 @@ namespace netlist
|
|||||||
|
|
||||||
void rebuild_list(); /* rebuild m_list after a load */
|
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 ...
|
std::vector<core_terminal_t *> m_core_terms; // save post-start m_list ...
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -707,6 +706,8 @@ namespace netlist
|
|||||||
state_var_u8 m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */
|
state_var_u8 m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void move_connections(net_t *new_net);
|
||||||
|
|
||||||
plib::linkedlist_t<core_terminal_t> m_list_active;
|
plib::linkedlist_t<core_terminal_t> m_list_active;
|
||||||
core_terminal_t * m_railterminal;
|
core_terminal_t * m_railterminal;
|
||||||
|
|
||||||
@ -750,7 +751,7 @@ namespace netlist
|
|||||||
/* internal state support
|
/* internal state support
|
||||||
* FIXME: get rid of this and implement export/import in MAME
|
* 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:
|
protected:
|
||||||
private:
|
private:
|
||||||
@ -772,12 +773,9 @@ namespace netlist
|
|||||||
nl_double &Q_Analog_state_ptr() { return m_cur_Analog; }
|
nl_double &Q_Analog_state_ptr() { return m_cur_Analog; }
|
||||||
|
|
||||||
//FIXME: needed by current solver code
|
//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; }
|
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:
|
private:
|
||||||
devices::matrix_solver_t *m_solver;
|
devices::matrix_solver_t *m_solver;
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "nl_config.h"
|
#include "nl_config.h"
|
||||||
|
#include "plib/palloc.h"
|
||||||
#include "plib/plists.h"
|
#include "plib/plists.h"
|
||||||
#include "plib/putil.h"
|
#include "plib/putil.h"
|
||||||
#include "nl_base.h"
|
#include "nl_base.h"
|
||||||
|
@ -678,8 +678,8 @@ void setup_t::resolve_inputs()
|
|||||||
int tries = 100;
|
int tries = 100;
|
||||||
while (m_links.size() > 0 && tries > 0) // FIXME: convert into constant
|
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 t1s = li->first;
|
||||||
const pstring t2s = li->second;
|
const pstring t2s = li->second;
|
||||||
@ -703,18 +703,20 @@ void setup_t::resolve_inputs()
|
|||||||
|
|
||||||
log().verbose("deleting empty nets ...");
|
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();)
|
netlist().m_nets.erase(
|
||||||
{
|
std::remove_if(netlist().m_nets.begin(), netlist().m_nets.end(),
|
||||||
if (net->get()->num_cons() == 0)
|
[](plib::owned_ptr<detail::net_t> &x)
|
||||||
{
|
{
|
||||||
log().verbose("Deleting net {1} ...", net->get()->name());
|
if (x->num_cons() == 0)
|
||||||
net = netlist().m_nets.erase(net);
|
{
|
||||||
}
|
x->netlist().log().verbose("Deleting net {1} ...", x->name());
|
||||||
else
|
return true;
|
||||||
++net;
|
}
|
||||||
}
|
else
|
||||||
|
return false;
|
||||||
|
}), netlist().m_nets.end());
|
||||||
|
|
||||||
pstring errstr("");
|
pstring errstr("");
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "plib/pstring.h"
|
#include "plib/pstring.h"
|
||||||
#include "plib/palloc.h"
|
|
||||||
#include "plib/pfmtlog.h"
|
#include "plib/pfmtlog.h"
|
||||||
#include "plib/pstream.h"
|
#include "plib/pstream.h"
|
||||||
#include "plib/putil.h"
|
#include "plib/putil.h"
|
||||||
|
@ -64,7 +64,9 @@ mempool::~mempool()
|
|||||||
for (auto & b : m_blocks)
|
for (auto & b : m_blocks)
|
||||||
{
|
{
|
||||||
if (b.m_num_alloc != 0)
|
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;
|
delete b.data;
|
||||||
}
|
}
|
||||||
m_blocks.clear();
|
m_blocks.clear();
|
||||||
@ -122,8 +124,8 @@ void mempool::free(void *ptr)
|
|||||||
fprintf(stderr, "Argh .. double free\n");
|
fprintf(stderr, "Argh .. double free\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
b->m_free = m_min_alloc;
|
//b->m_free = m_min_alloc;
|
||||||
b->cur_ptr = b->data;
|
//b->cur_ptr = b->data;
|
||||||
}
|
}
|
||||||
b->m_num_alloc--;
|
b->m_num_alloc--;
|
||||||
}
|
}
|
||||||
|
@ -117,14 +117,19 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
owned_ptr(const owned_ptr &r) = delete;
|
owned_ptr(const owned_ptr &r) = delete;
|
||||||
owned_ptr & operator =(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_is_owned = r.m_is_owned;
|
||||||
m_ptr = r.m_ptr;
|
m_ptr = r.m_ptr;
|
||||||
r.m_is_owned = false;
|
r.m_is_owned = false;
|
||||||
r.m_ptr = nullptr;
|
r.m_ptr = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
owned_ptr(owned_ptr &&r)
|
owned_ptr(owned_ptr &&r)
|
||||||
{
|
{
|
||||||
m_is_owned = r.m_is_owned;
|
m_is_owned = r.m_is_owned;
|
||||||
@ -143,7 +148,7 @@ public:
|
|||||||
|
|
||||||
~owned_ptr()
|
~owned_ptr()
|
||||||
{
|
{
|
||||||
if (m_is_owned && m_ptr != nullptr)
|
if (m_is_owned && (m_ptr != nullptr))
|
||||||
delete m_ptr;
|
delete m_ptr;
|
||||||
m_is_owned = false;
|
m_is_owned = false;
|
||||||
m_ptr = nullptr;
|
m_ptr = nullptr;
|
||||||
@ -164,25 +169,16 @@ public:
|
|||||||
a.m_ptr = new SC(std::forward<Args>(args)...);
|
a.m_ptr = new SC(std::forward<Args>(args)...);
|
||||||
return std::move(a);
|
return std::move(a);
|
||||||
}
|
}
|
||||||
void release()
|
SC * release()
|
||||||
{
|
{
|
||||||
|
SC *tmp = m_ptr;
|
||||||
m_is_owned = false;
|
m_is_owned = false;
|
||||||
m_ptr = nullptr;
|
m_ptr = nullptr;
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_owned() const { return m_is_owned; }
|
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 & operator *() const { return *m_ptr; }
|
SC & operator *() const { return *m_ptr; }
|
||||||
SC * get() const { return m_ptr; }
|
SC * get() const { return m_ptr; }
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "palloc.h"
|
|
||||||
#include "pstring.h"
|
#include "pstring.h"
|
||||||
|
|
||||||
namespace plib {
|
namespace plib {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
|
||||||
#include "pparser.h"
|
#include "pparser.h"
|
||||||
|
#include "plib/palloc.h"
|
||||||
|
|
||||||
namespace plib {
|
namespace plib {
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pstate.h"
|
#include "pstate.h"
|
||||||
|
#include "palloc.h"
|
||||||
|
|
||||||
namespace plib {
|
namespace plib {
|
||||||
state_manager_t::state_manager_t()
|
state_manager_t::state_manager_t()
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "pconfig.h"
|
#include "pconfig.h"
|
||||||
#include "pstring.h"
|
#include "pstring.h"
|
||||||
#include "palloc.h"
|
|
||||||
#include "pfmtlog.h"
|
#include "pfmtlog.h"
|
||||||
|
|
||||||
namespace plib {
|
namespace plib {
|
||||||
|
@ -157,9 +157,6 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets)
|
|||||||
|
|
||||||
if (net_proxy_output == nullptr)
|
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()));
|
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();
|
net_proxy_output = net_proxy_output_u.get();
|
||||||
m_inps.push_back(std::move(net_proxy_output_u));
|
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()
|
void NETLIB_NAME(solver)::post_start()
|
||||||
{
|
{
|
||||||
std::vector<analog_net_t::list_t> groups;
|
|
||||||
const bool use_specific = true;
|
const bool use_specific = true;
|
||||||
|
|
||||||
m_params.m_pivot = m_pivot();
|
m_params.m_pivot = m_pivot();
|
||||||
@ -729,25 +778,14 @@ void NETLIB_NAME(solver)::post_start()
|
|||||||
|
|
||||||
netlist().log().verbose("Scanning net groups ...");
|
netlist().log().verbose("Scanning net groups ...");
|
||||||
// determine net groups
|
// determine net groups
|
||||||
for (auto & net : netlist().m_nets)
|
|
||||||
{
|
net_splitter splitter;
|
||||||
netlist().log().debug("processing {1}\n", net->name());
|
|
||||||
if (!net->isRailNet())
|
splitter.run(netlist());
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup the solvers
|
// setup the solvers
|
||||||
netlist().log().verbose("Found {1} net groups in {2} nets\n", groups.size(), netlist().m_nets.size());
|
netlist().log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), netlist().m_nets.size());
|
||||||
for (auto & grp : groups)
|
for (auto & grp : splitter.groups)
|
||||||
{
|
{
|
||||||
std::unique_ptr<matrix_solver_t> ms;
|
std::unique_ptr<matrix_solver_t> ms;
|
||||||
unsigned net_count = static_cast<unsigned>(grp.size());
|
unsigned net_count = static_cast<unsigned>(grp.size());
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "nl_convert.h"
|
#include "nl_convert.h"
|
||||||
|
#include "plib/palloc.h"
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------
|
/*-------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user