diff options
Diffstat (limited to 'src/lib/netlist/nl_base.h')
-rw-r--r-- | src/lib/netlist/nl_base.h | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index b4f41396298..739b6dfc6fd 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -23,6 +23,7 @@ #include "plib/pstonum.h" #include "plib/pstream.h" #include "plib/ptime.h" +#include "plib/pexception.h" #include "nl_errstr.h" #include "nltypes.h" @@ -174,13 +175,13 @@ class NETLIB_NAME(name) : public device_t //============================================================ #if defined(MAME_DEBUG) || (NL_DEBUG == true) -#define nl_assert(x) do { if (1) if (!(x)) plib::pthrow<nl_exception>(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0) +#define nl_assert(x) passert_always(x); #define NL_NOEXCEPT #else -#define nl_assert(x) do { if (0) if (!(x)) { /*throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); */} } while (0) +#define nl_assert(x) do { } while (0) #define NL_NOEXCEPT noexcept #endif -#define nl_assert_always(x, msg) do { if (!(x)) plib::pthrow<nl_exception>("Fatal error: {1}\nCaused by assert: {2}:{3}: {4}", msg, __FILE__, __LINE__, #x); } while (0) +#define nl_assert_always(x, msg) passert_always_msg(x, msg) //============================================================ // Namespace starts @@ -424,9 +425,19 @@ namespace netlist store().insert({obj, aname}); } - static const T get(const C *obj) noexcept + static const T &get(const C *obj) noexcept { - return store().find(obj)->second; + try + { + auto ret(store().find(obj)); + nl_assert(ret != store().end()); + return ret->second; + } + catch (...) + { + nl_assert_always(true, "exception in property_store_t.get()"); + return *static_cast<T *>(nullptr); + } } static void remove(const C *obj) noexcept @@ -472,7 +483,7 @@ namespace netlist /// /// \returns name of the object. - pstring name() const noexcept + const pstring &name() const noexcept { return props::get(this); } @@ -492,7 +503,7 @@ namespace netlist struct netlist_ref { - explicit netlist_ref(netlist_state_t &nl); + explicit netlist_ref(netlist_t &nl); COPYASSIGNMOVE(netlist_ref, delete) @@ -1076,10 +1087,7 @@ namespace netlist ~device_t() noexcept override = default; template<class C, typename... Args> - void create_and_register_subdevice(const pstring &name, unique_pool_ptr<C> &dev, Args&&... args) - { - dev = pool().make_unique<C>(*this, name, std::forward<Args>(args)...); - } + void create_and_register_subdevice(const pstring &name, unique_pool_ptr<C> &dev, Args&&... args); void register_subalias(const pstring &name, detail::core_terminal_t &term); void register_subalias(const pstring &name, const pstring &aliased); @@ -1335,7 +1343,7 @@ namespace netlist public: using base_queue = timed_queue<plib::pqentry_t<net_t *, netlist_time>, false>; using entry_t = plib::pqentry_t<net_t *, netlist_time>; - explicit queue_t(netlist_state_t &nl); + explicit queue_t(netlist_t &nl); ~queue_t() noexcept override = default; queue_t(const queue_t &) = delete; @@ -1370,12 +1378,16 @@ namespace netlist // need to preserve order of device creation ... using devices_collection_type = std::vector<std::pair<pstring, owned_pool_ptr<core_device_t>>>; netlist_state_t(const pstring &aname, - netlist_t & anetlist, plib::unique_ptr<callbacks_t> &&callbacks); COPYASSIGNMOVE(netlist_state_t, delete) - ~netlist_state_t() noexcept = default; + /// \brief Destructor + /// + /// The destructor is virtual to allow implementation specific devices + /// to connect to the outside world. For examples see MAME netlist.cpp. + /// + virtual ~netlist_state_t() noexcept = default; friend class netlist_t; // allow access to private members @@ -1428,8 +1440,8 @@ namespace netlist plib::dynlib &lib() const noexcept { return *m_lib; } - netlist_t &exec() { return m_netlist; } - const netlist_t &exec() const { return m_netlist; } + netlist_t &exec() { return *m_netlist; } + const netlist_t &exec() const { return *m_netlist; } // state handling plib::state_manager_t &run_state_manager() { return m_state; } @@ -1536,12 +1548,21 @@ namespace netlist // sole use is to manage lifetime of family objects std::unordered_map<pstring, plib::unique_ptr<logic_family_desc_t>> m_family_cache; + template<typename T, typename... Args> + unique_pool_ptr<T> make_object(Args&&... args) + { + return m_pool.make_unique<T>(std::forward<Args>(args)...); + } + // memory pool - still needed in some places + nlmempool &pool() noexcept { return m_pool; } + const nlmempool &pool() const noexcept { return m_pool; } private: void reset(); + nlmempool m_pool; // must be deleted last! pstring m_name; - netlist_t &m_netlist; + unique_pool_ptr<netlist_t> m_netlist; plib::unique_ptr<plib::dynlib> m_lib; // external lib needs to be loaded as long as netlist exists plib::state_manager_t m_state; plib::unique_ptr<callbacks_t> m_callbacks; @@ -1599,7 +1620,7 @@ namespace netlist { public: - explicit netlist_t(const pstring &aname, plib::unique_ptr<callbacks_t> callbacks); + explicit netlist_t(netlist_state_t &state); COPYASSIGNMOVE(netlist_t, delete) @@ -1643,10 +1664,6 @@ namespace netlist void stop(); void reset(); - // state handling - - plib::state_manager_t &run_state_manager() noexcept { return m_state->run_state_manager(); } - // only used by nltool to create static c-code devices::NETLIB_NAME(solver) *solver() const noexcept { return m_solver; } @@ -1658,11 +1675,11 @@ namespace netlist return static_cast<X *>(m_solver)->gmin(); } - netlist_state_t &nlstate() noexcept { return *m_state; } - const netlist_state_t &nlstate() const noexcept { return *m_state; } + netlist_state_t &nlstate() noexcept { return m_state; } + const netlist_state_t &nlstate() const noexcept { return m_state; } - log_type & log() noexcept { return m_state->log(); } - const log_type &log() const noexcept { return m_state->log(); } + log_type & log() noexcept { return m_state.log(); } + const log_type &log() const noexcept { return m_state.log(); } void print_stats() const; @@ -1674,7 +1691,7 @@ namespace netlist template <bool KEEP_STATS> void process_queue_stats(netlist_time delta) noexcept; - plib::unique_ptr<netlist_state_t> m_state; + netlist_state_t & m_state; devices::NETLIB_NAME(solver) * m_solver; // mostly rw @@ -1725,6 +1742,12 @@ namespace netlist return m_netlist.nlstate(); } + template<class C, typename... Args> + void device_t::create_and_register_subdevice(const pstring &name, unique_pool_ptr<C> &dev, Args&&... args) + { + dev = state().make_object<C>(*this, name, std::forward<Args>(args)...); + } + template <typename T> param_num_t<T>::param_num_t(device_t &device, const pstring &name, const T val) : param_t(device, name) |