netlist: Code refactoring. (nw)

Replaced downcast with static_cast to avoid errors.
This commit is contained in:
couriersud 2019-01-14 23:32:51 +01:00
parent 05b89d3fcc
commit 28bc5506be
8 changed files with 77 additions and 58 deletions

View File

@ -123,7 +123,7 @@ public:
, m_cpu_device(nullptr)
, m_last(*this, "m_last", 0)
{
m_cpu_device = downcast<netlist_mame_cpu_device *>(&downcast<netlist_mame_device::netlist_mame_t &>(netlist()).parent());
m_cpu_device = downcast<netlist_mame_cpu_device *>(&static_cast<netlist_mame_device::netlist_mame_t &>(netlist()).parent());
}
ATTR_COLD void reset() override
@ -171,7 +171,7 @@ public:
, m_cpu_device(nullptr)
, m_last(*this, "m_last", 0)
{
m_cpu_device = downcast<netlist_mame_cpu_device *>(&downcast<netlist_mame_device::netlist_mame_t &>(netlist()).parent());
m_cpu_device = downcast<netlist_mame_cpu_device *>(&static_cast<netlist_mame_device::netlist_mame_t &>(netlist()).parent());
}
ATTR_COLD void reset() override
@ -238,7 +238,7 @@ public:
std::unique_ptr<plib::pistream> netlist_source_memregion_t::stream(const pstring &name)
{
memory_region *mem = downcast<netlist_mame_device::netlist_mame_t &>(setup().netlist()).machine().root_device().memregion(m_name.c_str());
memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().netlist()).machine().root_device().memregion(m_name.c_str());
return plib::make_unique_base<plib::pistream, plib::pimemstream>(mem->base(), mem->bytes());
}
@ -249,8 +249,7 @@ netlist_data_memregions_t::netlist_data_memregions_t(netlist::setup_t &setup)
std::unique_ptr<plib::pistream> netlist_data_memregions_t::stream(const pstring &name)
{
memory_region *mem = downcast<netlist_mame_device::netlist_mame_t &>(setup().netlist()).parent().memregion(name.c_str());
//memory_region *mem = downcast<netlist_mame_t &>(setup().netlist()).machine().root_device().memregion(name.c_str());
memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().netlist()).parent().memregion(name.c_str());
if (mem != nullptr)
{
return plib::make_unique_base<plib::pistream, plib::pimemstream>(mem->base(), mem->bytes());
@ -881,7 +880,7 @@ void netlist_mame_device::device_start()
}
}
netlist().start();
netlist().prepare_to_run();
netlist().save(*this, m_rem, "m_rem");
netlist().save(*this, m_div, "m_div");
@ -1016,7 +1015,7 @@ void netlist_mame_cpu_device::device_start()
state_add(STATE_GENPCBASE, "CURPC", m_genPC).noshow();
int index = 0;
for (auto &n : netlist().m_nets)
for (auto &n : netlist().nets())
{
if (n->is_logic())
{

View File

@ -183,7 +183,7 @@ void detail::queue_t::on_post_load()
netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize);
for (std::size_t i = 0; i < m_qsize; i++ )
{
detail::net_t *n = netlist().m_nets[m_net_ids[i]].get();
detail::net_t *n = netlist().nets()[m_net_ids[i]].get();
this->push(queue_t::entry_t(netlist_time::from_raw(m_times[i]),n));
}
}
@ -290,9 +290,9 @@ void netlist_t::remove_dev(core_device_t *dev)
);
}
void netlist_t::start()
void netlist_t::prepare_to_run()
{
setup().start_devices();
setup().register_dynamic_log_devices();
/* load the library ... */
@ -616,8 +616,8 @@ void netlist_t::print_stats() const
* static_cast<nperftime_t<NL_KEEP_STATISTICS>::type>(total_count)
/ static_cast<nperftime_t<NL_KEEP_STATISTICS>::type>(200000);
log().verbose("Queue Pushes {1:15}", queue().m_prof_call());
log().verbose("Queue Moves {1:15}", queue().m_prof_sortmove());
log().verbose("Queue Pushes {1:15}", m_queue.m_prof_call());
log().verbose("Queue Moves {1:15}", m_queue.m_prof_sortmove());
log().verbose("Total loop {1:15}", m_stat_mainloop());
/* Only one serialization should be counted in total time */
@ -627,7 +627,7 @@ void netlist_t::print_stats() const
log().verbose("Take the next lines with a grain of salt. They depend on the measurement implementation.");
log().verbose("Total overhead {1:15}", total_overhead);
nperftime_t<NL_KEEP_STATISTICS>::type overhead_per_pop = (m_stat_mainloop()-2*total_overhead - (total_time - total_overhead))
/ static_cast<nperftime_t<NL_KEEP_STATISTICS>::type>(queue().m_prof_call());
/ static_cast<nperftime_t<NL_KEEP_STATISTICS>::type>(m_queue.m_prof_call());
log().verbose("Overhead per pop {1:11}", overhead_per_pop );
log().verbose("");
for (auto &entry : m_devices)
@ -1048,7 +1048,7 @@ logic_output_t::logic_output_t(core_device_t &dev, const pstring &aname)
, m_my_net(dev.netlist(), name() + ".net", this)
{
this->set_net(&m_my_net);
netlist().m_nets.push_back(plib::owned_ptr<logic_net_t>(&m_my_net, false));
netlist().register_net(plib::owned_ptr<logic_net_t>(&m_my_net, false));
set_logic_family(dev.logic_family());
netlist().setup().register_term(*this);
}
@ -1085,7 +1085,7 @@ analog_output_t::analog_output_t(core_device_t &dev, const pstring &aname)
: analog_t(dev, aname, STATE_OUT)
, m_my_net(dev.netlist(), name() + ".net", this)
{
netlist().m_nets.push_back(plib::owned_ptr<analog_net_t>(&m_my_net, false));
netlist().register_net(plib::owned_ptr<analog_net_t>(&m_my_net, false));
this->set_net(&m_my_net);
//net().m_cur_Analog = NL_FCONST(0.0);

View File

@ -80,14 +80,15 @@ class NETLIB_NAME(name) : public device_t
: device_t(owner, name)
/*! Add this to a device definition to mark the device as dynamic.
* If NETLIB_IS_DYNAMIC(true) is added to the device definition the device
* is treated as an analog dynamic device, i.e. #NETLIB_UPDATE_TERMINALSI
* is called on a each step of the Newton-Raphson step
* of solving the linear equations.
*
* You may also use e.g. NETLIB_IS_DYNAMIC(m_func() != "") to only make the
* device a dynamic device if parameter m_func is set.
*/
*
* If NETLIB_IS_DYNAMIC(true) is added to the device definition the device
* is treated as an analog dynamic device, i.e. #NETLIB_UPDATE_TERMINALSI
* is called on a each step of the Newton-Raphson step
* of solving the linear equations.
*
* You may also use e.g. NETLIB_IS_DYNAMIC(m_func() != "") to only make the
* device a dynamic device if parameter m_func is set.
*/
#define NETLIB_IS_DYNAMIC(expr) \
public: virtual bool is_dynamic() const override { return expr; }
@ -1228,8 +1229,10 @@ namespace netlist
{
public:
using nets_collection_type = std::vector<plib::owned_ptr<detail::net_t>>;
explicit netlist_t(const pstring &aname, std::unique_ptr<callbacks_t> callbacks);
virtual ~netlist_t();
~netlist_t();
/* run functions */
@ -1242,14 +1245,24 @@ namespace netlist
void process_queue(const netlist_time &delta) NL_NOEXCEPT;
void abort_current_queue_slice() NL_NOEXCEPT { m_queue.retime(detail::queue_t::entry_t(m_time, nullptr)); }
const detail::queue_t &queue() const NL_NOEXCEPT { return m_queue; }
detail::queue_t &queue() NL_NOEXCEPT { return m_queue; }
/* setup functions - not needed by execute interface */
/* Control functions */
void start();
void stop();
void reset();
const detail::queue_t &queue() const NL_NOEXCEPT { return m_queue; }
detail::queue_t &queue() NL_NOEXCEPT { return m_queue; }
// ========================================================
// configuration section
// ========================================================
void prepare_to_run();
// FIXME: sort rebuild_lists out
void rebuild_lists(); /* must be called after post_load ! */
/* netlist build functions */
@ -1300,34 +1313,48 @@ namespace netlist
template<typename O, typename C> void save(O &owner, C &state, const pstring &stname)
{
this->state().save_item(static_cast<void *>(&owner), state, from_utf8(owner.name()) + pstring(".") + stname);
this->state().save_item(static_cast<void *>(&owner), state, owner.name() + pstring(".") + stname);
}
template<typename O, typename C> void save(O &owner, C *state, const pstring &stname, const std::size_t count)
{
this->state().save_state_ptr(static_cast<void *>(&owner), from_utf8(owner.name()) + pstring(".") + stname, plib::state_manager_t::datatype_f<C>::f(), count, state);
this->state().save_state_ptr(static_cast<void *>(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f<C>::f(), count, state);
}
plib::dynlib &lib() { return *m_lib; }
// FIXME: find something better
/* sole use is to manage lifetime of net objects */
std::vector<plib::owned_ptr<detail::net_t>> m_nets;
const nets_collection_type &nets() { return m_nets; }
template <typename T>
void register_net(plib::owned_ptr<T> &&net)
{
m_nets.push_back(std::move(net));
}
void delete_empty_nets()
{
m_nets.erase(
std::remove_if(m_nets.begin(), 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;
}), m_nets.end());
}
/* sole use is to manage lifetime of family objects */
std::vector<std::pair<pstring, std::unique_ptr<logic_family_desc_t>>> m_family_cache;
// FIXME: sort rebuild_lists out
void rebuild_lists(); /* must be called after post_load ! */
protected:
void print_stats() const;
private:
/* helper for save above */
static pstring from_utf8(const char *c) { return pstring(c); }
static pstring from_utf8(const pstring &c) { return c; }
core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const;
/* mostly rw */
@ -1349,7 +1376,9 @@ namespace netlist
nperftime_t<NL_KEEP_STATISTICS> m_stat_mainloop;
nperfcount_t<NL_KEEP_STATISTICS> m_perf_out_processed;
/* sole use is to manage lifetime of net objects */
std::vector<plib::owned_ptr<core_device_t>> m_devices;
nets_collection_type m_nets;
std::unique_ptr<callbacks_t> m_callbacks;
log_type m_log;

View File

@ -59,6 +59,8 @@
#define NL_DEBUG (false)
#define NL_KEEP_STATISTICS (0)
//#define NL_DEBUG (true)
//#define NL_KEEP_STATISTICS (1)
//============================================================
// General Macros

View File

@ -544,7 +544,7 @@ void setup_t::connect_terminals(detail::core_terminal_t &t1, detail::core_termin
log().debug("adding analog net ...\n");
// FIXME: Nets should have a unique name
auto anet = plib::palloc<analog_net_t>(netlist(),"net." + t1.name());
netlist().m_nets.push_back(plib::owned_ptr<analog_net_t>(anet, true));
netlist().register_net(plib::owned_ptr<analog_net_t>(anet, true));
t1.set_net(anet);
anet->add_terminal(t2);
anet->add_terminal(t1);
@ -687,18 +687,7 @@ void setup_t::resolve_inputs()
// delete empty nets
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());
netlist().delete_empty_nets();
pstring errstr("");
@ -719,7 +708,7 @@ void setup_t::resolve_inputs()
}
void setup_t::start_devices()
void setup_t::register_dynamic_log_devices()
{
pstring env = plib::util::environment("NL_LOGS", "");

View File

@ -245,7 +245,7 @@ namespace netlist
param_t *find_param(const pstring &param_in, bool required = true) const;
void start_devices();
void register_dynamic_log_devices();
void resolve_inputs();
/* handle namespace */

View File

@ -182,7 +182,7 @@ public:
log_setup(logs);
// start devices
this->start();
this->prepare_to_run();
// reset
this->reset();
}
@ -595,7 +595,7 @@ void tool_app_t::listdevices()
nt.setup().include("dummy");
nt.start();
nt.prepare_to_run();
std::vector<plib::owned_ptr<netlist::core_device_t>> devs;

View File

@ -215,7 +215,7 @@ struct net_splitter
void run(netlist_t &netlist)
{
for (auto & net : netlist.m_nets)
for (auto & net : netlist.nets())
{
netlist.log().debug("processing {1}\n", net->name());
if (!net->isRailNet() && net->num_cons() > 0)
@ -279,7 +279,7 @@ void NETLIB_NAME(solver)::post_start()
splitter.run(netlist());
// setup the solvers
log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), netlist().m_nets.size());
log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), netlist().nets().size());
for (auto & grp : splitter.groups)
{
matrix_solver_t *ms;