diff options
author | 2020-07-01 20:59:04 +0200 | |
---|---|---|
committer | 2020-07-01 20:59:04 +0200 | |
commit | 319be2dfd271ebf81ba3cf651be0b30695ec0d06 (patch) | |
tree | 08d9d10c35c10a495412292f628d41a82ed1873b | |
parent | 51ba9b48f08202939d06240eaa1dcfc7dfbd7c1c (diff) |
netlist: code maintenance and bug fixes.
* palloc.h/pmatrix2d.h: Fix static_assert warnings at the origin.
* Rework hints to broaden their use and fix NC hint.
* 74377: use NC hint
* plists.h: Fix debugging in MSVC
* Include cleanup: Move everything not needed by netlists from
nl_setup.h into core/setup.h
* Fix some clang tidy warnings
* srcclean
27 files changed, 431 insertions, 343 deletions
diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index a2a309d4a18..4910d7484e1 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -50,6 +50,7 @@ project "netlist" MAME_DIR .. "src/lib/netlist/nl_setup.cpp", MAME_DIR .. "src/lib/netlist/nl_setup.h", MAME_DIR .. "src/lib/netlist/nl_types.h", + MAME_DIR .. "src/lib/netlist/core/setup.h", MAME_DIR .. "src/lib/netlist/plib/pconfig.h", MAME_DIR .. "src/lib/netlist/plib/palloc.h", MAME_DIR .. "src/lib/netlist/plib/pchrono.h", diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index abd4486c362..aeb38da4d50 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -2,7 +2,7 @@ // copyright-holders:Couriersud #include "netlist/solver/nld_solver.h" -#include "netlist/nl_setup.h" +#include "netlist/nl_base.h" #include "nlid_twoterm.h" // FIXME: Remove QBJT_switch - no more use diff --git a/src/lib/netlist/core/setup.h b/src/lib/netlist/core/setup.h new file mode 100644 index 00000000000..d21b948f4ee --- /dev/null +++ b/src/lib/netlist/core/setup.h @@ -0,0 +1,323 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud + +/// +/// \file setup.h +/// + +#ifndef NL_CORE_SETUP_H_ +#define NL_CORE_SETUP_H_ + +#include "../nl_config.h" +#include "../nltypes.h" +#include "../nl_factory.h" +#include "../nl_setup.h" + +#include "../plib/ppreprocessor.h" +#include "../plib/pstream.h" +#include "../plib/pstring.h" + +#include <initializer_list> +#include <memory> +#include <stack> +#include <unordered_map> +#include <vector> + + +namespace netlist +{ + + // ---------------------------------------------------------------------------------------- + // Collection of models + // ---------------------------------------------------------------------------------------- + + class models_t + { + public: + using raw_map_t = std::unordered_map<pstring, pstring>; + using map_t = std::unordered_map<pstring, pstring>; + class model_t + { + public: + model_t(const pstring &model, const map_t &map) + : m_model(model), m_map(map) { } + + pstring value_str(const pstring &entity) const; + + nl_fptype value(const pstring &entity) const; + + pstring type() const { return value_str("COREMODEL"); } + + private: + static pstring model_string(const map_t &map); + + const pstring m_model; // only for error messages + const map_t &m_map; + }; + + models_t(const raw_map_t &models) + : m_models(models) + {} + + model_t get_model(const pstring &model); + + private: + + void model_parse(const pstring &model, map_t &map); + + const raw_map_t &m_models; + std::unordered_map<pstring, map_t> m_cache; + }; + + namespace detail + { + // ----------------------------------------------------------------------------- + // abstract_t + // ----------------------------------------------------------------------------- + + struct abstract_t + { + using link_t = std::pair<pstring, pstring>; + + abstract_t(log_type &log) : m_factory(log) { } + std::unordered_map<pstring, pstring> m_alias; + std::vector<link_t> m_links; + std::unordered_map<pstring, pstring> m_param_values; + models_t::raw_map_t m_models; + + // need to preserve order of device creation ... + std::vector<std::pair<pstring, factory::element_t *>> m_device_factory; + // lifetime control only - can be cleared before run + std::vector<std::pair<pstring, pstring>> m_defparams; + std::unordered_map<pstring, bool> m_hints; + factory::list_t m_factory; + }; + } // namespace detail + + // ----------------------------------------------------------------------------- + // param_ref_t + // ----------------------------------------------------------------------------- + + struct param_ref_t + { + param_ref_t() noexcept : m_device(nullptr), m_param(nullptr) {} + param_ref_t(core_device_t &device, param_t ¶m) noexcept + : m_device(&device) + , m_param(¶m) + { } + + ~param_ref_t() = default; + PCOPYASSIGNMOVE(param_ref_t, default) + + const core_device_t &device() const noexcept { return *m_device; } + param_t ¶m() const noexcept { return *m_param; } + + bool is_valid() const noexcept { return (m_device != nullptr) && (m_param != nullptr); } + private: + core_device_t *m_device; + param_t *m_param; + }; + + // ---------------------------------------------------------------------------------------- + // setup_t + // ---------------------------------------------------------------------------------------- + + class setup_t + { + public: + + explicit setup_t(netlist_state_t &nlstate); + ~setup_t() noexcept = default; + + PCOPYASSIGNMOVE(setup_t, delete) + + // called from param_t creation + void register_param_t(param_t ¶m); + pstring get_initial_param_val(const pstring &name, const pstring &def) const; + + void register_term(detail::core_terminal_t &term); + void register_term(terminal_t &term, terminal_t &other_term); + + // called from net_splitter + terminal_t *get_connected_terminal(const terminal_t &term) const noexcept + { + auto ret(m_connected_terminals.find(&term)); + return (ret != m_connected_terminals.end()) ? ret->second : nullptr; + } + + // get family -> truthtable + const logic_family_desc_t *family_from_model(const pstring &model); + + // FIXME: return param_ref_t + param_ref_t find_param(const pstring ¶m_in) const; + // needed by nltool + std::vector<pstring> get_terminals_for_device_name(const pstring &devname) const; + + // needed by proxy device to check power terminals + detail::core_terminal_t *find_terminal(const pstring &terminal_in, detail::terminal_type atype, bool required = true) const; + detail::core_terminal_t *find_terminal(const pstring &terminal_in, bool required = true) const; + pstring de_alias(const pstring &alias) const; + // FIXME: only needed by solver code outside of setup_t + bool connect(detail::core_terminal_t &t1, detail::core_terminal_t &t2); + + // run preparation + + void prepare_to_run(); + + models_t &models() noexcept { return m_models; } + const models_t &models() const noexcept { return m_models; } + + netlist_state_t &nlstate() { return m_nlstate; } + const netlist_state_t &nlstate() const { return m_nlstate; } + + nlparse_t &parser() { return m_parser; } + const nlparse_t &parser() const { return m_parser; } + + log_type &log() noexcept; + const log_type &log() const noexcept; + + // FIXME: needed from matrix_solver_t + void add_terminal(detail::net_t &net, detail::core_terminal_t &terminal) noexcept(false); + + private: + + void resolve_inputs(); + pstring resolve_alias(const pstring &name) const; + + void merge_nets(detail::net_t &thisnet, detail::net_t &othernet); + + void connect_terminals(detail::core_terminal_t &t1, detail::core_terminal_t &t2); + void connect_input_output(detail::core_terminal_t &in, detail::core_terminal_t &out); + void connect_terminal_output(terminal_t &in, detail::core_terminal_t &out); + void connect_terminal_input(terminal_t &term, detail::core_terminal_t &inp); + bool connect_input_input(detail::core_terminal_t &t1, detail::core_terminal_t &t2); + + // helpers + static pstring termtype_as_str(detail::core_terminal_t &in); + + devices::nld_base_proxy *get_d_a_proxy(const detail::core_terminal_t &out); + devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp); + detail::core_terminal_t &resolve_proxy(detail::core_terminal_t &term); + + // net manipulations + + void remove_terminal(detail::net_t &net, detail::core_terminal_t &terminal) noexcept(false); + void move_connections(detail::net_t &net, detail::net_t &dest_net); + void delete_empty_nets(); + + detail::abstract_t m_abstract; + nlparse_t m_parser; + netlist_state_t &m_nlstate; + + models_t m_models; + + // FIXME: currently only used during setup + devices::nld_netlistparams * m_netlist_params; + + // FIXME: can be cleared before run + std::unordered_map<pstring, detail::core_terminal_t *> m_terminals; + std::unordered_map<const terminal_t *, terminal_t *> m_connected_terminals; + std::unordered_map<pstring, param_ref_t> m_params; + std::unordered_map<const detail::core_terminal_t *, + devices::nld_base_proxy *> m_proxies; + std::vector<host_arena::unique_ptr<param_t>> m_defparam_lifetime; + + unsigned m_proxy_cnt; + }; + + // ---------------------------------------------------------------------------------------- + // Specific netlist psource_t implementations + // ---------------------------------------------------------------------------------------- + + class source_netlist_t : public plib::psource_t + { + public: + + source_netlist_t() = default; + + PCOPYASSIGNMOVE(source_netlist_t, delete) + ~source_netlist_t() noexcept override = default; + + virtual bool parse(nlparse_t &setup, const pstring &name); + }; + + class source_data_t : public plib::psource_t + { + public: + + source_data_t() = default; + + PCOPYASSIGNMOVE(source_data_t, delete) + ~source_data_t() noexcept override = default; + }; + + class source_string_t : public source_netlist_t + { + public: + + explicit source_string_t(const pstring &source) + : m_str(source) + { + } + + protected: + stream_ptr stream(const pstring &name) override; + + private: + pstring m_str; + }; + + class source_file_t : public source_netlist_t + { + public: + + explicit source_file_t(const pstring &filename) + : m_filename(filename) + { + } + + protected: + stream_ptr stream(const pstring &name) override; + + private: + pstring m_filename; + }; + + class source_mem_t : public source_netlist_t + { + public: + explicit source_mem_t(const char *mem) + : m_str(mem) + { + } + + protected: + stream_ptr stream(const pstring &name) override; + + private: + pstring m_str; + }; + + class source_proc_t : public source_netlist_t + { + public: + source_proc_t(const pstring &name, nlsetup_func setup_func) + : m_setup_func(setup_func) + , m_setup_func_name(name) + { + } + + bool parse(nlparse_t &setup, const pstring &name) override; + + protected: + stream_ptr stream(const pstring &name) override; + + private: + nlsetup_func m_setup_func; + pstring m_setup_func_name; + }; + +} // namespace netlist + + +#endif // NL_CORE_SETUP_H_ diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index 585637fb5f9..55bf27eb6fd 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -6,6 +6,7 @@ */ #include "nlid_proxy.h" +#include "core/setup.h" #include "nl_errstr.h" #include "solver/nld_solver.h" diff --git a/src/lib/netlist/macro/nlm_ttl74xx.cpp b/src/lib/netlist/macro/nlm_ttl74xx.cpp index 17f2a40f770..334b9dc8f5c 100644 --- a/src/lib/netlist/macro/nlm_ttl74xx.cpp +++ b/src/lib/netlist/macro/nlm_ttl74xx.cpp @@ -988,6 +988,15 @@ static NETLIST_START(TTL_74377_DIP) NET_C(A.CP, B.CP, C.CP, D.CP, E.CP, F.CP, G.CP, H.CP) NET_C(A.E, B.E, C.E, D.E, E.E, F.E, G.E, H.E) + HINT(A.QQ, NC) + HINT(B.QQ, NC) + HINT(C.QQ, NC) + HINT(D.QQ, NC) + HINT(E.QQ, NC) + HINT(F.QQ, NC) + HINT(G.QQ, NC) + HINT(H.QQ, NC) + DIPPINS( /* +--------------+ */ A.E, /* /E |1 ++ 20| VCC */ A.VCC, A.Q, /* Q0 |2 19| Q7 */ H.Q, diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index c55931ca9bc..f5e276c7601 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -5,11 +5,12 @@ #include "solver/nld_solver.h" #include "plib/palloc.h" +#include "plib/pdynlib.h" #include "plib/pfmtlog.h" #include "plib/pmempool.h" #include "plib/putil.h" -#include "plib/pdynlib.h" +#include "core/setup.h" #include "devices/nlid_proxy.h" #include "devices/nlid_system.h" #include "macro/nlm_base.h" diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 53921418fdf..4e2c84794dc 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -17,12 +17,13 @@ #include "plib/plists.h" #include "plib/pmempool.h" #include "plib/ppmf.h" -#include "plib/pstream.h" #include "plib/pstate.h" +#include "plib/pstream.h" #include "plib/ptimed_queue.h" #include "plib/ptypes.h" #include "nl_errstr.h" +#include "nl_factory.h" #include "nltypes.h" #include <initializer_list> diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index 813c2923246..5fa33a27295 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -53,7 +53,7 @@ /// kidniki performance by ~10%. /// /// More work is needed here. -#define NL_MEMPOOL_ALIGN (16) +#define NL_MEMPOOL_ALIGN (16) /// \brief Enable queue statistics. /// diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index 31d1d0e8068..25c957e5a07 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -10,9 +10,9 @@ #include "nltypes.h" #include "plib/palloc.h" +#include "plib/pmempool.h" #include "plib/ptypes.h" #include "plib/putil.h" -#include "plib/pmempool.h" #include <tuple> #include <utility> diff --git a/src/lib/netlist/nl_interface.h b/src/lib/netlist/nl_interface.h index d24f90be3d2..dba7bd5248a 100644 --- a/src/lib/netlist/nl_interface.h +++ b/src/lib/netlist/nl_interface.h @@ -12,6 +12,7 @@ #include "nl_base.h" #include "nl_setup.h" +#include "core/setup.h" #include <memory> #include <array> diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index 9a8561f4cf3..7c0ad9e7ff7 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -133,7 +133,7 @@ void parser_t::parse_netlist(const pstring &nlname) { require_token(m_tok_paren_left); // FIXME: Need to pass in parameter definition FIXME: get line number right - m_setup.register_lib_entry(get_identifier(), factory::properties("", plib::source_location("parser: " + nlname, 1))); + m_setup.register_lib_entry(get_identifier(), "", plib::source_location("parser: " + nlname, 1)); require_token(m_tok_paren_right); } else if (token.is(m_tok_NETLIST_END)) @@ -199,7 +199,7 @@ void parser_t::net_truthtable_start(const pstring &nlname) require_token(m_tok_paren_left); require_token(m_tok_paren_right); // FIXME: proper location - m_setup.truthtable_create(desc, factory::properties("+" + def_param, plib::source_location(nlname, 1))); + m_setup.truthtable_create(desc, "+" + def_param, plib::source_location(nlname, 1)); return; } } @@ -378,7 +378,7 @@ void parser_t::netdev_hint() pstring id(get_identifier()); require_token(m_tok_comma); pstring hint(get_identifier()); - m_setup.register_hint(id + ".HINT_" + hint); + m_setup.register_hint(id, ".HINT_" + hint); require_token(m_tok_paren_right); } diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index a1e70ad2804..1c9b802ddbc 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -3,6 +3,7 @@ #include "plib/palloc.h" #include "analog/nld_twoterm.h" +#include "core/setup.h" #include "devices/nlid_proxy.h" #include "devices/nlid_system.h" #include "devices/nlid_truthtable.h" @@ -21,9 +22,8 @@ namespace netlist // nl_parse_t // ---------------------------------------------------------------------------------------- - nlparse_t::nlparse_t(log_type &log, abstract_t &abstract) - : m_factory(log) - , m_abstract(abstract) + nlparse_t::nlparse_t(log_type &log, detail::abstract_t &abstract) + : m_abstract(abstract) , m_log(log) , m_frontier_cnt(0) { } @@ -70,7 +70,7 @@ namespace netlist factory::element_t **felem) { - auto *f = m_factory.factory_by_name(classname); + auto *f = factory().factory_by_name(classname); // make sure we parse macro library entries // FIXME: this could be done here if e.g. f @@ -150,8 +150,9 @@ namespace netlist *felem = f; } - void nlparse_t::register_hint(const pstring &name) + void nlparse_t::register_hint(const pstring &objname, const pstring &hintname) { + const auto name = build_fqn(objname) + hintname; if (!m_abstract.m_hints.insert({name, false}).second) { log().fatal(MF_ADDING_HINT_1(name)); @@ -255,9 +256,20 @@ namespace netlist m_abstract.m_defparams.emplace_back(namespace_prefix() + name, val); } - void nlparse_t::register_lib_entry(const pstring &name, factory::properties &&props) + factory::list_t &nlparse_t::factory() noexcept { - m_factory.add(plib::make_unique<factory::library_element_t, host_arena>(name, std::move(props))); + return m_abstract.m_factory; + } + + const factory::list_t &nlparse_t::factory() const noexcept + { + return m_abstract.m_factory; + } + + + void nlparse_t::register_lib_entry(const pstring &name, const pstring &def_params, plib::source_location &&loc) + { + factory().add(plib::make_unique<factory::library_element_t, host_arena>(name, factory::properties(def_params, std::move(loc)))); } void nlparse_t::register_frontier(const pstring &attach, const pstring &r_IN, @@ -293,10 +305,15 @@ namespace netlist register_link(attach, frontier_name + ".Q"); } - void nlparse_t::truthtable_create(tt_desc &desc, factory::properties &&props) + void nlparse_t::register_source_proc(const pstring &name, nlsetup_func func) + { + register_source<netlist::source_proc_t>(name, func); + } + + void nlparse_t::truthtable_create(tt_desc &desc, const pstring &def_params, plib::source_location &&loc) { - auto fac = factory::truthtable_create(desc, std::move(props)); - m_factory.add(std::move(fac)); + auto fac = factory::truthtable_create(desc, netlist::factory::properties(def_params, std::move(loc))); + factory().add(std::move(fac)); } pstring nlparse_t::namespace_prefix() const @@ -320,7 +337,7 @@ namespace netlist void nlparse_t::register_link_fqn(const pstring &sin, const pstring &sout) { - link_t temp = link_t(sin, sout); + detail::abstract_t::link_t temp(sin, sout); log().debug("link {1} <== {2}", sin, sout); m_abstract.m_links.push_back(temp); } @@ -417,7 +434,7 @@ namespace netlist setup_t::setup_t(netlist_state_t &nlstate) - : m_abstract() + : m_abstract(nlstate.log()) , m_parser(nlstate.log(), m_abstract) , m_nlstate(nlstate) , m_models(m_abstract.m_models) // FIXME : parse abstract_t only diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 3de4b3bd279..ac922f0fb32 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -13,11 +13,12 @@ #include "plib/ppreprocessor.h" #include "plib/pstream.h" #include "plib/pstring.h" +#include "plib/putil.h" #include "nl_config.h" -// FIXME: avoid including factory -#include "nl_factory.h" #include "nltypes.h" +// FIXME: avoid including factory +//#include "nl_factory.h" #include <initializer_list> #include <memory> @@ -61,7 +62,7 @@ setup.defparam(NET_STR(name), NET_STR(val)); #define HINT(name, val) \ - setup.register_hint(# name ".HINT_" # val); + setup.register_hint(# name , ".HINT_" # val); #define NETDEV_PARAMI(name, param, val) \ setup.register_param(# name "." # param, val); @@ -79,18 +80,16 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \ #define NETLIST_END() } #define LOCAL_SOURCE(name) \ - setup.register_source<netlist::source_proc_t>(# name, &NETLIST_NAME(name)); + setup.register_source_proc(# name, &NETLIST_NAME(name)); // FIXME: Need to pass in parameter definition #define LOCAL_LIB_ENTRY_1(name) \ LOCAL_SOURCE(name) \ - setup.register_lib_entry(# name, \ - netlist::factory::properties("", PSOURCELOC())); + setup.register_lib_entry(# name, "", PSOURCELOC()); #define LOCAL_LIB_ENTRY_2(name, param_spec) \ LOCAL_SOURCE(name) \ - setup.register_lib_entry(# name, \ - netlist::factory::properties(param_spec, PSOURCELOC())); + setup.register_lib_entry(# name, param_spec, PSOURCELOC()); #define LOCAL_LIB_ENTRY(...) PCALLVARARG(LOCAL_LIB_ENTRY_, __VA_ARGS__) @@ -109,14 +108,15 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \ // truthtable defines // ----------------------------------------------------------------------------- -#define TRUTHTABLE_START(cname, in, out, def_params) \ +#define TRUTHTABLE_START(cname, in, out, pdef_params) \ { \ netlist::tt_desc desc; \ desc.name = #cname ; \ desc.ni = in; \ desc.no = out; \ desc.family = ""; \ - netlist::factory::properties props(def_params, PSOURCELOC()); + auto sloc = PSOURCELOC(); \ + const pstring def_params = pdef_params; #define TT_HEAD(x) \ desc.desc.emplace_back(x); @@ -128,7 +128,7 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \ desc.family = x; #define TRUTHTABLE_END() \ - setup.truthtable_create(desc, std::move(props)); \ + setup.truthtable_create(desc, def_params, std::move(sloc)); \ } namespace netlist @@ -148,71 +148,11 @@ namespace netlist pstring family; }; - // ----------------------------------------------------------------------------- - // param_ref_t - // ----------------------------------------------------------------------------- - - struct param_ref_t - { - param_ref_t() noexcept : m_device(nullptr), m_param(nullptr) {} - param_ref_t(core_device_t &device, param_t ¶m) noexcept - : m_device(&device) - , m_param(¶m) - { } - - ~param_ref_t() = default; - PCOPYASSIGNMOVE(param_ref_t, default) - - const core_device_t &device() const noexcept { return *m_device; } - param_t ¶m() const noexcept { return *m_param; } - - bool is_valid() const noexcept { return (m_device != nullptr) && (m_param != nullptr); } - private: - core_device_t *m_device; - param_t *m_param; - }; - // ---------------------------------------------------------------------------------------- - // Collection of models + // static compiled netlist. // ---------------------------------------------------------------------------------------- - class models_t - { - public: - using raw_map_t = std::unordered_map<pstring, pstring>; - using map_t = std::unordered_map<pstring, pstring>; - class model_t - { - public: - model_t(const pstring &model, const map_t &map) - : m_model(model), m_map(map) { } - - pstring value_str(const pstring &entity) const; - - nl_fptype value(const pstring &entity) const; - - pstring type() const { return value_str("COREMODEL"); } - - private: - static pstring model_string(const map_t &map); - - const pstring m_model; // only for error messages - const map_t &m_map; - }; - - models_t(const raw_map_t &models) - : m_models(models) - {} - - model_t get_model(const pstring &model); - - private: - - void model_parse(const pstring &model, map_t &map); - - const raw_map_t &m_models; - std::unordered_map<pstring, map_t> m_cache; - }; + using nlsetup_func = void (*)(nlparse_t &); // ---------------------------------------------------------------------------------------- // nlparse_t @@ -221,23 +161,7 @@ namespace netlist class nlparse_t { public: - using link_t = std::pair<pstring, pstring>; - - struct abstract_t - { - std::unordered_map<pstring, pstring> m_alias; - std::vector<link_t> m_links; - std::unordered_map<pstring, pstring> m_param_values; - models_t::raw_map_t m_models; - - // need to preserve order of device creation ... - std::vector<std::pair<pstring, factory::element_t *>> m_device_factory; - // lifetime control only - can be cleared before run - std::vector<std::pair<pstring, pstring>> m_defparams; - std::unordered_map<pstring, bool> m_hints; - }; - - nlparse_t(log_type &log, abstract_t &abstract); + nlparse_t(log_type &log, detail::abstract_t &abstract); void register_model(const pstring &model_in); void register_alias(const pstring &alias, const pstring &out); @@ -254,7 +178,7 @@ namespace netlist register_dev(classname, name, std::vector<pstring>()); } - void register_hint(const pstring &name); + void register_hint(const pstring &objname, const pstring &hintname); void register_link(const pstring &sin, const pstring &sout); void register_link_arr(const pstring &terms); @@ -271,7 +195,7 @@ namespace netlist register_param(param, plib::narrow_cast<nl_fptype>(value)); } - void register_lib_entry(const pstring &name, factory::properties &&props); + void register_lib_entry(const pstring &name, const pstring &def_params, plib::source_location &&loc); void register_frontier(const pstring &attach, const pstring &r_IN, const pstring &r_OUT); @@ -285,7 +209,9 @@ namespace netlist m_sources.add_source(std::move(src)); } - void truthtable_create(tt_desc &desc, factory::properties &&props); + void register_source_proc(const pstring &name, nlsetup_func func); + + void truthtable_create(tt_desc &desc, const pstring &def_params, plib::source_location &&loc); // handle namespace @@ -326,8 +252,8 @@ namespace netlist // register a list of logs void register_dynamic_log_devices(const std::vector<pstring> &loglist); - factory::list_t &factory() noexcept { return m_factory; } - const factory::list_t &factory() const noexcept { return m_factory; } + factory::list_t &factory() noexcept; + const factory::list_t &factory() const noexcept; log_type &log() noexcept { return m_log; } const log_type &log() const noexcept { return m_log; } @@ -342,213 +268,12 @@ namespace netlist plib::psource_collection_t<> m_includes; std::stack<pstring> m_namespace_stack; plib::psource_collection_t<> m_sources; - // FIXME: convert to hash and deal with sorting in nltool - factory::list_t m_factory; - abstract_t &m_abstract; + detail::abstract_t & m_abstract; log_type &m_log; unsigned m_frontier_cnt; }; - // ---------------------------------------------------------------------------------------- - // setup_t - // ---------------------------------------------------------------------------------------- - - class setup_t - { - public: - - explicit setup_t(netlist_state_t &nlstate); - ~setup_t() noexcept = default; - - PCOPYASSIGNMOVE(setup_t, delete) - - // called from param_t creation - void register_param_t(param_t ¶m); - pstring get_initial_param_val(const pstring &name, const pstring &def) const; - - void register_term(detail::core_terminal_t &term); - void register_term(terminal_t &term, terminal_t &other_term); - - // called from net_splitter - terminal_t *get_connected_terminal(const terminal_t &term) const noexcept - { - auto ret(m_connected_terminals.find(&term)); - return (ret != m_connected_terminals.end()) ? ret->second : nullptr; - } - - // get family -> truthtable - const logic_family_desc_t *family_from_model(const pstring &model); - - // FIXME: return param_ref_t - param_ref_t find_param(const pstring ¶m_in) const; - // needed by nltool - std::vector<pstring> get_terminals_for_device_name(const pstring &devname) const; - - // needed by proxy device to check power terminals - detail::core_terminal_t *find_terminal(const pstring &terminal_in, detail::terminal_type atype, bool required = true) const; - detail::core_terminal_t *find_terminal(const pstring &terminal_in, bool required = true) const; - pstring de_alias(const pstring &alias) const; - // FIXME: only needed by solver code outside of setup_t - bool connect(detail::core_terminal_t &t1, detail::core_terminal_t &t2); - - // run preparation - - void prepare_to_run(); - - models_t &models() noexcept { return m_models; } - const models_t &models() const noexcept { return m_models; } - - netlist_state_t &nlstate() { return m_nlstate; } - const netlist_state_t &nlstate() const { return m_nlstate; } - - nlparse_t &parser() { return m_parser; } - const nlparse_t &parser() const { return m_parser; } - - log_type &log() noexcept; - const log_type &log() const noexcept; - - // FIXME: needed from matrix_solver_t - void add_terminal(detail::net_t &net, detail::core_terminal_t &terminal) noexcept(false); - - private: - - void resolve_inputs(); - pstring resolve_alias(const pstring &name) const; - - void merge_nets(detail::net_t &thisnet, detail::net_t &othernet); - - void connect_terminals(detail::core_terminal_t &t1, detail::core_terminal_t &t2); - void connect_input_output(detail::core_terminal_t &in, detail::core_terminal_t &out); - void connect_terminal_output(terminal_t &in, detail::core_terminal_t &out); - void connect_terminal_input(terminal_t &term, detail::core_terminal_t &inp); - bool connect_input_input(detail::core_terminal_t &t1, detail::core_terminal_t &t2); - - // helpers - static pstring termtype_as_str(detail::core_terminal_t &in); - - devices::nld_base_proxy *get_d_a_proxy(const detail::core_terminal_t &out); - devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp); - detail::core_terminal_t &resolve_proxy(detail::core_terminal_t &term); - - // net manipulations - - void remove_terminal(detail::net_t &net, detail::core_terminal_t &terminal) noexcept(false); - void move_connections(detail::net_t &net, detail::net_t &dest_net); - void delete_empty_nets(); - - nlparse_t::abstract_t m_abstract; - nlparse_t m_parser; - netlist_state_t &m_nlstate; - - models_t m_models; - - // FIXME: currently only used during setup - devices::nld_netlistparams * m_netlist_params; - - // FIXME: can be cleared before run - std::unordered_map<pstring, detail::core_terminal_t *> m_terminals; - std::unordered_map<const terminal_t *, terminal_t *> m_connected_terminals; - std::unordered_map<pstring, param_ref_t> m_params; - std::unordered_map<const detail::core_terminal_t *, - devices::nld_base_proxy *> m_proxies; - std::vector<host_arena::unique_ptr<param_t>> m_defparam_lifetime; - - unsigned m_proxy_cnt; - }; - - // ---------------------------------------------------------------------------------------- - // Specific netlist psource_t implementations - // ---------------------------------------------------------------------------------------- - - class source_netlist_t : public plib::psource_t - { - public: - - source_netlist_t() = default; - - PCOPYASSIGNMOVE(source_netlist_t, delete) - ~source_netlist_t() noexcept override = default; - - virtual bool parse(nlparse_t &setup, const pstring &name); - }; - - class source_data_t : public plib::psource_t - { - public: - - source_data_t() = default; - - PCOPYASSIGNMOVE(source_data_t, delete) - ~source_data_t() noexcept override = default; - }; - - class source_string_t : public source_netlist_t - { - public: - - explicit source_string_t(const pstring &source) - : m_str(source) - { - } - - protected: - stream_ptr stream(const pstring &name) override; - - private: - pstring m_str; - }; - - class source_file_t : public source_netlist_t - { - public: - - explicit source_file_t(const pstring &filename) - : m_filename(filename) - { - } - - protected: - stream_ptr stream(const pstring &name) override; - - private: - pstring m_filename; - }; - - class source_mem_t : public source_netlist_t - { - public: - explicit source_mem_t(const char *mem) - : m_str(mem) - { - } - - protected: - stream_ptr stream(const pstring &name) override; - - private: - pstring m_str; - }; - - class source_proc_t : public source_netlist_t - { - public: - source_proc_t(const pstring &name, void (*setup_func)(nlparse_t &)) - : m_setup_func(setup_func) - , m_setup_func_name(name) - { - } - - bool parse(nlparse_t &setup, const pstring &name) override; - - protected: - stream_ptr stream(const pstring &name) override; - - private: - void (*m_setup_func)(nlparse_t &); - pstring m_setup_func_name; - }; - // ----------------------------------------------------------------------------- // inline implementations // ----------------------------------------------------------------------------- diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h index b259ae55b76..1ed6f66ca0d 100644 --- a/src/lib/netlist/nltypes.h +++ b/src/lib/netlist/nltypes.h @@ -15,9 +15,9 @@ #include "nl_config.h" //#include "plib/pchrono.h" -#include "plib/ptypes.h" #include "plib/pstring.h" #include "plib/ptime.h" +#include "plib/ptypes.h" #include <memory> @@ -35,7 +35,7 @@ namespace plib class plog_base; struct plog_level; -} +} // namespace plib namespace netlist { @@ -58,6 +58,8 @@ namespace netlist class logic_family_desc_t; class terminal_t; + class models_t; + namespace devices { class nld_solver; @@ -75,6 +77,7 @@ namespace netlist namespace detail { + struct abstract_t; class core_terminal_t; class net_t; } // namespace detail diff --git a/src/lib/netlist/plib/mat_cr.h b/src/lib/netlist/plib/mat_cr.h index f066d44cd7b..17ce140c6e5 100644 --- a/src/lib/netlist/plib/mat_cr.h +++ b/src/lib/netlist/plib/mat_cr.h @@ -14,11 +14,11 @@ #include "parray.h" #include "pconfig.h" #include "pmath.h" +#include "pmatrix2d.h" #include "pomp.h" #include "pstate.h" #include "ptypes.h" #include "putil.h" -#include "pmatrix2d.h" #include <algorithm> #include <array> diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index e1ad17637fe..d082efc5d41 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -241,7 +241,7 @@ namespace plib { public: using value_type = T; using pointer = T *; - static /*constexpr*/ const std::size_t align_size = (ALIGN < 16) ? 16 : ALIGN; + static /*constexpr*/ const std::size_t align_size = ALIGN; using arena_type = ARENA; static_assert(align_size >= alignof(T), @@ -438,12 +438,13 @@ namespace plib { //unused_var(size); dec_alloc_stat(size); #if (PUSE_ALIGNED_ALLOCATION) - #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) + #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) + // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) _aligned_free(ptr); - #else - // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) + #else + // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) ::free(ptr); - #endif + #endif #else ::operator delete(ptr); #endif diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 65328327d76..848a813e094 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -69,7 +69,7 @@ /// #define PALIGN_VECTOROPT (32) -#define PALIGN_MIN_SIZE (16) +#define PALIGN_MIN_SIZE (16) #define PALIGNAS_CACHELINE() PALIGNAS(PALIGN_CACHELINE) #define PALIGNAS_VECTOROPT() PALIGNAS(PALIGN_VECTOROPT) diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 4430459b616..6929a10601b 100644..100755 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -81,17 +81,17 @@ namespace plib { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) iterator begin() const noexcept { return reinterpret_cast<iterator>(&m_buf[0]); } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - iterator end() const noexcept { return reinterpret_cast<iterator>(&m_buf[N]); } + iterator end() const noexcept { return reinterpret_cast<iterator>(&m_buf[0] + N); } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) iterator begin() noexcept { return reinterpret_cast<iterator>(&m_buf[0]); } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - iterator end() noexcept { return reinterpret_cast<iterator>(&m_buf[N]); } + iterator end() noexcept { return reinterpret_cast<iterator>(&m_buf[0] + N); } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) const_iterator cbegin() const noexcept { return reinterpret_cast<const_iterator>(&m_buf[0]); } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - const_iterator cend() const noexcept { return reinterpret_cast<const_iterator>(&m_buf[N]); } + const_iterator cend() const noexcept { return reinterpret_cast<const_iterator>(&m_buf[0] + N); } protected: diff --git a/src/lib/netlist/plib/pmatrix2d.h b/src/lib/netlist/plib/pmatrix2d.h index 4591d00b6f6..8cbba5aa410 100755 --- a/src/lib/netlist/plib/pmatrix2d.h +++ b/src/lib/netlist/plib/pmatrix2d.h @@ -23,7 +23,7 @@ namespace plib public: using size_type = std::size_t; using arena_type = A; - using allocator_type = typename A::template allocator_type<T>; + using allocator_type = typename A::template allocator_type<T, PALIGN_VECTOROPT>; static constexpr const size_type align_size = align_traits<allocator_type>::align_size; static constexpr const size_type stride_size = align_traits<allocator_type>::stride_size; @@ -138,10 +138,11 @@ namespace plib using size_type = std::size_t; using value_type = T; using arena_type = A; - using allocator_type = typename A::template allocator_type<T>; + using allocator_type = typename A::template allocator_type<T, PALIGN_VECTOROPT>; static constexpr const size_type align_size = align_traits<allocator_type>::align_size; static constexpr const size_type stride_size = align_traits<allocator_type>::stride_size; + pmatrix2d_vrl() noexcept : m_N(0), m_M(0), m_v() { @@ -155,6 +156,7 @@ namespace plib } PCOPYASSIGNMOVE(pmatrix2d_vrl, default) + ~pmatrix2d_vrl() = default; void resize(size_type N, size_type M) { diff --git a/src/lib/netlist/plib/pmempool.h b/src/lib/netlist/plib/pmempool.h index 60ea24c6641..4e678cb09d6 100644 --- a/src/lib/netlist/plib/pmempool.h +++ b/src/lib/netlist/plib/pmempool.h @@ -85,7 +85,7 @@ namespace plib { } b->m_free -= rs; b->m_num_alloc++; - void *ret = reinterpret_cast<void *>(b->m_data + b->m_cur); + void *ret = reinterpret_cast<void *>(b->m_data + b->m_cur); // NOLINT(cppcoreguidelines-pro-type-reinterpret auto capacity(rs); ret = std::align(align, size, ret, capacity); m_info.insert({ ret, info(b, b->m_cur)}); @@ -142,7 +142,7 @@ namespace plib { m_data_allocated = static_cast<std::uint8_t *>(mp.base_arena().allocate(mp.m_block_align, m_bytes_allocated)); void *r = m_data_allocated; std::align(mp.m_block_align, min_bytes, r, m_bytes_allocated); - m_data = reinterpret_cast<std::uint8_t *>(r); + m_data = reinterpret_cast<std::uint8_t *>(r); // NOLINT(cppcoreguidelines-pro-type-reinterpret } ~block() { diff --git a/src/lib/netlist/plib/ppreprocessor.cpp b/src/lib/netlist/plib/ppreprocessor.cpp index 6c4faf88efa..05cdb648f34 100644 --- a/src/lib/netlist/plib/ppreprocessor.cpp +++ b/src/lib/netlist/plib/ppreprocessor.cpp @@ -4,8 +4,8 @@ #include "ppreprocessor.h" #include "palloc.h" #include "pstonum.h" -#include "putil.h" #include "pstrutil.h" +#include "putil.h" namespace plib { diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 179a4f5ca98..9333681b007 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -11,8 +11,8 @@ #include "pconfig.h" #include "pfmtlog.h" -#include "pstring.h" #include "pgsl.h" +#include "pstring.h" #include <array> #include <fstream> @@ -151,7 +151,7 @@ public: { // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) const putf8string conv_utf8(text); - //m_strm->write(conv_utf8.c_str(), static_cast<std::streamsize>(plib::strlen(conv_utf8.c_str() ))); + //m_strm->write(conv_utf8.c_str(), static_cast<std::streamsize>(plib::strlen(conv_utf8.c_str() ))); ostream_write(*m_strm, conv_utf8.c_str(), string_info<pstring>::mem_size(conv_utf8)); } diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 44d025b5fb0..4cd19c47d08 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -53,8 +53,8 @@ public: constexpr bool operator==(const pstring_const_iterator& rhs) const noexcept { return p == rhs.p; } constexpr bool operator!=(const pstring_const_iterator& rhs) const noexcept { return p != rhs.p; } - reference operator*() const noexcept { return *reinterpret_cast<pointer>(&(*p)); } - pointer operator->() const noexcept { return reinterpret_cast<pointer>(&(*p)); } + reference operator*() const noexcept { return *reinterpret_cast<pointer>(&(*p)); } // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) + pointer operator->() const noexcept { return reinterpret_cast<pointer>(&(*p)); } // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) private: template <typename G> friend struct pstring_t; @@ -204,7 +204,7 @@ public: return ostrm; } - const_reference at(const size_type pos) const { return *reinterpret_cast<const ref_value_type *>(F::nthcode(m_str.c_str(),pos)); } + const_reference at(const size_type pos) const { return *reinterpret_cast<const ref_value_type *>(F::nthcode(m_str.c_str(),pos)); } // NOLINT(cppcoreguidelines-pro-type-reinterpret static constexpr const size_type npos = static_cast<size_type>(-1); @@ -256,7 +256,7 @@ struct putf_traits<1, CT> static std::size_t codelen(const mem_t *p) noexcept { - const auto *p1 = reinterpret_cast<const unsigned char *>(p); + const auto *p1 = reinterpret_cast<const unsigned char *>(p); // NOLINT(cppcoreguidelines-pro-type-reinterpret if ((*p1 & 0xE0) == 0xC0) // NOLINT return 2; if ((*p1 & 0xF0) == 0xE0) // NOLINT @@ -283,7 +283,7 @@ struct putf_traits<1, CT> static code_t code(const mem_t *p) noexcept { - const auto *p1 = reinterpret_cast<const unsigned char *>(p); + const auto *p1 = reinterpret_cast<const unsigned char *>(p); // NOLINT(cppcoreguidelines-pro-type-reinterpret if ((*p1 & 0x80) == 0x00) // NOLINT return *p1; if ((*p1 & 0xE0) == 0xC0) // NOLINT diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 25b4e6a9307..c1ce206bbf6 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -10,11 +10,12 @@ // *************************************************************************** #include "netlist/plib/pdynlib.h" -#include "netlist/plib/pmain.h" +#include "netlist/core/setup.h" #include "netlist/devices/net_lib.h" #include "netlist/nl_errstr.h" #include "netlist/nl_parser.h" #include "netlist/nl_setup.h" +#include "netlist/plib/pmain.h" #include "netlist/plib/pstrutil.h" #include "netlist/solver/nld_solver.h" #include "netlist/tools/nl_convert.h" diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index 6eb4878c9b2..ec457b934d3 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -2,6 +2,7 @@ // copyright-holders:Couriersud #include "nld_matrix_solver.h" +#include "core/setup.h" #include "nl_setup.h" #include "plib/putil.h" diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index c3a42f0721f..63b3592f83a 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -3,6 +3,7 @@ #include "netlist/nl_factory.h" +#include "core/setup.h" #include "netlist/nl_setup.h" // FIXME: only needed for splitter code #include "nld_matrix_solver.h" #include "nld_ms_direct.h" diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 490a275adc2..607dfa680bd 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -3,8 +3,8 @@ #include "plib/palloc.h" #include "plib/pstonum.h" -#include "plib/putil.h" #include "plib/pstrutil.h" +#include "plib/putil.h" #include "nl_convert.h" |