mirror of
https://github.com/holub/mame
synced 2025-07-08 11:21:56 +03:00
netlist: Fix logging during object construction. (nw)
This commit is contained in:
parent
1532d2078a
commit
0a17d35c13
@ -49,21 +49,16 @@ DEFINE_DEVICE_TYPE(NETLIST_STREAM_OUTPUT, netlist_mame_stream_output_device, "nl
|
||||
// Special netlist extension devices ....
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
class netlist_mame_device::netlist_mame_t : public netlist::netlist_t
|
||||
class netlist_mame_device::netlist_mame_callbacks_t : public netlist::callbacks_t
|
||||
{
|
||||
public:
|
||||
|
||||
netlist_mame_t(netlist_mame_device &parent, const pstring &aname)
|
||||
: netlist::netlist_t(aname)
|
||||
netlist_mame_callbacks_t(netlist_mame_device &parent)
|
||||
: netlist::callbacks_t()
|
||||
, m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
running_machine &machine() { return m_parent.machine(); }
|
||||
|
||||
|
||||
netlist_mame_device &parent() { return m_parent; }
|
||||
|
||||
protected:
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const override
|
||||
{
|
||||
@ -95,6 +90,24 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class netlist_mame_device::netlist_mame_t : public netlist::netlist_t
|
||||
{
|
||||
public:
|
||||
|
||||
netlist_mame_t(netlist_mame_device &parent, const pstring &aname)
|
||||
: netlist::netlist_t(aname, plib::make_unique<netlist_mame_device::netlist_mame_callbacks_t>(parent))
|
||||
, m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
running_machine &machine() { return m_parent.machine(); }
|
||||
netlist_mame_device &parent() { return m_parent; }
|
||||
|
||||
private:
|
||||
netlist_mame_device &m_parent;
|
||||
};
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
@ -173,7 +186,7 @@ public:
|
||||
|
||||
NETLIB_UPDATEI()
|
||||
{
|
||||
netlist_sig_t cur = m_in();
|
||||
netlist::netlist_sig_t cur = m_in();
|
||||
|
||||
// FIXME: make this a parameter
|
||||
// avoid calls due to noise
|
||||
@ -190,7 +203,7 @@ private:
|
||||
netlist::logic_input_t m_in;
|
||||
netlist_mame_logic_output_device::output_delegate m_callback;
|
||||
netlist_mame_cpu_device *m_cpu_device;
|
||||
netlist::state_var<netlist_sig_t> m_last;
|
||||
netlist::state_var<netlist::netlist_sig_t> m_last;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
@ -505,7 +518,7 @@ void netlist_mame_cpu_device::state_string_export(const device_state_entry &entr
|
||||
if (entry.index() & 1)
|
||||
str = string_format("%10.6f", *((double *)entry.dataptr()));
|
||||
else
|
||||
str = string_format("%d", *((netlist_sig_t *)entry.dataptr()));
|
||||
str = string_format("%d", *((netlist::netlist_sig_t *)entry.dataptr()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -837,8 +850,6 @@ void netlist_mame_device::device_start()
|
||||
|
||||
m_netlist = global_alloc(netlist_mame_t(*this, "netlist"));
|
||||
|
||||
m_netlist->load_base_libraries();
|
||||
|
||||
// register additional devices
|
||||
|
||||
nl_register_devices();
|
||||
|
@ -99,6 +99,7 @@ class netlist_mame_device : public device_t
|
||||
{
|
||||
public:
|
||||
class netlist_mame_t;
|
||||
class netlist_mame_callbacks_t;
|
||||
|
||||
// construction/destruction
|
||||
netlist_mame_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
|
@ -48,6 +48,20 @@ namespace netlist
|
||||
// nld_twoterm
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
template <class C>
|
||||
inline core_device_t &bselect(bool b, C &d1, core_device_t &d2)
|
||||
{
|
||||
core_device_t *h = dynamic_cast<core_device_t *>(&d1);
|
||||
return b ? *h : d2;
|
||||
}
|
||||
template<>
|
||||
inline core_device_t &bselect(bool b, netlist_t &d1, core_device_t &d2)
|
||||
{
|
||||
if (b)
|
||||
throw nl_exception("bselect with netlist and b==true");
|
||||
return d2;
|
||||
}
|
||||
|
||||
NETLIB_OBJECT(twoterm)
|
||||
{
|
||||
NETLIB_CONSTRUCTOR_EX(twoterm, bool terminals_owned = false)
|
||||
@ -87,12 +101,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
template <class C>
|
||||
static core_device_t &bselect(bool b, C &d1, core_device_t &d2)
|
||||
{
|
||||
core_device_t *h = dynamic_cast<core_device_t *>(&d1);
|
||||
return b ? *h : d2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -12,12 +12,40 @@
|
||||
#include "nl_config.h"
|
||||
#include "plib/pchrono.h"
|
||||
#include "plib/pstring.h"
|
||||
#include "plib/pfmtlog.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace netlist
|
||||
{
|
||||
/*! @brief netlist_sig_t is the type used for logic signals.
|
||||
*
|
||||
* This may be any of bool, uint8_t, uint16_t, uin32_t and uint64_t.
|
||||
* The choice has little to no impact on performance.
|
||||
*/
|
||||
using netlist_sig_t = std::uint32_t;
|
||||
|
||||
/**
|
||||
* @brief Interface definition for netlist callbacks into calling code
|
||||
*
|
||||
* A class inheriting from netlist_callbacks_t has to be passed to the netlist_t
|
||||
* constructor. Netlist does processing during construction and thus needs
|
||||
* the object passed completely constructed.
|
||||
*
|
||||
*/
|
||||
class callbacks_t
|
||||
{
|
||||
public:
|
||||
virtual ~callbacks_t() {}
|
||||
|
||||
/* logging callback */
|
||||
virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0;
|
||||
};
|
||||
|
||||
using log_type = plib::plog_base<callbacks_t, NL_DEBUG>;
|
||||
|
||||
|
||||
//============================================================
|
||||
// Performance tracking
|
||||
//============================================================
|
||||
|
@ -239,20 +239,22 @@ detail::terminal_type detail::core_terminal_t::type() const
|
||||
// netlist_t
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
netlist_t::netlist_t(const pstring &aname)
|
||||
netlist_t::netlist_t(const pstring &aname, std::unique_ptr<callbacks_t> callbacks)
|
||||
: m_time(netlist_time::zero())
|
||||
, m_queue(*this)
|
||||
, m_mainclock(nullptr)
|
||||
, m_solver(nullptr)
|
||||
, m_params(nullptr)
|
||||
, m_name(aname)
|
||||
, m_log(*this)
|
||||
, m_lib(nullptr)
|
||||
, m_state()
|
||||
, m_callbacks(std::move(callbacks)) // Order is important here
|
||||
, m_log(*m_callbacks)
|
||||
{
|
||||
state().save_item(this, static_cast<plib::state_manager_t::callback_t &>(m_queue), "m_queue");
|
||||
state().save_item(this, m_time, "m_time");
|
||||
m_setup = plib::make_unique<setup_t>(*this);
|
||||
NETLIST_NAME(base)(*m_setup);
|
||||
}
|
||||
|
||||
netlist_t::~netlist_t()
|
||||
@ -261,11 +263,6 @@ netlist_t::~netlist_t()
|
||||
m_devices.clear();
|
||||
}
|
||||
|
||||
void netlist_t::load_base_libraries()
|
||||
{
|
||||
NETLIST_NAME(base)(*m_setup);
|
||||
}
|
||||
|
||||
nl_double netlist_t::gmin() const NL_NOEXCEPT
|
||||
{
|
||||
return solver()->gmin();
|
||||
@ -694,7 +691,7 @@ void core_device_t::set_default_delegate(detail::core_terminal_t &term)
|
||||
term.m_delegate.set(&core_device_t::update, this);
|
||||
}
|
||||
|
||||
plib::plog_base<netlist_t, NL_DEBUG> &core_device_t::log()
|
||||
log_type & core_device_t::log()
|
||||
{
|
||||
return netlist().log();
|
||||
}
|
||||
|
@ -9,6 +9,11 @@
|
||||
#ifndef NLBASE_H_
|
||||
#define NLBASE_H_
|
||||
|
||||
#ifdef NL_PROHIBIT_BASEH_INCLUDE
|
||||
#error "nl_base.h included. Please correct."
|
||||
#endif
|
||||
|
||||
#include "netlist_types.h"
|
||||
#include "nl_lists.h"
|
||||
#include "nl_time.h"
|
||||
#include "plib/palloc.h" // owned_ptr
|
||||
@ -20,21 +25,6 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#ifdef NL_PROHIBIT_BASEH_INCLUDE
|
||||
#error "nl_base.h included. Please correct."
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
/*! @brief netlist_sig_t is the type used for logic signals.
|
||||
*
|
||||
* This may be any of bool, uint8_t, uint16_t, uin32_t and uint64_t.
|
||||
* The choice has little to no impact on performance.
|
||||
*/
|
||||
using netlist_sig_t = std::uint32_t;
|
||||
|
||||
//============================================================
|
||||
// MACROS / New Syntax
|
||||
//============================================================
|
||||
@ -221,6 +211,7 @@ namespace netlist
|
||||
class netlist_t;
|
||||
class core_device_t;
|
||||
class device_t;
|
||||
class callbacks_t;
|
||||
|
||||
//============================================================
|
||||
// Exceptions
|
||||
@ -1115,7 +1106,7 @@ namespace netlist
|
||||
update();
|
||||
}
|
||||
|
||||
plib::plog_base<netlist_t, NL_DEBUG> &log();
|
||||
log_type & log();
|
||||
|
||||
public:
|
||||
virtual void timestep(const nl_double st) { plib::unused_var(st); }
|
||||
@ -1178,6 +1169,7 @@ namespace netlist
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// nld_base_dummy : basis for dummy devices
|
||||
// FIXME: this is not the right place to define this
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
NETLIB_OBJECT(base_dummy)
|
||||
@ -1223,16 +1215,8 @@ namespace netlist
|
||||
{
|
||||
public:
|
||||
|
||||
explicit netlist_t(const pstring &aname);
|
||||
virtual ~netlist_t();
|
||||
|
||||
/**
|
||||
* @brief Load base libraries for diodes, transistors ...
|
||||
*
|
||||
* This must be called after netlist_t is created.
|
||||
*
|
||||
*/
|
||||
void load_base_libraries();
|
||||
explicit netlist_t(const pstring &aname, std::unique_ptr<callbacks_t> callbacks);
|
||||
~netlist_t();
|
||||
|
||||
/* run functions */
|
||||
|
||||
@ -1292,8 +1276,9 @@ namespace netlist
|
||||
/* logging and name */
|
||||
|
||||
pstring name() const { return m_name; }
|
||||
plib::plog_base<netlist_t, NL_DEBUG> &log() { return m_log; }
|
||||
const plib::plog_base<netlist_t, NL_DEBUG> &log() const { return m_log; }
|
||||
|
||||
log_type & log() { return m_log; }
|
||||
const log_type &log() const { return m_log; }
|
||||
|
||||
/* state related */
|
||||
|
||||
@ -1319,9 +1304,6 @@ namespace netlist
|
||||
// FIXME: sort rebuild_lists out
|
||||
void rebuild_lists(); /* must be called after post_load ! */
|
||||
|
||||
/* logging callback */
|
||||
virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
void print_stats() const;
|
||||
@ -1345,8 +1327,6 @@ namespace netlist
|
||||
devices::NETLIB_NAME(netlistparams) *m_params;
|
||||
|
||||
pstring m_name;
|
||||
std::unique_ptr<setup_t> m_setup;
|
||||
plib::plog_base<netlist_t, NL_DEBUG> m_log;
|
||||
std::unique_ptr<plib::dynlib> m_lib; // external lib needs to be loaded as long as netlist exists
|
||||
|
||||
plib::state_manager_t m_state;
|
||||
@ -1356,6 +1336,10 @@ namespace netlist
|
||||
nperfcount_t<NL_KEEP_STATISTICS> m_perf_out_processed;
|
||||
|
||||
std::vector<plib::owned_ptr<core_device_t>> m_devices;
|
||||
|
||||
std::unique_ptr<callbacks_t> m_callbacks;
|
||||
log_type m_log;
|
||||
std::unique_ptr<setup_t> m_setup;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -768,11 +768,11 @@ void setup_t::start_devices()
|
||||
}
|
||||
}
|
||||
|
||||
plib::plog_base<netlist_t, NL_DEBUG> &setup_t::log()
|
||||
log_type &setup_t::log()
|
||||
{
|
||||
return netlist().log();
|
||||
}
|
||||
const plib::plog_base<netlist_t, NL_DEBUG> &setup_t::log() const
|
||||
const log_type &setup_t::log() const
|
||||
{
|
||||
return netlist().log();
|
||||
}
|
||||
|
@ -288,8 +288,8 @@ namespace netlist
|
||||
/* helper - also used by nltool */
|
||||
const pstring resolve_alias(const pstring &name) const;
|
||||
|
||||
plib::plog_base<netlist_t, NL_DEBUG> &log();
|
||||
const plib::plog_base<netlist_t, NL_DEBUG> &log() const;
|
||||
log_type &log();
|
||||
const log_type &log() const;
|
||||
|
||||
//std::vector<std::pair<pstring, factory::element_t *>> m_device_factory;
|
||||
std::unordered_map<pstring, factory::element_t *> m_device_factory;
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef POMP_H_
|
||||
#define POMP_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "pconfig.h"
|
||||
|
||||
#if HAS_OPENMP
|
||||
|
@ -318,7 +318,7 @@ void ppreprocessor::error(const pstring &err)
|
||||
|
||||
int ppreprocessor::expr(const std::vector<pstring> &sexpr, std::size_t &start, int prio)
|
||||
{
|
||||
int val;
|
||||
int val = 0;
|
||||
pstring tok=sexpr[start];
|
||||
if (tok == "(")
|
||||
{
|
||||
|
@ -132,22 +132,35 @@ std::unique_ptr<plib::pistream> netlist_data_folder_t::stream(const pstring &fil
|
||||
return std::unique_ptr<plib::pistream>(nullptr);
|
||||
}
|
||||
|
||||
class netlist_tool_callbacks_t : public netlist::callbacks_t
|
||||
{
|
||||
public:
|
||||
netlist_tool_callbacks_t(tool_app_t &app)
|
||||
: netlist::callbacks_t()
|
||||
, m_app(app)
|
||||
{ }
|
||||
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const override;
|
||||
|
||||
private:
|
||||
tool_app_t &m_app;
|
||||
};
|
||||
|
||||
class netlist_tool_t : public netlist::netlist_t
|
||||
{
|
||||
public:
|
||||
|
||||
netlist_tool_t(tool_app_t &app, const pstring &aname)
|
||||
: netlist::netlist_t(aname), m_app(app)
|
||||
: netlist::netlist_t(aname, plib::make_unique<netlist_tool_callbacks_t>(app))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~netlist_tool_t() override
|
||||
~netlist_tool_t()
|
||||
{
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
load_base_libraries();
|
||||
}
|
||||
|
||||
void read_netlist(const pstring &filename, const pstring &name,
|
||||
@ -234,13 +247,10 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const override;
|
||||
|
||||
private:
|
||||
tool_app_t &m_app;
|
||||
};
|
||||
|
||||
void netlist_tool_t::vlog(const plib::plog_level &l, const pstring &ls) const
|
||||
void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls) const
|
||||
{
|
||||
pstring err = plib::pfmt("{}: {}\n")(l.name())(ls.c_str());
|
||||
// FIXME: ...
|
||||
|
@ -104,7 +104,7 @@ NETLIB_UPDATE(solver)
|
||||
if (nthreads > 1 && solvers.size() > 1)
|
||||
{
|
||||
plib::omp::set_num_threads(nthreads);
|
||||
plib::omp::for_static(static_cast<std::size_t>(0), solvers.size(), [this, &solvers](std::size_t i)
|
||||
plib::omp::for_static(static_cast<std::size_t>(0), solvers.size(), [&solvers](std::size_t i)
|
||||
{
|
||||
const netlist_time ts = solvers[i]->solve();
|
||||
plib::unused_var(ts);
|
||||
|
Loading…
Reference in New Issue
Block a user