From 1415421fd707ad02e0cfddf20bf70bbd045a9203 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 6 Jan 2019 13:17:20 +0100 Subject: More c++ alignment. pstring now behaves like std::string. (nw) This change removes all string extensions like trim, rpad, left, right, ... from pstring and replaces them by function templates. This aligns a lot better with the intentions of the standard library. --- src/lib/netlist/nl_setup.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index df761bc3f88..fb4cc424147 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -97,8 +97,8 @@ void setup_t::register_model(const pstring &model_in) auto pos = model_in.find(" "); if (pos == pstring::npos) log().fatal(MF_1_UNABLE_TO_PARSE_MODEL_1, model_in); - pstring model = model_in.left(pos).trim().ucase(); - pstring def = model_in.substr(pos + 1).trim(); + pstring model = plib::ucase(plib::trim(plib::left(model_in, pos))); + pstring def = plib::trim(model_in.substr(pos + 1)); if (!m_models.insert({model, def}).second) log().fatal(MF_1_MODEL_ALREADY_EXISTS_1, model_in); } @@ -797,15 +797,15 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map) pos = model.find("("); if (pos != pstring::npos) break; - key = model.ucase(); + key = plib::ucase(model); auto i = m_models.find(key); if (i == m_models.end()) log().fatal(MF_1_MODEL_NOT_FOUND, model); model = i->second; } - pstring xmodel = model.left(pos); + pstring xmodel = plib::left(model, pos); - if (xmodel.equals("_")) + if (xmodel == "_") map["COREMODEL"] = key; else { @@ -816,11 +816,11 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map) log().fatal(MF_1_MODEL_NOT_FOUND, model_in); } - pstring remainder = model.substr(pos + 1).trim(); - if (!remainder.endsWith(")")) + pstring remainder = plib::trim(model.substr(pos + 1)); + if (!plib::endsWith(remainder, ")")) log().fatal(MF_1_MODEL_ERROR_1, model); // FIMXE: Not optimal - remainder = remainder.left(remainder.length() - 1); + remainder = plib::left(remainder, remainder.size() - 1); std::vector pairs(plib::psplit(remainder," ", true)); for (pstring &pe : pairs) @@ -828,7 +828,7 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map) auto pose = pe.find("="); if (pose == pstring::npos) log().fatal(MF_1_MODEL_ERROR_ON_PAIR_1, model); - map[pe.left(pose).ucase()] = pe.substr(pose + 1); + map[plib::ucase(plib::left(pe, pose))] = pe.substr(pose + 1); } } @@ -836,7 +836,7 @@ const pstring setup_t::model_value_str(detail::model_map_t &map, const pstring & { pstring ret; - if (entity != entity.ucase()) + if (entity != plib::ucase(entity)) log().fatal(MF_2_MODEL_PARAMETERS_NOT_UPPERCASE_1_2, entity, model_string(map)); if (map.find(entity) == map.end()) @@ -852,7 +852,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) pstring tmp = model_value_str(map, entity); nl_double factor = NL_FCONST(1.0); - auto p = std::next(tmp.begin(), static_cast(tmp.length() - 1)); + auto p = std::next(tmp.begin(), static_cast(tmp.size() - 1)); switch (*p) { case 'M': factor = 1e6; break; @@ -868,8 +868,8 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) log().fatal(MF_1_UNKNOWN_NUMBER_FACTOR_IN_1, entity); } if (factor != NL_FCONST(1.0)) - tmp = tmp.left(tmp.length() - 1); - return tmp.as_double() * factor; + tmp = plib::left(tmp, tmp.size() - 1); + return plib::pstod(tmp) * factor; } class logic_family_std_proxy_t : public logic_family_desc_t @@ -970,11 +970,11 @@ bool setup_t::parse_stream(plib::putf8_reader &istrm, const pstring &name) return parser_t(reader2, *this).parse(name); } -void setup_t::register_define(pstring defstr) +void setup_t::register_define(const pstring &defstr) { auto p = defstr.find("="); if (p != pstring::npos) - register_define(defstr.left(p), defstr.substr(p+1)); + register_define(plib::left(defstr, p), defstr.substr(p+1)); else register_define(defstr, "1"); } @@ -997,12 +997,12 @@ bool source_t::parse(const pstring &name) std::unique_ptr source_string_t::stream(const pstring &name) { - return plib::make_unique_base(m_str.c_str(), m_str.mem_t_size()); + return plib::make_unique_base(m_str.c_str(), std::strlen(m_str.c_str())); } std::unique_ptr source_mem_t::stream(const pstring &name) { - return plib::make_unique_base(m_str.c_str(), m_str.mem_t_size()); + return plib::make_unique_base(m_str.c_str(), std::strlen(m_str.c_str())); } std::unique_ptr source_file_t::stream(const pstring &name) -- cgit v1.2.3-70-g09d2 From 3c6d9ac9a02d721a3245c1725b29dd6c10ce3ea7 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 6 Jan 2019 20:04:39 +0100 Subject: Code maintenance and fix for "pure virtual call" error. (nw) --- src/devices/machine/netlist.cpp | 2 ++ src/lib/netlist/nl_base.cpp | 7 +++++-- src/lib/netlist/nl_base.h | 8 ++++++++ src/lib/netlist/nl_errstr.h | 3 ++- src/lib/netlist/nl_setup.cpp | 21 +++++++++++---------- src/lib/netlist/nl_setup.h | 3 ++- src/lib/netlist/plib/pparser.cpp | 18 ++++-------------- src/lib/netlist/prg/nltool.cpp | 1 + 8 files changed, 35 insertions(+), 28 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index f6167cbd466..15a096a6536 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -837,6 +837,8 @@ 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(); diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 12ccabfd4ab..d984285b000 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -253,8 +253,6 @@ netlist_t::netlist_t(const pstring &aname) state().save_item(this, static_cast(m_queue), "m_queue"); state().save_item(this, m_time, "m_time"); m_setup = plib::make_unique(*this); - /* FIXME: doesn't really belong here */ - NETLIST_NAME(base)(*m_setup); } netlist_t::~netlist_t() @@ -263,6 +261,11 @@ 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(); diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 175c5218193..60294afedc8 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -1222,6 +1222,14 @@ namespace netlist 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(); + /* run functions */ const netlist_time &time() const NL_NOEXCEPT { return m_time; } diff --git a/src/lib/netlist/nl_errstr.h b/src/lib/netlist/nl_errstr.h index 35b1e4f6c60..d3f62f9e790 100644 --- a/src/lib/netlist/nl_errstr.h +++ b/src/lib/netlist/nl_errstr.h @@ -58,7 +58,8 @@ //#define MF_1_CLASS_1_NOT_FOUND "Class {1} not found!" #define MF_1_UNABLE_TO_PARSE_MODEL_1 "Unable to parse model: {1}" #define MF_1_MODEL_ALREADY_EXISTS_1 "Model already exists: {1}" -#define MF_1_ADDING_ALI1_TO_ALIAS_LIST "Error adding alias {1} to alias list" +#define MF_1_DEVICE_ALREADY_EXISTS_1 "Device already exists: {1}" +#define MF_1_ADDING_ALI1_TO_ALIAS_LIST "Error adding alias {1} to alias list" #define MF_1_DIP_PINS_MUST_BE_AN_EQUAL_NUMBER_OF_PINS_1 "You must pass an equal number of pins to DIPPINS {1}" #define MF_1_UNKNOWN_OBJECT_TYPE_1 "Unknown object type {1}" #define MF_2_INVALID_NUMBER_CONVERSION_1_2 "Invalid number conversion {1} : {2}" diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index fb4cc424147..c8e47cb17e3 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -78,17 +78,15 @@ void setup_t::register_dev(const pstring &classname, const pstring &name) log().fatal(MF_1_CLASS_1_NOT_FOUND, classname); /* make sure we parse macro library entries */ f->macro_actions(netlist(), name); - m_device_factory.push_back(std::pair(build_fqn(name), f)); + pstring key = build_fqn(name); + if (device_exists(key)) + log().fatal(MF_1_DEVICE_ALREADY_EXISTS_1, name); + m_device_factory[key] = f; } bool setup_t::device_exists(const pstring &name) const { - for (auto e : m_device_factory) - { - if (e.first == name) - return true; - } - return false; + return (m_device_factory.find(name) != m_device_factory.end()); } @@ -160,7 +158,7 @@ double setup_t::get_initial_param_val(const pstring &name, const double def) if (i != m_param_values.end()) { double vald = 0; - if (sscanf(i->second.c_str(), "%lf", &vald) != 1) + if (!plib::pstod_ne(i->second, vald)) log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); return vald; } @@ -173,9 +171,12 @@ int setup_t::get_initial_param_val(const pstring &name, const int def) auto i = m_param_values.find(name); if (i != m_param_values.end()) { - double vald = 0; - if (sscanf(i->second.c_str(), "%lf", &vald) != 1) + long vald = 0; + if (!plib::pstod_ne(i->second, vald)) log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); + if (vald - std::floor(vald) != 0.0) + log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); + return static_cast(vald); } else diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 1d84585236d..4f7146b3995 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -291,7 +291,8 @@ namespace netlist plib::plog_base &log(); const plib::plog_base &log() const; - std::vector> m_device_factory; + //std::vector> m_device_factory; + std::unordered_map m_device_factory; std::unordered_map m_alias; std::unordered_map m_param_values; diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 1a4db5b816c..298fa589fba 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -375,10 +375,7 @@ double ppreprocessor::expr(const std::vector &sexpr, std::size_t &start ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name) { auto idx = m_defines.find(name); - if (idx != m_defines.end()) - return &idx->second; - else - return nullptr; + return (idx != m_defines.end()) ? &idx->second : nullptr; } pstring ppreprocessor::replace_macros(const pstring &line) @@ -388,10 +385,7 @@ pstring ppreprocessor::replace_macros(const pstring &line) for (auto & elem : elems) { define_t *def = get_define(elem); - if (def != nullptr) - ret += def->m_replace; - else - ret += elem; + ret += (def != nullptr) ? def->m_replace : elem; } return ret; } @@ -409,11 +403,8 @@ static pstring catremainder(const std::vector &elems, std::size_t start pstring ppreprocessor::process_line(const pstring &line) { - //pstring lt = plib::trim(plib::replace_all(line, pstring("\t"), pstring(" "))); - pstring a = plib::replace_all(line, pstring("\t"), pstring(" ")); - pstring lt = plib::trim(a); + pstring lt = plib::trim(plib::replace_all(line, pstring("\t"), pstring(" "))); pstring ret; - m_lineno++; // FIXME ... revise and extend macro handling if (plib::startsWith(lt, "#")) { @@ -477,9 +468,7 @@ pstring ppreprocessor::process_line(const pstring &line) { lt = replace_macros(lt); if (m_ifflag == 0) - { ret += lt; - } } return ret; } @@ -490,6 +479,7 @@ void ppreprocessor::process(putf8_reader &istrm, putf8_writer &ostrm) pstring line; while (istrm.readline(line)) { + m_lineno++; line = process_line(line); ostrm.writeline(line); } diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 52ad8d3f55c..4fcb4ebdc30 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -147,6 +147,7 @@ public: void init() { + load_base_libraries(); } void read_netlist(const pstring &filename, const pstring &name, -- cgit v1.2.3-70-g09d2 From ae6185e5f660531ae47545b9c80f6c7056f6ecbc Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 7 Jan 2019 19:14:21 +1100 Subject: add C++ standard library headers for things that are used (nw) --- src/lib/netlist/nl_setup.cpp | 2 ++ src/lib/netlist/plib/palloc.h | 4 +++- src/lib/netlist/plib/pstring.h | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index c8e47cb17e3..cf89e4a8fae 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -17,6 +17,8 @@ #include "solver/nld_solver.h" #include "devices/nlid_truthtable.h" +#include + // ---------------------------------------------------------------------------------------- // setup_t // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index a35bc50ff17..3759d5819de 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -10,8 +10,10 @@ #include "pstring.h" -#include +#include #include +#include +#include namespace plib { diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 22ccd3749e4..67104a54213 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -7,10 +7,11 @@ #ifndef PSTRING_H_ #define PSTRING_H_ -#include +#include #include +#include #include -#include +#include // ---------------------------------------------------------------------------------------- // pstring: semi-immutable strings ... -- cgit v1.2.3-70-g09d2 From 4213a396d8652e7ea26c07c133932bd9f5a87faa Mon Sep 17 00:00:00 2001 From: couriersud Date: Thu, 10 Jan 2019 00:30:51 +0100 Subject: Improve type safety on string->numeric conversions. (nw) Also fixed an issue with 7497. ./nltool -t 5 -f src/mame/machine/nl_tp1983.cpp -v now runs again. --- src/lib/netlist/devices/net_lib.cpp | 2 +- src/lib/netlist/devices/nlid_system.h | 4 +- src/lib/netlist/devices/nlid_truthtable.cpp | 3 +- src/lib/netlist/nl_base.cpp | 4 +- src/lib/netlist/nl_config.h | 1 - src/lib/netlist/nl_parser.cpp | 8 +-- src/lib/netlist/nl_setup.cpp | 13 +++-- src/lib/netlist/plib/pfunction.cpp | 4 +- src/lib/netlist/plib/poptions.cpp | 40 +------------ src/lib/netlist/plib/poptions.h | 91 ++++++++++++++++++++--------- src/lib/netlist/plib/pparser.cpp | 15 +++-- src/lib/netlist/plib/pstring.h | 77 ++++++++++++++---------- src/lib/netlist/plib/putil.cpp | 30 ++++++++++ src/lib/netlist/plib/putil.h | 5 ++ src/lib/netlist/prg/nltool.cpp | 18 +++--- src/lib/netlist/prg/nlwav.cpp | 4 +- src/lib/netlist/solver/nld_solver.cpp | 2 +- src/lib/netlist/tools/nl_convert.cpp | 9 +-- 18 files changed, 197 insertions(+), 133 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/lib/netlist/devices/net_lib.cpp b/src/lib/netlist/devices/net_lib.cpp index 30ddf3af84c..dd77be5a9a2 100644 --- a/src/lib/netlist/devices/net_lib.cpp +++ b/src/lib/netlist/devices/net_lib.cpp @@ -74,7 +74,7 @@ namespace netlist ENTRYX(7485, TTL_7485, "+A0,+A1,+A2,+A3,+B0,+B1,+B2,+B3,+LTIN,+EQIN,+GTIN") ENTRYX(7490, TTL_7490, "+A,+B,+R1,+R2,+R91,+R92") ENTRYX(7493, TTL_7493, "+CLKA,+CLKB,+R1,+R2") - ENTRYX(7497, TTL_7497, "+CLK,+STRB,+EN,+UNITY,+CLR,+B0,+B1,+B2,+B3,+B4,+B5") + ENTRYX(7497, TTL_7497, "+CLK,+STRBQ,+ENQ,+UNITYQ,+CLR,+B0,+B1,+B2,+B3,+B4,+B5") ENTRYX(74107, TTL_74107, "+CLK,+J,+K,+CLRQ") ENTRYX(74107A, TTL_74107A, "+CLK,+J,+K,+CLRQ") ENTRYX(74123, TTL_74123, "") diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 881cce03592..5a874aef3df 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -136,7 +136,9 @@ namespace netlist unsigned long total = 0; for (unsigned i=0; i(plib::pstol(pat[i])); + // FIXME: use pstonum_ne + //pati[i] = plib::pstonum(pat[i]); + pati[i] = plib::pstonum(pat[i]); total += pati[i]; } netlist_time ttotal = netlist_time::zero(); diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index c3449d5b604..dbb9401425d 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -407,7 +407,8 @@ void truthtable_parser::parse(const std::vector &truthtable) val.set(j); else nl_assert_always(outs == "0", "Unknown value (not 0 or 1"); - netlist_time t = netlist_time::from_nsec(static_cast(plib::pstol(plib::trim(times[j])))); + // FIXME: error handling + netlist_time t = netlist_time::from_nsec(plib::pstonum(plib::trim(times[j]))); uint_least8_t k=0; while (m_timing_nt[k] != netlist_time::zero() && m_timing_nt[k] != t) k++; diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 5b132ebd554..a0eabcc7fbe 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -343,8 +343,8 @@ void netlist_t::start() auto p = setup().m_param_values.find(d->name() + ".HINT_NO_DEACTIVATE"); if (p != setup().m_param_values.end()) { - //FIXME: turn this into a proper function - auto v = plib::pstod(p->second);; + //FIXME: check for errors ... + double v = plib::pstonum(p->second);; if (std::abs(v - std::floor(v)) > 1e-6 ) log().fatal(MF_1_HND_VAL_NOT_SUPPORTED, p->second); d->set_hint_deactivate(v == 0.0); diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index d2f4dc75511..20ddf5c71a3 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -26,7 +26,6 @@ * linear memory pool. This is based of the assumption that * due to enhanced locality there will be less cache misses. * Your mileage may vary. - * This will cause crashes on OSX and thus is ignored on OSX. * */ #define USE_MEMPOOL (0) diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index a6a805826ce..1ff6ef6c6b7 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -403,7 +403,6 @@ nl_double parser_t::eval_param(const token_t tok) int i; int f=0; nl_double ret; - pstring val; for (i=1; i<6;i++) if (tok.str() == macs[i]) @@ -416,9 +415,10 @@ nl_double parser_t::eval_param(const token_t tok) } else { - val = tok.str(); - if (!plib::pstod_ne(val, ret)) - error(plib::pfmt("Parameter value <{1}> not double \n")(val)); + bool err; + ret = plib::pstonum_ne(tok.str(), err); + if (err) + error(plib::pfmt("Parameter value <{1}> not double \n")(tok.str())); } return ret * facs[f]; diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index cf89e4a8fae..28385d984cf 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -159,8 +159,9 @@ double setup_t::get_initial_param_val(const pstring &name, const double def) auto i = m_param_values.find(name); if (i != m_param_values.end()) { - double vald = 0; - if (!plib::pstod_ne(i->second, vald)) + bool err = false; + double vald = plib::pstonum_ne(i->second, err); + if (err) log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); return vald; } @@ -173,8 +174,9 @@ int setup_t::get_initial_param_val(const pstring &name, const int def) auto i = m_param_values.find(name); if (i != m_param_values.end()) { - long vald = 0; - if (!plib::pstod_ne(i->second, vald)) + bool err; + double vald = plib::pstonum_ne(i->second, err); + if (err) log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); if (vald - std::floor(vald) != 0.0) log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); @@ -872,7 +874,8 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) } if (factor != NL_FCONST(1.0)) tmp = plib::left(tmp, tmp.size() - 1); - return plib::pstod(tmp) * factor; + // FIXME: check for errors + return plib::pstonum(tmp) * factor; } class logic_family_std_proxy_t : public logic_family_desc_t diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index e9e2de009c8..f2ef3522813 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -69,7 +69,9 @@ void pfunction::compile_postfix(const std::vector &inputs, if (rc.m_cmd != PUSH_INPUT) { rc.m_cmd = PUSH_CONST; - if (!plib::pstod_ne(cmd, rc.m_param)) + bool err; + rc.m_param = plib::pstonum_ne(cmd, err); + if (err) throw plib::pexception(plib::pfmt("nld_function: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr)); stk += 1; } diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index d576eff0bb2..c790d1f55af 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -46,49 +46,13 @@ namespace plib { return 0; } - int option_str_limit::parse(const pstring &argument) - { - if (plib::container::contains(m_limit, argument)) - { - m_val = argument; - return 0; - } - else - return 1; - } - int option_bool::parse(const pstring &argument) { + unused_var(argument); m_val = true; return 0; } - int option_double::parse(const pstring &argument) - { - try - { - m_val = plib::pstod(argument); - return 0; - } - catch (...) - { - return 1; - } - } - - int option_long::parse(const pstring &argument) - { - try - { - m_val = plib::pstol(argument); - return 0; - } - catch (...) - { - return 1; - } - } - int option_vec::parse(const pstring &argument) { bool err = false; @@ -233,7 +197,7 @@ namespace plib { if (opt->has_argument()) { line += "="; - option_str_limit *ol = dynamic_cast(opt); + option_str_limit_base *ol = dynamic_cast(opt); if (ol) { for (auto &v : ol->limit()) diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index 491ac0b4d91..f3be4b061dd 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -102,72 +102,98 @@ private: pstring m_val; }; -class option_str_limit : public option +class option_str_limit_base : public option { public: - option_str_limit(options &parent, pstring ashort, pstring along, pstring defval, pstring limit, pstring help) - : option(parent, ashort, along, help, true), m_val(defval) - , m_limit(plib::psplit(limit, ":")) + option_str_limit_base(options &parent, pstring ashort, pstring along, std::vector &&limit, pstring help) + : option(parent, ashort, along, help, true) + , m_limit(limit) { } - - pstring operator ()() { return m_val; } - const std::vector &limit() { return m_limit; } + const std::vector &limit() const { return m_limit; } protected: - virtual int parse(const pstring &argument) override; private: - pstring m_val; std::vector m_limit; }; -class option_bool : public option + +template +class option_str_limit : public option_str_limit_base { public: - option_bool(options &parent, pstring ashort, pstring along, pstring help) - : option(parent, ashort, along, help, false), m_val(false) - {} + option_str_limit(options &parent, pstring ashort, pstring along, const T &defval, std::vector &&limit, pstring help) + : option_str_limit_base(parent, ashort, along, std::move(limit), help), m_val(defval) + { + } - bool operator ()() { return m_val; } + T operator ()() { return m_val; } + + pstring as_string() const { return limit()[m_val]; } protected: - virtual int parse(const pstring &argument) override; + virtual int parse(const pstring &argument) override + { + auto raw = plib::container::indexof(limit(), argument); + + if (raw != plib::container::npos) + { + m_val = static_cast(raw); + return 0; + } + else + return 1; + } private: - bool m_val; + T m_val; }; -class option_double : public option +class option_bool : public option { public: - option_double(options &parent, pstring ashort, pstring along, double defval, pstring help) - : option(parent, ashort, along, help, true), m_val(defval) + option_bool(options &parent, pstring ashort, pstring along, pstring help) + : option(parent, ashort, along, help, false), m_val(false) {} - double operator ()() { return m_val; } + bool operator ()() { return m_val; } protected: virtual int parse(const pstring &argument) override; private: - double m_val; + bool m_val; }; -class option_long : public option +template +class option_num : public option { public: - option_long(options &parent, pstring ashort, pstring along, long defval, pstring help) - : option(parent, ashort, along, help, true), m_val(defval) + option_num(options &parent, pstring ashort, pstring along, T defval, + pstring help, + T minval = std::numeric_limits::min(), + T maxval = std::numeric_limits::max() ) + : option(parent, ashort, along, help, true) + , m_val(defval) + , m_min(minval) + , m_max(maxval) {} - long operator ()() { return m_val; } + T operator ()() { return m_val; } protected: - virtual int parse(const pstring &argument) override; + virtual int parse(const pstring &argument) override + { + bool err; + m_val = pstonum_ne(argument, err); + return (err ? 1 : (m_val < m_min || m_val > m_max)); + } private: - long m_val; + T m_val; + T m_min; + T m_max; }; class option_vec : public option @@ -207,6 +233,17 @@ private: static pstring split_paragraphs(pstring text, unsigned width, unsigned indent, unsigned firstline_indent); + template + T *getopt_type() + { + for (auto & optbase : m_opts ) + { + if (auto opt = dynamic_cast(optbase)) + return opt; + } + return nullptr; + } + option *getopt_short(pstring arg); option *getopt_long(pstring arg); diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 298fa589fba..b18b3265440 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -122,6 +122,7 @@ pstring ptokenizer::get_identifier_or_number() return tok.str(); } +// FIXME: combine into template double ptokenizer::get_number_double() { token_t tok = get_token(); @@ -129,9 +130,9 @@ double ptokenizer::get_number_double() { error(pfmt("Expected a number, got <{1}>")(tok.str()) ); } - double ret = 0.0; - - if (!plib::pstod_ne(tok.str(), ret)) + bool err; + double ret = plib::pstonum_ne(tok.str(), err); + if (err) error(pfmt("Expected a number, got <{1}>")(tok.str()) ); return ret; } @@ -143,8 +144,9 @@ long ptokenizer::get_number_long() { error(pfmt("Expected a long int, got <{1}>")(tok.str()) ); } - long ret = 0; - if (!plib::pstol_ne(tok.str(), ret)) + bool err; + long ret = plib::pstonum_ne(tok.str(), err); + if (err) error(pfmt("Expected a long int, got <{1}>")(tok.str()) ); return ret; } @@ -326,7 +328,8 @@ double ppreprocessor::expr(const std::vector &sexpr, std::size_t &start else { tok=sexpr[start]; - val = plib::pstod(tok); + // FIXME: error handling + val = plib::pstonum(tok); start++; } while (start < sexpr.size()) diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 67104a54213..677ce9e43b8 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -9,8 +9,10 @@ #include #include +#include #include #include +#include #include // ---------------------------------------------------------------------------------------- @@ -518,57 +520,72 @@ namespace plib return pwstring(std::to_wstring(v)); } -#if (PSTRING_USE_STD_STRING) - inline double pstod(const std::string &str, std::size_t *e = nullptr) - { - return std::stod(str, e); - } + template + struct pstonum_helper; - inline long pstol(const std::string &str, std::size_t *e = nullptr, int base = 10) + template + struct pstonum_helper::value + && std::is_signed::value>::type> { - return std::stol(str, e, base); - } -#else + template + long long operator()(const S &arg, std::size_t *idx) + { + return std::stoll(arg, idx); + } + }; + template - double pstod(const T &str, std::size_t *e = nullptr) + struct pstonum_helper::value + && !std::is_signed::value>::type> { - return std::stod(str.cpp_string(), e); - } + template + unsigned long long operator()(const S &arg, std::size_t *idx) + { + return std::stoull(arg, idx); + } + }; template - long pstol(const T &str, std::size_t *e = nullptr, int base = 10) + struct pstonum_helper::value>::type> { - return std::stol(str.cpp_string(), e, base); - } -#endif + template + long double operator()(const S &arg, std::size_t *idx) + { + return std::stold(arg, idx); + } + }; - template - bool pstol_ne(const T &str, R &ret) + template + T pstonum(const S &arg) { - try + decltype(arg.c_str()) cstr = arg.c_str(); + std::size_t idx(0); + auto ret = pstonum_helper()(cstr, &idx); + if (ret >= std::numeric_limits::lowest() && ret <= std::numeric_limits::max()) + //&& (ret == T(0) || std::abs(ret) >= std::numeric_limits::min() )) { - std::size_t e = 0; - ret = pstol(str, &e); - return str.c_str()[e] == 0; + if (cstr[idx] != 0) + throw std::invalid_argument(std::string("Continuation after numeric value ends: ") + cstr); } - catch (...) + else { - return false; + throw std::out_of_range(std::string("Out of range: ") + cstr); } + return static_cast(ret); } - template - bool pstod_ne(const T &str, R &ret) + template + R pstonum_ne(const T &str, bool &err) noexcept { try { - std::size_t e = 0; - ret = pstod(str, &e); - return str.c_str()[e] == 0; + err = false; + return pstonum(str); } catch (...) { - return false; + err = true; + return R(0); } } diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp index 0d3a0ebca3f..92e0e6b3ab1 100644 --- a/src/lib/netlist/plib/putil.cpp +++ b/src/lib/netlist/plib/putil.cpp @@ -64,6 +64,36 @@ namespace plib return ret; } + std::vector psplit_r(const std::string &stri, + const std::string &token, + const std::size_t maxsplit) + { + std::string str(stri); + std::vector result; + std::size_t splits = 0; + + while(str.size()) + { + std::size_t index = str.rfind(token); + bool found = index!=std::string::npos; + if (found) + splits++; + if ((splits <= maxsplit || maxsplit == 0) && found) + { + result.push_back(str.substr(index+token.size())); + str = str.substr(0, index); + if (str.size()==0) + result.push_back(str); + } + else + { + result.push_back(str); + str = ""; + } + } + return result; + } + std::vector psplit(const pstring &str, const std::vector &onstrl) { pstring col = ""; diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 8d59c0357e2..914d9820560 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -16,6 +16,11 @@ namespace plib { + + // Avoid unused variable warnings + template + inline void unused_var(Ts&&...) {} + namespace util { const pstring buildpath(std::initializer_list list ); diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 4fcb4ebdc30..4395bd3bd17 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -23,7 +23,7 @@ public: tool_app_t() : plib::app(), opt_grp1(*this, "General options", "The following options apply to all commands."), - opt_cmd (*this, "c", "cmd", "run", "run:convert:listdevices:static:header:docheader", "run|convert|listdevices|static|header"), + opt_cmd (*this, "c", "cmd", 0, std::vector({"run","convert","listdevices","static","header","docheader"}), "run|convert|listdevices|static|header|docheader"), opt_file(*this, "f", "file", "-", "file to process (default is stdin)"), opt_defines(*this, "D", "define", "predefine value as macro, e.g. -Dname=value. If '=value' is omitted predefine it as 1. This option may be specified repeatedly."), opt_rfolders(*this, "r", "rom", "where to look for data files"), @@ -40,7 +40,7 @@ public: opt_loadstate(*this,"", "loadstate", "", "load state from file and continue from there"), opt_savestate(*this,"", "savestate", "", "save state to file at end of run"), opt_grp4(*this, "Options for convert command", "These options are only used by the convert command."), - opt_type(*this, "y", "type", "spice", "spice:eagle:rinf", "type of file to be converted: spice,eagle,rinf"), + opt_type(*this, "y", "type", 0, std::vector({"spice","eagle","rinf"}), "type of file to be converted: spice,eagle,rinf"), opt_ex1(*this, "nltool -c run -t 3.5 -f nl_examples/cdelay.c -n cap_delay", "Run netlist \"cap_delay\" from file nl_examples/cdelay.c for 3.5 seconds"), @@ -49,7 +49,7 @@ public: {} plib::option_group opt_grp1; - plib::option_str_limit opt_cmd; + plib::option_str_limit opt_cmd; plib::option_str opt_file; plib::option_vec opt_defines; plib::option_vec opt_rfolders; @@ -60,13 +60,13 @@ public: plib::option_group opt_grp2; plib::option_str opt_name; plib::option_group opt_grp3; - plib::option_double opt_ttr; + plib::option_num opt_ttr; plib::option_vec opt_logs; plib::option_str opt_inp; plib::option_str opt_loadstate; plib::option_str opt_savestate; plib::option_group opt_grp4; - plib::option_str_limit opt_type; + plib::option_str_limit opt_type; plib::option_example opt_ex1; plib::option_example opt_ex2; @@ -706,7 +706,7 @@ int tool_app_t::execute() try { - pstring cmd = opt_cmd(); + pstring cmd = opt_cmd.as_string(); if (cmd == "listdevices") listdevices(); else if (cmd == "run") @@ -734,19 +734,19 @@ int tool_app_t::execute() contents = ostrm.str(); pstring result; - if (opt_type() == "spice") + if (opt_type.as_string() == "spice") { nl_convert_spice_t c; c.convert(contents); result = c.result(); } - else if (opt_type() == "eagle") + else if (opt_type.as_string() == "eagle") { nl_convert_eagle_t c; c.convert(contents); result = c.result(); } - else if (opt_type() == "rinf") + else if (opt_type.as_string() == "rinf") { nl_convert_rinf_t c; c.convert(contents); diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 23491e88349..a1f14692364 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -24,8 +24,8 @@ public: {} plib::option_str opt_inp; plib::option_str opt_out; - plib::option_double opt_amp; - plib::option_long opt_rate; + plib::option_num opt_amp; + plib::option_num opt_rate; plib::option_bool opt_verb; plib::option_bool opt_quiet; plib::option_bool opt_version; diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 2158d725694..ad62ba17c28 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -268,7 +268,7 @@ void NETLIB_NAME(solver)::post_start() // Override log statistics pstring p = plib::util::environment("NL_STATS", ""); if (p != "") - m_params.m_log_stats = plib::pstol(p); + m_params.m_log_stats = plib::pstonum(p); else m_params.m_log_stats = m_log_stats(); diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index aff7d0da81b..4488396a131 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -214,7 +214,7 @@ double nl_convert_base_t::get_sp_val(const pstring &sin) ++p; pstring val = plib::left(sin, p); pstring unit = sin.substr(p); - double ret = get_sp_unit(unit) * plib::pstod(val); + double ret = get_sp_unit(unit) * plib::pstonum(val); return ret; } @@ -304,11 +304,12 @@ void nl_convert_spice_t::process_line(const pstring &line) /* check for fourth terminal ... should be numeric net * including "0" or start with "N" (ltspice) */ - long nval = 0; pstring model; pstring pins ="CBE"; + bool err; + ATTR_UNUSED long nval = plib::pstonum_ne(tt[4], err); - if ((!plib::pstol_ne(tt[4], nval) || plib::startsWith(tt[4], "N")) && tt.size() > 5) + if ((err || plib::startsWith(tt[4], "N")) && tt.size() > 5) model = tt[5]; else model = tt[4]; @@ -492,7 +493,7 @@ void nl_convert_eagle_t::convert(const pstring &contents) else if (plib::ucase(sval) == "LOW") add_device("TTL_INPUT", name, 0); else - add_device("ANALOG_INPUT", name, plib::pstod(sval)); + add_device("ANALOG_INPUT", name, plib::pstonum(sval)); add_pin_alias(name, "1", "Q"); break; case 'D': -- cgit v1.2.3-70-g09d2 From 633528eb31e7f318e6934476c85126dcf02fd457 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 13 Jan 2019 00:08:47 +0100 Subject: Improve dealing ownership in pstreams. (nw) I am not really happy with this. But I am missing some creativity currently. --- src/lib/netlist/devices/nld_log.cpp | 4 +- src/lib/netlist/nl_parser.h | 4 +- src/lib/netlist/nl_setup.cpp | 14 +-- src/lib/netlist/nl_setup.h | 2 +- src/lib/netlist/plib/pmain.cpp | 4 +- src/lib/netlist/plib/pparser.cpp | 4 +- src/lib/netlist/plib/pparser.h | 4 +- src/lib/netlist/plib/pstream.cpp | 29 ++--- src/lib/netlist/plib/pstream.h | 210 +++++++++++++++++++++++++++++------ src/lib/netlist/plib/pstring.h | 2 + src/lib/netlist/prg/nltool.cpp | 9 +- src/lib/netlist/prg/nlwav.cpp | 27 +++-- src/lib/netlist/solver/nld_ms_gcr.h | 4 +- src/lib/netlist/tools/nl_convert.cpp | 22 ++-- src/lib/netlist/tools/nl_convert.h | 4 +- 15 files changed, 239 insertions(+), 104 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp index 8125dacafe8..1d3ea7b1b75 100644 --- a/src/lib/netlist/devices/nld_log.cpp +++ b/src/lib/netlist/devices/nld_log.cpp @@ -19,8 +19,8 @@ namespace netlist { NETLIB_CONSTRUCTOR(log) , m_I(*this, "I") - , m_strm(plib::pfmt("{1}.log")(this->name())) - , m_writer(m_strm) + , m_strm(pstring(plib::pfmt("{1}.log")(this->name()))) + , m_writer(&m_strm) { } diff --git a/src/lib/netlist/nl_parser.h b/src/lib/netlist/nl_parser.h index a813629faa0..872cfa11954 100644 --- a/src/lib/netlist/nl_parser.h +++ b/src/lib/netlist/nl_parser.h @@ -16,8 +16,8 @@ namespace netlist class parser_t : public plib::ptokenizer { public: - parser_t(plib::putf8_reader &strm, setup_t &setup) - : plib::ptokenizer(strm), m_setup(setup) {} + parser_t(plib::putf8_reader &&strm, setup_t &setup) + : plib::ptokenizer(std::move(strm)), m_setup(setup) {} bool parse(const pstring &nlname = ""); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 28385d984cf..a02d5f5bbae 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -965,15 +965,15 @@ std::unique_ptr setup_t::get_data_stream(const pstring &name) } -bool setup_t::parse_stream(plib::putf8_reader &istrm, const pstring &name) +bool setup_t::parse_stream(plib::putf8_reader &&istrm, const pstring &name) { plib::pomemstream ostrm; - plib::putf8_writer owrt(ostrm); + plib::putf8_writer owrt(&ostrm); plib::ppreprocessor(&m_defines).process(istrm, owrt); - plib::pimemstream istrm2(ostrm); - plib::putf8_reader reader2(istrm2); - return parser_t(reader2, *this).parse(name); + plib::putf8_reader reader2 = plib::putf8_reader(plib::pimemstream(ostrm)); + + return parser_t(std::move(reader2), *this).parse(name); } void setup_t::register_define(const pstring &defstr) @@ -996,8 +996,8 @@ bool source_t::parse(const pstring &name) else { auto rstream = stream(name); - plib::putf8_reader reader(*rstream); - return m_setup.parse_stream(reader, name); + plib::putf8_reader reader(rstream.get()); + return m_setup.parse_stream(std::move(reader), name); } } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 4f7146b3995..cae829023a4 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -259,7 +259,7 @@ namespace netlist std::unique_ptr get_data_stream(const pstring &name); - bool parse_stream(plib::putf8_reader &istrm, const pstring &name); + bool parse_stream(plib::putf8_reader &&istrm, const pstring &name); /* register a source */ diff --git a/src/lib/netlist/plib/pmain.cpp b/src/lib/netlist/plib/pmain.cpp index 6edfe86b838..30b4a1948bd 100644 --- a/src/lib/netlist/plib/pmain.cpp +++ b/src/lib/netlist/plib/pmain.cpp @@ -37,8 +37,8 @@ namespace plib { : options() , pout_strm() , perr_strm() - , pout(pout_strm) - , perr(perr_strm) + , pout(&pout_strm) + , perr(&perr_strm) { } diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index b18b3265440..2d1a426f5a5 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -16,8 +16,8 @@ namespace plib { // A simple tokenizer // ---------------------------------------------------------------------------------------- -ptokenizer::ptokenizer(plib::putf8_reader &strm) -: m_strm(strm), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"') +ptokenizer::ptokenizer(plib::putf8_reader &&strm) +: m_strm(std::move(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"') { } diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 0dc2eb7dfbc..eb4f253c79b 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -19,7 +19,7 @@ namespace plib { class ptokenizer : nocopyassignmove { public: - explicit ptokenizer(plib::putf8_reader &strm); + ptokenizer(plib::putf8_reader &&strm); virtual ~ptokenizer(); @@ -123,7 +123,7 @@ private: bool eof() { return m_strm.eof(); } - putf8_reader &m_strm; + putf8_reader m_strm; int m_lineno; pstring m_cur_line; diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp index 50a39685f70..e0094e99e38 100644 --- a/src/lib/netlist/plib/pstream.cpp +++ b/src/lib/netlist/plib/pstream.cpp @@ -41,14 +41,6 @@ postream::~postream() { } -void postream::write(pistream &strm) -{ - char buf[1024]; - pos_type r; - while ((r=strm.read(buf, 1024)) > 0) - write(buf, r); -} - // ----------------------------------------------------------------------------- // Input file stream // ----------------------------------------------------------------------------- @@ -119,7 +111,7 @@ void pifilestream::vseek(const pos_type n) throw file_e("Generic file operation failed: {}", m_filename); } -pifilestream::pos_type pifilestream::vtell() +pifilestream::pos_type pifilestream::vtell() const { long ret = ftell(static_cast(m_file)); if (ret < 0) @@ -204,7 +196,7 @@ void pofilestream::vseek(const pos_type n) } } -pstream::pos_type pofilestream::vtell() +pstream::pos_type pofilestream::vtell() const { std::ptrdiff_t ret = ftell(static_cast(m_file)); if (ret < 0) @@ -263,6 +255,11 @@ pimemstream::pimemstream(const void *mem, const pos_type len) { } +pimemstream::pimemstream() + : pistream(FLAG_SEEKABLE), m_pos(0), m_len(0), m_mem(static_cast(nullptr)) +{ +} + pimemstream::pimemstream(const pomemstream &ostrm) : pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast(ostrm.memory())) { @@ -295,7 +292,7 @@ void pimemstream::vseek(const pos_type n) } -pimemstream::pos_type pimemstream::vtell() +pimemstream::pos_type pimemstream::vtell() const { return m_pos; } @@ -316,7 +313,8 @@ pomemstream::pomemstream() pomemstream::~pomemstream() { - pfree_array(m_mem); + if (m_mem != nullptr) + pfree_array(m_mem); } void pomemstream::vwrite(const void *buf, const pos_type n) @@ -359,7 +357,7 @@ void pomemstream::vseek(const pos_type n) } } -pstream::pos_type pomemstream::vtell() +pstream::pos_type pomemstream::vtell() const { return m_pos; } @@ -386,11 +384,6 @@ bool putf8_reader::readline(pstring &line) return true; } -putf8_fmt_writer::putf8_fmt_writer(postream &strm) -: pfmt_writer_t() -, putf8_writer(strm) -{ -} putf8_fmt_writer::~putf8_fmt_writer() { diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index a97ecd5cbd4..e8b6c38ac66 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -11,30 +11,51 @@ #include "pstring.h" #include "pfmtlog.h" #include "pexception.h" +#include "palloc.h" + +#define USE_CSTREAM (0) #include +#include + +#if USE_CSTREAM +#include +//#include +#include +#endif + namespace plib { + +#if USE_CSTREAM +typedef std::ostream postream; +typedef std::ofstream pofilestream; +typedef std::ostringstream postringstream; +typedef std::ostringstream pomemstream; + +#endif + // ----------------------------------------------------------------------------- // pstream: things common to all streams // ----------------------------------------------------------------------------- -class pstream : nocopyassignmove +class pstream : nocopyassign { public: using pos_type = std::size_t; + using size_type = std::size_t; static constexpr pos_type SEEK_EOF = static_cast(-1); bool seekable() const { return ((m_flags & FLAG_SEEKABLE) != 0); } - void seek(const pos_type n) + void seekp(const pos_type n) { - return vseek(n); + vseek(n); } - pos_type tell() + pos_type tellp() const { return vtell(); } @@ -43,10 +64,13 @@ protected: explicit pstream(const unsigned flags) : m_flags(flags) { } + pstream(pstream &&src) : m_flags(src.m_flags) + { + } ~pstream(); virtual void vseek(const pos_type n) = 0; - virtual pos_type vtell() = 0; + virtual pos_type vtell() const = 0; static constexpr unsigned FLAG_EOF = 0x01; static constexpr unsigned FLAG_SEEKABLE = 0x04; @@ -84,8 +108,9 @@ public: protected: explicit pistream(const unsigned flags) : pstream(flags) {} + explicit pistream(pistream &&src) : pstream(std::move(src)) {} /* read up to n bytes from stream */ - virtual pos_type vread(void *buf, const pos_type n) = 0; + virtual size_type vread(void *buf, const size_type n) = 0; }; @@ -93,23 +118,23 @@ protected: // postream: output stream // ----------------------------------------------------------------------------- +#if !USE_CSTREAM class postream : public pstream { public: virtual ~postream(); - void write(const void *buf, const pos_type n) + void write(const char *buf, const size_type n) { vwrite(buf, n); } - void write(pistream &strm); - protected: explicit postream(unsigned flags) : pstream(flags) {} + explicit postream(postream &&src) : pstream(std::move(src)) {} /* write n bytes to stream */ - virtual void vwrite(const void *buf, const pos_type n) = 0; + virtual void vwrite(const void *buf, const size_type n) = 0; private: }; @@ -123,6 +148,17 @@ class pomemstream : public postream public: pomemstream(); + + pomemstream(pomemstream &&src) + : postream(std::move(src)) + , m_pos(src.m_pos) + , m_capacity(src.m_capacity) + , m_size(src.m_size) + , m_mem(src.m_mem) + { + src.m_mem = nullptr; + } + virtual ~pomemstream() override; char *memory() const { return m_mem; } @@ -132,7 +168,7 @@ protected: /* write n bytes to stream */ virtual void vwrite(const void *buf, const pos_type) override; virtual void vseek(const pos_type n) override; - virtual pos_type vtell() override; + virtual pos_type vtell() const override; private: pos_type m_pos; @@ -146,6 +182,11 @@ class postringstream : public postream public: postringstream() : postream(0) { } + postringstream(postringstream &&src) + : postream(std::move(src)) + , m_buf(src.m_buf) + { src.m_buf = ""; } + virtual ~postringstream() override; const pstring &str() { return m_buf; } @@ -157,7 +198,7 @@ protected: m_buf += pstring(static_cast(buf), n); } virtual void vseek(const pos_type n) override { } - virtual pos_type vtell() override { return m_buf.size(); } + virtual pos_type vtell() const override { return m_buf.size(); } private: pstring m_buf; @@ -171,7 +212,18 @@ class pofilestream : public postream { public: - explicit pofilestream(const pstring &fname); + pofilestream(const pstring &fname); + pofilestream(pofilestream &&src) + : postream(std::move(src)) + , m_file(src.m_file) + , m_pos(src.m_pos) + , m_actually_close(src.m_actually_close) + , m_filename(src.m_filename) + { + src.m_file = nullptr; + src.m_actually_close = false; + } + virtual ~pofilestream() override; protected: @@ -179,7 +231,7 @@ protected: /* write n bytes to stream */ virtual void vwrite(const void *buf, const pos_type n) override; virtual void vseek(const pos_type n) override; - virtual pos_type vtell() override; + virtual pos_type vtell() const override; private: void *m_file; @@ -193,6 +245,7 @@ private: // ----------------------------------------------------------------------------- // pstderr: write to stderr // ----------------------------------------------------------------------------- +#endif class pstderr : public pofilestream { @@ -220,16 +273,27 @@ class pifilestream : public pistream { public: - explicit pifilestream(const pstring &fname); + pifilestream(const pstring &fname); virtual ~pifilestream() override; + pifilestream(pifilestream &&src) + : pistream(std::move(src)) + , m_file(src.m_file) + , m_pos(src.m_pos) + , m_actually_close(src.m_actually_close) + , m_filename(src.m_filename) + { + src.m_actually_close = false; + src.m_file = nullptr; + } + protected: pifilestream(void *file, const pstring &name, const bool do_close); /* read up to n bytes from stream */ virtual pos_type vread(void *buf, const pos_type n) override; virtual void vseek(const pos_type n) override; - virtual pos_type vtell() override; + virtual pos_type vtell() const override; private: void *m_file; @@ -261,15 +325,34 @@ class pimemstream : public pistream public: pimemstream(const void *mem, const pos_type len); + pimemstream(); + + pimemstream(pimemstream &&src) + : pistream(std::move(src)) + , m_pos(src.m_pos) + , m_len(src.m_len) + , m_mem(src.m_mem) + { + src.m_mem = nullptr; + } + explicit pimemstream(const pomemstream &ostrm); + virtual ~pimemstream() override; pos_type size() const { return m_len; } protected: + + void set_mem(const void *mem, const pos_type len) + { + m_mem = static_cast(mem); + m_len = len; + } + /* read up to n bytes from stream */ virtual pos_type vread(void *buf, const pos_type n) override; virtual void vseek(const pos_type n) override; - virtual pos_type vtell() override; + virtual pos_type vtell() const override; private: pos_type m_pos; @@ -284,12 +367,22 @@ private: class pistringstream : public pimemstream { public: - explicit pistringstream(const pstring &str) : pimemstream(str.c_str(), std::strlen(str.c_str())), m_str(str) { } + pistringstream(const pstring &str) + : pimemstream() + , m_str(str) + { + set_mem(m_str.c_str(), std::strlen(m_str.c_str())); + } + pistringstream(pistringstream &&src) + : pimemstream(std::move(src)), m_str(src.m_str) + { + set_mem(m_str.c_str(), std::strlen(m_str.c_str())); + } virtual ~pistringstream() override; private: /* only needed for a reference till destruction */ - pstring m_str; + const pstring m_str; }; // ----------------------------------------------------------------------------- @@ -298,35 +391,62 @@ private: /* this digests linux & dos/windows text files */ -class putf8_reader : plib::nocopyassignmove +class putf8_reader : plib::nocopyassign { public: - explicit putf8_reader(pistream &strm) : m_strm(strm) {} - virtual ~putf8_reader() {} + putf8_reader(pistream *strm) : m_strm(strm), m_stream_owned(false) {} + virtual ~putf8_reader() + { + if (m_stream_owned && m_strm != nullptr) + pfree(m_strm); + } + + putf8_reader(putf8_reader &&src) : m_strm(src.m_strm), m_stream_owned(src.m_stream_owned) + { + src.m_strm = nullptr; + src.m_stream_owned = false; + } + + putf8_reader(pimemstream &&strm) + : m_strm(palloc(std::move(strm))), + m_stream_owned(true) + {} - bool eof() const { return m_strm.eof(); } + putf8_reader(pifilestream &&strm) + : m_strm(palloc(std::move(strm))), + m_stream_owned(true) + {} + + putf8_reader(pistringstream &&strm) + : m_strm(palloc(std::move(strm))), + m_stream_owned(true) + {} + + + bool eof() const { return m_strm->eof(); } bool readline(pstring &line); bool readbyte1(char &b) { - return (m_strm.read(&b, 1) == 1); + return (m_strm->read(&b, 1) == 1); } bool readcode(putf8string::traits_type::code_t &c) { char b[4]; - if (m_strm.read(&b[0], 1) != 1) + if (m_strm->read(&b[0], 1) != 1) return false; const std::size_t l = putf8string::traits_type::codelen(b); for (std::size_t i = 1; i < l; i++) - if (m_strm.read(&b[i], 1) != 1) + if (m_strm->read(&b[i], 1) != 1) return false; c = putf8string::traits_type::code(b); return true; } private: - pistream &m_strm; + pistream *m_strm; + bool m_stream_owned; putf8string m_linebuf; }; @@ -334,10 +454,12 @@ private: // putf8writer_t: writer on top of ostream // ----------------------------------------------------------------------------- -class putf8_writer : plib::nocopyassignmove +class putf8_writer : plib::nocopyassign { public: - explicit putf8_writer(postream &strm) : m_strm(strm) {} + explicit putf8_writer(postream *strm) : m_strm(strm) {} + + putf8_writer(putf8_writer &&src) : m_strm(src.m_strm) {} virtual ~putf8_writer() {} void writeline(const pstring &line) const @@ -349,7 +471,7 @@ public: void write(const pstring &text) const { putf8string conv_utf8(text); - m_strm.write(conv_utf8.c_str(), conv_utf8.mem_t_size()); + m_strm->write(conv_utf8.c_str(), conv_utf8.mem_t_size()); } void write(const pstring::value_type c) const @@ -359,14 +481,19 @@ public: } private: - postream &m_strm; + postream *m_strm; }; class putf8_fmt_writer : public pfmt_writer_t, public putf8_writer { public: - explicit putf8_fmt_writer(postream &strm); + explicit putf8_fmt_writer(postream *strm) + : pfmt_writer_t() + , putf8_writer(strm) + { + } + virtual ~putf8_fmt_writer() override; //protected: @@ -379,16 +506,17 @@ private: // pbinary_writer_t: writer on top of ostream // ----------------------------------------------------------------------------- -class pbinary_writer : plib::nocopyassignmove +class pbinary_writer : plib::nocopyassign { public: explicit pbinary_writer(postream &strm) : m_strm(strm) {} + pbinary_writer(pbinary_writer &&src) : m_strm(src.m_strm) {} virtual ~pbinary_writer() {} template - void write(const T val) + void write(const T &val) { - m_strm.write(&val, sizeof(T)); + m_strm.write(reinterpret_cast(&val), sizeof(T)); } void write(const pstring &s) @@ -411,10 +539,11 @@ private: postream &m_strm; }; -class pbinary_reader : plib::nocopyassignmove +class pbinary_reader : plib::nocopyassign { public: explicit pbinary_reader(pistream &strm) : m_strm(strm) {} + pbinary_reader(pbinary_reader &&src) : m_strm(src.m_strm) { } virtual ~pbinary_reader() {} template @@ -447,6 +576,15 @@ private: pistream &m_strm; }; +inline void copystream(postream &dest, pistream &src) +{ + char buf[1024]; + pstream::pos_type r; + while ((r=src.read(buf, 1024)) > 0) + dest.write(buf, r); +} + + } #endif /* PSTREAM_H_ */ diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index ebdca57c9a5..515bbe70a57 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -147,6 +147,8 @@ public: *this += static_cast(c); // FIXME: codepage conversion for u8 } + operator string_type () const { return m_str; } + pstring_t &operator=(const pstring_t &string) { m_str = string.m_str; return *this; } template read_input(const netlist::setup_t &setup, pstring fn std::vector ret; if (fname != "") { - plib::pifilestream f(fname); - plib::putf8_reader r(f); + plib::putf8_reader r = plib::putf8_reader(plib::pifilestream(fname)); pstring l; while (r.readline(l)) { @@ -402,7 +401,7 @@ void tool_app_t::static_compile() opt_logs(), opt_defines(), opt_rfolders()); - plib::putf8_writer w(pout_strm); + plib::putf8_writer w(&pout_strm); std::map mp; nt.solver()->create_solver_code(mp); @@ -724,12 +723,12 @@ int tool_app_t::execute() if (opt_file() == "-") { plib::pstdin f; - ostrm.write(f); + plib::copystream(ostrm, f); } else { plib::pifilestream f(opt_file()); - ostrm.write(f); + plib::copystream(ostrm, f); } contents = ostrm.str(); diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 17d385f2c1a..1bc3505c206 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -51,38 +51,45 @@ private: * and data chunk length to the file. */ /* http://de.wikipedia.org/wiki/RIFF_WAVE */ + class wav_t { public: wav_t(plib::postream &strm, unsigned sr) : m_f(strm) { initialize(sr); - m_f.write(&m_fh, sizeof(m_fh)); - m_f.write(&m_fmt, sizeof(m_fmt)); - m_f.write(&m_data, sizeof(m_data)); + write(m_fh); + write(m_fmt); + write(m_data); } ~wav_t() { if (m_f.seekable()) { m_fh.filelen = m_data.len + sizeof(m_data) + sizeof(m_fh) + sizeof(m_fmt) - 8; - m_f.seek(0); - m_f.write(&m_fh, sizeof(m_fh)); - m_f.write(&m_fmt, sizeof(m_fmt)); + m_f.seekp(0); + write(m_fh); + write(m_fmt); //data.len = fmt.block_align * n; - m_f.write(&m_data, sizeof(m_data)); + write(m_data); } } unsigned channels() { return m_fmt.channels; } unsigned sample_rate() { return m_fmt.sample_rate; } + template + void write(const T &val) + { + m_f.write(reinterpret_cast(&val), sizeof(T)); + } + void write_sample(int sample) { m_data.len += m_fmt.block_align; int16_t ps = static_cast(sample); /* 16 bit sample, FIXME: Endianess? */ - m_f.write(&ps, sizeof(ps)); + write(ps); } private: @@ -150,7 +157,7 @@ public: void process() { - plib::putf8_reader reader(m_is); + plib::putf8_reader reader(&m_is); pstring line; while(reader.readline(line)) @@ -248,7 +255,7 @@ void nlwav_app::convert(long sample_rate) { plib::postream *fo = (opt_out() == "-" ? &pout_strm : plib::palloc(opt_out())); plib::pistream *fin = (opt_inp() == "-" ? &pin_strm : plib::palloc(opt_inp())); - plib::putf8_reader reader(*fin); + plib::putf8_reader reader(fin); wav_t *wo = plib::palloc(*fo, static_cast(sample_rate)); double dt = 1.0 / static_cast(wo->sample_rate()); diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index a17ca1ec282..dee76dd8281 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -298,7 +298,7 @@ template pstring matrix_solver_GCR_t::static_compile_name() { plib::postringstream t; - plib::putf8_fmt_writer w(t); + plib::putf8_fmt_writer w(&t); csc_private(w); std::hash h; @@ -309,7 +309,7 @@ template std::pair matrix_solver_GCR_t::create_solver_code() { plib::postringstream t; - plib::putf8_fmt_writer strm(t); + plib::putf8_fmt_writer strm(&t); pstring name = static_compile_name(); strm.writeline(plib::pfmt("extern \"C\" void {1}(double * __restrict m_A, double * __restrict RHS, double * __restrict V)\n")(name)); diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index b89e94ca3e5..6b6f3925a5a 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -42,8 +42,7 @@ using lib_map_t = std::unordered_map; static lib_map_t read_lib_map(const pstring &lm) { - plib::pistringstream istrm(lm); - plib::putf8_reader reader(istrm); + auto reader = plib::putf8_reader(plib::pistringstream(lm)); lib_map_t m; pstring line; while (reader.readline(line)) @@ -59,7 +58,7 @@ static lib_map_t read_lib_map(const pstring &lm) -------------------------------------------------*/ nl_convert_base_t::nl_convert_base_t() - : out(m_buf) + : out(&m_buf) , m_numberchars("0123456789-+e.") { } @@ -401,8 +400,8 @@ void nl_convert_spice_t::process_line(const pstring &line) Eagle converter -------------------------------------------------*/ -nl_convert_eagle_t::tokenizer::tokenizer(nl_convert_eagle_t &convert, plib::putf8_reader &strm) - : plib::ptokenizer(strm) +nl_convert_eagle_t::tokenizer::tokenizer(nl_convert_eagle_t &convert, plib::putf8_reader &&strm) + : plib::ptokenizer(std::move(strm)) , m_convert(convert) { set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-"); @@ -429,9 +428,8 @@ void nl_convert_eagle_t::tokenizer::verror(const pstring &msg, int line_num, con //FIXME: should accept a stream as well void nl_convert_eagle_t::convert(const pstring &contents) { - plib::pistringstream istrm(contents); - plib::putf8_reader reader(istrm); - tokenizer tok(*this, reader); + + tokenizer tok(*this, plib::putf8_reader(plib::pistringstream(contents))); out("NETLIST_START(dummy)\n"); add_term("GND", "GND"); @@ -539,8 +537,8 @@ void nl_convert_eagle_t::convert(const pstring &contents) RINF converter -------------------------------------------------*/ -nl_convert_rinf_t::tokenizer::tokenizer(nl_convert_rinf_t &convert, plib::putf8_reader &strm) - : plib::ptokenizer(strm) +nl_convert_rinf_t::tokenizer::tokenizer(nl_convert_rinf_t &convert, plib::putf8_reader &&strm) + : plib::ptokenizer(std::move(strm)) , m_convert(convert) { set_identifier_chars(".abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-"); @@ -579,9 +577,7 @@ void nl_convert_rinf_t::tokenizer::verror(const pstring &msg, int line_num, cons void nl_convert_rinf_t::convert(const pstring &contents) { - plib::pistringstream istrm(contents); - plib::putf8_reader reader(istrm); - tokenizer tok(*this, reader); + tokenizer tok(*this, plib::putf8_reader(plib::pistringstream(contents))); auto lm = read_lib_map(s_lib_map); out("NETLIST_START(dummy)\n"); diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index d3881320678..1433f75664c 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -166,7 +166,7 @@ public: class tokenizer : public plib::ptokenizer { public: - tokenizer(nl_convert_eagle_t &convert, plib::putf8_reader &strm); + tokenizer(nl_convert_eagle_t &convert, plib::putf8_reader &&strm); token_id_t m_tok_ADD; token_id_t m_tok_VALUE; @@ -202,7 +202,7 @@ public: class tokenizer : public plib::ptokenizer { public: - tokenizer(nl_convert_rinf_t &convert, plib::putf8_reader &strm); + tokenizer(nl_convert_rinf_t &convert, plib::putf8_reader &&strm); token_id_t m_tok_HEA; token_id_t m_tok_APP; -- cgit v1.2.3-70-g09d2 From 0a17d35c13f770e8b69fb0a68f1485631dfc3578 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 13 Jan 2019 19:57:39 +0100 Subject: netlist: Fix logging during object construction. (nw) --- src/devices/machine/netlist.cpp | 37 +++++++++++++++++--------- src/devices/machine/netlist.h | 1 + src/lib/netlist/analog/nlid_twoterm.h | 20 +++++++++----- src/lib/netlist/netlist_types.h | 28 ++++++++++++++++++++ src/lib/netlist/nl_base.cpp | 13 ++++----- src/lib/netlist/nl_base.h | 50 ++++++++++++----------------------- src/lib/netlist/nl_setup.cpp | 4 +-- src/lib/netlist/nl_setup.h | 4 +-- src/lib/netlist/plib/pomp.h | 2 ++ src/lib/netlist/plib/pparser.cpp | 2 +- src/lib/netlist/prg/nltool.cpp | 24 ++++++++++++----- src/lib/netlist/solver/nld_solver.cpp | 2 +- 12 files changed, 114 insertions(+), 73 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 137c9e6cf6c..ffd99d5437a 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -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(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 m_last; + netlist::state_var 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(); diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index b400acdf32a..dbd862a12e2 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -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); diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 624dd98e558..4ab5fcda89b 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -48,6 +48,20 @@ namespace netlist // nld_twoterm // ----------------------------------------------------------------------------- + template + inline core_device_t &bselect(bool b, C &d1, core_device_t &d2) + { + core_device_t *h = dynamic_cast(&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 - static core_device_t &bselect(bool b, C &d1, core_device_t &d2) - { - core_device_t *h = dynamic_cast(&d1); - return b ? *h : d2; - } }; diff --git a/src/lib/netlist/netlist_types.h b/src/lib/netlist/netlist_types.h index d5fe7b11e20..bbca9949e49 100644 --- a/src/lib/netlist/netlist_types.h +++ b/src/lib/netlist/netlist_types.h @@ -12,12 +12,40 @@ #include "nl_config.h" #include "plib/pchrono.h" #include "plib/pstring.h" +#include "plib/pfmtlog.h" #include #include 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; + + //============================================================ // Performance tracking //============================================================ diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 6a8ac148151..4bdec442f17 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -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) : 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(m_queue), "m_queue"); state().save_item(this, m_time, "m_time"); m_setup = plib::make_unique(*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 &core_device_t::log() +log_type & core_device_t::log() { return netlist().log(); } diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 24129821b4b..6e4f9c50543 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -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 -#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 &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); + ~netlist_t(); /* run functions */ @@ -1292,8 +1276,9 @@ namespace netlist /* logging and name */ pstring name() const { return m_name; } - plib::plog_base &log() { return m_log; } - const plib::plog_base &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 m_setup; - plib::plog_base m_log; std::unique_ptr 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 m_perf_out_processed; std::vector> m_devices; + + std::unique_ptr m_callbacks; + log_type m_log; + std::unique_ptr m_setup; }; // ----------------------------------------------------------------------------- diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index a02d5f5bbae..e876b2f7e8b 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -768,11 +768,11 @@ void setup_t::start_devices() } } -plib::plog_base &setup_t::log() +log_type &setup_t::log() { return netlist().log(); } -const plib::plog_base &setup_t::log() const +const log_type &setup_t::log() const { return netlist().log(); } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index cae829023a4..3894cad5415 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -288,8 +288,8 @@ namespace netlist /* helper - also used by nltool */ const pstring resolve_alias(const pstring &name) const; - plib::plog_base &log(); - const plib::plog_base &log() const; + log_type &log(); + const log_type &log() const; //std::vector> m_device_factory; std::unordered_map m_device_factory; diff --git a/src/lib/netlist/plib/pomp.h b/src/lib/netlist/plib/pomp.h index 221c0d61c00..f13df2539ac 100644 --- a/src/lib/netlist/plib/pomp.h +++ b/src/lib/netlist/plib/pomp.h @@ -9,6 +9,8 @@ #ifndef POMP_H_ #define POMP_H_ +#include + #include "pconfig.h" #if HAS_OPENMP diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index f70001530c4..43ed9e14d41 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -318,7 +318,7 @@ void ppreprocessor::error(const pstring &err) int ppreprocessor::expr(const std::vector &sexpr, std::size_t &start, int prio) { - int val; + int val = 0; pstring tok=sexpr[start]; if (tok == "(") { diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index c7c3ac652fd..0a5fba22d9e 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -132,22 +132,35 @@ std::unique_ptr netlist_data_folder_t::stream(const pstring &fil return std::unique_ptr(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(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: ... diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 760b7088e67..f9de00d417d 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -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(0), solvers.size(), [this, &solvers](std::size_t i) + plib::omp::for_static(static_cast(0), solvers.size(), [&solvers](std::size_t i) { const netlist_time ts = solvers[i]->solve(); plib::unused_var(ts); -- cgit v1.2.3-70-g09d2 From 5a594cf06999c42335f99cb5113522f40db2c835 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 13 Jan 2019 23:18:29 +0100 Subject: netlist: Improve type safety for parameters. (nw) --- src/devices/machine/netlist.h | 11 +++-- src/lib/netlist/nl_base.cpp | 42 ++++++------------- src/lib/netlist/nl_base.h | 95 +++++++++++++++++++++++++++++-------------- src/lib/netlist/nl_setup.cpp | 40 +++--------------- src/lib/netlist/nl_setup.h | 13 +++--- 5 files changed, 96 insertions(+), 105 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index dbd862a12e2..68723c0d982 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -18,9 +18,8 @@ class nld_sound_in; namespace netlist { class setup_t; - class param_double_t; - class param_int_t; - class param_logic_t; + template + class param_num_t; class param_ptr_t; } @@ -308,7 +307,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; private: - netlist::param_double_t *m_param; + netlist::param_num_t *m_param; bool m_auto_port; const char *m_param_name; double m_value_for_device_timer; @@ -403,7 +402,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; private: - netlist::param_int_t *m_param; + netlist::param_num_t *m_param; uint32_t m_mask; uint32_t m_shift; const char *m_param_name; @@ -442,7 +441,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; private: - netlist::param_logic_t *m_param; + netlist::param_num_t *m_param; uint32_t m_shift; const char *m_param_name; }; diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 4bdec442f17..76e991f574f 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -720,6 +720,11 @@ setup_t &device_t::setup() return netlist().setup(); } +const setup_t &device_t::setup() const +{ + return netlist().setup(); +} + void device_t::register_subalias(const pstring &name, detail::core_terminal_t &term) { pstring alias = this->name() + "." + name; @@ -1153,6 +1158,14 @@ void param_t::update_param() device().update_dev(); } +pstring param_t::get_initial(const device_t &dev, bool *found) +{ + pstring res = dev.setup().get_initial_param_val(this->name(), ""); + *found = (res != ""); + return res; +} + + const pstring param_model_t::model_type() { if (m_map.size() == 0) @@ -1174,27 +1187,6 @@ void param_str_t::changed() { } -param_double_t::param_double_t(device_t &device, const pstring &name, const double val) -: param_t(device, name) -{ - m_param = device.setup().get_initial_param_val(this->name(),val); - netlist().save(*this, m_param, "m_param"); -} - -param_int_t::param_int_t(device_t &device, const pstring &name, const int val) -: param_t(device, name) -{ - m_param = device.setup().get_initial_param_val(this->name(),val); - netlist().save(*this, m_param, "m_param"); -} - -param_logic_t::param_logic_t(device_t &device, const pstring &name, const bool val) -: param_t(device, name) -{ - m_param = device.setup().get_initial_param_val(this->name(),val); - netlist().save(*this, m_param, "m_param"); -} - param_ptr_t::param_ptr_t(device_t &device, const pstring &name, uint8_t * val) : param_t(device, name) { @@ -1222,14 +1214,6 @@ nl_double param_model_t::model_value(const pstring &entity) return netlist().setup().model_value(m_map, entity); } -param_data_t::param_data_t(device_t &device, const pstring &name) -: param_str_t(device, name, "") -{ -} - -void param_data_t::changed() -{ -} std::unique_ptr param_data_t::stream() { diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 6e4f9c50543..0b1b3285dd6 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -14,6 +14,7 @@ #endif #include "netlist_types.h" +#include "nl_errstr.h" #include "nl_lists.h" #include "nl_time.h" #include "plib/palloc.h" // owned_ptr @@ -906,6 +907,8 @@ namespace netlist void update_param(); + pstring get_initial(const device_t &dev, bool *found); + template void set(C &p, const C v) { @@ -918,46 +921,44 @@ namespace netlist }; - class param_ptr_t final: public param_t - { - public: - param_ptr_t(device_t &device, const pstring &name, std::uint8_t* val); - std::uint8_t * operator()() const NL_NOEXCEPT { return m_param; } - void setTo(std::uint8_t *param) { set(m_param, param); } - private: - std::uint8_t* m_param; - }; + // ----------------------------------------------------------------------------- + // numeric parameter template + // ----------------------------------------------------------------------------- - class param_logic_t final: public param_t + template + class param_num_t final: public param_t { public: - param_logic_t(device_t &device, const pstring &name, const bool val); - const bool &operator()() const NL_NOEXCEPT { return m_param; } - void setTo(const bool ¶m) { set(m_param, param); } + param_num_t(device_t &device, const pstring &name, const T val); + const T &operator()() const NL_NOEXCEPT { return m_param; } + void setTo(const T ¶m) { set(m_param, param); } private: - bool m_param; + T m_param; }; - class param_int_t final: public param_t - { - public: - param_int_t(device_t &device, const pstring &name, const int val); - const int &operator()() const NL_NOEXCEPT { return m_param; } - void setTo(const int ¶m) { set(m_param, param); } - private: - int m_param; - }; + /* FIXME: these should go as well */ + typedef param_num_t param_logic_t; + typedef param_num_t param_int_t; + typedef param_num_t param_double_t; - class param_double_t final: public param_t + // ----------------------------------------------------------------------------- + // pointer parameter + // ----------------------------------------------------------------------------- + + class param_ptr_t final: public param_t { public: - param_double_t(device_t &device, const pstring &name, const double val); - const double &operator()() const NL_NOEXCEPT { return m_param; } - void setTo(const double ¶m) { set(m_param, param); } + param_ptr_t(device_t &device, const pstring &name, std::uint8_t* val); + std::uint8_t * operator()() const NL_NOEXCEPT { return m_param; } + void setTo(std::uint8_t *param) { set(m_param, param); } private: - double m_param; + std::uint8_t* m_param; }; + // ----------------------------------------------------------------------------- + // string parameter + // ----------------------------------------------------------------------------- + class param_str_t : public param_t { public: @@ -981,6 +982,10 @@ namespace netlist pstring m_param; }; + // ----------------------------------------------------------------------------- + // model parameter + // ----------------------------------------------------------------------------- + class param_model_t : public param_str_t { public: @@ -1014,15 +1019,21 @@ namespace netlist detail::model_map_t m_map; }; + // ----------------------------------------------------------------------------- + // data parameter + // ----------------------------------------------------------------------------- class param_data_t : public param_str_t { public: - param_data_t(device_t &device, const pstring &name); + param_data_t(device_t &device, const pstring &name) + : param_str_t(device, name, "") + { + } std::unique_ptr stream(); protected: - virtual void changed() override; + virtual void changed() override { } }; // ----------------------------------------------------------------------------- @@ -1135,6 +1146,8 @@ namespace netlist virtual ~device_t() override; setup_t &setup(); + const setup_t &setup() const; + template void register_sub(const pstring &name, std::unique_ptr &dev, const Args&... args) @@ -1241,6 +1254,7 @@ namespace netlist /* netlist build functions */ setup_t &setup() NL_NOEXCEPT { return *m_setup; } + const setup_t &setup() const NL_NOEXCEPT { return *m_setup; } void register_dev(plib::owned_ptr dev); void remove_dev(core_device_t *dev); @@ -1366,6 +1380,27 @@ namespace netlist // inline implementations // ----------------------------------------------------------------------------- + template + param_num_t::param_num_t(device_t &device, const pstring &name, const T val) + : param_t(device, name) + { + //m_param = device.setup().get_initial_param_val(this->name(),val); + bool found = false; + pstring p = this->get_initial(device, &found); + if (found) + { + bool err = false; + T vald = plib::pstonum_ne(p, err); + if (err) + netlist().log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, p); + m_param = vald; + } + else + m_param = val; + + netlist().save(*this, m_param, "m_param"); + } + template param_rom_t::param_rom_t(device_t &device, const pstring &name) : param_data_t(device, name) diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index e876b2f7e8b..35702654708 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -145,7 +145,7 @@ pstring setup_t::termtype_as_str(detail::core_terminal_t &in) const return pstring("Error"); } -pstring setup_t::get_initial_param_val(const pstring &name, const pstring &def) +pstring setup_t::get_initial_param_val(const pstring &name, const pstring &def) const { auto i = m_param_values.find(name); if (i != m_param_values.end()) @@ -154,39 +154,6 @@ pstring setup_t::get_initial_param_val(const pstring &name, const pstring &def) return def; } -double setup_t::get_initial_param_val(const pstring &name, const double def) -{ - auto i = m_param_values.find(name); - if (i != m_param_values.end()) - { - bool err = false; - double vald = plib::pstonum_ne(i->second, err); - if (err) - log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); - return vald; - } - else - return def; -} - -int setup_t::get_initial_param_val(const pstring &name, const int def) -{ - auto i = m_param_values.find(name); - if (i != m_param_values.end()) - { - bool err; - double vald = plib::pstonum_ne(i->second, err); - if (err) - log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); - if (vald - std::floor(vald) != 0.0) - log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second); - - return static_cast(vald); - } - else - return def; -} - void setup_t::register_param(const pstring &name, param_t ¶m) { if (!m_params.insert({param.name(), param_ref_t(param.name(), param.device(), param)}).second) @@ -278,7 +245,10 @@ void setup_t::register_frontier(const pstring &attach, const double r_IN, const void setup_t::register_param(const pstring ¶m, const double value) { - register_param(param, plib::pfmt("{1:.9}").e(value)); + if (std::abs(value - std::floor(value)) > 1e-30 || std::abs(value) > 1e9) + register_param(param, plib::pfmt("{1:.9}").e(value)); + else + register_param(param, plib::pfmt("{1}")(static_cast(value))); } void setup_t::register_param(const pstring ¶m, const pstring &value) diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 3894cad5415..552c78e8b05 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -16,6 +16,7 @@ #include "nl_factory.h" #include "nl_config.h" #include "netlist_types.h" +#include "nl_errstr.h" #include #include @@ -212,9 +213,8 @@ namespace netlist pstring build_fqn(const pstring &obj_name) const; void register_param(const pstring &name, param_t ¶m); - pstring get_initial_param_val(const pstring &name, const pstring &def); - double get_initial_param_val(const pstring &name, const double def); - int get_initial_param_val(const pstring &name, const int def); + + pstring get_initial_param_val(const pstring &name, const pstring &def) const; void register_term(detail::core_terminal_t &obj); @@ -331,13 +331,12 @@ namespace netlist unsigned m_proxy_cnt; unsigned m_frontier_cnt; -}; + }; // ---------------------------------------------------------------------------------------- // base sources // ---------------------------------------------------------------------------------------- - class source_string_t : public source_t { public: @@ -400,6 +399,10 @@ namespace netlist pstring m_setup_func_name; }; + // ----------------------------------------------------------------------------- + // inline implementations + // ----------------------------------------------------------------------------- + } -- cgit v1.2.3-70-g09d2 From 28bc5506be542973518c4373d88bb204d45358d3 Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 14 Jan 2019 23:32:51 +0100 Subject: netlist: Code refactoring. (nw) Replaced downcast with static_cast to avoid errors. --- src/devices/machine/netlist.cpp | 13 +++--- src/lib/netlist/nl_base.cpp | 16 ++++---- src/lib/netlist/nl_base.h | 77 ++++++++++++++++++++++++----------- src/lib/netlist/nl_config.h | 2 + src/lib/netlist/nl_setup.cpp | 17 ++------ src/lib/netlist/nl_setup.h | 2 +- src/lib/netlist/prg/nltool.cpp | 4 +- src/lib/netlist/solver/nld_solver.cpp | 4 +- 8 files changed, 77 insertions(+), 58 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index ffd99d5437a..49ed1e3fe05 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -123,7 +123,7 @@ public: , m_cpu_device(nullptr) , m_last(*this, "m_last", 0) { - m_cpu_device = downcast(&downcast(netlist()).parent()); + m_cpu_device = downcast(&static_cast(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(&downcast(netlist()).parent()); + m_cpu_device = downcast(&static_cast(netlist()).parent()); } ATTR_COLD void reset() override @@ -238,7 +238,7 @@ public: std::unique_ptr netlist_source_memregion_t::stream(const pstring &name) { - memory_region *mem = downcast(setup().netlist()).machine().root_device().memregion(m_name.c_str()); + memory_region *mem = static_cast(setup().netlist()).machine().root_device().memregion(m_name.c_str()); return plib::make_unique_base(mem->base(), mem->bytes()); } @@ -249,8 +249,7 @@ netlist_data_memregions_t::netlist_data_memregions_t(netlist::setup_t &setup) std::unique_ptr netlist_data_memregions_t::stream(const pstring &name) { - memory_region *mem = downcast(setup().netlist()).parent().memregion(name.c_str()); - //memory_region *mem = downcast(setup().netlist()).machine().root_device().memregion(name.c_str()); + memory_region *mem = static_cast(setup().netlist()).parent().memregion(name.c_str()); if (mem != nullptr) { return plib::make_unique_base(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()) { diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 76e991f574f..d3de32d7d62 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -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::type>(total_count) / static_cast::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::type overhead_per_pop = (m_stat_mainloop()-2*total_overhead - (total_time - total_overhead)) - / static_cast::type>(queue().m_prof_call()); + / static_cast::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(&m_my_net, false)); + netlist().register_net(plib::owned_ptr(&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(&m_my_net, false)); + netlist().register_net(plib::owned_ptr(&m_my_net, false)); this->set_net(&m_my_net); //net().m_cur_Analog = NL_FCONST(0.0); diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index aab431d3b9a..9871da2a9d1 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -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>; + explicit netlist_t(const pstring &aname, std::unique_ptr 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 void save(O &owner, C &state, const pstring &stname) { - this->state().save_item(static_cast(&owner), state, from_utf8(owner.name()) + pstring(".") + stname); + this->state().save_item(static_cast(&owner), state, owner.name() + pstring(".") + stname); } template void save(O &owner, C *state, const pstring &stname, const std::size_t count) { - this->state().save_state_ptr(static_cast(&owner), from_utf8(owner.name()) + pstring(".") + stname, plib::state_manager_t::datatype_f::f(), count, state); + this->state().save_state_ptr(static_cast(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f::f(), count, state); } plib::dynlib &lib() { return *m_lib; } - // FIXME: find something better - /* sole use is to manage lifetime of net objects */ - std::vector> m_nets; + const nets_collection_type &nets() { return m_nets; } + + template + void register_net(plib::owned_ptr &&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 &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>> 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 m_stat_mainloop; nperfcount_t m_perf_out_processed; + /* sole use is to manage lifetime of net objects */ std::vector> m_devices; + nets_collection_type m_nets; std::unique_ptr m_callbacks; log_type m_log; diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index 20ddf5c71a3..b72e0ee9944 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -59,6 +59,8 @@ #define NL_DEBUG (false) #define NL_KEEP_STATISTICS (0) +//#define NL_DEBUG (true) +//#define NL_KEEP_STATISTICS (1) //============================================================ // General Macros diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 35702654708..8d0ffc66bc9 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -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(netlist(),"net." + t1.name()); - netlist().m_nets.push_back(plib::owned_ptr(anet, true)); + netlist().register_net(plib::owned_ptr(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 &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", ""); diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 552c78e8b05..25342e933f6 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -245,7 +245,7 @@ namespace netlist param_t *find_param(const pstring ¶m_in, bool required = true) const; - void start_devices(); + void register_dynamic_log_devices(); void resolve_inputs(); /* handle namespace */ diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 0a5fba22d9e..42de2fbd901 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -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> devs; diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index f9de00d417d..7373b2be963 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -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; -- cgit v1.2.3-70-g09d2 From c89439dd2365e1c1936ea1cd9fb934fb2f1c1576 Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 15 Jan 2019 23:42:16 +0100 Subject: netlist: refactored netlist creation. (nw) This is an effort to separate netlist creation from netlist execution. The primary target is to avoid that code which will only run during execution is able to call setup code and thus create ugly hacks. --- src/devices/machine/netlist.cpp | 10 +- src/lib/netlist/analog/nld_bjt.cpp | 22 ++-- src/lib/netlist/analog/nld_switches.cpp | 9 +- src/lib/netlist/analog/nlid_twoterm.cpp | 34 +++--- src/lib/netlist/analog/nlid_twoterm.h | 2 +- src/lib/netlist/devices/nld_4066.cpp | 10 +- src/lib/netlist/devices/nld_4316.cpp | 9 +- src/lib/netlist/devices/nld_log.cpp | 4 +- src/lib/netlist/devices/nlid_proxy.cpp | 10 +- src/lib/netlist/devices/nlid_proxy.h | 10 +- src/lib/netlist/devices/nlid_system.h | 2 +- src/lib/netlist/devices/nlid_truthtable.cpp | 2 +- src/lib/netlist/nl_base.cpp | 109 +++++++++++------- src/lib/netlist/nl_base.h | 163 ++++++++++++++++----------- src/lib/netlist/nl_config.h | 3 +- src/lib/netlist/nl_factory.cpp | 6 +- src/lib/netlist/nl_factory.h | 12 +- src/lib/netlist/nl_parser.h | 2 +- src/lib/netlist/nl_setup.cpp | 10 +- src/lib/netlist/nl_setup.h | 10 +- src/lib/netlist/solver/nld_matrix_solver.cpp | 6 +- src/lib/netlist/solver/nld_matrix_solver.h | 2 +- src/lib/netlist/solver/nld_ms_direct.h | 8 +- src/lib/netlist/solver/nld_ms_direct1.h | 2 +- src/lib/netlist/solver/nld_ms_direct2.h | 2 +- src/lib/netlist/solver/nld_ms_gcr.h | 2 +- src/lib/netlist/solver/nld_ms_gmres.h | 2 +- src/lib/netlist/solver/nld_ms_sm.h | 4 +- src/lib/netlist/solver/nld_ms_sor.h | 2 +- src/lib/netlist/solver/nld_ms_sor_mat.h | 2 +- src/lib/netlist/solver/nld_ms_w.h | 4 +- src/lib/netlist/solver/nld_solver.cpp | 6 +- src/lib/netlist/solver/nld_solver.h | 2 +- 33 files changed, 271 insertions(+), 212 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 49ed1e3fe05..75aa472e7e5 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -117,7 +117,7 @@ namespace { class NETLIB_NAME(analog_callback) : public netlist::device_t { public: - NETLIB_NAME(analog_callback)(netlist::netlist_t &anetlist, const pstring &name) + NETLIB_NAME(analog_callback)(netlist::netlist_base_t &anetlist, const pstring &name) : device_t(anetlist, name) , m_in(*this, "IN") , m_cpu_device(nullptr) @@ -165,7 +165,7 @@ private: class NETLIB_NAME(logic_callback) : public netlist::device_t { public: - NETLIB_NAME(logic_callback)(netlist::netlist_t &anetlist, const pstring &name) + NETLIB_NAME(logic_callback)(netlist::netlist_base_t &anetlist, const pstring &name) : device_t(anetlist, name) , m_in(*this, "IN") , m_cpu_device(nullptr) @@ -273,7 +273,7 @@ std::unique_ptr netlist_data_memregions_t::stream(const pstring class NETLIB_NAME(sound_out) : public netlist::device_t { public: - NETLIB_NAME(sound_out)(netlist::netlist_t &anetlist, const pstring &name) + NETLIB_NAME(sound_out)(netlist::netlist_base_t &anetlist, const pstring &name) : netlist::device_t(anetlist, name) , m_channel(*this, "CHAN", 0) , m_mult(*this, "MULT", 1000.0) @@ -311,7 +311,7 @@ public: NETLIB_UPDATEI() { nl_double val = m_in() * m_mult() + m_offset(); - sound_update(netlist().time()); + sound_update(exec().time()); /* ignore spikes */ if (std::abs(val) < 32767.0) m_cur = val; @@ -355,7 +355,7 @@ public: static const int MAX_INPUT_CHANNELS = 16; - NETLIB_NAME(sound_in)(netlist::netlist_t &anetlist, const pstring &name) + NETLIB_NAME(sound_in)(netlist::netlist_base_t &anetlist, const pstring &name) : netlist::device_t(anetlist, name) , m_inc(netlist::netlist_time::from_nsec(1)) , m_feedback(*this, "FB") // clock part diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index 83182847082..cf963465b09 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -185,8 +185,8 @@ NETLIB_OBJECT_DERIVED(QBJT_switch, QBJT) , m_RB(*this, "m_RB", true) , m_RC(*this, "m_RC", true) , m_BC_dummy(*this, "m_BC", true) - , m_gB(NETLIST_GMIN_DEFAULT) - , m_gC(NETLIST_GMIN_DEFAULT) + , m_gB(1e-9) + , m_gC(1e-9) , m_V(0.0) , m_state_on(*this, "m_state_on", 0) { @@ -299,10 +299,10 @@ NETLIB_RESET(QBJT_switch) m_state_on = 0; - m_RB.set(netlist().gmin(), 0.0, 0.0); - m_RC.set(netlist().gmin(), 0.0, 0.0); + m_RB.set(exec().gmin(), 0.0, 0.0); + m_RC.set(exec().gmin(), 0.0, 0.0); - m_BC_dummy.set(netlist().gmin() / 10.0, 0.0, 0.0); + m_BC_dummy.set(exec().gmin() / 10.0, 0.0, 0.0); } @@ -341,8 +341,8 @@ NETLIB_UPDATE_PARAM(QBJT_switch) //m_gB = d.gI(0.005 / alpha); - if (m_gB < netlist().gmin()) - m_gB = netlist().gmin(); + if (m_gB < exec().gmin()) + m_gB = exec().gmin(); m_gC = d.gI(0.005); // very rough estimate } @@ -353,8 +353,8 @@ NETLIB_UPDATE_TERMINALS(QBJT_switch) const unsigned new_state = (m_RB.deltaV() * m > m_V ) ? 1 : 0; if (m_state_on ^ new_state) { - const nl_double gb = new_state ? m_gB : netlist().gmin(); - const nl_double gc = new_state ? m_gC : netlist().gmin(); + const nl_double gb = new_state ? m_gB : exec().gmin(); + const nl_double gc = new_state ? m_gC : exec().gmin(); const nl_double v = new_state ? m_V * m : 0; m_RB.set(gb, v, 0.0); @@ -423,8 +423,8 @@ NETLIB_UPDATE_PARAM(QBJT_EB) m_alpha_f = BF / (1.0 + BF); m_alpha_r = BR / (1.0 + BR); - m_gD_BE.set_param(IS / m_alpha_f, NF, netlist().gmin()); - m_gD_BC.set_param(IS / m_alpha_r, NR, netlist().gmin()); + m_gD_BE.set_param(IS / m_alpha_f, NF, exec().gmin()); + m_gD_BC.set_param(IS / m_alpha_r, NR, exec().gmin()); } } //namespace analog diff --git a/src/lib/netlist/analog/nld_switches.cpp b/src/lib/netlist/analog/nld_switches.cpp index 1575551f260..042b61ce7e7 100644 --- a/src/lib/netlist/analog/nld_switches.cpp +++ b/src/lib/netlist/analog/nld_switches.cpp @@ -6,10 +6,13 @@ */ #include "nlid_twoterm.h" -#include "../nl_base.h" -#include "../nl_factory.h" +#include "netlist/nl_base.h" +#include "netlist/nl_factory.h" +#include "netlist/solver/nld_solver.h" -#define R_OFF (1.0 / netlist().gmin()) +/* FIXME : convert to parameters */ + +#define R_OFF (1.0 / exec().gmin()) #define R_ON 0.01 namespace netlist diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index f54c2b3e68f..0f6fc3688c2 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -100,7 +100,7 @@ NETLIB_UPDATE(twoterm) NETLIB_RESET(R_base) { NETLIB_NAME(twoterm)::reset(); - set_R(1.0 / netlist().gmin()); + set_R(1.0 / exec().gmin()); } NETLIB_UPDATE(R_base) @@ -115,13 +115,13 @@ NETLIB_UPDATE(R_base) NETLIB_UPDATE_PARAM(R) { update_dev(); - set_R(std::max(m_R(), netlist().gmin())); + set_R(std::max(m_R(), exec().gmin())); } NETLIB_RESET(R) { NETLIB_NAME(twoterm)::reset(); - set_R(std::max(m_R(), netlist().gmin())); + set_R(std::max(m_R(), exec().gmin())); } // ---------------------------------------------------------------------------------------- @@ -134,8 +134,8 @@ NETLIB_RESET(POT) if (m_DialIsLog()) v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0); - m_R1.set_R(std::max(m_R() * v, netlist().gmin())); - m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), netlist().gmin())); + m_R1.set_R(std::max(m_R() * v, exec().gmin())); + m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), exec().gmin())); } NETLIB_UPDATE_PARAM(POT) @@ -147,8 +147,8 @@ NETLIB_UPDATE_PARAM(POT) if (m_DialIsLog()) v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0); - m_R1.set_R(std::max(m_R() * v, netlist().gmin())); - m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), netlist().gmin())); + m_R1.set_R(std::max(m_R() * v, exec().gmin())); + m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), exec().gmin())); } @@ -164,7 +164,7 @@ NETLIB_RESET(POT2) v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0); if (m_Reverse()) v = 1.0 - v; - m_R1.set_R(std::max(m_R() * v, netlist().gmin())); + m_R1.set_R(std::max(m_R() * v, exec().gmin())); } @@ -178,7 +178,7 @@ NETLIB_UPDATE_PARAM(POT2) v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0); if (m_Reverse()) v = 1.0 - v; - m_R1.set_R(std::max(m_R() * v, netlist().gmin())); + m_R1.set_R(std::max(m_R() * v, exec().gmin())); } // ---------------------------------------------------------------------------------------- @@ -188,13 +188,13 @@ NETLIB_UPDATE_PARAM(POT2) NETLIB_RESET(C) { // FIXME: Startup conditions - set(netlist().gmin(), 0.0, -5.0 / netlist().gmin()); - //set(netlist().gmin(), 0.0, 0.0); + set(exec().gmin(), 0.0, -5.0 / exec().gmin()); + //set(exec().gmin(), 0.0, 0.0); } NETLIB_UPDATE_PARAM(C) { - m_GParallel = netlist().gmin(); + m_GParallel = exec().gmin(); } NETLIB_UPDATE(C) @@ -218,7 +218,7 @@ NETLIB_TIMESTEP(C) NETLIB_RESET(L) { - m_GParallel = netlist().gmin(); + m_GParallel = exec().gmin(); m_I = 0.0; m_G = m_GParallel; set_mat( m_G, -m_G, -m_I, @@ -254,7 +254,7 @@ NETLIB_RESET(D) nl_double Is = m_model.m_IS; nl_double n = m_model.m_N; - m_D.set_param(Is, n, netlist().gmin()); + m_D.set_param(Is, n, exec().gmin()); set(m_D.G(), 0.0, m_D.Ieq()); } @@ -263,7 +263,7 @@ NETLIB_UPDATE_PARAM(D) nl_double Is = m_model.m_IS; nl_double n = m_model.m_N; - m_D.set_param(Is, n, netlist().gmin()); + m_D.set_param(Is, n, exec().gmin()); } NETLIB_UPDATE(D) @@ -299,7 +299,7 @@ NETLIB_UPDATE(VS) NETLIB_TIMESTEP(VS) { this->set(1.0 / m_R(), - m_compiled.evaluate(std::vector({netlist().time().as_double()})), + m_compiled.evaluate(std::vector({exec().time().as_double()})), 0.0); } @@ -324,7 +324,7 @@ NETLIB_UPDATE(CS) NETLIB_TIMESTEP(CS) { - const double I = m_compiled.evaluate(std::vector({netlist().time().as_double()})); + const double I = m_compiled.evaluate(std::vector({exec().time().as_double()})); set_mat(0.0, 0.0, -I, 0.0, 0.0, I); } diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 4ab5fcda89b..efb9a8dd929 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -55,7 +55,7 @@ namespace netlist return b ? *h : d2; } template<> - inline core_device_t &bselect(bool b, netlist_t &d1, core_device_t &d2) + inline core_device_t &bselect(bool b, netlist_base_t &d1, core_device_t &d2) { if (b) throw nl_exception("bselect with netlist and b==true"); diff --git a/src/lib/netlist/devices/nld_4066.cpp b/src/lib/netlist/devices/nld_4066.cpp index b5f3b2f6bf2..2871e4898ae 100644 --- a/src/lib/netlist/devices/nld_4066.cpp +++ b/src/lib/netlist/devices/nld_4066.cpp @@ -5,10 +5,12 @@ * */ -#include "nlid_cmos.h" -#include "../analog/nlid_twoterm.h" #include "nld_4066.h" +#include "nlid_cmos.h" +#include "netlist/analog/nlid_twoterm.h" +#include "netlist/solver/nld_solver.h" + namespace netlist { namespace devices @@ -39,7 +41,7 @@ namespace netlist { // Start in off condition // FIXME: is ROFF correct? - m_R.set_R(NL_FCONST(1.0) / netlist().gmin()); + m_R.set_R(NL_FCONST(1.0) / exec().gmin()); } @@ -54,7 +56,7 @@ namespace netlist if (in < low) { - R = NL_FCONST(1.0) / netlist().gmin(); + R = NL_FCONST(1.0) / exec().gmin(); } else if (in > high) { diff --git a/src/lib/netlist/devices/nld_4316.cpp b/src/lib/netlist/devices/nld_4316.cpp index 0bce54cc6c3..4290c65670c 100644 --- a/src/lib/netlist/devices/nld_4316.cpp +++ b/src/lib/netlist/devices/nld_4316.cpp @@ -5,9 +5,10 @@ * */ -#include "nlid_cmos.h" -#include "../analog/nlid_twoterm.h" #include "nld_4316.h" +#include "nlid_cmos.h" +#include "netlist/analog/nlid_twoterm.h" +#include "netlist/solver/nld_solver.h" namespace netlist { namespace devices { @@ -37,7 +38,7 @@ namespace netlist { namespace devices { NETLIB_RESET(CD4316_GATE) { - m_R.set_R(NL_FCONST(1.0) / netlist().gmin()); + m_R.set_R(NL_FCONST(1.0) / exec().gmin()); } NETLIB_UPDATE(CD4316_GATE) @@ -46,7 +47,7 @@ namespace netlist { namespace devices { if (m_S() && !m_E()) m_R.set_R(m_base_r()); else - m_R.set_R(NL_FCONST(1.0) / netlist().gmin()); + m_R.set_R(NL_FCONST(1.0) / exec().gmin()); m_R.m_P.schedule_solve_after(NLTIME_FROM_NS(1)); } diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp index 1d3ea7b1b75..03f7cae779c 100644 --- a/src/lib/netlist/devices/nld_log.cpp +++ b/src/lib/netlist/devices/nld_log.cpp @@ -27,7 +27,7 @@ namespace netlist NETLIB_UPDATEI() { /* use pstring::sprintf, it is a LOT faster */ - m_writer.writeline(plib::pfmt("{1:.9} {2}").e(netlist().time().as_double()).e(static_cast(m_I()))); + m_writer.writeline(plib::pfmt("{1:.9} {2}").e(exec().time().as_double()).e(static_cast(m_I()))); } NETLIB_RESETI() { } @@ -46,7 +46,7 @@ namespace netlist NETLIB_UPDATEI() { - m_writer.writeline(plib::pfmt("{1:.9} {2}").e(netlist().time().as_double()).e(static_cast(m_I() - m_I2()))); + m_writer.writeline(plib::pfmt("{1:.9} {2}").e(exec().time().as_double()).e(static_cast(m_I() - m_I2()))); } NETLIB_RESETI() { } diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index 4c3ec6f67aa..c5ad63f3910 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -20,7 +20,7 @@ namespace netlist // nld_base_proxy // ----------------------------------------------------------------------------- - nld_base_proxy::nld_base_proxy(netlist_t &anetlist, const pstring &name, + nld_base_proxy::nld_base_proxy(netlist_base_t &anetlist, const pstring &name, logic_t *inout_proxied, detail::core_terminal_t *proxy_inout) : device_t(anetlist, name) { @@ -37,7 +37,7 @@ namespace netlist // nld_a_to_d_proxy // ---------------------------------------------------------------------------------------- - nld_base_a_to_d_proxy::nld_base_a_to_d_proxy(netlist_t &anetlist, const pstring &name, + nld_base_a_to_d_proxy::nld_base_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied, detail::core_terminal_t *in_proxy) : nld_base_proxy(anetlist, name, in_proxied, in_proxy) , m_Q(*this, "Q") @@ -46,7 +46,7 @@ namespace netlist nld_base_a_to_d_proxy::~nld_base_a_to_d_proxy() {} - nld_a_to_d_proxy::nld_a_to_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *in_proxied) + nld_a_to_d_proxy::nld_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied) : nld_base_a_to_d_proxy(anetlist, name, in_proxied, &m_I) , m_I(*this, "I") { @@ -81,7 +81,7 @@ namespace netlist // nld_d_to_a_proxy // ---------------------------------------------------------------------------------------- - nld_base_d_to_a_proxy::nld_base_d_to_a_proxy(netlist_t &anetlist, const pstring &name, + nld_base_d_to_a_proxy::nld_base_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied, detail::core_terminal_t &proxy_out) : nld_base_proxy(anetlist, name, out_proxied, &proxy_out) , m_I(*this, "I") @@ -92,7 +92,7 @@ namespace netlist { } - nld_d_to_a_proxy::nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied) + nld_d_to_a_proxy::nld_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied) : nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P) , m_GNDHack(*this, "_Q") , m_RV(*this, "RV") diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index 821cfa56d9d..eb1f2b3fe87 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -26,7 +26,7 @@ namespace netlist NETLIB_OBJECT(base_proxy) { public: - nld_base_proxy(netlist_t &anetlist, const pstring &name, + nld_base_proxy(netlist_base_t &anetlist, const pstring &name, logic_t *inout_proxied, detail::core_terminal_t *proxy_inout); virtual ~nld_base_proxy(); @@ -55,7 +55,7 @@ namespace netlist protected: - nld_base_a_to_d_proxy(netlist_t &anetlist, const pstring &name, + nld_base_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied, detail::core_terminal_t *in_proxy); private: @@ -67,7 +67,7 @@ namespace netlist NETLIB_OBJECT_DERIVED(a_to_d_proxy, base_a_to_d_proxy) { public: - nld_a_to_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *in_proxied); + nld_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied); virtual ~nld_a_to_d_proxy() override; @@ -93,7 +93,7 @@ namespace netlist virtual logic_input_t &in() { return m_I; } protected: - nld_base_d_to_a_proxy(netlist_t &anetlist, const pstring &name, + nld_base_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied, detail::core_terminal_t &proxy_out); logic_input_t m_I; @@ -104,7 +104,7 @@ namespace netlist NETLIB_OBJECT_DERIVED(d_to_a_proxy, base_d_to_a_proxy) { public: - nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied); + nld_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied); virtual ~nld_d_to_a_proxy() override {} protected: diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index d1a8a04bb41..6acda365c8f 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -65,7 +65,7 @@ namespace netlist logic_net_t &net = m_Q.net(); // this is only called during setup ... net.toggle_new_Q(); - net.set_time(netlist().time() + m_inc); + net.set_time(exec().time() + m_inc); } public: diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index 0b53652df6c..4cebc8c1b4c 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -233,7 +233,7 @@ namespace netlist : netlist_base_factory_truthtable_t(name, classname, def_param, sourcefile) { } - plib::owned_ptr Create(netlist_t &anetlist, const pstring &name) override + plib::owned_ptr Create(netlist_base_t &anetlist, const pstring &name) override { typedef nld_truthtable_t tt_type; truthtable_parser desc_s(m_NO, m_NI, &m_ttbl.m_initialized, diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index d3de32d7d62..9c19d10f0c9 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -90,15 +90,15 @@ public: m_R_low = 1.0; m_R_high = 130.0; } - virtual plib::owned_ptr create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const override; - virtual plib::owned_ptr create_a_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *proxied) const override; + virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; + virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; }; -plib::owned_ptr logic_family_ttl_t::create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const +plib::owned_ptr logic_family_ttl_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const { return plib::owned_ptr::Create(anetlist, name, proxied); } -plib::owned_ptr logic_family_ttl_t::create_a_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *proxied) const +plib::owned_ptr logic_family_ttl_t::create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const { return plib::owned_ptr::Create(anetlist, name, proxied); } @@ -117,15 +117,15 @@ public: m_R_low = 10.0; m_R_high = 10.0; } - virtual plib::owned_ptr create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const override; - virtual plib::owned_ptr create_a_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *proxied) const override; + virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; + virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; }; -plib::owned_ptr logic_family_cd4xxx_t::create_d_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *proxied) const +plib::owned_ptr logic_family_cd4xxx_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const { return plib::owned_ptr::Create(anetlist, name, proxied); } -plib::owned_ptr logic_family_cd4xxx_t::create_a_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *proxied) const +plib::owned_ptr logic_family_cd4xxx_t::create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const { return plib::owned_ptr::Create(anetlist, name, proxied); } @@ -168,7 +168,7 @@ void detail::queue_t::on_pre_save() { netlist().log().debug("on_pre_save\n"); m_qsize = this->size(); - netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize); + netlist().log().debug("current time {1} qsize {2}\n", exec().time().as_double(), m_qsize); for (std::size_t i = 0; i < m_qsize; i++ ) { m_times[i] = this->listptr()[i].m_exec_time.as_raw(); @@ -180,7 +180,7 @@ void detail::queue_t::on_pre_save() void detail::queue_t::on_post_load() { this->clear(); - netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize); + netlist().log().debug("current time {1} qsize {2}\n", exec().time().as_double(), m_qsize); for (std::size_t i = 0; i < m_qsize; i++ ) { detail::net_t *n = netlist().nets()[m_net_ids[i]].get(); @@ -240,35 +240,43 @@ detail::terminal_type detail::core_terminal_t::type() const // ---------------------------------------------------------------------------------------- netlist_t::netlist_t(const pstring &aname, std::unique_ptr callbacks) - : m_time(netlist_time::zero()) - , m_queue(*this) + : netlist_base_t(aname, std::move(callbacks)) + , m_time(netlist_time::zero()) , m_mainclock(nullptr) + , m_queue(*this) , m_solver(nullptr) - , m_params(nullptr) +{ + state().save_item(this, static_cast(m_queue), "m_queue"); + state().save_item(this, m_time, "m_time"); +} + +netlist_t::~netlist_t() +{ +} + +// ---------------------------------------------------------------------------------------- +// netlist_t +// ---------------------------------------------------------------------------------------- + +netlist_base_t::netlist_base_t(const pstring &aname, std::unique_ptr callbacks) + :m_params(nullptr) , m_name(aname) , m_lib(nullptr) , m_state() , m_callbacks(std::move(callbacks)) // Order is important here , m_log(*m_callbacks) { - state().save_item(this, static_cast(m_queue), "m_queue"); - state().save_item(this, m_time, "m_time"); m_setup = plib::make_unique(*this); NETLIST_NAME(base)(*m_setup); } -netlist_t::~netlist_t() +netlist_base_t::~netlist_base_t() { m_nets.clear(); m_devices.clear(); } -nl_double netlist_t::gmin() const NL_NOEXCEPT -{ - return solver()->gmin(); -} - -void netlist_t::register_dev(plib::owned_ptr dev) +void netlist_base_t::register_dev(plib::owned_ptr dev) { for (auto & d : m_devices) if (d->name() == dev->name()) @@ -276,7 +284,7 @@ void netlist_t::register_dev(plib::owned_ptr dev) m_devices.push_back(std::move(dev)); } -void netlist_t::remove_dev(core_device_t *dev) +void netlist_base_t::remove_dev(core_device_t *dev) { m_devices.erase( std::remove_if( @@ -290,7 +298,23 @@ void netlist_t::remove_dev(core_device_t *dev) ); } -void netlist_t::prepare_to_run() +void netlist_base_t::delete_empty_nets() +{ + m_nets.erase( + std::remove_if(m_nets.begin(), m_nets.end(), + [](plib::owned_ptr &x) + { + if (x->num_cons() == 0) + { + x->netlist().log().verbose("Deleting net {1} ...", x->name()); + return true; + } + else + return false; + }), m_nets.end()); +} + +void netlist_base_t::prepare_to_run() { setup().register_dynamic_log_devices(); @@ -310,7 +334,7 @@ void netlist_t::prepare_to_run() log().debug("Searching for solver and parameters ...\n"); - m_solver = get_single_device("solver"); + auto solver = get_single_device("solver"); m_params = get_single_device("parameter"); /* create devices */ @@ -326,9 +350,6 @@ void netlist_t::prepare_to_run() } } - log().debug("Searching for mainclock\n"); - m_mainclock = get_single_device("mainclock"); - bool use_deactivate = (m_params->m_use_deactivate() ? true : false); for (auto &d : m_devices) @@ -370,14 +391,14 @@ void netlist_t::prepare_to_run() log().verbose("initialize solver ...\n"); - if (m_solver == nullptr) + if (solver == nullptr) { for (auto &p : m_nets) if (p->is_analog()) log().fatal(MF_0_NO_SOLVER); } else - m_solver->post_start(); + solver->post_start(); for (auto &n : m_nets) for (auto & term : n->m_core_terms) @@ -398,7 +419,7 @@ void netlist_t::stop() m_solver->stop(); } -detail::net_t *netlist_t::find_net(const pstring &name) const +detail::net_t *netlist_base_t::find_net(const pstring &name) const { for (auto & net : m_nets) if (net->name() == name) @@ -407,7 +428,7 @@ detail::net_t *netlist_t::find_net(const pstring &name) const return nullptr; } -std::size_t netlist_t::find_net_id(const detail::net_t *net) const +std::size_t netlist_base_t::find_net_id(const detail::net_t *net) const { for (std::size_t i = 0; i < m_nets.size(); i++) if (m_nets[i].get() == net) @@ -417,7 +438,7 @@ std::size_t netlist_t::find_net_id(const detail::net_t *net) const -void netlist_t::rebuild_lists() +void netlist_base_t::rebuild_lists() { for (auto & net : m_nets) net->rebuild_list(); @@ -426,6 +447,12 @@ void netlist_t::rebuild_lists() void netlist_t::reset() { + log().debug("Searching for mainclock\n"); + m_mainclock = get_single_device("mainclock"); + + log().debug("Searching for solver\n"); + m_solver = get_single_device("solver"); + m_time = netlist_time::zero(); m_queue.clear(); if (m_mainclock != nullptr) @@ -638,7 +665,7 @@ void netlist_t::print_stats() const } } -core_device_t *netlist_t::get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const +core_device_t *netlist_base_t::get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const { core_device_t *ret = nullptr; for (auto &d : m_devices) @@ -659,7 +686,7 @@ core_device_t *netlist_t::get_single_device(const pstring &classname, bool (*cc) // core_device_t // ---------------------------------------------------------------------------------------- -core_device_t::core_device_t(netlist_t &owner, const pstring &name) +core_device_t::core_device_t(netlist_base_t &owner, const pstring &name) : object_t(name) , logic_family_t() , netlist_ref(owner) @@ -700,7 +727,7 @@ log_type & core_device_t::log() // device_t // ---------------------------------------------------------------------------------------- -device_t::device_t(netlist_t &owner, const pstring &name) +device_t::device_t(netlist_base_t &owner, const pstring &name) : core_device_t(owner, name) { } @@ -780,7 +807,7 @@ detail::family_setter_t::family_setter_t(core_device_t &dev, const logic_family_ // net_t // ---------------------------------------------------------------------------------------- -detail::net_t::net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr) +detail::net_t::net_t(netlist_base_t &nl, const pstring &aname, core_terminal_t *mr) : object_t(aname) , netlist_ref(nl) , m_new_Q(*this, "m_new_Q", 0) @@ -805,10 +832,10 @@ void detail::net_t::add_to_active_list(core_terminal_t &term) NL_NOEXCEPT railterminal().device().do_inc_active(); if (m_in_queue == QS_DELAYED_DUE_TO_INACTIVE) { - if (m_time > netlist().time()) + if (m_time > exec().time()) { m_in_queue = QS_QUEUED; /* pending */ - netlist().queue().push({m_time, this}); + exec().queue().push({m_time, this}); } else { @@ -934,7 +961,7 @@ void detail::net_t::move_connections(detail::net_t &dest_net) // logic_net_t // ---------------------------------------------------------------------------------------- -logic_net_t::logic_net_t(netlist_t &nl, const pstring &aname, detail::core_terminal_t *mr) +logic_net_t::logic_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr) : net_t(nl, aname, mr) { } @@ -947,7 +974,7 @@ logic_net_t::~logic_net_t() // analog_net_t // ---------------------------------------------------------------------------------------- -analog_net_t::analog_net_t(netlist_t &nl, const pstring &aname, detail::core_terminal_t *mr) +analog_net_t::analog_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr) : net_t(nl, aname, mr) , m_cur_Analog(*this, "m_cur_Analog", 0.0) , m_solver(nullptr) diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 9871da2a9d1..3d8ef2401d5 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -211,6 +211,7 @@ namespace netlist class net_t; class setup_t; class netlist_t; + class netlist_base_t; class core_device_t; class device_t; class callbacks_t; @@ -246,9 +247,9 @@ namespace netlist logic_family_desc_t(); virtual ~logic_family_desc_t(); - virtual plib::owned_ptr create_d_a_proxy(netlist_t &anetlist, const pstring &name, + virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const = 0; - virtual plib::owned_ptr create_a_d_proxy(netlist_t &anetlist, const pstring &name, + virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const = 0; double fixed_V() const { return m_fixed_V; } @@ -424,16 +425,19 @@ namespace netlist struct detail::netlist_ref { - explicit constexpr netlist_ref(netlist_t &nl) : m_netlist(nl) { } + explicit constexpr netlist_ref(netlist_base_t &nl) : m_netlist(nl) { } - C14CONSTEXPR netlist_t & netlist() NL_NOEXCEPT { return m_netlist; } - constexpr const netlist_t & netlist() const NL_NOEXCEPT { return m_netlist; } + C14CONSTEXPR netlist_base_t & netlist() NL_NOEXCEPT { return m_netlist; } + constexpr const netlist_base_t & netlist() const NL_NOEXCEPT { return m_netlist; } + + netlist_t & exec() NL_NOEXCEPT { return *reinterpret_cast(&m_netlist); } + const netlist_t & exec() const NL_NOEXCEPT { return *reinterpret_cast(&m_netlist); } protected: ~netlist_ref() = default; // prohibit polymorphic destruction private: - netlist_t & m_netlist; + netlist_base_t & m_netlist; }; @@ -465,8 +469,11 @@ namespace netlist /*! The netlist owning the owner of this object. * \returns reference to netlist object. */ - netlist_t &netlist() NL_NOEXCEPT; - const netlist_t &netlist() const NL_NOEXCEPT; + netlist_base_t &netlist() NL_NOEXCEPT; + const netlist_base_t &netlist() const NL_NOEXCEPT; + + netlist_t &exec() NL_NOEXCEPT; + const netlist_t &exec() const NL_NOEXCEPT; private: core_device_t & m_device; @@ -709,7 +716,7 @@ namespace netlist QS_DELIVERED }; - net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr = nullptr); + net_t(netlist_base_t &nl, const pstring &aname, core_terminal_t *mr = nullptr); virtual ~net_t(); void reset(); @@ -769,7 +776,7 @@ namespace netlist { public: - logic_net_t(netlist_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); + logic_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); virtual ~logic_net_t(); const netlist_sig_t & Q() const NL_NOEXCEPT { return m_cur_Q; } @@ -820,7 +827,7 @@ namespace netlist friend class detail::net_t; - analog_net_t(netlist_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); + analog_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); virtual ~analog_net_t(); @@ -1069,7 +1076,7 @@ namespace netlist public detail::netlist_ref { public: - core_device_t(netlist_t &owner, const pstring &name); + core_device_t(netlist_base_t &owner, const pstring &name); core_device_t(core_device_t &owner, const pstring &name); virtual ~core_device_t(); @@ -1141,7 +1148,7 @@ namespace netlist { public: - device_t(netlist_t &owner, const pstring &name); + device_t(netlist_base_t &owner, const pstring &name); device_t(core_device_t &owner, const pstring &name); virtual ~device_t() override; @@ -1224,31 +1231,14 @@ namespace netlist // netlist_t // ----------------------------------------------------------------------------- - - class netlist_t : private plib::nocopyassignmove + class netlist_base_t : private plib::nocopyassignmove { public: using nets_collection_type = std::vector>; - explicit netlist_t(const pstring &aname, std::unique_ptr callbacks); - ~netlist_t(); - - /* run functions */ - - const netlist_time &time() const NL_NOEXCEPT { return m_time; } - devices::NETLIB_NAME(solver) *solver() const NL_NOEXCEPT { return m_solver; } - - /* never use this in constructors! */ - nl_double gmin() const NL_NOEXCEPT; - - 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 */ + explicit netlist_base_t(const pstring &aname, std::unique_ptr callbacks); + ~netlist_base_t(); /* Control functions */ @@ -1330,41 +1320,23 @@ namespace netlist 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 &x) - { - if (x->num_cons() == 0) - { - x->netlist().log().verbose("Deleting net {1} ...", x->name()); - return true; - } - else - return false; - }), m_nets.end()); - } + void delete_empty_nets(); /* sole use is to manage lifetime of family objects */ std::vector>> m_family_cache; protected: - void print_stats() const; + /* sole use is to manage lifetime of net objects */ + std::vector> m_devices; + nets_collection_type m_nets; private: core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const; - /* mostly rw */ - netlist_time m_time; - detail::queue_t m_queue; - /* mostly ro */ - devices::NETLIB_NAME(mainclock) * m_mainclock; - devices::NETLIB_NAME(solver) * m_solver; devices::NETLIB_NAME(netlistparams) *m_params; pstring m_name; @@ -1372,17 +1344,62 @@ namespace netlist plib::state_manager_t m_state; - // performance - nperftime_t m_stat_mainloop; - nperfcount_t m_perf_out_processed; - /* sole use is to manage lifetime of net objects */ - std::vector> m_devices; - nets_collection_type m_nets; - - std::unique_ptr m_callbacks; + std::unique_ptr m_callbacks; log_type m_log; std::unique_ptr m_setup; + }; + + + class netlist_t : public netlist_base_t + { + public: + + using nets_collection_type = std::vector>; + + explicit netlist_t(const pstring &aname, std::unique_ptr callbacks); + ~netlist_t(); + + /* run functions */ + + const netlist_time &time() const NL_NOEXCEPT { return m_time; } + + 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; } + + /* Control functions */ + + void stop(); + void reset(); + + /* only used by nltool to create static c-code */ + devices::NETLIB_NAME(solver) *solver() const NL_NOEXCEPT { return m_solver; } + + /* force late type resolution */ + template + nl_double gmin(X *solv = nullptr) const NL_NOEXCEPT + { + return static_cast(m_solver)->gmin(); + } + + protected: + + void print_stats() const; + + private: + /* mostly rw */ + netlist_time m_time; + devices::NETLIB_NAME(mainclock) * m_mainclock; + detail::queue_t m_queue; + + devices::NETLIB_NAME(solver) * m_solver; + + // performance + nperftime_t m_stat_mainloop; + nperfcount_t m_perf_out_processed; }; // ----------------------------------------------------------------------------- @@ -1482,11 +1499,11 @@ namespace netlist if ((num_cons() != 0)) { if (is_queued()) - netlist().queue().remove(this); - m_time = netlist().time() + delay; + exec().queue().remove(this); + m_time = exec().time() + delay; m_in_queue = (!m_list_active.empty()) ? QS_QUEUED : QS_DELAYED_DUE_TO_INACTIVE; /* queued ? */ if (m_in_queue == QS_QUEUED) - netlist().queue().push(queue_t::entry_t(m_time, this)); + exec().queue().push(queue_t::entry_t(m_time, this)); } } @@ -1532,16 +1549,26 @@ namespace netlist } } - inline netlist_t &detail::device_object_t::netlist() NL_NOEXCEPT + inline netlist_base_t &detail::device_object_t::netlist() NL_NOEXCEPT { return m_device.netlist(); } - inline const netlist_t &detail::device_object_t::netlist() const NL_NOEXCEPT + inline const netlist_base_t &detail::device_object_t::netlist() const NL_NOEXCEPT { return m_device.netlist(); } + inline netlist_t &detail::device_object_t::exec() NL_NOEXCEPT + { + return m_device.exec(); + } + + inline const netlist_t &detail::device_object_t::exec() const NL_NOEXCEPT + { + return m_device.exec(); + } + template template state_var::state_var(O &owner, const pstring &name, const T &value) diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index b72e0ee9944..dd94981d4ee 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -49,9 +49,8 @@ // savings are eaten up by effort // FIXME: Convert into solver parameter #define USE_LINEAR_PREDICTION (0) -#define NETLIST_GMIN_DEFAULT (1e-9) - +#define NETLIST_GMIN_DEFAULT (1e-9) //============================================================ // DEBUGGING diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp index bfefe5dd5e0..973b1b7814f 100644 --- a/src/lib/netlist/nl_factory.cpp +++ b/src/lib/netlist/nl_factory.cpp @@ -20,7 +20,7 @@ namespace netlist { namespace factory class NETLIB_NAME(wrapper) : public device_t { public: - NETLIB_NAME(wrapper)(netlist_t &anetlist, const pstring &name) + NETLIB_NAME(wrapper)(netlist_base_t &anetlist, const pstring &name) : device_t(anetlist, name) { } @@ -91,12 +91,12 @@ factory::element_t * list_t::factory_by_name(const pstring &devname) // factory_lib_entry_t: factory class to wrap macro based chips/elements // ----------------------------------------------------------------------------- -plib::owned_ptr library_element_t::Create(netlist_t &anetlist, const pstring &name) +plib::owned_ptr library_element_t::Create(netlist_base_t &anetlist, const pstring &name) { return plib::owned_ptr::Create(anetlist, name); } -void library_element_t::macro_actions(netlist_t &anetlist, const pstring &name) +void library_element_t::macro_actions(netlist_base_t &anetlist, const pstring &name) { anetlist.setup().namespace_push(name); anetlist.setup().include(this->name()); diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index 2e5ba33c8b1..77da4193951 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -40,7 +40,7 @@ factory::constructor_ptr_t decl_ ## chip = NETLIB_NAME(chip ## _c); namespace netlist { - class netlist_t; + class netlist_base_t; class device_t; class setup_t; @@ -58,8 +58,8 @@ namespace factory { const pstring &def_param, const pstring &sourcefile); virtual ~element_t(); - virtual plib::owned_ptr Create(netlist_t &anetlist, const pstring &name) = 0; - virtual void macro_actions(netlist_t &anetlist, const pstring &name) {} + virtual plib::owned_ptr Create(netlist_base_t &anetlist, const pstring &name) = 0; + virtual void macro_actions(netlist_base_t &anetlist, const pstring &name) {} const pstring &name() const { return m_name; } const pstring &classname() const { return m_classname; } @@ -84,7 +84,7 @@ namespace factory { const pstring &def_param, const pstring &sourcefile) : element_t(name, classname, def_param, sourcefile) { } - plib::owned_ptr Create(netlist_t &anetlist, const pstring &name) override + plib::owned_ptr Create(netlist_base_t &anetlist, const pstring &name) override { return plib::owned_ptr::Create(anetlist, name); } @@ -143,9 +143,9 @@ namespace factory { const pstring &def_param, const pstring &source) : element_t(name, classname, def_param, source) { } - plib::owned_ptr Create(netlist_t &anetlist, const pstring &name) override; + plib::owned_ptr Create(netlist_base_t &anetlist, const pstring &name) override; - void macro_actions(netlist_t &anetlist, const pstring &name) override; + void macro_actions(netlist_base_t &anetlist, const pstring &name) override; private: }; diff --git a/src/lib/netlist/nl_parser.h b/src/lib/netlist/nl_parser.h index 872cfa11954..26f9179c040 100644 --- a/src/lib/netlist/nl_parser.h +++ b/src/lib/netlist/nl_parser.h @@ -39,7 +39,7 @@ namespace netlist void net_truthtable_start(const pstring &nlname); /* for debugging messages */ - netlist_t &netlist() { return m_setup.netlist(); } + netlist_base_t &netlist() { return m_setup.netlist(); } virtual void verror(const pstring &msg, int line_num, const pstring &line) override; private: diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 8d0ffc66bc9..9d004c76c28 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -25,7 +25,7 @@ namespace netlist { -setup_t::setup_t(netlist_t &netlist) +setup_t::setup_t(netlist_base_t &netlist) : m_netlist(netlist) , m_factory(*this) , m_proxy_cnt(0) @@ -841,17 +841,17 @@ class logic_family_std_proxy_t : public logic_family_desc_t { public: logic_family_std_proxy_t() { } - virtual plib::owned_ptr create_d_a_proxy(netlist_t &anetlist, + virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; - virtual plib::owned_ptr create_a_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *proxied) const override; + virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; }; -plib::owned_ptr logic_family_std_proxy_t::create_d_a_proxy(netlist_t &anetlist, +plib::owned_ptr logic_family_std_proxy_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const { return plib::owned_ptr::Create(anetlist, name, proxied); } -plib::owned_ptr logic_family_std_proxy_t::create_a_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *proxied) const +plib::owned_ptr logic_family_std_proxy_t::create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const { return plib::owned_ptr::Create(anetlist, name, proxied); } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 25342e933f6..3b2f5c874a6 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -127,7 +127,7 @@ namespace netlist class core_device_t; class param_t; class setup_t; - class netlist_t; + class netlist_base_t; class logic_family_desc_t; class terminal_t; @@ -204,11 +204,11 @@ namespace netlist using link_t = std::pair; - explicit setup_t(netlist_t &netlist); + explicit setup_t(netlist_base_t &netlist); ~setup_t(); - netlist_t &netlist() { return m_netlist; } - const netlist_t &netlist() const { return m_netlist; } + netlist_base_t &netlist() { return m_netlist; } + const netlist_base_t &netlist() const { return m_netlist; } pstring build_fqn(const pstring &obj_name) const; @@ -319,7 +319,7 @@ namespace netlist devices::nld_base_proxy *get_d_a_proxy(detail::core_terminal_t &out); devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp); - netlist_t &m_netlist; + netlist_base_t &m_netlist; std::unordered_map m_params; std::vector m_links; factory::list_t m_factory; diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index 0b2e89df08f..fd76b88dee8 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -74,7 +74,7 @@ void terms_for_net_t::set_pointers() // matrix_solver // ---------------------------------------------------------------------------------------- -matrix_solver_t::matrix_solver_t(netlist_t &anetlist, const pstring &name, +matrix_solver_t::matrix_solver_t(netlist_base_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params) : device_t(anetlist, name) , m_params(*params) @@ -439,7 +439,7 @@ void matrix_solver_t::solve_base() const netlist_time matrix_solver_t::solve() { - const netlist_time now = netlist().time(); + const netlist_time now = exec().time(); const netlist_time delta = now - m_last_step; // We are already up to date. Avoid oscillations. @@ -545,7 +545,7 @@ void matrix_solver_t::log_stats() static_cast(this->m_stat_newton_raphson) / static_cast(this->m_stat_vsolver_calls)); log().verbose(" {1:10} invocations ({2:6.0} Hz) {3:10} gs fails ({4:6.2} %) {5:6.3} average", this->m_stat_calculations, - static_cast(this->m_stat_calculations) / this->netlist().time().as_double(), + static_cast(this->m_stat_calculations) / this->exec().time().as_double(), this->m_iterative_fail, 100.0 * static_cast(this->m_iterative_fail) / static_cast(this->m_stat_calculations), diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index 5cbbe59b8d0..044d431468b 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -144,7 +144,7 @@ public: protected: - matrix_solver_t(netlist_t &anetlist, const pstring &name, + matrix_solver_t(netlist_base_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params); void setup_base(analog_net_t::list_t &nets); diff --git a/src/lib/netlist/solver/nld_ms_direct.h b/src/lib/netlist/solver/nld_ms_direct.h index defa03bc044..7414f16db4c 100644 --- a/src/lib/netlist/solver/nld_ms_direct.h +++ b/src/lib/netlist/solver/nld_ms_direct.h @@ -36,8 +36,8 @@ class matrix_solver_direct_t: public matrix_solver_t friend class matrix_solver_t; public: - matrix_solver_direct_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); - matrix_solver_direct_t(netlist_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params, const std::size_t size); + matrix_solver_direct_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); + matrix_solver_direct_t(netlist_base_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params, const std::size_t size); virtual ~matrix_solver_direct_t() override; @@ -253,7 +253,7 @@ unsigned matrix_solver_direct_t::vsolve_non_dynamic(const bool n } template -matrix_solver_direct_t::matrix_solver_direct_t(netlist_t &anetlist, const pstring &name, +matrix_solver_direct_t::matrix_solver_direct_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) : matrix_solver_t(anetlist, name, ASCENDING, params) , m_dim(size) @@ -269,7 +269,7 @@ matrix_solver_direct_t::matrix_solver_direct_t(netlist_t &anetli } template -matrix_solver_direct_t::matrix_solver_direct_t(netlist_t &anetlist, const pstring &name, +matrix_solver_direct_t::matrix_solver_direct_t(netlist_base_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params, const std::size_t size) : matrix_solver_t(anetlist, name, sort, params) , m_dim(size) diff --git a/src/lib/netlist/solver/nld_ms_direct1.h b/src/lib/netlist/solver/nld_ms_direct1.h index 4967a9dc637..4ffbb833bc3 100644 --- a/src/lib/netlist/solver/nld_ms_direct1.h +++ b/src/lib/netlist/solver/nld_ms_direct1.h @@ -19,7 +19,7 @@ class matrix_solver_direct1_t: public matrix_solver_direct_t<1,1> { public: - matrix_solver_direct1_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params) + matrix_solver_direct1_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params) : matrix_solver_direct_t<1, 1>(anetlist, name, params, 1) {} virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override; diff --git a/src/lib/netlist/solver/nld_ms_direct2.h b/src/lib/netlist/solver/nld_ms_direct2.h index 65cf30c0202..75bfd6e0803 100644 --- a/src/lib/netlist/solver/nld_ms_direct2.h +++ b/src/lib/netlist/solver/nld_ms_direct2.h @@ -19,7 +19,7 @@ class matrix_solver_direct2_t: public matrix_solver_direct_t<2,2> { public: - matrix_solver_direct2_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params) + matrix_solver_direct2_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params) : matrix_solver_direct_t<2, 2>(anetlist, name, params, 2) {} virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override; diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index dee76dd8281..b49d9e64602 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -28,7 +28,7 @@ class matrix_solver_GCR_t: public matrix_solver_t { public: - matrix_solver_GCR_t(netlist_t &anetlist, const pstring &name, + matrix_solver_GCR_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) : matrix_solver_t(anetlist, name, matrix_solver_t::ASCENDING, params) , m_dim(size) diff --git a/src/lib/netlist/solver/nld_ms_gmres.h b/src/lib/netlist/solver/nld_ms_gmres.h index 2a73d45d3d1..4310af1b8de 100644 --- a/src/lib/netlist/solver/nld_ms_gmres.h +++ b/src/lib/netlist/solver/nld_ms_gmres.h @@ -29,7 +29,7 @@ class matrix_solver_GMRES_t: public matrix_solver_direct_t { public: - matrix_solver_GMRES_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) + matrix_solver_GMRES_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) : matrix_solver_direct_t(anetlist, name, matrix_solver_t::ASCENDING, params, size) , m_use_iLU_preconditioning(true) , m_use_more_precise_stop_condition(false) diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index 42d35e9b14c..4b0f6940798 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -54,7 +54,7 @@ class matrix_solver_sm_t: public matrix_solver_t public: - matrix_solver_sm_t(netlist_t &anetlist, const pstring &name, + matrix_solver_sm_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); virtual ~matrix_solver_sm_t() override; @@ -307,7 +307,7 @@ unsigned matrix_solver_sm_t::vsolve_non_dynamic(const bool newto } template -matrix_solver_sm_t::matrix_solver_sm_t(netlist_t &anetlist, const pstring &name, +matrix_solver_sm_t::matrix_solver_sm_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) : matrix_solver_t(anetlist, name, NOSORT, params) , m_dim(size) diff --git a/src/lib/netlist/solver/nld_ms_sor.h b/src/lib/netlist/solver/nld_ms_sor.h index eea692d6c47..1cc588a3e29 100644 --- a/src/lib/netlist/solver/nld_ms_sor.h +++ b/src/lib/netlist/solver/nld_ms_sor.h @@ -26,7 +26,7 @@ class matrix_solver_SOR_t: public matrix_solver_direct_t { public: - matrix_solver_SOR_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) + matrix_solver_SOR_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) : matrix_solver_direct_t(anetlist, name, matrix_solver_t::ASCENDING, params, size) , m_lp_fact(*this, "m_lp_fact", 0) { diff --git a/src/lib/netlist/solver/nld_ms_sor_mat.h b/src/lib/netlist/solver/nld_ms_sor_mat.h index 50bcac1a52d..7e80877d36e 100644 --- a/src/lib/netlist/solver/nld_ms_sor_mat.h +++ b/src/lib/netlist/solver/nld_ms_sor_mat.h @@ -29,7 +29,7 @@ class matrix_solver_SOR_mat_t: public matrix_solver_direct_t public: - matrix_solver_SOR_mat_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params, std::size_t size) + matrix_solver_SOR_mat_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, std::size_t size) : matrix_solver_direct_t(anetlist, name, matrix_solver_t::DESCENDING, params, size) , m_Vdelta(*this, "m_Vdelta", 0.0) , m_omega(*this, "m_omega", params->m_gs_sor) diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h index 4a2710a513d..ac7ea36a6a7 100644 --- a/src/lib/netlist/solver/nld_ms_w.h +++ b/src/lib/netlist/solver/nld_ms_w.h @@ -60,7 +60,7 @@ class matrix_solver_w_t: public matrix_solver_t friend class matrix_solver_t; public: - matrix_solver_w_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); + matrix_solver_w_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size); virtual ~matrix_solver_w_t() override; @@ -374,7 +374,7 @@ unsigned matrix_solver_w_t::vsolve_non_dynamic(const bool newton } template -matrix_solver_w_t::matrix_solver_w_t(netlist_t &anetlist, const pstring &name, +matrix_solver_w_t::matrix_solver_w_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size) : matrix_solver_t(anetlist, name, NOSORT, params) ,m_cnt(0) diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 7373b2be963..f7a25fa7fcc 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -95,7 +95,7 @@ NETLIB_UPDATE(solver) /* force solving during start up if there are no time-step devices */ /* FIXME: Needs a more elegant solution */ - bool force_solve = (netlist().time() < netlist_time::from_double(2 * m_params.m_max_timestep)); + bool force_solve = (exec().time() < netlist_time::from_double(2 * m_params.m_max_timestep)); std::size_t nthreads = std::min(static_cast(m_parallel()), plib::omp::get_max_threads()); @@ -128,7 +128,7 @@ NETLIB_UPDATE(solver) } template -matrix_solver_t * create_it(netlist_t &nl, pstring name, solver_parameters_t ¶ms, std::size_t size) +matrix_solver_t * create_it(netlist_base_t &nl, pstring name, solver_parameters_t ¶ms, std::size_t size) { return plib::palloc(nl, name, ¶ms, size); } @@ -213,7 +213,7 @@ struct net_splitter } } - void run(netlist_t &netlist) + void run(netlist_base_t &netlist) { for (auto & net : netlist.nets()) { diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h index 8619f66f095..a52730773a7 100644 --- a/src/lib/netlist/solver/nld_solver.h +++ b/src/lib/netlist/solver/nld_solver.h @@ -68,7 +68,7 @@ NETLIB_OBJECT(solver) void post_start(); void stop(); - nl_double gmin() { return m_gmin(); } + nl_double gmin() const { return m_gmin(); } void create_solver_code(std::map &mp); -- cgit v1.2.3-70-g09d2 From a527525e52d086c7550f87c82cba5f8204e4d61a Mon Sep 17 00:00:00 2001 From: couriersud Date: Wed, 16 Jan 2019 23:51:28 +0100 Subject: netlist: More run/setup separation. (nw) Still some distance ahead in properly separating execution and setup. --- src/devices/machine/netlist.cpp | 40 ++-- src/lib/netlist/analog/nlid_twoterm.h | 7 +- src/lib/netlist/devices/nlid_proxy.cpp | 4 +- src/lib/netlist/devices/nlid_system.h | 2 +- src/lib/netlist/nl_base.cpp | 288 ++++++++------------------- src/lib/netlist/nl_base.h | 216 +++++++++++--------- src/lib/netlist/nl_factory.h | 12 +- src/lib/netlist/nl_lists.h | 6 +- src/lib/netlist/nl_parser.h | 2 +- src/lib/netlist/nl_setup.cpp | 138 ++++++++++++- src/lib/netlist/nl_setup.h | 24 ++- src/lib/netlist/prg/nltool.cpp | 24 ++- src/lib/netlist/solver/nld_matrix_solver.cpp | 12 +- src/lib/netlist/solver/nld_ms_direct.h | 4 +- src/lib/netlist/solver/nld_ms_gcr.h | 4 +- src/lib/netlist/solver/nld_ms_sm.h | 4 +- src/lib/netlist/solver/nld_ms_w.h | 4 +- src/lib/netlist/solver/nld_solver.cpp | 26 +-- 18 files changed, 439 insertions(+), 378 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 75aa472e7e5..9f588368f8e 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -123,7 +123,7 @@ public: , m_cpu_device(nullptr) , m_last(*this, "m_last", 0) { - m_cpu_device = downcast(&static_cast(netlist()).parent()); + m_cpu_device = downcast(&static_cast(exec()).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(&static_cast(netlist()).parent()); + m_cpu_device = downcast(&static_cast(exec()).parent()); } ATTR_COLD void reset() override @@ -238,7 +238,7 @@ public: std::unique_ptr netlist_source_memregion_t::stream(const pstring &name) { - memory_region *mem = static_cast(setup().netlist()).machine().root_device().memregion(m_name.c_str()); + memory_region *mem = static_cast(setup().exec()).machine().root_device().memregion(m_name.c_str()); return plib::make_unique_base(mem->base(), mem->bytes()); } @@ -249,7 +249,7 @@ netlist_data_memregions_t::netlist_data_memregions_t(netlist::setup_t &setup) std::unique_ptr netlist_data_memregions_t::stream(const pstring &name) { - memory_region *mem = static_cast(setup().netlist()).parent().memregion(name.c_str()); + memory_region *mem = static_cast(setup().exec()).parent().memregion(name.c_str()); if (mem != nullptr) { return plib::make_unique_base(mem->base(), mem->bytes()); @@ -301,7 +301,7 @@ public: { int pos = (upto - m_last_buffer_time) / m_sample_time; if (pos > m_bufsize) - netlist().log().fatal("sound {1}: pos {2} exceeded bufsize {3}\n", name().c_str(), pos, m_bufsize); + state().log().fatal("sound {1}: pos {2} exceeded bufsize {3}\n", name().c_str(), pos, m_bufsize); while (m_last_pos < pos ) { m_buffer[m_last_pos++] = (stream_sample_t) m_cur; @@ -388,7 +388,7 @@ public: if ((*m_channels[i].m_param_name)() != pstring("")) { if (i != m_num_channels) - netlist().log().fatal("sound input numbering has to be sequential!"); + state().log().fatal("sound input numbering has to be sequential!"); m_num_channels++; m_channels[i].m_param = dynamic_cast(setup().find_param((*m_channels[i].m_param_name)(), true)); } @@ -451,7 +451,7 @@ private: netlist::setup_t &netlist_mame_device::setup() { - return m_netlist->setup(); + return m_netlist->nlstate().setup(); } void netlist_mame_device::register_memregion_source(netlist::setup_t &setup, const char *name) @@ -585,7 +585,7 @@ void netlist_mame_analog_output_device::custom_netlist_additions(netlist::setup_ plib::owned_ptr dev = plib::owned_ptr::Create(setup.netlist(), setup.build_fqn(dname)); static_cast(dev.get())->register_callback(std::move(m_delegate)); - setup.netlist().register_dev(std::move(dev)); + setup.netlist().add_dev(std::move(dev)); setup.register_link(dname + ".IN", pin); } @@ -620,7 +620,7 @@ void netlist_mame_logic_output_device::custom_netlist_additions(netlist::setup_t plib::owned_ptr dev = plib::owned_ptr::Create(setup.netlist(), setup.build_fqn(dname)); static_cast(dev.get())->register_callback(std::move(m_delegate)); - setup.netlist().register_dev(std::move(dev)); + setup.netlist().add_dev(std::move(dev)); setup.register_link(dname + ".IN", pin); } @@ -880,11 +880,11 @@ void netlist_mame_device::device_start() } } - netlist().prepare_to_run(); + setup().prepare_to_run(); - netlist().save(*this, m_rem, "m_rem"); - netlist().save(*this, m_div, "m_div"); - netlist().save(*this, m_old, "m_old"); + netlist().nlstate().save(*this, m_rem, "m_rem"); + netlist().nlstate().save(*this, m_div, "m_div"); + netlist().nlstate().save(*this, m_old, "m_old"); save_state(); @@ -922,15 +922,15 @@ ATTR_COLD void netlist_mame_device::device_post_load() { LOGDEVCALLS("device_post_load\n"); - netlist().state().post_load(); - netlist().rebuild_lists(); + netlist().run_state_manager().post_load(); + netlist().nlstate().rebuild_lists(); } ATTR_COLD void netlist_mame_device::device_pre_save() { LOGDEVCALLS("device_pre_save\n"); - netlist().state().pre_save(); + netlist().run_state_manager().pre_save(); } void netlist_mame_device::update_icount() @@ -951,7 +951,7 @@ void netlist_mame_device::check_mame_abort_slice() ATTR_COLD void netlist_mame_device::save_state() { - for (auto const & s : netlist().state().save_list()) + for (auto const & s : netlist().run_state_manager().save_list()) { netlist().log().debug("saving state for {1}\n", s->m_name.c_str()); if (s->m_dt.is_float) @@ -1015,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().nets()) + for (auto &n : netlist().nlstate().nets()) { if (n->is_logic()) { @@ -1120,7 +1120,7 @@ void netlist_mame_sound_device::device_start() // Configure outputs - std::vector outdevs = netlist().get_device_list(); + std::vector outdevs = netlist().nlstate().get_device_list(); if (outdevs.size() == 0) fatalerror("No output devices"); @@ -1147,7 +1147,7 @@ void netlist_mame_sound_device::device_start() m_in = nullptr; - std::vector indevs = netlist().get_device_list(); + std::vector indevs = netlist().nlstate().get_device_list(); if (indevs.size() > 1) fatalerror("A maximum of one input device is allowed!"); if (indevs.size() == 1) diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index efb9a8dd929..cb856763176 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -33,7 +33,8 @@ #ifndef NLID_TWOTERM_H_ #define NLID_TWOTERM_H_ -#include "../nl_base.h" +#include "netlist/nl_base.h" +#include "netlist/nl_setup.h" #include "../plib/pfunction.h" // ----------------------------------------------------------------------------- @@ -400,7 +401,7 @@ public: , m_R(*this, "R", 0.1) , m_V(*this, "V", 0.0) , m_func(*this,"FUNC", "") - , m_compiled(this->name() + ".FUNCC", this, this->netlist().state()) + , m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) { register_subalias("P", m_P); register_subalias("N", m_N); @@ -431,7 +432,7 @@ public: NETLIB_CONSTRUCTOR_DERIVED(CS, twoterm) , m_I(*this, "I", 1.0) , m_func(*this,"FUNC", "") - , m_compiled(this->name() + ".FUNCC", this, this->netlist().state()) + , m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) { register_subalias("P", m_P); register_subalias("N", m_N); diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index c5ad63f3910..d4163a74c42 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -111,9 +111,9 @@ namespace netlist for (int i = 0; i < 3; i++) { pstring devname = out_proxied->device().name(); - auto tp = netlist().setup().find_terminal(devname + "." + power_syms[i][0], + auto tp = setup().find_terminal(devname + "." + power_syms[i][0], detail::terminal_type::INPUT, false); - auto tn = netlist().setup().find_terminal(devname + "." + power_syms[i][1], + auto tn = setup().find_terminal(devname + "." + power_syms[i][1], detail::terminal_type::INPUT, false); if (tp != nullptr && tn != nullptr) { diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 6acda365c8f..498ce657818 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -317,7 +317,7 @@ namespace netlist , m_N(*this, "N", 1) , m_func(*this, "FUNC", "A0") , m_Q(*this, "Q") - , m_compiled(this->name() + ".FUNCC", this, this->netlist().state()) + , m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) { std::vector inps; for (int i=0; i < m_N(); i++) diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 9c19d10f0c9..831818b8c39 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -146,7 +146,7 @@ const logic_family_desc_t *family_CD4XXX() // queue_t // ---------------------------------------------------------------------------------------- -detail::queue_t::queue_t(netlist_t &nl) +detail::queue_t::queue_t(netlist_state_t &nl) : timed_queue, false, NL_KEEP_STATISTICS>(512) , netlist_ref(nl) , plib::state_manager_t::callback_t() @@ -158,7 +158,7 @@ detail::queue_t::queue_t(netlist_t &nl) void detail::queue_t::register_state(plib::state_manager_t &manager, const pstring &module) { - //netlist().log().debug("register_state\n"); + //state().log().debug("register_state\n"); manager.save_item(this, m_qsize, module + "." + "qsize"); manager.save_item(this, &m_times[0], module + "." + "times", m_times.size()); manager.save_item(this, &m_net_ids[0], module + "." + "names", m_net_ids.size()); @@ -166,13 +166,13 @@ void detail::queue_t::register_state(plib::state_manager_t &manager, const pstri void detail::queue_t::on_pre_save() { - netlist().log().debug("on_pre_save\n"); + state().log().debug("on_pre_save\n"); m_qsize = this->size(); - netlist().log().debug("current time {1} qsize {2}\n", exec().time().as_double(), m_qsize); + state().log().debug("current time {1} qsize {2}\n", exec().time().as_double(), m_qsize); for (std::size_t i = 0; i < m_qsize; i++ ) { m_times[i] = this->listptr()[i].m_exec_time.as_raw(); - m_net_ids[i] = netlist().find_net_id(this->listptr()[i].m_object); + m_net_ids[i] = state().find_net_id(this->listptr()[i].m_object); } } @@ -180,14 +180,21 @@ void detail::queue_t::on_pre_save() void detail::queue_t::on_post_load() { this->clear(); - netlist().log().debug("current time {1} qsize {2}\n", exec().time().as_double(), m_qsize); + state().log().debug("current time {1} qsize {2}\n", exec().time().as_double(), m_qsize); for (std::size_t i = 0; i < m_qsize; i++ ) { - detail::net_t *n = netlist().nets()[m_net_ids[i]].get(); + detail::net_t *n = state().nets()[m_net_ids[i]].get(); this->push(queue_t::entry_t(netlist_time::from_raw(m_times[i]),n)); } } +// ---------------------------------------------------------------------------------------- +// netlist_ref_t +// ---------------------------------------------------------------------------------------- + +detail::netlist_ref::netlist_ref(netlist_state_t &nl) +: m_netlist(nl.setup().exec()) { } + // ---------------------------------------------------------------------------------------- // object_t // ---------------------------------------------------------------------------------------- @@ -230,7 +237,7 @@ detail::terminal_type detail::core_terminal_t::type() const return terminal_type::OUTPUT; else { - netlist().log().fatal(MF_1_UNKNOWN_TYPE_FOR_OBJECT, name()); + state().log().fatal(MF_1_UNKNOWN_TYPE_FOR_OBJECT, name()); return terminal_type::TERMINAL; // please compiler } } @@ -240,14 +247,18 @@ detail::terminal_type detail::core_terminal_t::type() const // ---------------------------------------------------------------------------------------- netlist_t::netlist_t(const pstring &aname, std::unique_ptr callbacks) - : netlist_base_t(aname, std::move(callbacks)) + : m_state(plib::make_unique(aname, + std::move(callbacks), + plib::make_unique(*this))) // FIXME, ugly but needed to have netlist_state_t constructed first , m_time(netlist_time::zero()) , m_mainclock(nullptr) - , m_queue(*this) + , m_queue(*m_state) , m_solver(nullptr) { - state().save_item(this, static_cast(m_queue), "m_queue"); - state().save_item(this, m_time, "m_time"); + devices::initialize_factory(nlstate().setup().factory()); + NETLIST_NAME(base)(nlstate().setup()); + run_state_manager().save_item(this, static_cast(m_queue), "m_queue"); + run_state_manager().save_item(this, m_time, "m_time"); } netlist_t::~netlist_t() @@ -258,157 +269,29 @@ netlist_t::~netlist_t() // netlist_t // ---------------------------------------------------------------------------------------- -netlist_base_t::netlist_base_t(const pstring &aname, std::unique_ptr callbacks) - :m_params(nullptr) - , m_name(aname) - , m_lib(nullptr) - , m_state() - , m_callbacks(std::move(callbacks)) // Order is important here - , m_log(*m_callbacks) -{ - m_setup = plib::make_unique(*this); - NETLIST_NAME(base)(*m_setup); -} - -netlist_base_t::~netlist_base_t() -{ - m_nets.clear(); - m_devices.clear(); -} - -void netlist_base_t::register_dev(plib::owned_ptr dev) +netlist_state_t::netlist_state_t(const pstring &aname, + std::unique_ptr &&callbacks, + std::unique_ptr &&setup) +: m_params(nullptr) +, m_name(aname) +, m_state() +, m_callbacks(std::move(callbacks)) // Order is important here +, m_log(*m_callbacks) +, m_setup(std::move(setup)) { - for (auto & d : m_devices) - if (d->name() == dev->name()) - log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d->name()); - m_devices.push_back(std::move(dev)); + pstring libpath = plib::util::environment("NL_BOOSTLIB", plib::util::buildpath({".", "nlboost.so"})); + m_lib = plib::make_unique(libpath); } -void netlist_base_t::remove_dev(core_device_t *dev) -{ - m_devices.erase( - std::remove_if( - m_devices.begin(), - m_devices.end(), - [&] (plib::owned_ptr const& p) - { - return p.get() == dev; - }), - m_devices.end() - ); -} -void netlist_base_t::delete_empty_nets() +netlist_state_t::~netlist_state_t() { - m_nets.erase( - std::remove_if(m_nets.begin(), m_nets.end(), - [](plib::owned_ptr &x) - { - if (x->num_cons() == 0) - { - x->netlist().log().verbose("Deleting net {1} ...", x->name()); - return true; - } - else - return false; - }), m_nets.end()); + nets().clear(); + m_devices.clear(); } -void netlist_base_t::prepare_to_run() -{ - setup().register_dynamic_log_devices(); - - /* load the library ... */ - - /* make sure the solver and parameters are started first! */ - - for (auto & e : setup().m_device_factory) - { - if ( setup().factory().is_class(e.second) - || setup().factory().is_class(e.second)) - { - auto dev = plib::owned_ptr(e.second->Create(*this, e.first)); - register_dev(std::move(dev)); - } - } - - log().debug("Searching for solver and parameters ...\n"); - auto solver = get_single_device("solver"); - m_params = get_single_device("parameter"); - /* create devices */ - - log().debug("Creating devices ...\n"); - for (auto & e : setup().m_device_factory) - { - if ( !setup().factory().is_class(e.second) - && !setup().factory().is_class(e.second)) - { - auto dev = plib::owned_ptr(e.second->Create(*this, e.first)); - register_dev(std::move(dev)); - } - } - - bool use_deactivate = (m_params->m_use_deactivate() ? true : false); - - for (auto &d : m_devices) - { - if (use_deactivate) - { - auto p = setup().m_param_values.find(d->name() + ".HINT_NO_DEACTIVATE"); - if (p != setup().m_param_values.end()) - { - //FIXME: check for errors ... - double v = plib::pstonum(p->second); - if (std::abs(v - std::floor(v)) > 1e-6 ) - log().fatal(MF_1_HND_VAL_NOT_SUPPORTED, p->second); - d->set_hint_deactivate(v == 0.0); - } - } - else - d->set_hint_deactivate(false); - } - - pstring libpath = plib::util::environment("NL_BOOSTLIB", plib::util::buildpath({".", "nlboost.so"})); - m_lib = plib::make_unique(libpath); - - /* resolve inputs */ - setup().resolve_inputs(); - - log().verbose("looking for two terms connected to rail nets ..."); - for (auto & t : get_device_list()) - { - if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet()) - { - log().warning(MW_3_REMOVE_DEVICE_1_CONNECTED_ONLY_TO_RAILS_2_3, - t->name(), t->m_N.net().name(), t->m_P.net().name()); - t->m_N.net().remove_terminal(t->m_N); - t->m_P.net().remove_terminal(t->m_P); - remove_dev(t); - } - } - - log().verbose("initialize solver ...\n"); - - if (solver == nullptr) - { - for (auto &p : m_nets) - if (p->is_analog()) - log().fatal(MF_0_NO_SOLVER); - } - else - solver->post_start(); - - for (auto &n : m_nets) - for (auto & term : n->m_core_terms) - { - //core_device_t *dev = reinterpret_cast(term->m_delegate.object()); - core_device_t *dev = &term->device(); - dev->set_default_delegate(*term); - } - -} void netlist_t::stop() { @@ -419,7 +302,7 @@ void netlist_t::stop() m_solver->stop(); } -detail::net_t *netlist_base_t::find_net(const pstring &name) const +detail::net_t *netlist_state_t::find_net(const pstring &name) const { for (auto & net : m_nets) if (net->name() == name) @@ -428,7 +311,7 @@ detail::net_t *netlist_base_t::find_net(const pstring &name) const return nullptr; } -std::size_t netlist_base_t::find_net_id(const detail::net_t *net) const +std::size_t netlist_state_t::find_net_id(const detail::net_t *net) const { for (std::size_t i = 0; i < m_nets.size(); i++) if (m_nets[i].get() == net) @@ -438,7 +321,7 @@ std::size_t netlist_base_t::find_net_id(const detail::net_t *net) const -void netlist_base_t::rebuild_lists() +void netlist_state_t::rebuild_lists() { for (auto & net : m_nets) net->rebuild_list(); @@ -448,10 +331,10 @@ void netlist_base_t::rebuild_lists() void netlist_t::reset() { log().debug("Searching for mainclock\n"); - m_mainclock = get_single_device("mainclock"); + m_mainclock = m_state->get_single_device("mainclock"); log().debug("Searching for solver\n"); - m_solver = get_single_device("solver"); + m_solver = m_state->get_single_device("solver"); m_time = netlist_time::zero(); m_queue.clear(); @@ -460,16 +343,16 @@ void netlist_t::reset() //if (m_solver != nullptr) // m_solver->do_reset(); - std::unordered_map m; - - for (auto &d : m_devices) - { - m[d.get()] = d->get_hint_deactivate(); - } + m_state->reset(); +} +void netlist_state_t::reset() +{ + //FIXME: never used ??? + std::unordered_map m; // Reset all nets once ! - for (auto & n : m_nets) + for (auto & n : nets()) n->reset(); // Reset all devices once ! @@ -545,8 +428,7 @@ void netlist_t::reset() #if 1 /* the above may screw up m_active and the list */ - for (auto &n : m_nets) - n->rebuild_list(); + rebuild_lists(); #endif } @@ -610,18 +492,18 @@ void netlist_t::print_stats() const if (nperftime_t::enabled) { std::vector index; - for (size_t i=0; im_devices.size(); i++) index.push_back(i); std::sort(index.begin(), index.end(), - [&](size_t i1, size_t i2) { return m_devices[i1]->m_stat_total_time.total() < m_devices[i2]->m_stat_total_time.total(); }); + [&](size_t i1, size_t i2) { return m_state->m_devices[i1]->m_stat_total_time.total() < m_state->m_devices[i2]->m_stat_total_time.total(); }); nperftime_t::type total_time(0); uint_least64_t total_count(0); for (auto & j : index) { - auto entry = m_devices[j].get(); + auto entry = m_state->m_devices[j].get(); log().verbose("Device {1:20} : {2:12} {3:12} {4:15} {5:12}", entry->name(), entry->m_stat_call_count(), entry->m_stat_total_time.count(), entry->m_stat_total_time.total(), entry->m_stat_inc_active()); @@ -657,7 +539,7 @@ void netlist_t::print_stats() const / static_cast::type>(m_queue.m_prof_call()); log().verbose("Overhead per pop {1:11}", overhead_per_pop ); log().verbose(""); - for (auto &entry : m_devices) + for (auto &entry : m_state->m_devices) { if (entry->m_stat_inc_active() > 3 * entry->m_stat_total_time.count()) log().verbose("HINT({}, NO_DEACTIVATE)", entry->name()); @@ -665,7 +547,7 @@ void netlist_t::print_stats() const } } -core_device_t *netlist_base_t::get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const +core_device_t *netlist_state_t::get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const { core_device_t *ret = nullptr; for (auto &d : m_devices) @@ -673,7 +555,7 @@ core_device_t *netlist_base_t::get_single_device(const pstring &classname, bool if (cc(d.get())) { if (ret != nullptr) - this->log().fatal(MF_1_MORE_THAN_ONE_1_DEVICE_FOUND, classname); + m_log.fatal(MF_1_MORE_THAN_ONE_1_DEVICE_FOUND, classname); else ret = d.get(); } @@ -699,13 +581,13 @@ core_device_t::core_device_t(netlist_base_t &owner, const pstring &name) core_device_t::core_device_t(core_device_t &owner, const pstring &name) : object_t(owner.name() + "." + name) , logic_family_t() - , netlist_ref(owner.netlist()) + , netlist_ref(owner.state()) , m_hint_deactivate(false) { set_logic_family(owner.logic_family()); if (logic_family() == nullptr) set_logic_family(family_TTL()); - owner.netlist().register_dev(plib::owned_ptr(this, false)); + state().add_dev(plib::owned_ptr(this, false)); } core_device_t::~core_device_t() @@ -720,7 +602,7 @@ void core_device_t::set_default_delegate(detail::core_terminal_t &term) log_type & core_device_t::log() { - return netlist().log(); + return state().log(); } // ---------------------------------------------------------------------------------------- @@ -744,12 +626,12 @@ device_t::~device_t() setup_t &device_t::setup() { - return netlist().setup(); + return state().setup(); } const setup_t &device_t::setup() const { - return netlist().setup(); + return state().setup(); } void device_t::register_subalias(const pstring &name, detail::core_terminal_t &term) @@ -795,7 +677,7 @@ void device_t::connect_post_start(detail::core_terminal_t &t1, detail::core_term detail::family_setter_t::family_setter_t(core_device_t &dev, const pstring &desc) { - dev.set_logic_family(dev.netlist().setup().family_from_model(desc)); + dev.set_logic_family(dev.setup().family_from_model(desc)); } detail::family_setter_t::family_setter_t(core_device_t &dev, const logic_family_desc_t *desc) @@ -820,7 +702,7 @@ detail::net_t::net_t(netlist_base_t &nl, const pstring &aname, core_terminal_t * detail::net_t::~net_t() { - netlist().state().remove_save_items(this); + state().run_state_manager().remove_save_items(this); } void detail::net_t::add_to_active_list(core_terminal_t &term) NL_NOEXCEPT @@ -859,7 +741,7 @@ void detail::net_t::rebuild_list() m_list_active.clear(); for (auto & term : m_core_terms) - if (term->state() != logic_t::STATE_INP_PASSIVE) + if (term->terminal_state() != logic_t::STATE_INP_PASSIVE) { m_list_active.push_back(term); } @@ -870,7 +752,7 @@ void detail::net_t::process(const std::uint_fast8_t mask) for (auto & p : m_list_active) { p.device().m_stat_call_count.inc(); - if ((p.state() & mask)) + if ((p.terminal_state() & mask)) { p.device().m_stat_total_time.start(); p.m_delegate(); @@ -921,7 +803,7 @@ void detail::net_t::reset() for (core_terminal_t *ct : m_core_terms) { ct->reset(); - if (ct->state() != logic_t::STATE_INP_PASSIVE) + if (ct->terminal_state() != logic_t::STATE_INP_PASSIVE) m_list_active.push_back(ct); } } @@ -930,7 +812,7 @@ void detail::net_t::add_terminal(detail::core_terminal_t &terminal) { for (auto &t : m_core_terms) if (t == &terminal) - netlist().log().fatal(MF_2_NET_1_DUPLICATE_TERMINAL_2, name(), + state().log().fatal(MF_2_NET_1_DUPLICATE_TERMINAL_2, name(), t->name()); terminal.set_net(this); @@ -946,7 +828,7 @@ void detail::net_t::remove_terminal(detail::core_terminal_t &terminal) plib::container::remove(m_core_terms, &terminal); } else - netlist().log().fatal(MF_2_REMOVE_TERMINAL_1_FROM_NET_2, terminal.name(), + state().log().fatal(MF_2_REMOVE_TERMINAL_1_FROM_NET_2, terminal.name(), this->name()); } @@ -1035,7 +917,7 @@ terminal_t::terminal_t(core_device_t &dev, const pstring &aname) , m_go1(nullptr) , m_gt1(nullptr) { - netlist().setup().register_term(*this); + state().setup().register_term(*this); } terminal_t::~terminal_t() @@ -1072,12 +954,12 @@ void terminal_t::schedule_solve_after(const netlist_time &after) logic_output_t::logic_output_t(core_device_t &dev, const pstring &aname) : logic_t(dev, aname, STATE_OUT) - , m_my_net(dev.netlist(), name() + ".net", this) + , m_my_net(dev.state(), name() + ".net", this) { this->set_net(&m_my_net); - netlist().register_net(plib::owned_ptr(&m_my_net, false)); + state().register_net(plib::owned_ptr(&m_my_net, false)); set_logic_family(dev.logic_family()); - netlist().setup().register_term(*this); + state().setup().register_term(*this); } logic_output_t::~logic_output_t() @@ -1097,7 +979,7 @@ void logic_output_t::initial(const netlist_sig_t val) analog_input_t::analog_input_t(core_device_t &dev, const pstring &aname) : analog_t(dev, aname, STATE_INP_ACTIVE) { - netlist().setup().register_term(*this); + state().setup().register_term(*this); } analog_input_t::~analog_input_t() @@ -1110,13 +992,13 @@ analog_input_t::~analog_input_t() 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) + , m_my_net(dev.state(), name() + ".net", this) { - netlist().register_net(plib::owned_ptr(&m_my_net, false)); + state().register_net(plib::owned_ptr(&m_my_net, false)); this->set_net(&m_my_net); //net().m_cur_Analog = NL_FCONST(0.0); - netlist().setup().register_term(*this); + state().setup().register_term(*this); } analog_output_t::~analog_output_t() @@ -1137,7 +1019,7 @@ logic_input_t::logic_input_t(core_device_t &dev, const pstring &aname, : logic_t(dev, aname, STATE_INP_ACTIVE, delegate) { set_logic_family(dev.logic_family()); - netlist().setup().register_term(*this); + state().setup().register_term(*this); } logic_input_t::~logic_input_t() @@ -1172,7 +1054,7 @@ param_t::param_type_t param_t::param_type() const return POINTER; else { - netlist().log().fatal(MF_1_UNKNOWN_PARAM_TYPE, name()); + state().log().fatal(MF_1_UNKNOWN_PARAM_TYPE, name()); return POINTER; /* Please compiler */ } } @@ -1196,7 +1078,7 @@ pstring param_t::get_initial(const device_t &dev, bool *found) const pstring param_model_t::model_type() { if (m_map.size() == 0) - netlist().setup().model_parse(this->Value(), m_map); + state().setup().model_parse(this->Value(), m_map); return m_map["COREMODEL"]; } @@ -1223,28 +1105,28 @@ param_ptr_t::param_ptr_t(device_t &device, const pstring &name, uint8_t * val) void param_model_t::changed() { - netlist().log().fatal(MF_1_MODEL_1_CAN_NOT_BE_CHANGED_AT_RUNTIME, name()); + state().log().fatal(MF_1_MODEL_1_CAN_NOT_BE_CHANGED_AT_RUNTIME, name()); m_map.clear(); } const pstring param_model_t::model_value_str(const pstring &entity) { if (m_map.size() == 0) - netlist().setup().model_parse(this->Value(), m_map); - return netlist().setup().model_value_str(m_map, entity); + state().setup().model_parse(this->Value(), m_map); + return state().setup().model_value_str(m_map, entity); } nl_double param_model_t::model_value(const pstring &entity) { if (m_map.size() == 0) - netlist().setup().model_parse(this->Value(), m_map); - return netlist().setup().model_value(m_map, entity); + state().setup().model_parse(this->Value(), m_map); + return state().setup().model_value(m_map, entity); } std::unique_ptr param_data_t::stream() { - return device().netlist().setup().get_data_stream(Value()); + return device().setup().get_data_stream(Value()); } bool detail::core_terminal_t::is_logic() const NL_NOEXCEPT diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 3d8ef2401d5..72e87fd4964 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -211,7 +211,8 @@ namespace netlist class net_t; class setup_t; class netlist_t; - class netlist_base_t; + class netlist_state_t; + typedef netlist_state_t netlist_base_t; class core_device_t; class device_t; class callbacks_t; @@ -425,19 +426,22 @@ namespace netlist struct detail::netlist_ref { - explicit constexpr netlist_ref(netlist_base_t &nl) : m_netlist(nl) { } + explicit netlist_ref(netlist_state_t &nl); - C14CONSTEXPR netlist_base_t & netlist() NL_NOEXCEPT { return m_netlist; } - constexpr const netlist_base_t & netlist() const NL_NOEXCEPT { return m_netlist; } + netlist_state_t & state(); + const netlist_state_t & state() const; - netlist_t & exec() NL_NOEXCEPT { return *reinterpret_cast(&m_netlist); } - const netlist_t & exec() const NL_NOEXCEPT { return *reinterpret_cast(&m_netlist); } + setup_t & setup(); + const setup_t & setup() const; + + C14CONSTEXPR netlist_t & exec() NL_NOEXCEPT { return m_netlist; } + constexpr const netlist_t & exec() const NL_NOEXCEPT { return m_netlist; } protected: ~netlist_ref() = default; // prohibit polymorphic destruction private: - netlist_base_t & m_netlist; + netlist_t & m_netlist; }; @@ -469,8 +473,8 @@ namespace netlist /*! The netlist owning the owner of this object. * \returns reference to netlist object. */ - netlist_base_t &netlist() NL_NOEXCEPT; - const netlist_base_t &netlist() const NL_NOEXCEPT; + netlist_base_t &state() NL_NOEXCEPT; + const netlist_base_t &state() const NL_NOEXCEPT; netlist_t &exec() NL_NOEXCEPT; const netlist_t &exec() const NL_NOEXCEPT; @@ -534,7 +538,7 @@ namespace netlist bool is_analog() const NL_NOEXCEPT; bool is_state(const state_e astate) const NL_NOEXCEPT { return (m_state == astate); } - const state_e &state() const NL_NOEXCEPT { return m_state; } + const state_e &terminal_state() const NL_NOEXCEPT { return m_state; } void set_state(const state_e astate) NL_NOEXCEPT { m_state = astate; } void reset() { set_state(is_type(OUTPUT) ? STATE_OUT : STATE_INP_ACTIVE); } @@ -1156,7 +1160,6 @@ namespace netlist setup_t &setup(); const setup_t &setup() const; - template void register_sub(const pstring &name, std::unique_ptr &dev, const Args&... args) { @@ -1213,7 +1216,7 @@ namespace netlist { public: typedef pqentry_t entry_t; - explicit queue_t(netlist_t &nl); + explicit queue_t(netlist_state_t &nl); protected: @@ -1228,55 +1231,21 @@ namespace netlist }; // ----------------------------------------------------------------------------- - // netlist_t + // netlist_state__t // ----------------------------------------------------------------------------- - class netlist_base_t : private plib::nocopyassignmove + class netlist_state_t : private plib::nocopyassignmove { public: - using nets_collection_type = std::vector>; + using devices_collection_type = std::vector>; + netlist_state_t(const pstring &aname, + std::unique_ptr &&callbacks, + std::unique_ptr &&setup); - explicit netlist_base_t(const pstring &aname, std::unique_ptr callbacks); - ~netlist_base_t(); - - /* Control functions */ - - void stop(); - void reset(); - - // ======================================================== - // configuration section - // ======================================================== - - void prepare_to_run(); - - // FIXME: sort rebuild_lists out - void rebuild_lists(); /* must be called after post_load ! */ - - /* netlist build functions */ - - setup_t &setup() NL_NOEXCEPT { return *m_setup; } - const setup_t &setup() const NL_NOEXCEPT { return *m_setup; } - - void register_dev(plib::owned_ptr dev); - void remove_dev(core_device_t *dev); + ~netlist_state_t(); - detail::net_t *find_net(const pstring &name) const; - std::size_t find_net_id(const detail::net_t *net) const; - - template - std::vector get_device_list() const - { - std::vector tmp; - for (auto &d : m_devices) - { - device_class *dev = dynamic_cast(d.get()); - if (dev != nullptr) - tmp.push_back(dev); - } - return tmp; - } + friend class netlist_t; // allow access to private members template static bool check_class(core_device_t *p) @@ -1297,66 +1266,103 @@ namespace netlist log_type & log() { return m_log; } const log_type &log() const { return m_log; } - /* state related */ + plib::dynlib &lib() { return *m_lib; } + + /* state handling */ - plib::state_manager_t &state() { return m_state; } + plib::state_manager_t &run_state_manager() { return m_state; } template void save(O &owner, C &state, const pstring &stname) { - this->state().save_item(static_cast(&owner), state, owner.name() + pstring(".") + stname); + this->run_state_manager().save_item(static_cast(&owner), state, owner.name() + pstring(".") + stname); } template void save(O &owner, C *state, const pstring &stname, const std::size_t count) { - this->state().save_state_ptr(static_cast(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f::f(), count, state); + this->run_state_manager().save_state_ptr(static_cast(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f::f(), count, state); } - plib::dynlib &lib() { return *m_lib; } + core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const; - const nets_collection_type &nets() { return m_nets; } + detail::net_t *find_net(const pstring &name) const; + std::size_t find_net_id(const detail::net_t *net) const; template - void register_net(plib::owned_ptr &&net) + void register_net(plib::owned_ptr &&net) { m_nets.push_back(std::move(net)); } + + devices::NETLIB_NAME(netlistparams) *m_params; + + template + inline std::vector get_device_list() { - m_nets.push_back(std::move(net)); + std::vector tmp; + for (auto &d : m_devices) + { + device_class *dev = dynamic_cast(d.get()); + if (dev != nullptr) + tmp.push_back(dev); + } + return tmp; + } + + void add_dev(plib::owned_ptr dev) + { + for (auto & d : m_devices) + if (d->name() == dev->name()) + log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d->name()); + m_devices.push_back(std::move(dev)); } - void delete_empty_nets(); + void remove_dev(core_device_t *dev) + { + m_devices.erase( + std::remove_if( + m_devices.begin(), + m_devices.end(), + [&] (plib::owned_ptr const& p) + { + return p.get() == dev; + }), + m_devices.end() + ); + } /* sole use is to manage lifetime of family objects */ std::vector>> m_family_cache; - protected: - - /* sole use is to manage lifetime of net objects */ - std::vector> m_devices; - nets_collection_type m_nets; + setup_t &setup() NL_NOEXCEPT { return *m_setup; } + const setup_t &setup() const NL_NOEXCEPT { return *m_setup; } - private: + nets_collection_type & nets() { return m_nets; } + devices_collection_type & devices() { return m_devices; } - core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const; + // FIXME: make a postload member and include code there + void rebuild_lists(); /* must be called after post_load ! */ - /* mostly ro */ + private: - devices::NETLIB_NAME(netlistparams) *m_params; + void reset(); pstring m_name; std::unique_ptr m_lib; // external lib needs to be loaded as long as netlist exists - plib::state_manager_t m_state; + std::unique_ptr m_callbacks; + log_type m_log; + std::unique_ptr m_setup; + nets_collection_type m_nets; + /* sole use is to manage lifetime of net objects */ + devices_collection_type m_devices; - std::unique_ptr m_callbacks; - log_type m_log; - std::unique_ptr m_setup; }; + // ----------------------------------------------------------------------------- + // netlist_t + // ----------------------------------------------------------------------------- - class netlist_t : public netlist_base_t + class netlist_t { public: - using nets_collection_type = std::vector>; - explicit netlist_t(const pstring &aname, std::unique_ptr callbacks); ~netlist_t(); @@ -1375,6 +1381,10 @@ namespace netlist void stop(); void reset(); + /* state handling */ + + plib::state_manager_t &run_state_manager() { return m_state->run_state_manager(); } + /* only used by nltool to create static c-code */ devices::NETLIB_NAME(solver) *solver() const NL_NOEXCEPT { return m_solver; } @@ -1385,11 +1395,17 @@ namespace netlist return static_cast(m_solver)->gmin(); } - protected: + netlist_state_t &nlstate() NL_NOEXCEPT { return *m_state; } + const netlist_state_t &nlstate() const { return *m_state; } + + log_type & log() { return m_state->log(); } + const log_type &log() const { return m_state->log(); } void print_stats() const; private: + std::unique_ptr m_state; + /* mostly rw */ netlist_time m_time; devices::NETLIB_NAME(mainclock) * m_mainclock; @@ -1426,6 +1442,26 @@ namespace netlist // inline implementations // ----------------------------------------------------------------------------- + inline netlist_state_t & detail::netlist_ref::state() + { + return m_netlist.nlstate(); + } + + inline const netlist_state_t & detail::netlist_ref::state() const + { + return m_netlist.nlstate(); + } + + inline setup_t & detail::netlist_ref::setup() + { + return m_netlist.nlstate().setup(); + } + + inline const setup_t & detail::netlist_ref::setup() const + { + return m_netlist.nlstate().setup(); + } + template param_num_t::param_num_t(device_t &device, const pstring &name, const T val) : param_t(device, name) @@ -1438,13 +1474,13 @@ namespace netlist bool err = false; T vald = plib::pstonum_ne(p, err); if (err) - netlist().log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, p); + device.state().log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, p); m_param = vald; } else m_param = val; - netlist().save(*this, m_param, "m_param"); + device.state().save(*this, m_param, "m_param"); } template @@ -1455,7 +1491,7 @@ namespace netlist if (f != nullptr) f->read(&m_data[0],1<::state_var(O &owner, const pstring &name, const T &value) : m_value(value) { - owner.netlist().save(owner, m_value, name); + owner.state().save(owner, m_value, name); } template template state_var::state_var(O &owner, const pstring &name, const T & value) { - owner.netlist().save(owner, m_value, name); + owner.state().save(owner, m_value, name); for (std::size_t i=0; i Create(netlist_base_t &anetlist, const pstring &name) = 0; - virtual void macro_actions(netlist_base_t &anetlist, const pstring &name) {} + virtual plib::owned_ptr Create(netlist_state_t &anetlist, const pstring &name) = 0; + virtual void macro_actions(netlist_state_t &anetlist, const pstring &name) {} const pstring &name() const { return m_name; } const pstring &classname() const { return m_classname; } @@ -84,7 +84,7 @@ namespace factory { const pstring &def_param, const pstring &sourcefile) : element_t(name, classname, def_param, sourcefile) { } - plib::owned_ptr Create(netlist_base_t &anetlist, const pstring &name) override + plib::owned_ptr Create(netlist_state_t &anetlist, const pstring &name) override { return plib::owned_ptr::Create(anetlist, name); } @@ -143,9 +143,9 @@ namespace factory { const pstring &def_param, const pstring &source) : element_t(name, classname, def_param, source) { } - plib::owned_ptr Create(netlist_base_t &anetlist, const pstring &name) override; + plib::owned_ptr Create(netlist_state_t &anetlist, const pstring &name) override; - void macro_actions(netlist_base_t &anetlist, const pstring &name) override; + void macro_actions(netlist_state_t &anetlist, const pstring &name) override; private: }; diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 9e8007e24cd..76e7afc4e48 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -62,10 +62,10 @@ namespace netlist struct pqentry_t final { constexpr pqentry_t() noexcept : m_exec_time(), m_object(nullptr) { } - constexpr pqentry_t(const Time &t, const Element &o) noexcept : m_exec_time(t), m_object(o) { } + constexpr pqentry_t(const Time t, const Element o) noexcept : m_exec_time(t), m_object(o) { } ~pqentry_t() = default; constexpr pqentry_t(const pqentry_t &e) noexcept = default; - constexpr pqentry_t(pqentry_t &&e) = default; + constexpr pqentry_t(pqentry_t &&e) noexcept = default; pqentry_t& operator=(pqentry_t && other) noexcept = default; pqentry_t& operator=(const pqentry_t &other) noexcept = default; @@ -131,7 +131,7 @@ namespace netlist } void pop() noexcept { --m_end; } - const T &top() const noexcept { return *(m_end-1); } + const T top() const noexcept { return *(m_end-1); } template void remove(const R &elem) noexcept diff --git a/src/lib/netlist/nl_parser.h b/src/lib/netlist/nl_parser.h index 26f9179c040..a36ca39e29e 100644 --- a/src/lib/netlist/nl_parser.h +++ b/src/lib/netlist/nl_parser.h @@ -39,7 +39,7 @@ namespace netlist void net_truthtable_start(const pstring &nlname); /* for debugging messages */ - netlist_base_t &netlist() { return m_setup.netlist(); } + netlist_state_t &netlist() { return m_setup.netlist(); } virtual void verror(const pstring &msg, int line_num, const pstring &line) override; private: diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 9d004c76c28..5e7a0e8933c 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -25,13 +25,12 @@ namespace netlist { -setup_t::setup_t(netlist_base_t &netlist) +setup_t::setup_t(netlist_t &netlist) : m_netlist(netlist) , m_factory(*this) , m_proxy_cnt(0) , m_frontier_cnt(0) { - devices::initialize_factory(m_factory); } setup_t::~setup_t() @@ -45,6 +44,16 @@ setup_t::~setup_t() m_sources.clear(); } +netlist_state_t &setup_t::netlist() +{ + return m_netlist.nlstate(); +} +const netlist_state_t &setup_t::netlist() const +{ + return m_netlist.nlstate(); +} + + pstring setup_t::build_fqn(const pstring &obj_name) const { if (m_namespace_stack.empty()) @@ -381,7 +390,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out) proxy = new_proxy.get(); - netlist().register_dev(std::move(new_proxy)); + m_netlist.nlstate().add_dev(std::move(new_proxy)); } return proxy; } @@ -420,7 +429,7 @@ devices::nld_base_proxy *setup_t::get_a_d_proxy(detail::core_terminal_t &inp) inp.net().m_core_terms.clear(); // clear the list } ret->out().net().add_terminal(inp); - netlist().register_dev(std::move(new_proxy)); + m_netlist.nlstate().add_dev(std::move(new_proxy)); return ret; } } @@ -687,7 +696,7 @@ void setup_t::resolve_inputs() // delete empty nets - netlist().delete_empty_nets(); + delete_empty_nets(); pstring errstr(""); @@ -722,7 +731,7 @@ void setup_t::register_dynamic_log_devices() auto nc = factory().factory_by_name("LOG")->Create(netlist(), name); register_link(name + ".I", ll); log().debug(" dynamic link {1}: <{2}>\n",ll, name); - netlist().register_dev(std::move(nc)); + m_netlist.nlstate().add_dev(std::move(nc)); } } } @@ -944,6 +953,123 @@ void setup_t::register_define(const pstring &defstr) register_define(defstr, "1"); } +// ---------------------------------------------------------------------------------------- +// Device handling +// ---------------------------------------------------------------------------------------- + +void setup_t::delete_empty_nets() +{ + netlist().nets().erase( + std::remove_if(netlist().nets().begin(), netlist().nets().end(), + [](plib::owned_ptr &x) + { + if (x->num_cons() == 0) + { + x->state().log().verbose("Deleting net {1} ...", x->name()); + return true; + } + else + return false; + }), netlist().nets().end()); +} + +// ---------------------------------------------------------------------------------------- +// Run preparation +// ---------------------------------------------------------------------------------------- + +void setup_t::prepare_to_run() +{ + register_dynamic_log_devices(); + + /* load the library ... */ + + /* make sure the solver and parameters are started first! */ + + for (auto & e : m_device_factory) + { + if ( factory().is_class(e.second) + || factory().is_class(e.second)) + { + auto dev = plib::owned_ptr(e.second->Create(netlist(), e.first)); + m_netlist.nlstate().add_dev(std::move(dev)); + } + } + + log().debug("Searching for solver and parameters ...\n"); + + auto solver = netlist().get_single_device("solver"); + netlist().m_params = netlist().get_single_device("parameter"); + + /* create devices */ + + log().debug("Creating devices ...\n"); + for (auto & e : m_device_factory) + { + if ( !factory().is_class(e.second) + && !factory().is_class(e.second)) + { + auto dev = plib::owned_ptr(e.second->Create(netlist(), e.first)); + m_netlist.nlstate().add_dev(std::move(dev)); + } + } + + bool use_deactivate = (netlist().m_params->m_use_deactivate() ? true : false); + + for (auto &d : netlist().devices()) + { + if (use_deactivate) + { + auto p = m_param_values.find(d->name() + ".HINT_NO_DEACTIVATE"); + if (p != m_param_values.end()) + { + //FIXME: check for errors ... + double v = plib::pstonum(p->second); + if (std::abs(v - std::floor(v)) > 1e-6 ) + log().fatal(MF_1_HND_VAL_NOT_SUPPORTED, p->second); + d->set_hint_deactivate(v == 0.0); + } + } + else + d->set_hint_deactivate(false); + } + + /* resolve inputs */ + resolve_inputs(); + + log().verbose("looking for two terms connected to rail nets ..."); + for (auto & t : m_netlist.nlstate().get_device_list()) + { + if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet()) + { + log().warning(MW_3_REMOVE_DEVICE_1_CONNECTED_ONLY_TO_RAILS_2_3, + t->name(), t->m_N.net().name(), t->m_P.net().name()); + t->m_N.net().remove_terminal(t->m_N); + t->m_P.net().remove_terminal(t->m_P); + m_netlist.nlstate().remove_dev(t); + } + } + + log().verbose("initialize solver ...\n"); + + if (solver == nullptr) + { + for (auto &p : netlist().nets()) + if (p->is_analog()) + log().fatal(MF_0_NO_SOLVER); + } + else + solver->post_start(); + + for (auto &n : netlist().nets()) + for (auto & term : n->m_core_terms) + { + //core_device_t *dev = reinterpret_cast(term->m_delegate.object()); + core_device_t *dev = &term->device(); + dev->set_default_delegate(*term); + } + +} + // ---------------------------------------------------------------------------------------- // base sources // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 3b2f5c874a6..193905ed62b 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -12,6 +12,7 @@ #include "plib/putil.h" #include "plib/pstream.h" #include "plib/pparser.h" +#include "plib/pstate.h" #include "nl_factory.h" #include "nl_config.h" @@ -127,7 +128,8 @@ namespace netlist class core_device_t; class param_t; class setup_t; - class netlist_base_t; + class netlist_state_t; + class netlist_t; class logic_family_desc_t; class terminal_t; @@ -204,11 +206,15 @@ namespace netlist using link_t = std::pair; - explicit setup_t(netlist_base_t &netlist); + explicit setup_t(netlist_t &netlist); ~setup_t(); - netlist_base_t &netlist() { return m_netlist; } - const netlist_base_t &netlist() const { return m_netlist; } + + netlist_state_t &netlist(); + const netlist_state_t &netlist() const; + + netlist_t &exec() { return m_netlist; } + const netlist_t &exec() const { return m_netlist; } pstring build_fqn(const pstring &obj_name) const; @@ -301,6 +307,14 @@ namespace netlist /* needed by proxy */ detail::core_terminal_t *find_terminal(const pstring &outname_in, const detail::terminal_type atype, bool required = true); + /* core net handling */ + + void delete_empty_nets(); + + /* run preparation */ + + void prepare_to_run(); + private: detail::core_terminal_t *find_terminal(const pstring &outname_in, bool required = true); @@ -319,7 +333,7 @@ namespace netlist devices::nld_base_proxy *get_d_a_proxy(detail::core_terminal_t &out); devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp); - netlist_base_t &m_netlist; + netlist_t &m_netlist; std::unordered_map m_params; std::vector m_links; factory::list_t m_factory; diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 42de2fbd901..6f68ea18135 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -163,6 +163,8 @@ public: { } + netlist::setup_t &setup() { return nlstate().setup(); } + void read_netlist(const pstring &filename, const pstring &name, const std::vector &logs, const std::vector &defines, @@ -179,15 +181,15 @@ public: setup().register_source(plib::make_unique_base(setup(), filename)); setup().include(name); - log_setup(logs); + create_dynamic_logs(logs); // start devices - this->prepare_to_run(); + setup().prepare_to_run(); // reset this->reset(); } - void log_setup(const std::vector &logs) + void create_dynamic_logs(const std::vector &logs) { log().debug("Creating dynamic logs ...\n"); for (auto & log : logs) @@ -200,15 +202,15 @@ public: std::vector save_state() { - state().pre_save(); + run_state_manager().pre_save(); std::size_t size = 0; - for (auto const & s : state().save_list()) + for (auto const & s : run_state_manager().save_list()) size += s->m_dt.size * s->m_count; std::vector buf(size); char *p = buf.data(); - for (auto const & s : state().save_list()) + for (auto const & s : run_state_manager().save_list()) { std::size_t sz = s->m_dt.size * s->m_count; if (s->m_dt.is_float || s->m_dt.is_integral) @@ -224,7 +226,7 @@ public: void load_state(std::vector &buf) { std::size_t size = 0; - for (auto const & s : state().save_list()) + for (auto const & s : run_state_manager().save_list()) size += s->m_dt.size * s->m_count; if (buf.size() != size) @@ -232,7 +234,7 @@ public: char *p = buf.data(); - for (auto const & s : state().save_list()) + for (auto const & s : run_state_manager().save_list()) { std::size_t sz = s->m_dt.size * s->m_count; if (s->m_dt.is_float || s->m_dt.is_integral) @@ -241,8 +243,8 @@ public: log().fatal("found unsupported save element {1}\n", s->m_name); p += sz; } - state().post_load(); - rebuild_lists(); + run_state_manager().post_load(); + nlstate().rebuild_lists(); } protected: @@ -595,7 +597,7 @@ void tool_app_t::listdevices() nt.setup().include("dummy"); - nt.prepare_to_run(); + nt.setup().prepare_to_run(); std::vector> devs; diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index fd76b88dee8..d43d37eaf18 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -344,13 +344,13 @@ void matrix_solver_t::setup_matrix() { pstring num = plib::pfmt("{1}")(k); - netlist().save(*this, m_terms[k]->m_last_V, "lastV." + num); - netlist().save(*this, m_terms[k]->m_DD_n_m_1, "m_DD_n_m_1." + num); - netlist().save(*this, m_terms[k]->m_h_n_m_1, "m_h_n_m_1." + num); + state().save(*this, m_terms[k]->m_last_V, "lastV." + num); + state().save(*this, m_terms[k]->m_DD_n_m_1, "m_DD_n_m_1." + num); + state().save(*this, m_terms[k]->m_h_n_m_1, "m_h_n_m_1." + num); - netlist().save(*this, m_terms[k]->go(),"GO" + num, m_terms[k]->count()); - netlist().save(*this, m_terms[k]->gt(),"GT" + num, m_terms[k]->count()); - netlist().save(*this, m_terms[k]->Idr(),"IDR" + num , m_terms[k]->count()); + state().save(*this, m_terms[k]->go(),"GO" + num, m_terms[k]->count()); + state().save(*this, m_terms[k]->gt(),"GT" + num, m_terms[k]->count()); + state().save(*this, m_terms[k]->Idr(),"IDR" + num , m_terms[k]->count()); } for (unsigned k=0; k::vsetup(analog_net_t::list_t &nets) t->m_nzrd.push_back(static_cast(N())); } - netlist().save(*this, m_last_RHS, "m_last_RHS"); + state().save(*this, m_last_RHS, "m_last_RHS"); for (std::size_t k = 0; k < N(); k++) - netlist().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k)); + state().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k)); } diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index b49d9e64602..0f5c041061f 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -151,7 +151,7 @@ void matrix_solver_GCR_t::vsetup(analog_net_t::list_t &nets) // FIXME: Move me - if (netlist().lib().isLoaded()) + if (state().lib().isLoaded()) { pstring symname = static_compile_name(); #if 0 @@ -161,7 +161,7 @@ void matrix_solver_GCR_t::vsetup(analog_net_t::list_t &nets) else this->log().warning("External static solver {1} not found ...", symname); #else - m_proc.load(this->netlist().lib(), symname); + m_proc.load(this->state().lib(), symname); if (m_proc.resolved()) this->log().warning("External static solver {1} found ...", symname); else diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index 4b0f6940798..81517fcdc1e 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -122,10 +122,10 @@ void matrix_solver_sm_t::vsetup(analog_net_t::list_t &nets) { matrix_solver_t::setup_base(nets); - netlist().save(*this, m_last_RHS, "m_last_RHS"); + state().save(*this, m_last_RHS, "m_last_RHS"); for (unsigned k = 0; k < N(); k++) - netlist().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k)); + state().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k)); } diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h index ac7ea36a6a7..faaeb50b3d3 100644 --- a/src/lib/netlist/solver/nld_ms_w.h +++ b/src/lib/netlist/solver/nld_ms_w.h @@ -133,10 +133,10 @@ void matrix_solver_w_t::vsetup(analog_net_t::list_t &nets) { matrix_solver_t::setup_base(nets); - netlist().save(*this, m_last_RHS, "m_last_RHS"); + state().save(*this, m_last_RHS, "m_last_RHS"); for (unsigned k = 0; k < N(); k++) - netlist().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k)); + state().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k)); } diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index f7a25fa7fcc..c578dedefbf 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -138,42 +138,42 @@ matrix_solver_t * NETLIB_NAME(solver)::create_solver(std::size_t size, const pst { if (m_method() == "SOR_MAT") { - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); //typedef matrix_solver_SOR_mat_t solver_sor_mat; - //return plib::make_unique(netlist(), solvername, &m_params, size); + //return plib::make_unique(state(), solvername, &m_params, size); } else if (m_method() == "MAT_CR") { if (size > 0) // GCR always outperforms MAT solver { - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } else { - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } } else if (m_method() == "MAT") { - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } else if (m_method() == "SM") { /* Sherman-Morrison Formula */ - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } else if (m_method() == "W") { /* Woodbury Formula */ - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } else if (m_method() == "SOR") { - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } else if (m_method() == "GMRES") { - return create_it>(netlist(), solvername, m_params, size); + return create_it>(state(), solvername, m_params, size); } else { @@ -276,10 +276,10 @@ void NETLIB_NAME(solver)::post_start() net_splitter splitter; - splitter.run(netlist()); + splitter.run(state()); // setup the solvers - log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), netlist().nets().size()); + log().verbose("Found {1} net groups in {2} nets\n", splitter.groups.size(), state().nets().size()); for (auto & grp : splitter.groups) { matrix_solver_t *ms; @@ -291,13 +291,13 @@ void NETLIB_NAME(solver)::post_start() #if 1 case 1: if (use_specific) - ms = plib::palloc(netlist(), sname, &m_params); + ms = plib::palloc(state(), sname, &m_params); else ms = create_solver<1,1>(1, sname); break; case 2: if (use_specific) - ms = plib::palloc(netlist(), sname, &m_params); + ms = plib::palloc(state(), sname, &m_params); else ms = create_solver<2,2>(2, sname); break; -- cgit v1.2.3-70-g09d2 From 17d32e0bd5b98761fea3e1f42f73bdb8d197ea69 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 19 Jan 2019 18:17:35 +0100 Subject: netlist: pstream and ppreprocessor (now a pistream) refactoring. (nw) --- src/lib/netlist/nl_parser.cpp | 11 ++- src/lib/netlist/nl_parser.h | 8 ++- src/lib/netlist/nl_setup.cpp | 21 ++---- src/lib/netlist/nl_setup.h | 2 +- src/lib/netlist/plib/pparser.cpp | 33 ++++----- src/lib/netlist/plib/pparser.h | 53 ++++++++++++--- src/lib/netlist/plib/pstream.cpp | 20 ++---- src/lib/netlist/plib/pstream.h | 128 ++++++++++++++++++++--------------- src/lib/netlist/prg/nlwav.cpp | 27 ++++---- src/lib/netlist/tools/nl_convert.cpp | 26 ++++--- 10 files changed, 182 insertions(+), 147 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index a2ab7623b3b..460ff3819bf 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -24,14 +24,13 @@ void parser_t::verror(const pstring &msg, int line_num, const pstring &line) //throw error; } - bool parser_t::parse(const pstring &nlname) { - set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-"); - set_number_chars(".0123456789", "0123456789eE-."); //FIXME: processing of numbers - //set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13)); - set_whitespace(pstring("") + ' ' + static_cast(9) + static_cast(10) + static_cast(13)); - set_comment("/*", "*/", "//"); + this->identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-") + .number_chars(".0123456789", "0123456789eE-.") //FIXME: processing of numbers + //set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13)); + .whitespace(pstring("") + ' ' + static_cast(9) + static_cast(10) + static_cast(13)) + .comment("/*", "*/", "//"); m_tok_param_left = register_token("("); m_tok_param_right = register_token(")"); m_tok_comma = register_token(","); diff --git a/src/lib/netlist/nl_parser.h b/src/lib/netlist/nl_parser.h index a36ca39e29e..f14250ea7d1 100644 --- a/src/lib/netlist/nl_parser.h +++ b/src/lib/netlist/nl_parser.h @@ -16,8 +16,12 @@ namespace netlist class parser_t : public plib::ptokenizer { public: - parser_t(plib::putf8_reader &&strm, setup_t &setup) - : plib::ptokenizer(std::move(strm)), m_setup(setup) {} + template + parser_t(T &&strm, setup_t &setup) + : plib::ptokenizer(std::move(strm)) + , m_setup(setup) + { + } bool parse(const pstring &nlname = ""); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 5e7a0e8933c..67a8afe94b9 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -907,6 +907,11 @@ void setup_t::tt_factory_create(tt_desc &desc, const pstring &sourcefile) // Sources // ---------------------------------------------------------------------------------------- +bool setup_t::parse_stream(std::unique_ptr istrm, const pstring &name) +{ + return parser_t(std::move(plib::ppreprocessor(&m_defines).process(std::move(istrm))), *this).parse(name); +} + void setup_t::include(const pstring &netlist_name) { for (auto &source : m_sources) @@ -932,18 +937,6 @@ std::unique_ptr setup_t::get_data_stream(const pstring &name) return std::unique_ptr(nullptr); } - -bool setup_t::parse_stream(plib::putf8_reader &&istrm, const pstring &name) -{ - plib::pomemstream ostrm; - plib::putf8_writer owrt(&ostrm); - - plib::ppreprocessor(&m_defines).process(istrm, owrt); - plib::putf8_reader reader2 = plib::putf8_reader(plib::pimemstream(ostrm)); - - return parser_t(std::move(reader2), *this).parse(name); -} - void setup_t::register_define(const pstring &defstr) { auto p = defstr.find("="); @@ -1080,9 +1073,7 @@ bool source_t::parse(const pstring &name) return false; else { - auto rstream = stream(name); - plib::putf8_reader reader(rstream.get()); - return m_setup.parse_stream(std::move(reader), name); + return m_setup.parse_stream(stream(name), name); } } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 193905ed62b..53efe523bcc 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -265,7 +265,7 @@ namespace netlist std::unique_ptr get_data_stream(const pstring &name); - bool parse_stream(plib::putf8_reader &&istrm, const pstring &name); + bool parse_stream(std::unique_ptr istrm, const pstring &name); /* register a source */ diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 43ed9e14d41..f7b7c7bae36 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -16,11 +16,6 @@ namespace plib { // A simple tokenizer // ---------------------------------------------------------------------------------------- -ptokenizer::ptokenizer(plib::putf8_reader &&strm) -: m_strm(std::move(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"') -{ -} - ptokenizer::~ptokenizer() { } @@ -274,7 +269,11 @@ void ptokenizer::error(const pstring &errs) // ---------------------------------------------------------------------------------------- ppreprocessor::ppreprocessor(std::vector *defines) -: m_ifflag(0), m_level(0), m_lineno(0) +: pistream() +, m_ifflag(0) +, m_level(0) +, m_lineno(0) +, m_pos(0) { m_expr_sep.push_back("!"); m_expr_sep.push_back("("); @@ -304,6 +303,18 @@ void ppreprocessor::error(const pstring &err) throw pexception("PREPRO ERROR: " + err); } +pstream::size_type ppreprocessor::vread(value_type *buf, const pstream::size_type n) +{ + size_type bytes = std::min(m_buf.size() - m_pos, n); + + if (bytes==0) + return 0; + + std::memcpy(buf, m_buf.c_str() + m_pos, bytes); + m_pos += bytes; + return bytes; +} + #define CHECKTOK2(p_op, p_prio) \ else if (tok == # p_op) \ { \ @@ -462,15 +473,5 @@ pstring ppreprocessor::process_line(const pstring &line) } -void ppreprocessor::process(putf8_reader &istrm, putf8_writer &ostrm) -{ - pstring line; - while (istrm.readline(line)) - { - m_lineno++; - line = process_line(line); - ostrm.writeline(line); - } -} } diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 17f43284e2c..36ecd02e017 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -19,7 +19,11 @@ namespace plib { class ptokenizer : nocopyassignmove { public: - ptokenizer(plib::putf8_reader &&strm); + template + ptokenizer(T &&strm) + : m_strm(std::move(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"') + { + } virtual ~ptokenizer(); @@ -98,15 +102,16 @@ public: return ret; } - void set_identifier_chars(pstring s) { m_identifier_chars = s; } - void set_number_chars(pstring st, pstring rem) { m_number_chars_start = st; m_number_chars = rem; } - void set_string_char(pstring::value_type c) { m_string = c; } - void set_whitespace(pstring s) { m_whitespace = s; } - void set_comment(pstring start, pstring end, pstring line) + ptokenizer & identifier_chars(pstring s) { m_identifier_chars = s; return *this; } + ptokenizer & number_chars(pstring st, pstring rem) { m_number_chars_start = st; m_number_chars = rem; return *this; } + ptokenizer & string_char(pstring::value_type c) { m_string = c; return *this; } + ptokenizer & whitespace(pstring s) { m_whitespace = s; return *this; } + ptokenizer & comment(pstring start, pstring end, pstring line) { m_tok_comment_start = register_token(start); m_tok_comment_end = register_token(end); m_tok_line_comment = register_token(line); + return *this; } token_t get_token_internal(); @@ -145,7 +150,7 @@ private: }; -class ppreprocessor : plib::nocopyassignmove +class ppreprocessor : public pistream { public: @@ -159,11 +164,39 @@ public: }; explicit ppreprocessor(std::vector *defines = nullptr); - virtual ~ppreprocessor() {} + virtual ~ppreprocessor() override {} - void process(putf8_reader &istrm, putf8_writer &ostrm); + template + ppreprocessor & process(T &&istrm) + { + putf8_reader reader(std::move(istrm)); + pstring line; + while (reader.readline(line)) + { + m_lineno++; + line = process_line(line); + m_buf += decltype(m_buf)(line.c_str()) + static_cast(10); + } + return *this; + } + + ppreprocessor(ppreprocessor &&s) + : m_defines(s.m_defines) + , m_expr_sep(s.m_expr_sep) + , m_ifflag(s.m_ifflag) + , m_level(s.m_level) + , m_lineno(s.m_lineno) + , m_buf(s.m_buf) + , m_pos(s.m_pos) + { + } protected: + + virtual size_type vread(value_type *buf, const size_type n) override; + virtual void vseek(const pos_type n) override { } + virtual pos_type vtell() const override { return m_pos; } + int expr(const std::vector &sexpr, std::size_t &start, int prio); define_t *get_define(const pstring &name); pstring replace_macros(const pstring &line); @@ -179,6 +212,8 @@ private: std::uint_least64_t m_ifflag; // 31 if levels int m_level; int m_lineno; + pstring_t m_buf; + pos_type m_pos; }; } diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp index e0094e99e38..9c99438811c 100644 --- a/src/lib/netlist/plib/pstream.cpp +++ b/src/lib/netlist/plib/pstream.cpp @@ -29,18 +29,10 @@ pstream::~pstream() // pistream: input stream // ----------------------------------------------------------------------------- -pistream::~pistream() -{ -} - // ----------------------------------------------------------------------------- // postream: output stream // ----------------------------------------------------------------------------- -postream::~postream() -{ -} - // ----------------------------------------------------------------------------- // Input file stream // ----------------------------------------------------------------------------- @@ -83,7 +75,7 @@ pifilestream::~pifilestream() } } -pifilestream::pos_type pifilestream::vread(void *buf, const pos_type n) +pifilestream::pos_type pifilestream::vread(value_type *buf, const pos_type n) { pos_type r = fread(buf, 1, n, static_cast(m_file)); if (r < n) @@ -172,7 +164,7 @@ pofilestream::~pofilestream() } } -void pofilestream::vwrite(const void *buf, const pos_type n) +void pofilestream::vwrite(const value_type *buf, const pos_type n) { std::size_t r = fwrite(buf, 1, n, static_cast(m_file)); if (r < n) @@ -269,13 +261,13 @@ pimemstream::~pimemstream() { } -pimemstream::pos_type pimemstream::vread(void *buf, const pos_type n) +pimemstream::pos_type pimemstream::vread(value_type *buf, const pos_type n) { pos_type ret = (m_pos + n <= m_len) ? n : m_len - m_pos; if (ret > 0) { - std::copy(m_mem + m_pos, m_mem + m_pos + ret, static_cast(buf)); + std::copy(m_mem + m_pos, m_mem + m_pos + ret, reinterpret_cast(buf)); m_pos += ret; } @@ -317,7 +309,7 @@ pomemstream::~pomemstream() pfree_array(m_mem); } -void pomemstream::vwrite(const void *buf, const pos_type n) +void pomemstream::vwrite(const value_type *buf, const pos_type n) { if (m_pos + n >= m_capacity) { @@ -333,7 +325,7 @@ void pomemstream::vwrite(const void *buf, const pos_type n) pfree_array(o); } - std::copy(static_cast(buf), static_cast(buf) + n, m_mem + m_pos); + std::copy(buf, buf + n, m_mem + m_pos); m_pos += n; m_size = std::max(m_pos, m_size); } diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index e8b6c38ac66..cc86a1a39ea 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -61,6 +61,9 @@ public: } protected: + pstream() : m_flags(0) + { + } explicit pstream(const unsigned flags) : m_flags(flags) { } @@ -93,52 +96,62 @@ private: // pistream: input stream // ----------------------------------------------------------------------------- -class pistream : public pstream +template +class pistream_base : public pstream { public: - virtual ~pistream(); + typedef T value_type; + + virtual ~pistream_base() { } bool eof() const { return ((flags() & FLAG_EOF) != 0); } - pos_type read(void *buf, const pos_type n) + pos_type read(T *buf, const pos_type n) { return vread(buf, n); } protected: - explicit pistream(const unsigned flags) : pstream(flags) {} - explicit pistream(pistream &&src) : pstream(std::move(src)) {} + pistream_base() : pstream(0) {} + explicit pistream_base(const unsigned flags) : pstream(flags) {} + explicit pistream_base(pistream_base &&src) : pstream(std::move(src)) {} /* read up to n bytes from stream */ - virtual size_type vread(void *buf, const size_type n) = 0; - + virtual size_type vread(T *buf, const size_type n) = 0; }; +typedef pistream_base pistream; + // ----------------------------------------------------------------------------- // postream: output stream // ----------------------------------------------------------------------------- #if !USE_CSTREAM -class postream : public pstream +template +class postream_base : public pstream { public: - virtual ~postream(); + typedef T value_type; + + virtual ~postream_base() { } - void write(const char *buf, const size_type n) + void write(const T *buf, const size_type n) { vwrite(buf, n); } protected: - explicit postream(unsigned flags) : pstream(flags) {} - explicit postream(postream &&src) : pstream(std::move(src)) {} + explicit postream_base(unsigned flags) : pstream(flags) {} + explicit postream_base(postream_base &&src) : pstream(std::move(src)) {} /* write n bytes to stream */ - virtual void vwrite(const void *buf, const size_type n) = 0; + virtual void vwrite(const T *buf, const size_type n) = 0; private: }; +typedef postream_base postream; + // ----------------------------------------------------------------------------- // pomemstream: output string stream // ----------------------------------------------------------------------------- @@ -166,7 +179,7 @@ public: protected: /* write n bytes to stream */ - virtual void vwrite(const void *buf, const pos_type) override; + virtual void vwrite(const value_type *buf, const pos_type) override; virtual void vseek(const pos_type n) override; virtual pos_type vtell() const override; @@ -193,9 +206,9 @@ public: protected: /* write n bytes to stream */ - virtual void vwrite(const void *buf, const pos_type n) override + virtual void vwrite(const value_type *buf, const pos_type n) override { - m_buf += pstring(static_cast(buf), n); + m_buf += pstring(reinterpret_cast(buf), n); } virtual void vseek(const pos_type n) override { } virtual pos_type vtell() const override { return m_buf.size(); } @@ -229,7 +242,7 @@ public: protected: pofilestream(void *file, const pstring &name, const bool do_close); /* write n bytes to stream */ - virtual void vwrite(const void *buf, const pos_type n) override; + virtual void vwrite(const value_type *buf, const pos_type n) override; virtual void vseek(const pos_type n) override; virtual pos_type vtell() const override; @@ -291,7 +304,7 @@ protected: pifilestream(void *file, const pstring &name, const bool do_close); /* read up to n bytes from stream */ - virtual pos_type vread(void *buf, const pos_type n) override; + virtual pos_type vread(value_type *buf, const pos_type n) override; virtual void vseek(const pos_type n) override; virtual pos_type vtell() const override; @@ -350,7 +363,7 @@ protected: } /* read up to n bytes from stream */ - virtual pos_type vread(void *buf, const pos_type n) override; + virtual pos_type vread(value_type *buf, const pos_type n) override; virtual void vseek(const pos_type n) override; virtual pos_type vtell() const override; @@ -391,65 +404,68 @@ private: /* this digests linux & dos/windows text files */ + +template +struct constructor_helper +{ + std::unique_ptr operator()(T &&s) { return std::move(plib::make_unique(std::move(s))); } +}; + class putf8_reader : plib::nocopyassign { public: - putf8_reader(pistream *strm) : m_strm(strm), m_stream_owned(false) {} - virtual ~putf8_reader() - { - if (m_stream_owned && m_strm != nullptr) - pfree(m_strm); - } - putf8_reader(putf8_reader &&src) : m_strm(src.m_strm), m_stream_owned(src.m_stream_owned) + virtual ~putf8_reader() { - src.m_strm = nullptr; - src.m_stream_owned = false; } - putf8_reader(pimemstream &&strm) - : m_strm(palloc(std::move(strm))), - m_stream_owned(true) - {} - - putf8_reader(pifilestream &&strm) - : m_strm(palloc(std::move(strm))), - m_stream_owned(true) - {} + template + friend struct constructor_helper; - putf8_reader(pistringstream &&strm) - : m_strm(palloc(std::move(strm))), - m_stream_owned(true) + template + putf8_reader(T &&strm) + : m_strm(std::move(constructor_helper()(std::move(strm)))) {} - bool eof() const { return m_strm->eof(); } bool readline(pstring &line); - bool readbyte1(char &b) + bool readbyte1(pistream::value_type &b) { return (m_strm->read(&b, 1) == 1); } bool readcode(putf8string::traits_type::code_t &c) { - char b[4]; + pistream::value_type b[4]; if (m_strm->read(&b[0], 1) != 1) return false; - const std::size_t l = putf8string::traits_type::codelen(b); + const std::size_t l = putf8string::traits_type::codelen(reinterpret_cast(&b)); for (std::size_t i = 1; i < l; i++) if (m_strm->read(&b[i], 1) != 1) return false; - c = putf8string::traits_type::code(b); + c = putf8string::traits_type::code(reinterpret_cast(&b)); return true; } private: - pistream *m_strm; - bool m_stream_owned; + std::unique_ptr m_strm; putf8string m_linebuf; }; +template <> +struct constructor_helper +{ + std::unique_ptr operator()(putf8_reader &&s) { return std::move(s.m_strm); } +}; + +template <> +struct constructor_helper> +{ + std::unique_ptr operator()(std::unique_ptr &&s) { return std::move(s); } +}; + + // ----------------------------------------------------------------------------- // putf8writer_t: writer on top of ostream // ----------------------------------------------------------------------------- @@ -471,7 +487,7 @@ public: void write(const pstring &text) const { putf8string conv_utf8(text); - m_strm->write(conv_utf8.c_str(), conv_utf8.mem_t_size()); + m_strm->write(reinterpret_cast(conv_utf8.c_str()), conv_utf8.mem_t_size()); } void write(const pstring::value_type c) const @@ -516,13 +532,13 @@ public: template void write(const T &val) { - m_strm.write(reinterpret_cast(&val), sizeof(T)); + m_strm.write(reinterpret_cast(&val), sizeof(T)); } void write(const pstring &s) { - const char *sm = s.c_str(); - const std::size_t sl = std::strlen(sm); + const postream::value_type *sm = reinterpret_cast(s.c_str()); + const std::size_t sl = std::strlen(s.c_str()); write(sl); m_strm.write(sm, sl); } @@ -532,7 +548,7 @@ public: { std::size_t sz = val.size(); write(sz); - m_strm.write(val.data(), sizeof(T) * sz); + m_strm.write(reinterpret_cast(val.data()), sizeof(T) * sz); } private: @@ -549,7 +565,7 @@ public: template void read(T &val) { - m_strm.read(&val, sizeof(T)); + m_strm.read(reinterpret_cast(&val), sizeof(T)); } void read( pstring &s) @@ -557,7 +573,7 @@ public: std::size_t sz = 0; read(sz); plib::string_info::mem_t *buf = new plib::string_info::mem_t[sz+1]; - m_strm.read(buf, sz); + m_strm.read(reinterpret_cast(buf), sz); buf[sz] = 0; s = pstring(buf); delete [] buf; @@ -569,7 +585,7 @@ public: std::size_t sz = 0; read(sz); val.resize(sz); - m_strm.read(val.data(), sizeof(T) * sz); + m_strm.read(reinterpret_cast(val.data()), sizeof(T) * sz); } private: @@ -578,7 +594,7 @@ private: inline void copystream(postream &dest, pistream &src) { - char buf[1024]; + postream::value_type buf[1024]; pstream::pos_type r; while ((r=src.read(buf, 1024)) > 0) dest.write(buf, r); diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 1bc3505c206..361b1db5195 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -82,7 +82,7 @@ public: template void write(const T &val) { - m_f.write(reinterpret_cast(&val), sizeof(T)); + m_f.write(reinterpret_cast(&val), sizeof(T)); } void write_sample(int sample) @@ -153,11 +153,11 @@ class log_processor { public: typedef plib::pmfp callback_type; - log_processor(plib::pistream &is, callback_type cb) : m_is(is), m_cb(cb) { } + log_processor(callback_type cb) : m_cb(cb) { } - void process() + void process(std::unique_ptr &&is) { - plib::putf8_reader reader(&m_is); + plib::putf8_reader reader(std::move(is)); pstring line; while(reader.readline(line)) @@ -169,7 +169,6 @@ public: } private: - plib::pistream &m_is; callback_type m_cb; }; @@ -254,8 +253,10 @@ private: void nlwav_app::convert(long sample_rate) { plib::postream *fo = (opt_out() == "-" ? &pout_strm : plib::palloc(opt_out())); - plib::pistream *fin = (opt_inp() == "-" ? &pin_strm : plib::palloc(opt_inp())); - plib::putf8_reader reader(fin); + std::unique_ptr fin = (opt_inp() == "-" ? + plib::make_unique() + : plib::make_unique(opt_inp())); + plib::putf8_reader reader(std::move(fin)); wav_t *wo = plib::palloc(*fo, static_cast(sample_rate)); double dt = 1.0 / static_cast(wo->sample_rate()); @@ -324,8 +325,6 @@ void nlwav_app::convert(long sample_rate) #endif } plib::pfree(wo); - if (opt_inp() != "-") - plib::pfree(fin); if (opt_out() != "-") plib::pfree(fo); @@ -341,15 +340,17 @@ void nlwav_app::convert(long sample_rate) void nlwav_app::convert1(long sample_rate) { plib::postream *fo = (opt_out() == "-" ? &pout_strm : plib::palloc(opt_out())); - plib::pistream *fin = (opt_inp() == "-" ? &pin_strm : plib::palloc(opt_inp())); + std::unique_ptr fin = (opt_inp() == "-" ? + plib::make_unique() + : plib::make_unique(opt_inp())); double dt = 1.0 / static_cast(sample_rate); wavwriter *wo = plib::palloc(*fo, static_cast(sample_rate), opt_amp()); aggregator ag(dt, aggregator::callback_type(&wavwriter::process, wo)); - log_processor lp(*fin, log_processor::callback_type(&aggregator::process, &ag)); + log_processor lp(log_processor::callback_type(&aggregator::process, &ag)); - lp.process(); + lp.process(std::move(fin)); if (!opt_quiet()) { @@ -360,8 +361,6 @@ void nlwav_app::convert1(long sample_rate) } plib::pfree(wo); - if (opt_inp() != "-") - plib::pfree(fin); if (opt_out() != "-") plib::pfree(fo); diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 52665ce1f78..998ebf53c7e 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -405,13 +405,12 @@ nl_convert_eagle_t::tokenizer::tokenizer(nl_convert_eagle_t &convert, plib::putf : plib::ptokenizer(std::move(strm)) , m_convert(convert) { - set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-"); - set_number_chars(".0123456789", "0123456789eE-."); //FIXME: processing of numbers - //set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13)); - set_whitespace(pstring("") + ' ' + static_cast(9) + static_cast(10) + static_cast(13)); - /* FIXME: gnetlist doesn't print comments */ - set_comment("/*", "*/", "//"); - set_string_char('\''); + this->identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-") + .number_chars(".0123456789", "0123456789eE-.") //FIXME: processing of numbers + .whitespace(pstring("") + ' ' + static_cast(9) + static_cast(10) + static_cast(13)) + /* FIXME: gnetlist doesn't print comments */ + .comment("/*", "*/", "//") + .string_char('\''); m_tok_ADD = register_token("ADD"); m_tok_VALUE = register_token("VALUE"); m_tok_SIGNAL = register_token("SIGNAL"); @@ -542,13 +541,12 @@ nl_convert_rinf_t::tokenizer::tokenizer(nl_convert_rinf_t &convert, plib::putf8_ : plib::ptokenizer(std::move(strm)) , m_convert(convert) { - set_identifier_chars(".abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-"); - set_number_chars("0123456789", "0123456789eE-."); //FIXME: processing of numbers - //set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13)); - set_whitespace(pstring("") + ' ' + static_cast(9) + static_cast(10) + static_cast(13)); - /* FIXME: gnetlist doesn't print comments */ - set_comment("","","//"); // FIXME:needs to be confirmed - set_string_char('"'); + this->identifier_chars(".abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-") + .number_chars("0123456789", "0123456789eE-.") //FIXME: processing of numbers + .whitespace(pstring("") + ' ' + static_cast(9) + static_cast(10) + static_cast(13)) + /* FIXME: gnetlist doesn't print comments */ + .comment("","","//") // FIXME:needs to be confirmed + .string_char('"'); m_tok_HEA = register_token(".HEA"); m_tok_APP = register_token(".APP"); m_tok_TIM = register_token(".TIM"); -- cgit v1.2.3-70-g09d2 From f9f341f4d6341f345012e3523e039a8242c601e1 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 2 Feb 2019 14:56:56 +0100 Subject: netlist: fix some issues. (nw) --- src/lib/netlist/macro/nlm_ttl74xx.cpp | 5 ++- src/lib/netlist/nl_lists.h | 4 +- src/lib/netlist/nl_setup.cpp | 39 ++++++++++++++++++-- src/lib/netlist/nl_setup.h | 17 +++++---- src/lib/netlist/prg/nltool.cpp | 69 ++++++++++++++++------------------- 5 files changed, 82 insertions(+), 52 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/lib/netlist/macro/nlm_ttl74xx.cpp b/src/lib/netlist/macro/nlm_ttl74xx.cpp index df1b873a468..6fef8253224 100644 --- a/src/lib/netlist/macro/nlm_ttl74xx.cpp +++ b/src/lib/netlist/macro/nlm_ttl74xx.cpp @@ -825,8 +825,9 @@ NETLIST_END() NETLIST_START(TTL74XX_lib) - NET_MODEL("DM7414 SCHMITT_TRIGGER(VTP=1.7 VTM=0.9 VI=4.35 RI=6.15k VOH=3.5 ROH=120 VOL=0.1 ROL=37.5 TPLH=15 TPHL=15)") - NET_MODEL("DM74LS14 SCHMITT_TRIGGER(VTP=1.6 VTM=0.8 VI=4.4 RI=19.3k VOH=3.45 ROH=130 VOL=0.1 ROL=31.2 TPLH=15 TPHL=15)") + NET_MODEL("DM7414 SCHMITT_TRIGGER(VTP=1.7 VTM=0.9 VI=4.35 RI=6.15k VOH=3.5 ROH=120 VOL=0.1 ROL=37.5 TPLH=15 TPHL=15)") + NET_MODEL("TTL_7414_GATE SCHMITT_TRIGGER(VTP=1.7 VTM=0.9 VI=4.35 RI=6.15k VOH=3.5 ROH=120 VOL=0.1 ROL=37.5 TPLH=15 TPHL=15)") + NET_MODEL("DM74LS14 SCHMITT_TRIGGER(VTP=1.6 VTM=0.8 VI=4.4 RI=19.3k VOH=3.45 ROH=130 VOL=0.1 ROL=31.2 TPLH=15 TPHL=15)") //NET_MODEL("DM7414 FAMILY(FV=5 IVL=0.16 IVH=0.4 OVL=0.1 OVH=0.05 ORL=10.0 ORH=1.0e8)") diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 116af2d5cd0..924dfb19e39 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -136,9 +136,7 @@ namespace netlist { if (QueueOp::equal(*i, elem)) { - --m_end; - for (;i < m_end; ++i) - *i = std::move(*(i+1)); + std::copy(i+1, m_end--, i); return; } } diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 67a8afe94b9..291e95add83 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -295,6 +295,42 @@ const pstring setup_t::resolve_alias(const pstring &name) const return ret; } +std::vector setup_t::get_terminals_for_device_name(const pstring &devname) +{ + std::vector terms; + for (auto & t : m_terminals) + { + if (plib::startsWith(t.second->name(), devname)) + { + pstring tn(t.second->name().substr(devname.length()+1)); + if (tn.find(".") == pstring::npos) + terms.push_back(tn); + } + } + + for (auto & t : m_alias) + { + if (plib::startsWith(t.first, devname)) + { + pstring tn(t.first.substr(devname.length()+1)); + //printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), tn.c_str()); + if (tn.find(".") == pstring::npos) + { + terms.push_back(tn); + pstring resolved = resolve_alias(t.first); + //printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), resolved.c_str()); + if (resolved != t.first) + { + auto found = std::find(terms.begin(), terms.end(), resolved.substr(devname.length()+1)); + if (found!=terms.end()) + terms.erase(found); + } + } + } + } + return terms; +} + detail::core_terminal_t *setup_t::find_terminal(const pstring &terminal_in, bool required) { const pstring &tname = resolve_alias(terminal_in); @@ -371,9 +407,6 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out) auto new_proxy = out_cast.logic_family()->create_d_a_proxy(netlist(), x, &out_cast); m_proxy_cnt++; - - //new_proxy->start_dev(); - /* connect all existing terminals to new net */ for (auto & p : out.net().m_core_terms) diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 174147af01c..4becfe1ee0c 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -294,16 +294,12 @@ namespace netlist /* helper - also used by nltool */ const pstring resolve_alias(const pstring &name) const; + /* needed by nltool */ + std::vector get_terminals_for_device_name(const pstring &devname); + log_type &log(); const log_type &log() const; - //std::vector> m_device_factory; - std::unordered_map m_device_factory; - - std::unordered_map m_alias; - std::unordered_map m_param_values; - std::unordered_map m_terminals; - /* needed by proxy */ detail::core_terminal_t *find_terminal(const pstring &outname_in, const detail::terminal_type atype, bool required = true); @@ -333,6 +329,13 @@ namespace netlist devices::nld_base_proxy *get_d_a_proxy(detail::core_terminal_t &out); devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp); + //std::vector> m_device_factory; + std::unordered_map m_device_factory; + + std::unordered_map m_alias; + std::unordered_map m_param_values; + std::unordered_map m_terminals; + netlist_t &m_netlist; std::unordered_map m_params; std::vector m_links; diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index f77a5966b0e..3c9839a7845 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -31,21 +31,30 @@ public: opt_quiet(*this, "q", "quiet", "be quiet - no warnings"), opt_version(*this, "", "version", "display version and exit"), opt_help(*this, "h", "help", "display help and exit"), + opt_grp2(*this, "Options for run and static commands", "These options apply to run and static commands."), opt_name(*this, "n", "name", "", "the netlist in file specified by ""-f"" option to run; default is first one"), + opt_grp3(*this, "Options for run command", "These options are only used by the run command."), opt_ttr (*this, "t", "time_to_run", 1.0, "time to run the emulation (seconds)"), opt_logs(*this, "l", "log" , "define terminal to log. This option may be specified repeatedly."), opt_inp(*this, "i", "input", "", "input file to process (default is none)"), opt_loadstate(*this,"", "loadstate", "", "load state from file and continue from there"), opt_savestate(*this,"", "savestate", "", "save state to file at end of run"), + opt_grp4(*this, "Options for convert command", "These options are only used by the convert command."), opt_type(*this, "y", "type", 0, std::vector({"spice","eagle","rinf"}), "type of file to be converted: spice,eagle,rinf"), + opt_grp5(*this, "Options for header command", "These options are only used by the header command."), + opt_tabwidth(*this, "", "tab-width", 4, "Tab width for output."), + opt_linewidth(*this,"", "line-width", 72, "Line width for output."), + opt_ex1(*this, "nltool -c run -t 3.5 -f nl_examples/cdelay.c -n cap_delay", "Run netlist \"cap_delay\" from file nl_examples/cdelay.c for 3.5 seconds"), opt_ex2(*this, "nltool --cmd=listdevices", - "List all known devices.") + "List all known devices."), + opt_ex3(*this, "nltool --cmd=header --tab-width=8 --line-width=80", + "Create the header file needed for including netlists as code.") {} plib::option_group opt_grp1; @@ -67,8 +76,12 @@ public: plib::option_str opt_savestate; plib::option_group opt_grp4; plib::option_str_limit opt_type; + plib::option_group opt_grp5; + plib::option_num opt_tabwidth; + plib::option_num opt_linewidth; plib::option_example opt_ex1; plib::option_example opt_ex2; + plib::option_example opt_ex3; int execute(); pstring usage(); @@ -261,7 +274,6 @@ void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls throw netlist::nl_exception(err); } - struct input_t { input_t(const netlist::setup_t &setup, const pstring &line) @@ -429,13 +441,26 @@ void tool_app_t::static_compile() void tool_app_t::mac_out(const pstring &s, const bool cont) { - static constexpr unsigned RIGHT = 72; if (cont) { - unsigned adj = 0; + unsigned pos = 0; + pstring r; for (const auto &x : s) - adj += (x == '\t' ? 3 : 0); - pout("{1}\\\n", plib::rpad(s, pstring(" "), RIGHT-1-adj)); + { + if (x == '\t') + { + auto pos_mod_4 = pos % opt_tabwidth(); + auto tab_adj = opt_tabwidth() - pos_mod_4; + r += plib::rpad(pstring(""), pstring(" "), tab_adj); + pos += tab_adj; + } + else + { + r += x; + pos++; + } + } + pout("{1}\\\n", plib::rpad(r, pstring(" "), opt_linewidth()-1)); } else pout("{1}\n", s); @@ -604,42 +629,12 @@ void tool_app_t::listdevices() for (auto & f : list) { pstring out = plib::pfmt("{1:-20} {2}(")(f->classname())(f->name()); - std::vector terms; f->macro_actions(nt.setup().netlist(), f->name() + "_lc"); auto d = f->Create(nt.setup().netlist(), f->name() + "_lc"); // get the list of terminals ... - for (auto & t : nt.setup().m_terminals) - { - if (plib::startsWith(t.second->name(), d->name())) - { - pstring tn(t.second->name().substr(d->name().length()+1)); - if (tn.find(".") == pstring::npos) - terms.push_back(tn); - } - } - - for (auto & t : nt.setup().m_alias) - { - if (plib::startsWith(t.first, d->name())) - { - pstring tn(t.first.substr(d->name().length()+1)); - //printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), tn.c_str()); - if (tn.find(".") == pstring::npos) - { - terms.push_back(tn); - pstring resolved = nt.setup().resolve_alias(t.first); - //printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), resolved.c_str()); - if (resolved != t.first) - { - auto found = std::find(terms.begin(), terms.end(), resolved.substr(d->name().length()+1)); - if (found!=terms.end()) - terms.erase(found); - } - } - } - } + std::vector terms(nt.setup().get_terminals_for_device_name(d->name())); out += "," + f->param_desc(); for (auto p : plib::psplit(f->param_desc(),",") ) -- cgit v1.2.3-70-g09d2 From c87a487d6de35479210d36dcf53d2c96a478601a Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 4 Feb 2019 00:27:23 +0100 Subject: netlist: Refactoring and some functionality enhancements. (nw) - Removed dead code. - nltool now adds a define NLTOOL_VERSION. This can be tested in netlists. It is used in kidniki to ensure I stop committing debug parameters. - Optimized the proposal for no-deactivate hints. - Documented in breakout that hints were manually optimized. - Minor optimizations in the order of 2% enhancement. --- src/devices/machine/netlist.cpp | 6 +-- src/devices/machine/netlist.h | 1 - src/lib/netlist/devices/nld_9310.cpp | 31 +++++++------- src/lib/netlist/devices/nld_9316.cpp | 34 +++++----------- src/lib/netlist/devices/nld_system.cpp | 23 +++++++++++ src/lib/netlist/devices/nlid_system.h | 15 +++---- src/lib/netlist/devices/nlid_truthtable.h | 4 +- src/lib/netlist/nl_base.cpp | 68 ++++++++++--------------------- src/lib/netlist/nl_base.h | 59 +++++++++++++++++++++------ src/lib/netlist/nl_setup.cpp | 11 ++--- src/lib/netlist/nl_setup.h | 13 ++++-- src/lib/netlist/plib/plists.h | 3 +- src/lib/netlist/plib/poptions.cpp | 6 +-- src/lib/netlist/plib/poptions.h | 26 ++++++------ src/lib/netlist/plib/pparser.cpp | 14 +++---- src/lib/netlist/plib/pparser.h | 6 ++- src/lib/netlist/plib/pstate.cpp | 4 +- src/lib/netlist/plib/pstate.h | 4 +- src/lib/netlist/plib/putil.h | 4 ++ src/lib/netlist/prg/nltool.cpp | 21 ++++++---- src/lib/netlist/prg/nlwav.cpp | 10 ++--- src/mame/audio/nl_kidniki.cpp | 9 ++++ src/mame/machine/nl_breakout.cpp | 47 ++++++++++++++++++--- 23 files changed, 250 insertions(+), 169 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 6795dcb9d6a..fc76132a731 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -301,7 +301,7 @@ public: { int pos = (upto - m_last_buffer_time) / m_sample_time; if (pos > m_bufsize) - state().log().fatal("sound {1}: pos {2} exceeded bufsize {3}\n", name().c_str(), pos, m_bufsize); + throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), pos, m_bufsize); while (m_last_pos < pos ) { m_buffer[m_last_pos++] = (stream_sample_t) m_cur; @@ -1050,10 +1050,8 @@ ATTR_COLD uint64_t netlist_mame_cpu_device::execute_cycles_to_clocks(uint64_t cy ATTR_HOT void netlist_mame_cpu_device::execute_run() { - bool check_debugger = ((device_t::machine().debug_flags & DEBUG_FLAG_ENABLED) != 0); - // debugging //m_ppc = m_pc; // copy PC to previous PC - if (check_debugger) + if (debugger_enabled()) { while (m_icount > 0) { diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index d79e9e298c2..06edb4beaa4 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -109,7 +109,6 @@ public: ATTR_HOT inline netlist::setup_t &setup(); ATTR_HOT inline netlist_mame_t &netlist() { return *m_netlist; } - ATTR_HOT inline const netlist::netlist_time last_time_update() { return m_old; } ATTR_HOT void update_icount(netlist::netlist_time time); ATTR_HOT void check_mame_abort_slice(); diff --git a/src/lib/netlist/devices/nld_9310.cpp b/src/lib/netlist/devices/nld_9310.cpp index 4348de20417..cbc197a70d8 100644 --- a/src/lib/netlist/devices/nld_9310.cpp +++ b/src/lib/netlist/devices/nld_9310.cpp @@ -158,32 +158,35 @@ namespace netlist NETLIB_UPDATE(9310_sub) { + auto cnt(m_cnt); + if (m_loadq) { - if (m_cnt < MAXCNT - 1) + if (cnt < MAXCNT - 1) { - ++m_cnt; - update_outputs(m_cnt); + ++cnt; + update_outputs(cnt); } - else if (m_cnt == MAXCNT - 1) + else if (cnt == MAXCNT - 1) { - m_cnt = MAXCNT; + cnt = MAXCNT; m_RC.push(m_ent, NLTIME_FROM_NS(20)); m_QA.push(1, NLTIME_FROM_NS(20)); } else // MAXCNT { m_RC.push(0, NLTIME_FROM_NS(20)); - m_cnt = 0; - update_outputs_all(m_cnt, NLTIME_FROM_NS(20)); + cnt = 0; + update_outputs_all(cnt, NLTIME_FROM_NS(20)); } } else { - m_cnt = m_ABCD->read_ABCD(); - m_RC.push(m_ent & (m_cnt == MAXCNT), NLTIME_FROM_NS(27)); - update_outputs_all(m_cnt, NLTIME_FROM_NS(22)); + cnt = m_ABCD->read_ABCD(); + m_RC.push(m_ent & (cnt == MAXCNT), NLTIME_FROM_NS(27)); + update_outputs_all(cnt, NLTIME_FROM_NS(22)); } + m_cnt = cnt; } NETLIB_UPDATE(9310) @@ -224,10 +227,10 @@ namespace netlist #if 0 // for (int i=0; i<4; i++) // m_Q[i], (cnt >> i) & 1, delay[i]); - m_QA, (cnt >> 0) & 1, out_delay); - m_QB, (cnt >> 1) & 1, out_delay); - m_QC, (cnt >> 2) & 1, out_delay); - m_QD, (cnt >> 3) & 1, out_delay); + m_QA.push((cnt >> 0) & 1, out_delay); + m_QB.push((cnt >> 1) & 1, out_delay); + m_QC.push((cnt >> 2) & 1, out_delay); + m_QD.push((cnt >> 3) & 1, out_delay); #else if ((cnt & 1) == 1) m_QA.push(1, out_delay); diff --git a/src/lib/netlist/devices/nld_9316.cpp b/src/lib/netlist/devices/nld_9316.cpp index 20858ebc74f..69dd1c1c6ca 100644 --- a/src/lib/netlist/devices/nld_9316.cpp +++ b/src/lib/netlist/devices/nld_9316.cpp @@ -105,27 +105,15 @@ namespace netlist NETLIB_HANDLER(9316, clk) { + auto cnt(m_cnt); if (m_LOADQ()) { - ++m_cnt &= MAXCNT; - //m_RC.push(m_ENT() && (m_cnt == MAXCNT), NLTIME_FROM_NS(27)); -#if 0 - if (m_cnt == MAXCNT) - { - m_RC.push(m_ENT(), NLTIME_FROM_NS(27)); - update_outputs_all(MAXCNT, NLTIME_FROM_NS(20)); - } - else if (m_cnt == 0) - { - m_RC.push(0, NLTIME_FROM_NS(27)); - update_outputs_all(0, NLTIME_FROM_NS(20)); - } - else - update_outputs_all(m_cnt, NLTIME_FROM_NS(20)); -#else - if (m_cnt > 0 && m_cnt < MAXCNT) - update_outputs_all(m_cnt, NLTIME_FROM_NS(20)); - else if (m_cnt == 0) + ++cnt &= MAXCNT; + //m_RC.push(m_ENT() && (cnt == MAXCNT), NLTIME_FROM_NS(27)); + + if (cnt > 0 && cnt < MAXCNT) + update_outputs_all(cnt, NLTIME_FROM_NS(20)); + else if (cnt == 0) { m_RC.push(0, NLTIME_FROM_NS(27)); update_outputs_all(0, NLTIME_FROM_NS(20)); @@ -135,14 +123,14 @@ namespace netlist m_RC.push(m_ENT(), NLTIME_FROM_NS(27)); update_outputs_all(MAXCNT, NLTIME_FROM_NS(20)); } -#endif } else { - m_cnt = m_abcd; - m_RC.push(m_ENT() && (m_cnt == MAXCNT), NLTIME_FROM_NS(27)); - update_outputs_all(m_cnt, NLTIME_FROM_NS(22)); + cnt = m_abcd; + m_RC.push(m_ENT() && (cnt == MAXCNT), NLTIME_FROM_NS(27)); + update_outputs_all(cnt, NLTIME_FROM_NS(22)); } + m_cnt = cnt; } NETLIB_UPDATE(9316) diff --git a/src/lib/netlist/devices/nld_system.cpp b/src/lib/netlist/devices/nld_system.cpp index 24af4527a70..134017d06b0 100644 --- a/src/lib/netlist/devices/nld_system.cpp +++ b/src/lib/netlist/devices/nld_system.cpp @@ -40,15 +40,38 @@ namespace netlist { m_cnt = 0; m_off = netlist_time::from_double(m_offset()); + m_feedback.m_delegate = NETLIB_DELEGATE(extclock, update); + + //m_feedback.m_delegate .set(&NETLIB_NAME(extclock)::update, this); //m_Q.initial(0); } + NETLIB_HANDLER(extclock, clk2) + { + m_Q.push((m_cnt & 1) ^ 1, m_inc[m_cnt]); + if (++m_cnt >= m_size) + m_cnt = 0; + } + + NETLIB_HANDLER(extclock, clk2_pow2) + { + m_Q.push((m_cnt & 1) ^ 1, m_inc[m_cnt]); + m_cnt = (++m_cnt) & (m_size-1); + } + NETLIB_UPDATE(extclock) { m_Q.push((m_cnt & 1) ^ 1, m_inc[m_cnt] + m_off); m_off = netlist_time::zero(); if (++m_cnt >= m_size) m_cnt = 0; + + // continue with optimized clock handlers .... + + if ((m_size & (m_size-1)) == 0) // power of 2? + m_feedback.m_delegate.set(&NETLIB_NAME(extclock)::clk2_pow2, this); + else + m_feedback.m_delegate.set(&NETLIB_NAME(extclock)::clk2, this); } // ----------------------------------------------------------------------------- diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 3d878646549..7271084bbc1 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -52,7 +52,7 @@ namespace netlist NETLIB_RESETI() { - m_Q.net().set_time(netlist_time::zero()); + m_Q.net().set_next_scheduled_time(netlist_time::zero()); } NETLIB_UPDATE_PARAMI() @@ -65,7 +65,7 @@ namespace netlist logic_net_t &net = m_Q.net(); // this is only called during setup ... net.toggle_new_Q(); - net.set_time(exec().time() + m_inc); + net.set_next_scheduled_time(exec().time() + m_inc); } public: @@ -73,13 +73,6 @@ namespace netlist param_double_t m_freq; netlist_time m_inc; - - static void mc_update(logic_net_t &net) - { - net.toggle_new_Q(); - net.update_devs(); - } - }; // ----------------------------------------------------------------------------- @@ -158,6 +151,10 @@ namespace netlist NETLIB_UPDATEI(); NETLIB_RESETI(); //NETLIB_UPDATE_PARAMI(); + + NETLIB_HANDLERI(clk2); + NETLIB_HANDLERI(clk2_pow2); + protected: param_double_t m_freq; diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h index f0f85e037de..c633a6991a1 100644 --- a/src/lib/netlist/devices/nlid_truthtable.h +++ b/src/lib/netlist/devices/nlid_truthtable.h @@ -179,7 +179,7 @@ namespace devices m_I[i].activate(); //nstate |= (m_I[i]() ? (1 << i) : 0); nstate |= (m_I[i]() << i); - mt = std::max(this->m_I[i].net().time(), mt); + mt = std::max(this->m_I[i].net().next_scheduled_time(), mt); } else for (std::size_t i = 0; i < m_NI; i++) @@ -208,7 +208,7 @@ namespace devices { //nstate |= (m_I[i]() ? (1 << i) : 0); nstate |= (m_I[i]() << i); - mt = std::max(this->m_I[i].net().time(), mt); + mt = std::max(this->m_I[i].net().next_scheduled_time(), mt); } else for (std::size_t i = 0; i < m_NI; i++) diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 14807111ff2..4ce980dbba8 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -164,11 +164,9 @@ void detail::queue_t::register_state(plib::state_manager_t &manager, const pstri manager.save_item(this, &m_net_ids[0], module + "." + "names", m_net_ids.size()); } -void detail::queue_t::on_pre_save() +void detail::queue_t::on_pre_save(plib::state_manager_t &manager) { - state().log().debug("on_pre_save\n"); m_qsize = this->size(); - state().log().debug("qsize {1}\n", m_qsize); for (std::size_t i = 0; i < m_qsize; i++ ) { m_times[i] = this->listptr()[i].m_exec_time.as_raw(); @@ -177,10 +175,9 @@ void detail::queue_t::on_pre_save() } -void detail::queue_t::on_post_load() +void detail::queue_t::on_post_load(plib::state_manager_t &manager) { this->clear(); - state().log().debug("qsize {1}\n", m_qsize); for (std::size_t i = 0; i < m_qsize; i++ ) { detail::net_t *n = state().nets()[m_net_ids[i]].get(); @@ -247,11 +244,11 @@ detail::terminal_type detail::core_terminal_t::type() const // ---------------------------------------------------------------------------------------- netlist_t::netlist_t(const pstring &aname, std::unique_ptr callbacks) - : m_state(plib::make_unique(aname, + : m_time(netlist_time::zero()) + , m_mainclock(nullptr) + , m_state(plib::make_unique(aname, std::move(callbacks), plib::make_unique(*this))) // FIXME, ugly but needed to have netlist_state_t constructed first - , m_time(netlist_time::zero()) - , m_mainclock(nullptr) , m_queue(*m_state) , m_solver(nullptr) { @@ -272,8 +269,7 @@ netlist_t::~netlist_t() netlist_state_t::netlist_state_t(const pstring &aname, std::unique_ptr &&callbacks, std::unique_ptr &&setup) -: m_params(nullptr) -, m_name(aname) +: m_name(aname) , m_state() , m_callbacks(std::move(callbacks)) // Order is important here , m_log(*m_callbacks) @@ -339,7 +335,7 @@ void netlist_t::reset() m_time = netlist_time::zero(); m_queue.clear(); if (m_mainclock != nullptr) - m_mainclock->m_Q.net().set_time(netlist_time::zero()); + m_mainclock->m_Q.net().set_next_scheduled_time(netlist_time::zero()); //if (m_solver != nullptr) // m_solver->reset(); @@ -452,7 +448,7 @@ void netlist_t::process_queue(const netlist_time delta) NL_NOEXCEPT { logic_net_t &mc_net(m_mainclock->m_Q.net()); const netlist_time inc(m_mainclock->m_inc); - netlist_time mc_time(mc_net.time()); + netlist_time mc_time(mc_net.next_scheduled_time()); do { @@ -474,7 +470,7 @@ void netlist_t::process_queue(const netlist_time delta) NL_NOEXCEPT else break; } while (true); //while (e.m_object != nullptr); - mc_net.set_time(mc_time); + mc_net.set_next_scheduled_time(mc_time); } m_stat_mainloop.stop(); } @@ -503,6 +499,9 @@ void netlist_t::print_stats() const total_count += entry->m_stat_total_time.count(); } + log().verbose("Total calls : {1:12} {2:12} {3:12}", total_count, + total_time, total_time / total_count); + nperftime_t overhead; nperftime_t test; overhead.start(); @@ -531,10 +530,16 @@ void netlist_t::print_stats() const / static_cast::type>(m_queue.m_prof_call()); log().verbose("Overhead per pop {1:11}", overhead_per_pop ); log().verbose(""); + + auto trigger = total_count * 200 / 1000000; // 200 ppm for (auto &entry : m_state->m_devices) { - if (entry->m_stat_inc_active() > 3 * entry->m_stat_total_time.count()) - log().verbose("HINT({}, NO_DEACTIVATE)", entry->name()); + // Factor of 3 offers best performace increase + if (entry->m_stat_inc_active() > 3 * entry->m_stat_total_time.count() + && entry->m_stat_inc_active() > trigger) + log().verbose("HINT({}, NO_DEACTIVATE) // {} {} {}", entry->name(), + static_cast(entry->m_stat_inc_active()) / static_cast(entry->m_stat_total_time.count()), + entry->m_stat_inc_active(), entry->m_stat_total_time.count()); } } } @@ -687,7 +692,7 @@ detail::net_t::net_t(netlist_base_t &nl, const pstring &aname, core_terminal_t * , m_new_Q(*this, "m_new_Q", 0) , m_cur_Q (*this, "m_cur_Q", 0) , m_in_queue(*this, "m_in_queue", QS_DELIVERED) - , m_time(*this, "m_time", netlist_time::zero()) + , m_next_scheduled_time(*this, "m_time", netlist_time::zero()) , m_railterminal(mr) { } @@ -697,35 +702,6 @@ detail::net_t::~net_t() state().run_state_manager().remove_save_items(this); } -void detail::net_t::add_to_active_list(core_terminal_t &term) NL_NOEXCEPT -{ - const bool was_empty = m_list_active.empty(); - m_list_active.push_front(&term); - if (was_empty) - { - railterminal().device().do_inc_active(); - if (m_in_queue == QS_DELAYED_DUE_TO_INACTIVE) - { - if (m_time > exec().time()) - { - m_in_queue = QS_QUEUED; /* pending */ - exec().queue().push({m_time, this}); - } - else - { - m_in_queue = QS_DELIVERED; - m_cur_Q = m_new_Q; - } - } - } -} - -void detail::net_t::remove_from_active_list(core_terminal_t &term) NL_NOEXCEPT -{ - m_list_active.remove(&term); - if (m_list_active.empty()) - railterminal().device().do_dec_active(); -} void detail::net_t::rebuild_list() { @@ -779,7 +755,7 @@ void detail::net_t::update_devs() NL_NOEXCEPT void detail::net_t::reset() { - m_time = netlist_time::zero(); + m_next_scheduled_time = netlist_time::zero(); m_in_queue = QS_DELIVERED; m_new_Q = 0; diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index ca75046b3e5..35ecc694cfd 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -732,8 +732,8 @@ namespace netlist void update_devs() NL_NOEXCEPT; - const netlist_time time() const noexcept { return m_time; } - void set_time(netlist_time ntime) noexcept { m_time = ntime; } + const netlist_time next_scheduled_time() const noexcept { return m_next_scheduled_time; } + void set_next_scheduled_time(netlist_time ntime) noexcept { m_next_scheduled_time = ntime; } bool isRailNet() const noexcept { return !(m_railterminal == nullptr); } core_terminal_t & railterminal() const noexcept { return *m_railterminal; } @@ -761,7 +761,7 @@ namespace netlist state_var m_cur_Q; state_var m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */ - state_var m_time; + state_var m_next_scheduled_time; private: plib::linkedlist_t m_list_active; @@ -803,7 +803,7 @@ namespace netlist if (newQ != m_new_Q) { m_in_queue = QS_DELAYED_DUE_TO_INACTIVE; - m_time = at; + m_next_scheduled_time = at; } m_cur_Q = m_new_Q = newQ; } @@ -1204,8 +1204,8 @@ namespace netlist protected: void register_state(plib::state_manager_t &manager, const pstring &module) override; - void on_pre_save() override; - void on_post_load() override; + void on_pre_save(plib::state_manager_t &manager) override; + void on_post_load(plib::state_manager_t &manager) override; private: std::size_t m_qsize; @@ -1272,8 +1272,6 @@ namespace netlist template void register_net(plib::owned_ptr &&net) { m_nets.push_back(std::move(net)); } - devices::NETLIB_NAME(netlistparams) *m_params; - template inline std::vector get_device_list() { @@ -1387,11 +1385,10 @@ namespace netlist void print_stats() const; private: - std::unique_ptr m_state; - /* mostly rw */ netlist_time m_time; devices::NETLIB_NAME(mainclock) * m_mainclock; + std::unique_ptr m_state; detail::queue_t m_queue; devices::NETLIB_NAME(solver) * m_solver; @@ -1517,15 +1514,50 @@ namespace netlist { if ((num_cons() != 0)) { + auto &lexec(exec()); + auto &q(lexec.queue()); + auto nst(lexec.time() + delay); + if (is_queued()) - exec().queue().remove(this); - m_time = exec().time() + delay; + q.remove(this); m_in_queue = (!m_list_active.empty()) ? QS_QUEUED : QS_DELAYED_DUE_TO_INACTIVE; /* queued ? */ if (m_in_queue == QS_QUEUED) - exec().queue().push(queue_t::entry_t(m_time, this)); + q.push(queue_t::entry_t(nst, this)); + m_next_scheduled_time = nst; } } + inline void detail::net_t::add_to_active_list(core_terminal_t &term) NL_NOEXCEPT + { + if (m_list_active.empty()) + { + m_list_active.push_front(&term); + railterminal().device().do_inc_active(); + if (m_in_queue == QS_DELAYED_DUE_TO_INACTIVE) + { + if (m_next_scheduled_time > exec().time()) + { + m_in_queue = QS_QUEUED; /* pending */ + exec().queue().push({m_next_scheduled_time, this}); + } + else + { + m_in_queue = QS_DELIVERED; + m_cur_Q = m_new_Q; + } + } + } + else + m_list_active.push_front(&term); + } + + inline void detail::net_t::remove_from_active_list(core_terminal_t &term) NL_NOEXCEPT + { + m_list_active.remove(&term); + if (m_list_active.empty()) + railterminal().device().do_dec_active(); + } + inline const analog_net_t & analog_t::net() const NL_NOEXCEPT { return static_cast(core_terminal_t::net()); @@ -1583,6 +1615,7 @@ namespace netlist return m_device.exec(); } + inline const netlist_t &detail::device_object_t::exec() const NL_NOEXCEPT { return m_device.exec(); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 291e95add83..cef51f481db 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -27,6 +27,7 @@ namespace netlist { setup_t::setup_t(netlist_t &netlist) : m_netlist(netlist) + , m_netlist_params(nullptr) , m_factory(*this) , m_proxy_cnt(0) , m_frontier_cnt(0) @@ -970,13 +971,13 @@ std::unique_ptr setup_t::get_data_stream(const pstring &name) return std::unique_ptr(nullptr); } -void setup_t::register_define(const pstring &defstr) +void setup_t::add_define(const pstring &defstr) { auto p = defstr.find("="); if (p != pstring::npos) - register_define(plib::left(defstr, p), defstr.substr(p+1)); + add_define(plib::left(defstr, p), defstr.substr(p+1)); else - register_define(defstr, "1"); + add_define(defstr, "1"); } // ---------------------------------------------------------------------------------------- @@ -1024,7 +1025,7 @@ void setup_t::prepare_to_run() log().debug("Searching for solver and parameters ...\n"); auto solver = netlist().get_single_device("solver"); - netlist().m_params = netlist().get_single_device("parameter"); + m_netlist_params = netlist().get_single_device("parameter"); /* create devices */ @@ -1039,7 +1040,7 @@ void setup_t::prepare_to_run() } } - bool use_deactivate = (netlist().m_params->m_use_deactivate() ? true : false); + bool use_deactivate = m_netlist_params->m_use_deactivate() ? true : false; for (auto &d : netlist().devices()) { diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 4becfe1ee0c..25201bee1b5 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -123,6 +123,7 @@ namespace netlist namespace devices { class nld_base_proxy; + class nld_netlistparams; } class core_device_t; @@ -274,8 +275,12 @@ namespace netlist m_sources.push_back(std::move(src)); } - void register_define(pstring def, pstring val) { m_defines.push_back(plib::ppreprocessor::define_t(def, val)); } - void register_define(const pstring &defstr); + void add_define(pstring def, pstring val) + { + m_defines.insert({ def, plib::ppreprocessor::define_t(def, val)}); + } + + void add_define(const pstring &defstr); factory::list_t &factory() { return m_factory; } const factory::list_t &factory() const { return m_factory; } @@ -337,14 +342,16 @@ namespace netlist std::unordered_map m_terminals; netlist_t &m_netlist; + devices::nld_netlistparams *m_netlist_params; std::unordered_map m_params; + std::vector m_links; factory::list_t m_factory; std::unordered_map m_models; std::stack m_namespace_stack; source_t::list_t m_sources; - std::vector m_defines; + plib::ppreprocessor::defines_map_type m_defines; unsigned m_proxy_cnt; unsigned m_frontier_cnt; diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 5574f095484..d440d76de2a 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -152,9 +152,10 @@ public: void remove(const LC *elem) noexcept { auto p = &m_head; - for ( ; *p != elem; p = &((*p)->m_next)) + while(*p != elem) { //nl_assert(*p != nullptr); + p = &((*p)->m_next); } (*p) = elem->m_next; } diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index 43e992f9225..dcb8e3931f3 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -219,7 +219,7 @@ namespace plib { } pstring options::help(pstring description, pstring usage, - unsigned width, unsigned indent) + unsigned width, unsigned indent) const { pstring ret; @@ -293,7 +293,7 @@ namespace plib { return ret; } - option *options::getopt_short(pstring arg) + option *options::getopt_short(pstring arg) const { for (auto & optbase : m_opts) { @@ -303,7 +303,7 @@ namespace plib { } return nullptr; } - option *options::getopt_long(pstring arg) + option *options::getopt_long(pstring arg) const { for (auto & optbase : m_opts) { diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index 4a8e6d788d7..925329e80d4 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -27,7 +27,7 @@ public: option_base(options &parent, pstring help); virtual ~option_base(); - pstring help() { return m_help; } + pstring help() const { return m_help; } private: pstring m_help; }; @@ -39,7 +39,7 @@ public: : option_base(parent, help), m_group(group) { } ~option_group(); - pstring group() { return m_group; } + pstring group() const { return m_group; } private: pstring m_group; }; @@ -51,7 +51,7 @@ public: : option_base(parent, help), m_example(group) { } ~option_example(); - pstring example() { return m_example; } + pstring example() const { return m_example; } private: pstring m_example; }; @@ -93,7 +93,7 @@ public: : option(parent, ashort, along, help, true), m_val(defval) {} - pstring operator ()() { return m_val; } + pstring operator ()() const { return m_val; } protected: virtual int parse(const pstring &argument) override; @@ -128,7 +128,7 @@ public: { } - T operator ()() { return m_val; } + T operator ()() const { return m_val; } pstring as_string() const { return limit()[m_val]; } @@ -157,7 +157,7 @@ public: : option(parent, ashort, along, help, false), m_val(false) {} - bool operator ()() { return m_val; } + bool operator ()() const { return m_val; } protected: virtual int parse(const pstring &argument) override; @@ -180,7 +180,7 @@ public: , m_max(maxval) {} - T operator ()() { return m_val; } + T operator ()() const { return m_val; } protected: virtual int parse(const pstring &argument) override @@ -203,7 +203,7 @@ public: : option(parent, ashort, along, help, true) {} - std::vector operator ()() { return m_val; } + const std::vector &operator ()() const { return m_val; } protected: virtual int parse(const pstring &argument) override; @@ -233,9 +233,9 @@ public: int parse(int argc, char *argv[]); pstring help(pstring description, pstring usage, - unsigned width = 72, unsigned indent = 20); + unsigned width = 72, unsigned indent = 20) const; - pstring app() { return m_app; } + pstring app() const { return m_app; } private: static pstring split_paragraphs(pstring text, unsigned width, unsigned indent, @@ -244,7 +244,7 @@ private: void check_consistency(); template - T *getopt_type() + T *getopt_type() const { for (auto & optbase : m_opts ) { @@ -254,8 +254,8 @@ private: return nullptr; } - option *getopt_short(pstring arg); - option *getopt_long(pstring arg); + option *getopt_short(pstring arg) const; + option *getopt_long(pstring arg) const; std::vector m_opts; pstring m_app; diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 48e29570b4c..d666ad11054 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -268,7 +268,7 @@ void ptokenizer::error(const pstring &errs) // A simple preprocessor // ---------------------------------------------------------------------------------------- -ppreprocessor::ppreprocessor(std::vector *defines) +ppreprocessor::ppreprocessor(defines_map_type *defines) : pistream() , m_ifflag(0) , m_level(0) @@ -292,12 +292,7 @@ ppreprocessor::ppreprocessor(std::vector *defines) m_defines.insert({"__PLIB_PREPROCESSOR__", define_t("__PLIB_PREPROCESSOR__", "1")}); if (defines != nullptr) - { - for (auto & p : *defines) - { - m_defines.insert({p.m_name, p}); - } - } + m_defines = *defines; } void ppreprocessor::error(const pstring &err) @@ -524,7 +519,10 @@ pstring ppreprocessor::process_line(pstring line) } } else - error(pfmt("unknown directive on line {1}: {2}")(m_lineno)(line)); + { + if (m_ifflag == 0) + error(pfmt("unknown directive on line {1}: {2}")(m_lineno)(replace_macros(line))); + } } else { diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 1eeb92d797b..3829e8cdcc8 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -163,7 +163,9 @@ public: pstring m_replace; }; - explicit ppreprocessor(std::vector *defines = nullptr); + using defines_map_type = std::unordered_map; + + explicit ppreprocessor(defines_map_type *defines = nullptr); virtual ~ppreprocessor() override {} template @@ -214,7 +216,7 @@ private: pstring process_line(pstring line); pstring process_comments(pstring line); - std::unordered_map m_defines; + defines_map_type m_defines; std::vector m_expr_sep; std::uint_least64_t m_ifflag; // 31 if levels diff --git a/src/lib/netlist/plib/pstate.cpp b/src/lib/netlist/plib/pstate.cpp index 3cab5dec127..a5465bfed46 100644 --- a/src/lib/netlist/plib/pstate.cpp +++ b/src/lib/netlist/plib/pstate.cpp @@ -48,13 +48,13 @@ void state_manager_t::remove_save_items(const void *owner) void state_manager_t::pre_save() { for (auto & s : m_custom) - s->m_callback->on_pre_save(); + s->m_callback->on_pre_save(*this); } void state_manager_t::post_load() { for (auto & s : m_custom) - s->m_callback->on_post_load(); + s->m_callback->on_post_load(*this); } template<> void state_manager_t::save_item(const void *owner, callback_t &state, const pstring &stname) diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index 5b8acc92221..3a908cba2d2 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -56,8 +56,8 @@ public: virtual ~callback_t(); virtual void register_state(state_manager_t &manager, const pstring &module) = 0; - virtual void on_pre_save() = 0; - virtual void on_post_load() = 0; + virtual void on_pre_save(state_manager_t &manager) = 0; + virtual void on_post_load(state_manager_t &manager) = 0; protected: }; diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 4212677c81c..023a0271ce2 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -14,6 +14,10 @@ #include #include // <<= needed by windows build +#define PSTRINGIFY_HELP(y) # y +#define PSTRINGIFY(x) PSTRINGIFY_HELP(x) + + namespace plib { diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 3c9839a7845..984f8703079 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -17,6 +17,8 @@ #include +#define NLTOOL_VERSION 20190202 + class tool_app_t : public plib::app { public: @@ -36,7 +38,7 @@ public: opt_name(*this, "n", "name", "", "the netlist in file specified by ""-f"" option to run; default is first one"), opt_grp3(*this, "Options for run command", "These options are only used by the run command."), - opt_ttr (*this, "t", "time_to_run", 1.0, "time to run the emulation (seconds)"), + opt_ttr (*this, "t", "time_to_run", 1.0, "time to run the emulation (seconds)\n\n abc def\n\n xyz"), opt_logs(*this, "l", "log" , "define terminal to log. This option may be specified repeatedly."), opt_inp(*this, "i", "input", "", "input file to process (default is none)"), opt_loadstate(*this,"", "loadstate", "", "load state from file and continue from there"), @@ -99,6 +101,8 @@ private: void listdevices(); + std::vector m_options; + }; static NETLIST_START(dummy) @@ -186,7 +190,7 @@ public: // read the netlist ... for (auto & d : defines) - setup().register_define(d); + setup().add_define(d); for (auto & r : roms) setup().register_source(plib::make_unique_base(setup(), r)); @@ -347,7 +351,7 @@ void tool_app_t::run() nt.read_netlist(opt_file(), opt_name(), opt_logs(), - opt_defines(), opt_rfolders()); + m_options, opt_rfolders()); std::vector inps = read_input(nt.setup(), opt_inp()); @@ -423,7 +427,7 @@ void tool_app_t::static_compile() nt.read_netlist(opt_file(), opt_name(), opt_logs(), - opt_defines(), opt_rfolders()); + m_options, opt_rfolders()); plib::putf8_writer w(&pout_strm); std::map mp; @@ -543,9 +547,9 @@ void tool_app_t::create_header() if (last_source != e->sourcefile()) { last_source = e->sourcefile(); - pout("{1}\n", plib::rpad(pstring("// "), pstring("-"), 72)); + pout("{1}\n", plib::rpad(pstring("// "), pstring("-"), opt_linewidth())); pout("{1}{2}\n", pstring("// Source: "), plib::replace_all(e->sourcefile(), "../", "")); - pout("{1}\n", plib::rpad(pstring("// "), pstring("-"), 72)); + pout("{1}\n", plib::rpad(pstring("// "), pstring("-"), opt_linewidth())); } cmac(e.get()); } @@ -697,7 +701,7 @@ int tool_app_t::execute() if (opt_version()) { pout( - "nltool (netlist) 0.1\n" + "nltool (netlist) " PSTRINGIFY(NLTOOL_VERSION) "\n" "Copyright (C) 2019 Couriersud\n" "License GPLv2+: GNU GPL version 2 or later .\n" "This is free software: you are free to change and redistribute it.\n" @@ -706,6 +710,9 @@ int tool_app_t::execute() return 0; } + m_options = opt_defines(); + m_options.push_back("NLTOOL_VERSION=" PSTRINGIFY(NLTOOL_VERSION)); + try { pstring cmd = opt_cmd.as_string(); diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 8116e48111a..c25330627b6 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -381,11 +381,11 @@ public: nlwav_app() : plib::app(), opt_fmt(*this, "f", "format", 0, std::vector({"wav","vcda","vcdd"}), - "output format. Available options are wav|vcda|vcdd.\n" - "wav : multichannel wav output\n" - "vcda : analog VCD output\n" - "vcdd : digital VCD output\n" - "Digital signals are created using the high and low options" + "output format. Available options are wav|vcda|vcdd." + " wav : multichannel wav output" + " vcda : analog VCD output" + " vcdd : digital VCD output" + " Digital signals are created using the --high and --low options" ), opt_out(*this, "o", "output", "-", "output file"), opt_rate(*this, "r", "rate", 48000, "sample rate of output file"), diff --git a/src/mame/audio/nl_kidniki.cpp b/src/mame/audio/nl_kidniki.cpp index 7865ea40750..9e8c47247af 100644 --- a/src/mame/audio/nl_kidniki.cpp +++ b/src/mame/audio/nl_kidniki.cpp @@ -2,8 +2,17 @@ // copyright-holders:Andrew Gardner, Couriersud #include "netlist/devices/net_lib.h" +#ifdef NLBASE_H_ +#error Somehow nl_base.h made it into the include chain. +#endif + +#ifndef NLTOOL_VERSION #define USE_FRONTIERS 1 #define USE_FIXED_STV 1 +#else +#define USE_FRONTIERS 0 +#define USE_FIXED_STV 1 +#endif /* ---------------------------------------------------------------------------- * Library section header START diff --git a/src/mame/machine/nl_breakout.cpp b/src/mame/machine/nl_breakout.cpp index 87426734036..0823df42350 100644 --- a/src/mame/machine/nl_breakout.cpp +++ b/src/mame/machine/nl_breakout.cpp @@ -1702,22 +1702,19 @@ CIRCUIT_LAYOUT( breakout ) NET_C(GND, D9.1, D9.2, D9.13, D9.3, D9.4, D9.5) - HINT(A3.1.sub, NO_DEACTIVATE) +#if 1 + // 158% -- manually optimized HINT(B6.s3, NO_DEACTIVATE) HINT(C4.s3, NO_DEACTIVATE) HINT(C4.s4, NO_DEACTIVATE) HINT(C5.s3, NO_DEACTIVATE) HINT(C5.s4, NO_DEACTIVATE) - HINT(D3.2.sub, NO_DEACTIVATE) HINT(E2.s2, NO_DEACTIVATE) HINT(E3.s2, NO_DEACTIVATE) HINT(E5.s4, NO_DEACTIVATE) - HINT(E8.2.sub, NO_DEACTIVATE) HINT(E9.s6, NO_DEACTIVATE) - HINT(F5.2.sub, NO_DEACTIVATE) HINT(H2.s1, NO_DEACTIVATE) HINT(H3.s1, NO_DEACTIVATE) - HINT(H6.sub, NO_DEACTIVATE) HINT(J3.s4, NO_DEACTIVATE) HINT(J5, NO_DEACTIVATE) HINT(J6.sub, NO_DEACTIVATE) @@ -1729,9 +1726,47 @@ CIRCUIT_LAYOUT( breakout ) HINT(M4.s2, NO_DEACTIVATE) HINT(M6.sub, NO_DEACTIVATE) HINT(M8.s1, NO_DEACTIVATE) - HINT(N6.sub, NO_DEACTIVATE) HINT(N7.s3, NO_DEACTIVATE) +#else + // 152% hints provided by log output + HINT(M4.s2, NO_DEACTIVATE) // 29.001761 197676 6816 + HINT(M3.s3, NO_DEACTIVATE) // inf 129571 0 + HINT(N7.s3, NO_DEACTIVATE) // inf 7850387 0 + HINT(M3.s2, NO_DEACTIVATE) // 23.234535 395870 17038 + HINT(M3.s1, NO_DEACTIVATE) // 14.500880 197676 13632 + HINT(L7.s3, NO_DEACTIVATE) // 122672.000000 122672 1 + HINT(L7.s2, NO_DEACTIVATE) // 122672.000000 122672 1 + HINT(K7.s4, NO_DEACTIVATE) // 122673.000000 122673 1 + HINT(K7.s3, NO_DEACTIVATE) // 122672.000000 122672 1 + HINT(K7.s2, NO_DEACTIVATE) // 122673.000000 122673 1 + HINT(K7.s1, NO_DEACTIVATE) // 122673.000000 122673 1 + HINT(K4.s4, NO_DEACTIVATE) // 1438.774735 4202661 2921 + HINT(K4.s2, NO_DEACTIVATE) // 3.939380 847790 215209 + HINT(E2.s2, NO_DEACTIVATE) // 108.050000 315506 2920 + HINT(L7.s4, NO_DEACTIVATE) // 122672.000000 122672 1 + HINT(E9.s6, NO_DEACTIVATE) // inf 129571 0 + HINT(J2.s6, NO_DEACTIVATE) // 493.408951 959187 1944 + HINT(C5.s3, NO_DEACTIVATE) // inf 195514 0 + HINT(M3.s4, NO_DEACTIVATE) // 27.744898 418726 15092 + HINT(J8.s1, NO_DEACTIVATE) // 40890.000000 122670 3 + HINT(E3.s2, NO_DEACTIVATE) // 203581.000000 203581 1 + HINT(M9.s4, NO_DEACTIVATE) // inf 323268 0 + HINT(L4.s2, NO_DEACTIVATE) // 7.290053 1192536 163584 + HINT(J3.s4, NO_DEACTIVATE) // 393.639951 957726 2433 + HINT(L7.s1, NO_DEACTIVATE) // inf 122672 0 + HINT(F2.s1, NO_DEACTIVATE) // 286289.000000 286289 1 + HINT(M8.s1, NO_DEACTIVATE) // 129571.000000 129571 1 + HINT(J7.s2, NO_DEACTIVATE) // inf 122672 0 + HINT(H2.s1, NO_DEACTIVATE) // 393.839704 958212 2433 + HINT(H3.s1, NO_DEACTIVATE) // 3.932473 850122 216180 + HINT(J2.s5, NO_DEACTIVATE) // 26.140344 203581 7788 + HINT(J7.s1, NO_DEACTIVATE) // inf 122672 0 + HINT(J8.s3, NO_DEACTIVATE) // 40890.000000 122670 3 + + +#endif + CIRCUIT_LAYOUT_END /* -- cgit v1.2.3-70-g09d2 From 3b899b86e67e3a5cc093d2dd9c0dcaeed197c806 Mon Sep 17 00:00:00 2001 From: couriersud Date: Wed, 6 Feb 2019 10:24:34 +0100 Subject: netlist: Refactoring after adding clang-tidy support to netlist makefile - convert macros to c++ code. - order of device creation should not depend on std lib. - some state saving cleanup. - added support for clang-tidy to makefile. - modifications triggered by clang-tidy-9. --- src/devices/machine/netlist.cpp | 17 ++- src/lib/netlist/analog/nld_bjt.cpp | 8 +- src/lib/netlist/analog/nld_opamps.cpp | 4 +- src/lib/netlist/analog/nld_switches.cpp | 6 +- src/lib/netlist/analog/nlid_fourterm.cpp | 26 ++-- src/lib/netlist/analog/nlid_fourterm.h | 37 ++---- src/lib/netlist/analog/nlid_twoterm.cpp | 10 +- src/lib/netlist/analog/nlid_twoterm.h | 21 ++- src/lib/netlist/build/makefile | 53 +++++++- src/lib/netlist/devices/net_lib.h | 30 ++--- src/lib/netlist/devices/nld_4066.cpp | 14 +- src/lib/netlist/devices/nld_4316.cpp | 9 +- src/lib/netlist/devices/nld_74165.cpp | 1 + src/lib/netlist/devices/nld_7448.cpp | 2 +- src/lib/netlist/devices/nld_7483.cpp | 2 +- src/lib/netlist/devices/nld_74ls629.cpp | 2 +- src/lib/netlist/devices/nld_log.cpp | 2 +- src/lib/netlist/devices/nld_mm5837.cpp | 6 +- src/lib/netlist/devices/nld_r2r_dac.cpp | 4 +- src/lib/netlist/devices/nld_schmitt.cpp | 10 +- src/lib/netlist/devices/nlid_cmos.h | 2 +- src/lib/netlist/devices/nlid_proxy.cpp | 20 +-- src/lib/netlist/devices/nlid_proxy.h | 12 +- src/lib/netlist/devices/nlid_system.h | 17 +-- src/lib/netlist/devices/nlid_truthtable.cpp | 9 +- src/lib/netlist/devices/nlid_truthtable.h | 8 +- src/lib/netlist/macro/nlm_cd4xxx.cpp | 2 +- src/lib/netlist/netlist_types.h | 13 +- src/lib/netlist/nl_base.cpp | 153 +++++++--------------- src/lib/netlist/nl_base.h | 187 ++++++++++++++------------- src/lib/netlist/nl_config.h | 13 +- src/lib/netlist/nl_factory.cpp | 11 +- src/lib/netlist/nl_factory.h | 20 ++- src/lib/netlist/nl_lists.h | 12 +- src/lib/netlist/nl_parser.cpp | 8 +- src/lib/netlist/nl_parser.h | 8 +- src/lib/netlist/nl_setup.cpp | 91 ++++++++----- src/lib/netlist/nl_setup.h | 39 +++--- src/lib/netlist/nl_time.h | 48 ++++--- src/lib/netlist/plib/gmres.h | 8 +- src/lib/netlist/plib/mat_cr.h | 18 +-- src/lib/netlist/plib/palloc.cpp | 8 +- src/lib/netlist/plib/palloc.h | 4 +- src/lib/netlist/plib/parray.h | 6 +- src/lib/netlist/plib/pchrono.cpp | 4 +- src/lib/netlist/plib/pchrono.h | 17 ++- src/lib/netlist/plib/pconfig.h | 9 -- src/lib/netlist/plib/pdynlib.cpp | 4 +- src/lib/netlist/plib/pdynlib.h | 2 +- src/lib/netlist/plib/pexception.cpp | 28 +--- src/lib/netlist/plib/pexception.h | 26 +--- src/lib/netlist/plib/pfmtlog.cpp | 11 +- src/lib/netlist/plib/pfmtlog.h | 34 +++-- src/lib/netlist/plib/pfunction.cpp | 13 +- src/lib/netlist/plib/pfunction.h | 4 +- src/lib/netlist/plib/plists.h | 10 +- src/lib/netlist/plib/pmain.cpp | 5 - src/lib/netlist/plib/pmain.h | 8 +- src/lib/netlist/plib/pomp.h | 6 +- src/lib/netlist/plib/poptions.cpp | 24 +--- src/lib/netlist/plib/poptions.h | 19 ++- src/lib/netlist/plib/pparser.cpp | 45 +++---- src/lib/netlist/plib/pparser.h | 39 +++--- src/lib/netlist/plib/ppmf.h | 14 +- src/lib/netlist/plib/pstate.cpp | 18 +-- src/lib/netlist/plib/pstate.h | 43 +++--- src/lib/netlist/plib/pstream.cpp | 37 +----- src/lib/netlist/plib/pstream.h | 119 ++++++++--------- src/lib/netlist/plib/pstring.cpp | 2 +- src/lib/netlist/plib/pstring.h | 81 ++++++------ src/lib/netlist/plib/ptypes.h | 30 ++--- src/lib/netlist/plib/putil.cpp | 16 +-- src/lib/netlist/plib/putil.h | 28 +++- src/lib/netlist/plib/vector_ops.h | 4 +- src/lib/netlist/prg/nltool.cpp | 32 ++--- src/lib/netlist/prg/nlwav.cpp | 24 ++-- src/lib/netlist/solver/nld_matrix_solver.cpp | 59 ++++----- src/lib/netlist/solver/nld_matrix_solver.h | 28 ++-- src/lib/netlist/solver/nld_ms_direct.h | 32 ++--- src/lib/netlist/solver/nld_ms_direct1.h | 2 +- src/lib/netlist/solver/nld_ms_direct2.h | 2 +- src/lib/netlist/solver/nld_ms_gcr.h | 20 ++- src/lib/netlist/solver/nld_ms_gmres.h | 14 +- src/lib/netlist/solver/nld_ms_sm.h | 30 ++--- src/lib/netlist/solver/nld_ms_sor.h | 26 ++-- src/lib/netlist/solver/nld_ms_sor_mat.h | 12 +- src/lib/netlist/solver/nld_ms_w.h | 32 ++--- src/lib/netlist/solver/nld_solver.cpp | 26 ++-- src/lib/netlist/solver/nld_solver.h | 10 +- src/lib/netlist/tools/nl_convert.cpp | 8 +- src/lib/netlist/tools/nl_convert.h | 20 +-- 91 files changed, 966 insertions(+), 1092 deletions(-) (limited to 'src/lib/netlist/nl_setup.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index fc76132a731..957d4575672 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -581,11 +581,12 @@ void netlist_mame_analog_output_device::custom_netlist_additions(netlist::setup_ { const pstring pin(m_in); pstring dname = pstring("OUT_") + pin; + pstring dfqn = setup.build_fqn(dname); m_delegate.bind_relative_to(owner()->machine().root_device()); - plib::owned_ptr dev = plib::owned_ptr::Create(setup.netlist(), setup.build_fqn(dname)); + plib::owned_ptr dev = plib::owned_ptr::Create(setup.netlist(), dfqn); static_cast(dev.get())->register_callback(std::move(m_delegate)); - setup.netlist().add_dev(std::move(dev)); + setup.netlist().add_dev(dfqn, std::move(dev)); setup.register_link(dname + ".IN", pin); } @@ -616,11 +617,13 @@ void netlist_mame_logic_output_device::custom_netlist_additions(netlist::setup_t { pstring pin(m_in); pstring dname = "OUT_" + pin; + pstring dfqn = setup.build_fqn(dname); + m_delegate.bind_relative_to(owner()->machine().root_device()); - plib::owned_ptr dev = plib::owned_ptr::Create(setup.netlist(), setup.build_fqn(dname)); + plib::owned_ptr dev = plib::owned_ptr::Create(setup.netlist(), dfqn); static_cast(dev.get())->register_callback(std::move(m_delegate)); - setup.netlist().add_dev(std::move(dev)); + setup.netlist().add_dev(dfqn, std::move(dev)); setup.register_link(dname + ".IN", pin); } @@ -882,9 +885,9 @@ void netlist_mame_device::device_start() setup().prepare_to_run(); - netlist().nlstate().save(*this, m_rem, "m_rem"); - netlist().nlstate().save(*this, m_div, "m_div"); - netlist().nlstate().save(*this, m_old, "m_old"); + netlist().nlstate().save(*this, m_rem, this->name(), "m_rem"); + netlist().nlstate().save(*this, m_div, this->name(), "m_div"); + netlist().nlstate().save(*this, m_old, this->name(), "m_old"); save_state(); diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index bd2e55e145f..7f8e57a8511 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -6,8 +6,8 @@ */ #include "../solver/nld_solver.h" -#include "nlid_twoterm.h" #include "../nl_setup.h" +#include "nlid_twoterm.h" #include @@ -248,10 +248,6 @@ public: register_subalias("B", m_D_EB.m_N); // Anode register_subalias("C", m_D_CB.m_P); // Cathode - //register_term("_B1", m_D_CB.m_N); // Anode - - //register_term("_E1", m_D_EC.m_P); - //register_term("_C1", m_D_EC.m_N); connect(m_D_EB.m_P, m_D_EC.m_P); connect(m_D_EB.m_N, m_D_CB.m_N); @@ -432,6 +428,6 @@ NETLIB_UPDATE_PARAM(QBJT_EB) namespace devices { NETLIB_DEVICE_IMPL_NS(analog, QBJT_EB, "QBJT_EB", "MODEL") NETLIB_DEVICE_IMPL_NS(analog, QBJT_switch, "QBJT_SW", "MODEL") - } + } // namespace devices } // namespace netlist diff --git a/src/lib/netlist/analog/nld_opamps.cpp b/src/lib/netlist/analog/nld_opamps.cpp index b65ff0a9edd..53ba7b3897d 100644 --- a/src/lib/netlist/analog/nld_opamps.cpp +++ b/src/lib/netlist/analog/nld_opamps.cpp @@ -8,8 +8,8 @@ #include "nld_opamps.h" #include "../nl_base.h" #include "../nl_errstr.h" -#include "nlid_twoterm.h" #include "nlid_fourterm.h" +#include "nlid_twoterm.h" #include @@ -240,5 +240,5 @@ namespace netlist namespace devices { NETLIB_DEVICE_IMPL_NS(analog, opamp, "OPAMP", "MODEL") - } + } // namespace devices } // namespace netlist diff --git a/src/lib/netlist/analog/nld_switches.cpp b/src/lib/netlist/analog/nld_switches.cpp index 7f650737de8..0e62fe13952 100644 --- a/src/lib/netlist/analog/nld_switches.cpp +++ b/src/lib/netlist/analog/nld_switches.cpp @@ -27,7 +27,7 @@ namespace netlist { NETLIB_CONSTRUCTOR(switch1) , m_R(*this, "R") - , m_POS(*this, "POS", 0) + , m_POS(*this, "POS", false) { register_subalias("1", m_R.m_P); register_subalias("2", m_R.m_N); @@ -75,7 +75,7 @@ namespace netlist NETLIB_CONSTRUCTOR(switch2) , m_R1(*this, "R1") , m_R2(*this, "R2") - , m_POS(*this, "POS", 0) + , m_POS(*this, "POS", false) { connect(m_R1.m_N, m_R2.m_N); @@ -139,5 +139,5 @@ namespace netlist namespace devices { NETLIB_DEVICE_IMPL_NS(analog, switch1, "SWITCH", "") NETLIB_DEVICE_IMPL_NS(analog, switch2, "SWITCH2", "") - } + } // namespace devices } // namespace netlist diff --git a/src/lib/netlist/analog/nlid_fourterm.cpp b/src/lib/netlist/analog/nlid_fourterm.cpp index 7cd9bd83561..f4451c55023 100644 --- a/src/lib/netlist/analog/nlid_fourterm.cpp +++ b/src/lib/netlist/analog/nlid_fourterm.cpp @@ -24,16 +24,16 @@ namespace netlist NETLIB_RESET(VCCS) { const nl_double m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A - const nl_double GI = NL_FCONST(1.0) / m_RI(); + const nl_double GI = plib::constants::one / m_RI(); m_IP.set(GI); m_IN.set(GI); - m_OP.set(m_mult, NL_FCONST(0.0)); - m_OP1.set(-m_mult, NL_FCONST(0.0)); + m_OP.set(m_mult, plib::constants::zero); + m_OP1.set(-m_mult, plib::constants::zero); - m_ON.set(-m_mult, NL_FCONST(0.0)); - m_ON1.set(m_mult, NL_FCONST(0.0)); + m_ON.set(-m_mult, plib::constants::zero); + m_ON1.set(m_mult, plib::constants::zero); } NETLIB_UPDATE(VCCS) @@ -79,11 +79,11 @@ NETLIB_UPDATE_TERMINALS(LVCCS) const nl_double beta = m_mult * (1.0 - X*X); const nl_double I = m_cur_limit() * X - beta * m_vi; - m_OP.set(beta, NL_FCONST(0.0), I); - m_OP1.set(-beta, NL_FCONST(0.0)); + m_OP.set(beta, plib::constants::zero, I); + m_OP1.set(-beta, plib::constants::zero); - m_ON.set(-beta, NL_FCONST(0.0), -I); - m_ON1.set(beta, NL_FCONST(0.0)); + m_ON.set(-beta, plib::constants::zero, -I); + m_ON1.set(beta, plib::constants::zero); } // ---------------------------------------------------------------------------------------- @@ -106,11 +106,11 @@ NETLIB_UPDATE_PARAM(CCCS) NETLIB_RESET(VCVS) { - m_gfac = NL_FCONST(1.0) / m_RO(); + m_gfac = plib::constants::one / m_RO(); NETLIB_NAME(VCCS)::reset(); - m_OP2.set(NL_FCONST(1.0) / m_RO()); - m_ON2.set(NL_FCONST(1.0) / m_RO()); + m_OP2.set(plib::constants::one / m_RO()); + m_ON2.set(plib::constants::one / m_RO()); } } //namespace analog @@ -120,5 +120,5 @@ NETLIB_RESET(VCVS) NETLIB_DEVICE_IMPL_NS(analog, VCCS, "VCCS", "") NETLIB_DEVICE_IMPL_NS(analog, CCCS, "CCCS", "") NETLIB_DEVICE_IMPL_NS(analog, LVCCS, "LVCCS", "") - } + } // namespace devices } // namespace netlist diff --git a/src/lib/netlist/analog/nlid_fourterm.h b/src/lib/netlist/analog/nlid_fourterm.h index a0984221cae..800a9d1cfb8 100644 --- a/src/lib/netlist/analog/nlid_fourterm.h +++ b/src/lib/netlist/analog/nlid_fourterm.h @@ -9,6 +9,7 @@ #define NLID_FOURTERM_H_ #include "../nl_base.h" +#include "../plib/putil.h" namespace netlist { namespace analog { @@ -40,26 +41,17 @@ namespace netlist { NETLIB_CONSTRUCTOR(VCCS) , m_G(*this, "G", 1.0) , m_RI(*this, "RI", 1e9) - , m_OP(*this, "OP") - , m_ON(*this, "ON") - , m_IP(*this, "IP") - , m_IN(*this, "IN") - , m_OP1(*this, "_OP1") - , m_ON1(*this, "_ON1") + , m_OP(*this, "OP", &m_IP) + , m_ON(*this, "ON", &m_IP) + , m_IP(*this, "IP", &m_IN) // <= this should be NULL and terminal be filtered out prior to solving... + , m_IN(*this, "IN", &m_IP) // <= this should be NULL and terminal be filtered out prior to solving... + , m_OP1(*this, "_OP1", &m_IN) + , m_ON1(*this, "_ON1", &m_IN) , m_gfac(1.0) { - m_IP.m_otherterm = &m_IN; // <= this should be NULL and terminal be filtered out prior to solving... - m_IN.m_otherterm = &m_IP; // <= this should be NULL and terminal be filtered out prior to solving... - - m_OP.m_otherterm = &m_IP; - m_OP1.m_otherterm = &m_IN; - - m_ON.m_otherterm = &m_IP; - m_ON1.m_otherterm = &m_IN; - connect(m_OP, m_OP1); connect(m_ON, m_ON1); - m_gfac = NL_FCONST(1.0); + m_gfac = plib::constants::one; } param_double_t m_G; @@ -137,7 +129,7 @@ namespace netlist { public: NETLIB_CONSTRUCTOR_DERIVED(CCCS, VCCS) { - m_gfac = NL_FCONST(1.0) / m_RI(); + m_gfac = plib::constants::one / m_RI(); } protected: @@ -180,12 +172,9 @@ namespace netlist { public: NETLIB_CONSTRUCTOR_DERIVED(VCVS, VCCS) , m_RO(*this, "RO", 1.0) - , m_OP2(*this, "_OP2") - , m_ON2(*this, "_ON2") + , m_OP2(*this, "_OP2", &m_ON2) + , m_ON2(*this, "_ON2", &m_OP2) { - m_OP2.m_otherterm = &m_ON2; - m_ON2.m_otherterm = &m_OP2; - connect(m_OP2, m_OP1); connect(m_ON2, m_ON1); } @@ -202,7 +191,7 @@ namespace netlist { }; - } -} + } // namespace analog +} // namespace netlist #endif /* NLD_FOURTERM_H_ */ diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index 51c17b92267..5b4bf064093 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -7,8 +7,8 @@ #include "../solver/nld_solver.h" -#include "nlid_twoterm.h" #include "../nl_factory.h" +#include "nlid_twoterm.h" #include @@ -70,7 +70,7 @@ void generic_diode::update_diode(const nl_double nVd) } else { - const double a = std::max((nVd - m_Vd) * m_VtInv, NL_FCONST(-0.99)); + const double a = std::max((nVd - m_Vd) * m_VtInv, plib::constants()(-0.99)); m_Vd = m_Vd + std::log1p(a) * m_Vt; //const double IseVDVt = m_Is * std::exp(m_Vd * m_VtInv); const double IseVDVt = std::exp(m_logIs + m_Vd * m_VtInv); @@ -145,7 +145,7 @@ NETLIB_RESET(POT) v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0); m_R1.set_R(std::max(m_R() * v, exec().gmin())); - m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), exec().gmin())); + m_R2.set_R(std::max(m_R() * (plib::constants::one - v), exec().gmin())); } NETLIB_UPDATE_PARAM(POT) @@ -158,7 +158,7 @@ NETLIB_UPDATE_PARAM(POT) v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0); m_R1.set_R(std::max(m_R() * v, exec().gmin())); - m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), exec().gmin())); + m_R2.set_R(std::max(m_R() * (plib::constants::one - v), exec().gmin())); } @@ -288,6 +288,6 @@ NETLIB_UPDATE_TERMINALS(D) NETLIB_DEVICE_IMPL_NS(analog, D, "DIODE", "MODEL") NETLIB_DEVICE_IMPL_NS(analog, VS, "VS", "V") NETLIB_DEVICE_IMPL_NS(analog, CS, "CS", "I") - } + } // namespace devices } // namespace netlist diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 5571e17867d..aa165d58a4e 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -33,9 +33,9 @@ #ifndef NLID_TWOTERM_H_ #define NLID_TWOTERM_H_ +#include "../plib/pfunction.h" #include "netlist/nl_base.h" #include "netlist/nl_setup.h" -#include "../plib/pfunction.h" // ----------------------------------------------------------------------------- // Implementation @@ -52,12 +52,13 @@ namespace netlist template inline core_device_t &bselect(bool b, C &d1, core_device_t &d2) { - core_device_t *h = dynamic_cast(&d1); + auto *h = dynamic_cast(&d1); return b ? *h : d2; } template<> inline core_device_t &bselect(bool b, netlist_base_t &d1, core_device_t &d2) { + plib::unused_var(d1); if (b) throw nl_exception("bselect with netlist and b==true"); return d2; @@ -66,11 +67,9 @@ namespace netlist NETLIB_OBJECT(twoterm) { NETLIB_CONSTRUCTOR_EX(twoterm, bool terminals_owned = false) - , m_P(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "1") - , m_N(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "2") + , m_P(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "1", &m_N) + , m_N(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "2", &m_P) { - m_P.m_otherterm = &m_N; - m_N.m_otherterm = &m_P; } terminal_t m_P; @@ -124,7 +123,7 @@ NETLIB_OBJECT_DERIVED(R_base, twoterm) public: void set_R(const nl_double R) { - const nl_double G = NL_FCONST(1.0) / R; + const nl_double G = plib::constants::one / R; set_mat( G, -G, 0.0, -G, G, 0.0); } @@ -166,7 +165,7 @@ NETLIB_OBJECT(POT) , m_R2(*this, "_R2") , m_R(*this, "R", 10000) , m_Dial(*this, "DIAL", 0.5) - , m_DialIsLog(*this, "DIALLOG", 0) + , m_DialIsLog(*this, "DIALLOG", false) { register_subalias("1", m_R1.m_P); register_subalias("2", m_R1.m_N); @@ -195,8 +194,8 @@ NETLIB_OBJECT(POT2) , m_R1(*this, "_R1") , m_R(*this, "R", 10000) , m_Dial(*this, "DIAL", 0.5) - , m_DialIsLog(*this, "DIALLOG", 0) - , m_Reverse(*this, "REVERSE", 0) + , m_DialIsLog(*this, "DIALLOG", false) + , m_Reverse(*this, "REVERSE", false) { register_subalias("1", m_R1.m_P); register_subalias("2", m_R1.m_N); @@ -489,7 +488,7 @@ private: }; - } //namespace devices + } // namespace analog } // namespace netlist #endif /* NLD_TWOTERM_H_ */ diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 33618e346b5..8996ba242ec 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -12,6 +12,28 @@ SRC = .. VSBUILD = $(SRC)/buildVS DOC = $(SRC)/documentation +TIDY_DB = ../compile_commands.json + +TIDY_FLAGSX = -checks=*,-google*,-hicpp*,-readability*,-fuchsia*,-llvm-header-guard, +TIDY_FLAGSX += -modernize-use-using,-cppcoreguidelines-pro-type-reinterpret-cast, +TIDY_FLAGSX += -cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory, +TIDY_FLAGSX += -modernize-use-default-member-init,-cert-*,-cppcoreguidelines-pro-bounds-constant-array-index, +TIDY_FLAGSX += -modernize-pass-by-value,-misc-macro-parentheses,-cppcoreguidelines-pro-type-static-cast-downcast, +TIDY_FLAGSX += -cppcoreguidelines-special-member-functions,-cppcoreguidelines-pro-bounds-array-to-pointer-decay, +TIDY_FLAGSX += -performance-unnecessary-value-param,-android-*,-cppcoreguidelines-avoid-magic-numbers, +TIDY_FLAGSX += -cppcoreguidelines-macro-usage,-misc-non-private-member-variables-in-classes, +TIDY_FLAGSX += -cppcoreguidelines-non-private-member-variables-in-classes, +TIDY_FLAGSX += -cppcoreguidelines-avoid-c-arrays,-modernize-avoid-c-arrays, +TIDY_FLAGSX += -performance-unnecessary-copy-initialization, +TIDY_FLAGSX += -bugprone-macro-parentheses + +space := +space += +TIDY_FLAGS = $(subst $(space),,$(TIDY_FLAGSX)) + +#TIDY_FLAGS = -checks=llvm-include-order -fix +#TIDY_FLAGS = -checks=llvm-namespace-comment -fix +#TIDY_FLAGS = -checks=modernize-use-override -fix ifeq ($(subst Windows_NT,windows,$(OS)),windows) OBJ = obj/mingw @@ -32,6 +54,7 @@ LD = @g++ MD = @mkdir RM = @rm DOXYGEN = @doxygen +CLANG_TIDY = clang-tidy-9 TARGETS = nltool nlwav @@ -154,6 +177,8 @@ DOCS = \ $(DOC)/test1-50r.svg \ ALL_OBJS = $(OBJS) $(PMAIN) $(NLOBJ)/prg/nltool.o $(NLOBJ)/prg/nlwav.o + +ALL_TIDY_FILES = $(ALL_OBJS:.o=.json) SOURCES = $(patsubst $(OBJ)%, $(SRC)%, $(ALL_OBJS:.o=.cpp)) ALLFILES = $(SOURCES) $(VSBUILDS) $(DOCS) @@ -207,7 +232,7 @@ native: $(MAKE) CEXTRAFLAGS="-march=native -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter" clang: - $(MAKE) CC=clang++ LD=clang++ CEXTRAFLAGS="-march=native -Wno-unused-parameter -Weverything -Werror -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors" + $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Wno-unused-parameter -Weverything -Werror -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors" clang-5: $(MAKE) CC=clang++-5.0 LD=clang++-5.0 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-inconsistent-missing-destructor-override -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-weak-template-vtables -Wno-exit-time-destructors" @@ -216,6 +241,8 @@ nvcc: $(MAKE) CC=/usr/local/cuda-9.0/bin/nvcc LD=/usr/local/cuda-9.2/bin/nvcc \ CEXTRAFLAGS="-x cu -DNVCCBUILD=1 --expt-extended-lambda --expt-relaxed-constexpr --default-stream per-thread --restrict" +tidy_db: compile_commands_prefix $(ALL_TIDY_FILES) compile_commands_postfix + # # -Wno-c++11-narrowing : seems a bit broken # Mostly done: -Wno-weak-vtables -Wno-cast-align @@ -256,6 +283,18 @@ ifeq ($(filter $(MAKECMDGOALS),$(MAKEFILE_TARGETS_WITHOUT_INCLUDE)),) -include .depend endif +#------------------------------------------------- +# clang tidy +#------------------------------------------------- +tidy: tidy_db + @echo running tidy + @for i in $(SOURCES); do \ + $(CLANG_TIDY) $$i $(TIDY_FLAGS) -header-filter=.*; \ + done + +tidy_db: compile_commands_prefix $(ALL_TIDY_FILES) compile_commands_postfix + + #------------------------------------------------- # generic rules #------------------------------------------------- @@ -277,3 +316,15 @@ $(OBJ)/%.a: $(RM) $@ $(AR) $(ARFLAGS) $@ $^ +$(OBJ)/%.json: $(SRC)/%.cpp + @echo Building compile database entry for $< ... + @echo { \"directory\": \".\", >> $(TIDY_DB) + @echo \"command\": \"$(CC) $(CDEFS) $(CFLAGS) -c $< -o dummy.o\", >> $(TIDY_DB) + @echo \"file\": \"$(CURDIR)/$<\" } >> $(TIDY_DB) + @echo "," >> $(TIDY_DB) + +compile_commands_prefix: + @echo "[" > $(TIDY_DB) + +compile_commands_postfix: + @echo "]" >> $(TIDY_DB) diff --git a/src/lib/netlist/devices/net_lib.h b/src/lib/netlist/devices/net_lib.h index 4809f330c6b..6cd2b6349f1 100644 --- a/src/lib/netlist/devices/net_lib.h +++ b/src/lib/netlist/devices/net_lib.h @@ -35,19 +35,8 @@ #include "nld_2102A.h" #include "nld_2716.h" -#include "nld_tms4800.h" #include "nld_4020.h" #include "nld_4066.h" -#include "nld_7448.h" -#include "nld_7450.h" -#include "nld_7473.h" -#include "nld_7474.h" -#include "nld_7475.h" -#include "nld_7483.h" -#include "nld_7485.h" -#include "nld_7490.h" -#include "nld_7493.h" -#include "nld_7497.h" #include "nld_74107.h" #include "nld_74123.h" #include "nld_74153.h" @@ -61,21 +50,32 @@ #include "nld_74193.h" #include "nld_74194.h" #include "nld_74365.h" +#include "nld_7448.h" +#include "nld_7450.h" +#include "nld_7473.h" +#include "nld_7474.h" +#include "nld_7475.h" +#include "nld_7483.h" +#include "nld_7485.h" +#include "nld_7490.h" +#include "nld_7493.h" +#include "nld_7497.h" #include "nld_74ls629.h" -#include "nld_82S16.h" #include "nld_82S115.h" #include "nld_82S123.h" #include "nld_82S126.h" +#include "nld_82S16.h" #include "nld_9310.h" #include "nld_9316.h" #include "nld_9322.h" +#include "nld_tms4800.h" #include "nld_am2847.h" #include "nld_dm9314.h" #include "nld_dm9334.h" -#include "nld_ne555.h" #include "nld_mm5837.h" +#include "nld_ne555.h" #include "nld_r2r_dac.h" @@ -86,15 +86,15 @@ #include "nld_log.h" #include "../macro/nlm_cd4xxx.h" -#include "../macro/nlm_ttl74xx.h" #include "../macro/nlm_opamp.h" #include "../macro/nlm_other.h" +#include "../macro/nlm_ttl74xx.h" #include "../analog/nld_bjt.h" #include "../analog/nld_fourterm.h" +#include "../analog/nld_opamps.h" #include "../analog/nld_switches.h" #include "../analog/nld_twoterm.h" -#include "../analog/nld_opamps.h" #include "nld_legacy.h" #endif diff --git a/src/lib/netlist/devices/nld_4066.cpp b/src/lib/netlist/devices/nld_4066.cpp index c4598f4fd1a..81a9a07ef0b 100644 --- a/src/lib/netlist/devices/nld_4066.cpp +++ b/src/lib/netlist/devices/nld_4066.cpp @@ -7,9 +7,9 @@ #include "nld_4066.h" -#include "nlid_cmos.h" #include "netlist/analog/nlid_twoterm.h" #include "netlist/solver/nld_solver.h" +#include "nlid_cmos.h" namespace netlist { @@ -41,28 +41,28 @@ namespace netlist { // Start in off condition // FIXME: is ROFF correct? - m_R.set_R(NL_FCONST(1.0) / exec().gmin()); + m_R.set_R(plib::constants::one / exec().gmin()); } NETLIB_UPDATE(CD4066_GATE) { nl_double sup = (m_supply.vdd() - m_supply.vss()); - nl_double low = NL_FCONST(0.45) * sup; - nl_double high = NL_FCONST(0.55) * sup; + nl_double low = plib::constants()(0.45) * sup; + nl_double high = plib::constants()(0.55) * sup; nl_double in = m_control() - m_supply.vss(); - nl_double rON = m_base_r() * NL_FCONST(5.0) / sup; + nl_double rON = m_base_r() * plib::constants()(5.0) / sup; nl_double R = -1.0; if (in < low) { - R = NL_FCONST(1.0) / exec().gmin(); + R = plib::constants::one / exec().gmin(); } else if (in > high) { R = rON; } - if (R > NL_FCONST(0.0)) + if (R > plib::constants::zero) { m_R.update(); m_R.set_R(R); diff --git a/src/lib/netlist/devices/nld_4316.cpp b/src/lib/netlist/devices/nld_4316.cpp index 6774e1e1408..c34a0602147 100644 --- a/src/lib/netlist/devices/nld_4316.cpp +++ b/src/lib/netlist/devices/nld_4316.cpp @@ -6,9 +6,9 @@ */ #include "nld_4316.h" -#include "nlid_cmos.h" #include "netlist/analog/nlid_twoterm.h" #include "netlist/solver/nld_solver.h" +#include "nlid_cmos.h" namespace netlist { namespace devices { @@ -38,7 +38,7 @@ namespace netlist { namespace devices { NETLIB_RESET(CD4316_GATE) { - m_R.set_R(NL_FCONST(1.0) / exec().gmin()); + m_R.set_R(plib::constants::one / exec().gmin()); } NETLIB_UPDATE(CD4316_GATE) @@ -47,10 +47,11 @@ namespace netlist { namespace devices { if (m_S() && !m_E()) m_R.set_R(m_base_r()); else - m_R.set_R(NL_FCONST(1.0) / exec().gmin()); + m_R.set_R(plib::constants::one / exec().gmin()); m_R.solve_later(NLTIME_FROM_NS(1)); } NETLIB_DEVICE_IMPL(CD4316_GATE, "CD4316_GATE", "") -} } // namesapce netlist::devices +} // namespace devices + } // namespace netlist diff --git a/src/lib/netlist/devices/nld_74165.cpp b/src/lib/netlist/devices/nld_74165.cpp index 6ad95da091f..a8aef44b623 100644 --- a/src/lib/netlist/devices/nld_74165.cpp +++ b/src/lib/netlist/devices/nld_74165.cpp @@ -86,6 +86,7 @@ namespace netlist } else if (!m_CLK() || m_CLKINH()) { + // FIXME: qh is overwritten below? qh = old_qh; } else if (!m_last_CLK) diff --git a/src/lib/netlist/devices/nld_7448.cpp b/src/lib/netlist/devices/nld_7448.cpp index 239d6b50921..f14714de17c 100644 --- a/src/lib/netlist/devices/nld_7448.cpp +++ b/src/lib/netlist/devices/nld_7448.cpp @@ -133,7 +133,7 @@ namespace netlist #else -#define BITS7(b6,b5,b4,b3,b2,b1,b0) (b6<<6) | (b5<<5) | (b4<<4) | (b3<<3) | (b2<<2) | (b1<<1) | (b0<<0) +#define BITS7(b6,b5,b4,b3,b2,b1,b0) ((b6)<<6) | ((b5)<<5) | ((b4)<<4) | ((b3)<<3) | ((b2)<<2) | ((b1)<<1) | ((b0)<<0) static constexpr uint8_t tab7448[16] = { diff --git a/src/lib/netlist/devices/nld_7483.cpp b/src/lib/netlist/devices/nld_7483.cpp index 2fbdeb7e52b..285fbeee19e 100644 --- a/src/lib/netlist/devices/nld_7483.cpp +++ b/src/lib/netlist/devices/nld_7483.cpp @@ -107,7 +107,7 @@ namespace netlist NETLIB_UPDATE(7483) { - uint8_t r = static_cast(m_a + m_b + m_C0()); + auto r = static_cast(m_a + m_b + m_C0()); if (r != m_lastr) { diff --git a/src/lib/netlist/devices/nld_74ls629.cpp b/src/lib/netlist/devices/nld_74ls629.cpp index bdebea3a45e..5383501043c 100644 --- a/src/lib/netlist/devices/nld_74ls629.cpp +++ b/src/lib/netlist/devices/nld_74ls629.cpp @@ -210,7 +210,7 @@ namespace netlist freq += k9 * v_rng * v_freq_3; freq += k10 * v_rng * v_freq_4; - freq *= NL_FCONST(0.1e-6) / m_CAP(); + freq *= plib::constants()(0.1e-6) / m_CAP(); // FIXME: we need a possibility to remove entries from queue ... // or an exact model ... diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp index 107cd3863c0..c99fcb5a9bc 100644 --- a/src/lib/netlist/devices/nld_log.cpp +++ b/src/lib/netlist/devices/nld_log.cpp @@ -6,8 +6,8 @@ */ #include "../nl_base.h" -#include "../plib/pstream.h" #include "../plib/pfmtlog.h" +#include "../plib/pstream.h" #include "nld_log.h" //#include "sound/wavwrite.h" diff --git a/src/lib/netlist/devices/nld_mm5837.cpp b/src/lib/netlist/devices/nld_mm5837.cpp index eb2840d31fa..93ba4683a0a 100644 --- a/src/lib/netlist/devices/nld_mm5837.cpp +++ b/src/lib/netlist/devices/nld_mm5837.cpp @@ -6,8 +6,8 @@ */ #include "nld_mm5837.h" -#include "../solver/nld_matrix_solver.h" #include "../analog/nlid_twoterm.h" +#include "../solver/nld_matrix_solver.h" #define R_LOW (1000.0) #define R_HIGH (1000.0) @@ -69,7 +69,7 @@ namespace netlist { //m_V0.initial(0.0); //m_RV.do_reset(); - m_RV.set(NL_FCONST(1.0) / R_LOW, 0.0, 0.0); + m_RV.set(plib::constants::one / R_LOW, 0.0, 0.0); m_inc = netlist_time::from_double(1.0 / m_FREQ()); if (m_FREQ() < 24000 || m_FREQ() > 56000) log().warning(MW_1_FREQUENCY_OUTSIDE_OF_SPECS_1, m_FREQ()); @@ -108,7 +108,7 @@ namespace netlist // We only need to update the net first if this is a time stepping net if (m_is_timestep) m_RV.update(); - m_RV.set(NL_FCONST(1.0) / R, V, 0.0); + m_RV.set(plib::constants::one / R, V, plib::constants::zero); m_RV.solve_later(NLTIME_FROM_NS(1)); } diff --git a/src/lib/netlist/devices/nld_r2r_dac.cpp b/src/lib/netlist/devices/nld_r2r_dac.cpp index a622ebe52ab..594ee185600 100644 --- a/src/lib/netlist/devices/nld_r2r_dac.cpp +++ b/src/lib/netlist/devices/nld_r2r_dac.cpp @@ -6,8 +6,8 @@ */ #include "../nl_base.h" -#include "../nl_factory.h" #include "../analog/nlid_twoterm.h" +#include "../nl_factory.h" namespace netlist { @@ -50,6 +50,6 @@ namespace netlist namespace devices { NETLIB_DEVICE_IMPL_NS(analog, r2r_dac, "R2R_DAC", "VIN,R,N") - } + } // namespace devices } // namespace netlist diff --git a/src/lib/netlist/devices/nld_schmitt.cpp b/src/lib/netlist/devices/nld_schmitt.cpp index a21f50c0681..ed3783535a0 100644 --- a/src/lib/netlist/devices/nld_schmitt.cpp +++ b/src/lib/netlist/devices/nld_schmitt.cpp @@ -7,9 +7,9 @@ #include "nld_schmitt.h" +#include "../analog/nlid_twoterm.h" #include "../nl_base.h" #include "../nl_errstr.h" -#include "../analog/nlid_twoterm.h" #include "../solver/nld_solver.h" #include @@ -85,8 +85,8 @@ namespace netlist m_RVI.reset(); m_RVO.reset(); m_is_timestep = m_RVO.m_P.net().solver()->has_timestep_devices(); - m_RVI.set(NL_FCONST(1.0) / m_model.m_RI, m_model.m_VI, 0.0); - m_RVO.set(NL_FCONST(1.0) / m_model.m_ROL, m_model.m_VOL, 0.0); + m_RVI.set(plib::constants::one / m_model.m_RI, m_model.m_VI, 0.0); + m_RVO.set(plib::constants::one / m_model.m_ROL, m_model.m_VOL, 0.0); } NETLIB_UPDATEI() @@ -98,7 +98,7 @@ namespace netlist m_last_state = 0; if (m_is_timestep) m_RVO.update(); - m_RVO.set(NL_FCONST(1.0) / m_model.m_ROH, m_model.m_VOH, 0.0); + m_RVO.set(plib::constants::one / m_model.m_ROH, m_model.m_VOH, 0.0); m_RVO.solve_later(); } } @@ -109,7 +109,7 @@ namespace netlist m_last_state = 1; if (m_is_timestep) m_RVO.update(); - m_RVO.set(NL_FCONST(1.0) / m_model.m_ROL, m_model.m_VOL, 0.0); + m_RVO.set(plib::constants::one / m_model.m_ROL, m_model.m_VOL, 0.0); m_RVO.solve_later(); } } diff --git a/src/lib/netlist/devices/nlid_cmos.h b/src/lib/netlist/devices/nlid_cmos.h index f9999aebcc0..053cc9b5b5e 100644 --- a/src/lib/netlist/devices/nlid_cmos.h +++ b/src/lib/netlist/devices/nlid_cmos.h @@ -8,8 +8,8 @@ #ifndef NLID_CMOS_H_ #define NLID_CMOS_H_ -#include "../nl_setup.h" #include "../nl_base.h" +#include "../nl_setup.h" namespace netlist { diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index 741c864246d..44d3d3af9a5 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -29,10 +29,6 @@ namespace netlist m_proxy_term = proxy_inout; } - nld_base_proxy::~nld_base_proxy() - { - } - // ---------------------------------------------------------------------------------------- // nld_a_to_d_proxy // ---------------------------------------------------------------------------------------- @@ -44,18 +40,12 @@ namespace netlist { } - nld_base_a_to_d_proxy::~nld_base_a_to_d_proxy() {} - nld_a_to_d_proxy::nld_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied) : nld_base_a_to_d_proxy(anetlist, name, in_proxied, &m_I) , m_I(*this, "I") { } - nld_a_to_d_proxy::~nld_a_to_d_proxy() - { - } - NETLIB_RESET(a_to_d_proxy) { } @@ -88,10 +78,6 @@ namespace netlist { } - nld_base_d_to_a_proxy::~nld_base_d_to_a_proxy() - { - } - nld_d_to_a_proxy::nld_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied) : nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P) , m_GNDHack(*this, "_Q") @@ -139,13 +125,13 @@ namespace netlist m_last_state = -1; m_RV.reset(); m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices(); - m_RV.set(NL_FCONST(1.0) / logic_family()->R_low(), + m_RV.set(plib::constants::one / logic_family()->R_low(), logic_family()->low_V(0.0, supply_V), 0.0); } NETLIB_UPDATE(d_to_a_proxy) { - const int state = static_cast(m_I()); + const auto state = static_cast(m_I()); if (state != m_last_state) { // FIXME: Variable voltage @@ -160,7 +146,7 @@ namespace netlist { m_RV.update(); } - m_RV.set(NL_FCONST(1.0) / R, V, 0.0); + m_RV.set(plib::constants::one / R, V, 0.0); m_RV.solve_later(); } } diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index eb1f2b3fe87..034f7c3d9ba 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -11,8 +11,8 @@ #ifndef NLID_PROXY_H_ #define NLID_PROXY_H_ -#include "../nl_setup.h" #include "../analog/nlid_twoterm.h" +#include "../nl_setup.h" namespace netlist { @@ -29,7 +29,7 @@ namespace netlist nld_base_proxy(netlist_base_t &anetlist, const pstring &name, logic_t *inout_proxied, detail::core_terminal_t *proxy_inout); - virtual ~nld_base_proxy(); + ~nld_base_proxy() override = default; logic_t &term_proxied() const { return *m_term_proxied; } detail::core_terminal_t &proxy_term() const { return *m_proxy_term; } @@ -49,7 +49,7 @@ namespace netlist { public: - virtual ~nld_base_a_to_d_proxy(); + ~nld_base_a_to_d_proxy() override = default; virtual logic_output_t &out() { return m_Q; } @@ -69,7 +69,7 @@ namespace netlist public: nld_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied); - virtual ~nld_a_to_d_proxy() override; + ~nld_a_to_d_proxy() override = default; analog_input_t m_I; @@ -88,7 +88,7 @@ namespace netlist NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy) { public: - virtual ~nld_base_d_to_a_proxy(); + ~nld_base_d_to_a_proxy() override = default; virtual logic_input_t &in() { return m_I; } @@ -105,7 +105,7 @@ namespace netlist { public: nld_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied); - virtual ~nld_d_to_a_proxy() override {} + ~nld_d_to_a_proxy() override = default; protected: diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 7271084bbc1..f98a74f043f 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -11,9 +11,9 @@ #ifndef NLID_SYSTEM_H_ #define NLID_SYSTEM_H_ +#include "../analog/nlid_twoterm.h" #include "../nl_base.h" #include "../nl_setup.h" -#include "../analog/nlid_twoterm.h" #include "../plib/putil.h" namespace netlist @@ -27,7 +27,7 @@ namespace netlist NETLIB_OBJECT(netlistparams) { NETLIB_CONSTRUCTOR(netlistparams) - , m_use_deactivate(*this, "USE_DEACTIVATE", 0) + , m_use_deactivate(*this, "USE_DEACTIVATE", false) { } NETLIB_UPDATEI() { } @@ -125,18 +125,15 @@ namespace netlist std::vector pat(plib::psplit(m_pattern(),",")); m_off = netlist_time::from_double(m_offset()); - unsigned long pati[32]; - for (int pI = 0; pI < 32; pI++) - { - pati[pI] = 0; - } + netlist_time::mult_type pati[32] = { 0 }; + m_size = static_cast(pat.size()); - unsigned long total = 0; + netlist_time::mult_type total = 0; for (unsigned i=0; i(pat[i]); - pati[i] = plib::pstonum(pat[i]); + pati[i] = plib::pstonum(pat[i]); total += pati[i]; } netlist_time ttotal = netlist_time::zero(); @@ -177,7 +174,7 @@ namespace netlist { NETLIB_CONSTRUCTOR(logic_input) , m_Q(*this, "Q") - , m_IN(*this, "IN", 0) + , m_IN(*this, "IN", false) /* make sure we get the family first */ , m_FAMILY(*this, "FAMILY", "FAMILY(TYPE=TTL)") { diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index 2377071c4e2..5eda50e0357 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -6,9 +6,9 @@ */ #include "nlid_truthtable.h" -#include "../plib/plists.h" #include "../nl_setup.h" #include "../plib/palloc.h" +#include "../plib/plists.h" #include @@ -394,7 +394,7 @@ void truthtable_parser::parse(const std::vector &truthtable) else nl_assert_always(outs == "0", "Unknown value (not 0 or 1"); // FIXME: error handling - netlist_time t = netlist_time::from_nsec(plib::pstonum(plib::trim(times[j]))); + netlist_time t = netlist_time::from_nsec(plib::pstonum(plib::trim(times[j]))); uint_least8_t k=0; while (m_timing_nt[k] != netlist_time::zero() && m_timing_nt[k] != t) k++; @@ -451,11 +451,6 @@ netlist_base_factory_truthtable_t::netlist_base_factory_truthtable_t(const pstri { } -netlist_base_factory_truthtable_t::~netlist_base_factory_truthtable_t() -{ -} - - #define ENTRYY(n, m, s) case (n * 100 + m): \ { using xtype = netlist_factory_truthtable_t; \ ret = plib::palloc(desc.name, desc.classname, desc.def_param, s); } break diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h index 6896c656750..c344feda2d4 100644 --- a/src/lib/netlist/devices/nlid_truthtable.h +++ b/src/lib/netlist/devices/nlid_truthtable.h @@ -10,8 +10,8 @@ #ifndef NLID_TRUTHTABLE_H_ #define NLID_TRUTHTABLE_H_ -#include "../nl_setup.h" #include "../nl_base.h" +#include "../nl_setup.h" #include "../plib/putil.h" #define NETLIB_TRUTHTABLE(cname, nIN, nOUT) \ @@ -90,8 +90,10 @@ namespace devices struct truthtable_t { truthtable_t() - : m_initialized(false) + : m_timing_index{0} + , m_initialized(false) {} + type_t m_out_state[m_size]; uint_least8_t m_timing_index[m_size * m_NO]; netlist_time m_timing_nt[16]; @@ -217,7 +219,7 @@ namespace devices netlist_base_factory_truthtable_t(const pstring &name, const pstring &classname, const pstring &def_param, const pstring &sourcefile); - virtual ~netlist_base_factory_truthtable_t(); + ~netlist_base_factory_truthtable_t() override = default; std::vector m_desc; const logic_family_desc_t *m_family; diff --git a/src/lib/netlist/macro/nlm_cd4xxx.cpp b/src/lib/netlist/macro/nlm_cd4xxx.cpp index 9ce786ca85e..a9d622032fd 100644 --- a/src/lib/netlist/macro/nlm_cd4xxx.cpp +++ b/src/lib/netlist/macro/nlm_cd4xxx.cpp @@ -2,10 +2,10 @@ // copyright-holders:Couriersud #include "nlm_cd4xxx.h" -#include "../devices/nld_system.h" #include "../devices/nld_4020.h" #include "../devices/nld_4066.h" #include "../devices/nld_4316.h" +#include "../devices/nld_system.h" /* * CD4001BC: Quad 2-Input NOR Buffered B Series Gate diff --git a/src/lib/netlist/netlist_types.h b/src/lib/netlist/netlist_types.h index bbca9949e49..9edd19e0ace 100644 --- a/src/lib/netlist/netlist_types.h +++ b/src/lib/netlist/netlist_types.h @@ -9,13 +9,14 @@ #ifndef NETLIST_TYPES_H_ #define NETLIST_TYPES_H_ +#include +#include + #include "nl_config.h" #include "plib/pchrono.h" -#include "plib/pstring.h" #include "plib/pfmtlog.h" +#include "plib/pstring.h" -#include -#include namespace netlist { @@ -37,7 +38,7 @@ namespace netlist class callbacks_t { public: - virtual ~callbacks_t() {} + virtual ~callbacks_t() = default; /* logging callback */ virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0; @@ -74,7 +75,7 @@ namespace netlist */ using model_map_t = std::unordered_map; - } -} + } // namespace detail +} // namespace netlist #endif /* NETLIST_TYPES_H_ */ diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 24cb7cc8890..7447ddb5f02 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -8,18 +8,18 @@ #include "solver/nld_matrix_solver.h" #include "solver/nld_solver.h" -#include "plib/putil.h" #include "plib/palloc.h" +#include "plib/putil.h" -#include "nl_base.h" -#include "devices/nlid_system.h" #include "devices/nlid_proxy.h" +#include "devices/nlid_system.h" #include "macro/nlm_base.h" +#include "nl_base.h" #include "nl_errstr.h" -#include #include +#include #include namespace netlist @@ -56,26 +56,18 @@ namespace detail } } -} - -nl_exception::~nl_exception() -{ -} +} // namespace detail // ---------------------------------------------------------------------------------------- // logic_family_ttl_t // ---------------------------------------------------------------------------------------- +// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init, modernize-use-equals-default) logic_family_desc_t::logic_family_desc_t() { } -logic_family_desc_t::~logic_family_desc_t() -{ -} - - class logic_family_ttl_t : public logic_family_desc_t { public: @@ -90,8 +82,8 @@ public: m_R_low = 1.0; m_R_high = 130.0; } - virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; - virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; + plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; + plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; }; plib::owned_ptr logic_family_ttl_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const @@ -117,8 +109,8 @@ public: m_R_low = 10.0; m_R_high = 10.0; } - virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; - virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; + plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; + plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; }; plib::owned_ptr logic_family_cd4xxx_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const @@ -166,6 +158,7 @@ void detail::queue_t::register_state(plib::state_manager_t &manager, const pstri void detail::queue_t::on_pre_save(plib::state_manager_t &manager) { + plib::unused_var(manager); m_qsize = this->size(); for (std::size_t i = 0; i < m_qsize; i++ ) { @@ -177,6 +170,7 @@ void detail::queue_t::on_pre_save(plib::state_manager_t &manager) void detail::queue_t::on_post_load(plib::state_manager_t &manager) { + plib::unused_var(manager); this->clear(); for (std::size_t i = 0; i < m_qsize; i++ ) { @@ -197,17 +191,15 @@ detail::netlist_ref::netlist_ref(netlist_state_t &nl) // ---------------------------------------------------------------------------------------- detail::object_t::object_t(const pstring &aname) - : m_name(plib::make_unique(aname)) +// : m_name(aname) { + name_hash().insert({this, aname}); } -detail::object_t::~object_t() +pstring detail::object_t::name() const { -} - -const pstring &detail::object_t::name() const -{ - return *m_name; + return name_hash().find(this)->second; + //return m_name; } // ---------------------------------------------------------------------------------------- @@ -258,10 +250,6 @@ netlist_t::netlist_t(const pstring &aname, std::unique_ptr callback run_state_manager().save_item(this, m_time, "m_time"); } -netlist_t::~netlist_t() -{ -} - // ---------------------------------------------------------------------------------------- // netlist_t // ---------------------------------------------------------------------------------------- @@ -355,7 +343,7 @@ void netlist_state_t::reset() // Reset all devices once ! log().verbose("Call reset on all devices:"); for (auto & dev : m_devices) - dev->reset(); + dev.second->reset(); // Make sure everything depending on parameters is set // Currently analog input and logic input also @@ -363,7 +351,7 @@ void netlist_state_t::reset() log().verbose("Call update_param on all devices:"); for (auto & dev : m_devices) - dev->update_param(); + dev.second->update_param(); // Step all devices once ! /* @@ -389,14 +377,14 @@ void netlist_state_t::reset() t.push_back(&term->m_delegate); term->m_delegate(); } - core_device_t *dev = reinterpret_cast(term->m_delegate.object()); + auto *dev = reinterpret_cast(term->m_delegate.object()); if (!plib::container::contains(d, dev)) d.push_back(dev); } log().verbose("Devices not yet updated:"); for (auto &dev : m_devices) - if (!plib::container::contains(d, dev.get())) - log().verbose("\t ...{1}", dev->name()); + if (!plib::container::contains(d, dev.second.get())) + log().verbose("\t ...{1}", dev.second->name()); //x->update_dev(); } break; @@ -409,7 +397,7 @@ void netlist_state_t::reset() std::size_t i = m_devices.size(); while (i>0) - m_devices[--i]->update(); + m_devices[--i].second->update(); for (auto &n : m_nets) // only used if USE_COPY_INSTEAD_OF_REFERENCE == 1 n->update_inputs(); @@ -420,7 +408,7 @@ void netlist_state_t::reset() { log().verbose("Using brute force forward startup strategy"); for (auto &d : m_devices) - d->update(); + d.second->update(); } break; } @@ -434,11 +422,11 @@ void netlist_state_t::reset() void netlist_t::process_queue(const netlist_time delta) NL_NOEXCEPT { + auto sm_guard(m_stat_mainloop.guard()); netlist_time stop(m_time + delta); m_queue.push(detail::queue_t::entry_t(stop, nullptr)); - auto sm_guard(m_stat_mainloop.guard()); if (m_mainclock == nullptr) { @@ -491,14 +479,14 @@ void netlist_t::print_stats() const index.push_back(i); std::sort(index.begin(), index.end(), - [&](size_t i1, size_t i2) { return m_state->m_devices[i1]->m_stat_total_time.total() < m_state->m_devices[i2]->m_stat_total_time.total(); }); + [&](size_t i1, size_t i2) { return m_state->m_devices[i1].second->m_stat_total_time.total() < m_state->m_devices[i2].second->m_stat_total_time.total(); }); nperftime_t::type total_time(0); - uint_least64_t total_count(0); + netlist_time::mult_type total_count(0); for (auto & j : index) { - auto entry = m_state->m_devices[j].get(); + auto entry = m_state->m_devices[j].second.get(); log().verbose("Device {1:20} : {2:12} {3:12} {4:15} {5:12}", entry->name(), entry->m_stat_call_count(), entry->m_stat_total_time.count(), entry->m_stat_total_time.total(), entry->m_stat_inc_active()); @@ -543,12 +531,13 @@ void netlist_t::print_stats() const auto trigger = total_count * 200 / 1000000; // 200 ppm for (auto &entry : m_state->m_devices) { + auto ep = entry.second.get(); // Factor of 3 offers best performace increase - if (entry->m_stat_inc_active() > 3 * entry->m_stat_total_time.count() - && entry->m_stat_inc_active() > trigger) - log().verbose("HINT({}, NO_DEACTIVATE) // {} {} {}", entry->name(), - static_cast(entry->m_stat_inc_active()) / static_cast(entry->m_stat_total_time.count()), - entry->m_stat_inc_active(), entry->m_stat_total_time.count()); + if (ep->m_stat_inc_active() > 3 * ep->m_stat_total_time.count() + && ep->m_stat_inc_active() > trigger) + log().verbose("HINT({}, NO_DEACTIVATE) // {} {} {}", ep->name(), + static_cast(ep->m_stat_inc_active()) / static_cast(ep->m_stat_total_time.count()), + ep->m_stat_inc_active(), ep->m_stat_total_time.count()); } } } @@ -558,12 +547,12 @@ core_device_t *netlist_state_t::get_single_device(const pstring &classname, bool core_device_t *ret = nullptr; for (auto &d : m_devices) { - if (cc(d.get())) + if (cc(d.second.get())) { if (ret != nullptr) m_log.fatal(MF_1_MORE_THAN_ONE_1_DEVICE_FOUND, classname); else - ret = d.get(); + ret = d.second.get(); } } return ret; @@ -595,11 +584,7 @@ core_device_t::core_device_t(core_device_t &owner, const pstring &name) set_logic_family(owner.logic_family()); if (logic_family() == nullptr) set_logic_family(family_TTL()); - state().add_dev(plib::owned_ptr(this, false)); -} - -core_device_t::~core_device_t() -{ + state().add_dev(this->name(), plib::owned_ptr(this, false)); } void core_device_t::set_default_delegate(detail::core_terminal_t &term) @@ -627,11 +612,6 @@ device_t::device_t(core_device_t &owner, const pstring &name) { } -device_t::~device_t() -{ - //log().debug("~net_device_t\n"); -} - setup_t &device_t::setup() { return state().setup(); @@ -683,6 +663,11 @@ void device_t::connect_post_start(detail::core_terminal_t &t1, detail::core_term // family_setter_t // ----------------------------------------------------------------------------- +// NOLINTNEXTLINE(modernize-use-equals-default) +detail::family_setter_t::family_setter_t() +{ +} + detail::family_setter_t::family_setter_t(core_device_t &dev, const pstring &desc) { dev.set_logic_family(dev.setup().family_from_model(desc)); @@ -776,7 +761,7 @@ void detail::net_t::reset() m_new_Q = 0; m_cur_Q = 0; - analog_net_t *p = dynamic_cast(this); + auto *p = dynamic_cast(this); if (p != nullptr) p->m_cur_Analog = 0.0; @@ -833,10 +818,6 @@ logic_net_t::logic_net_t(netlist_base_t &nl, const pstring &aname, detail::core_ { } -logic_net_t::~logic_net_t() -{ -} - // ---------------------------------------------------------------------------------------- // analog_net_t // ---------------------------------------------------------------------------------------- @@ -848,10 +829,6 @@ analog_net_t::analog_net_t(netlist_base_t &nl, const pstring &aname, detail::cor { } -analog_net_t::~analog_net_t() -{ -} - // ---------------------------------------------------------------------------------------- // core_terminal_t // ---------------------------------------------------------------------------------------- @@ -869,19 +846,11 @@ detail::core_terminal_t::core_terminal_t(core_device_t &dev, const pstring &anam { } -detail::core_terminal_t::~core_terminal_t() -{ -} - analog_t::analog_t(core_device_t &dev, const pstring &aname, const state_e state) : core_terminal_t(dev, aname, state) { } -analog_t::~analog_t() -{ -} - logic_t::logic_t(core_device_t &dev, const pstring &aname, const state_e state, nldelegate delegate) : core_terminal_t(dev, aname, state, delegate) @@ -890,28 +859,20 @@ logic_t::logic_t(core_device_t &dev, const pstring &aname, const state_e state, { } -logic_t::~logic_t() -{ -} - // ---------------------------------------------------------------------------------------- // terminal_t // ---------------------------------------------------------------------------------------- -terminal_t::terminal_t(core_device_t &dev, const pstring &aname) +terminal_t::terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm) : analog_t(dev, aname, STATE_BIDIR) -, m_otherterm(nullptr) , m_Idr1(nullptr) , m_go1(nullptr) , m_gt1(nullptr) +, m_otherterm(otherterm) { state().setup().register_term(*this); } -terminal_t::~terminal_t() -{ -} - void terminal_t::solve_now() { // Nets may belong to railnets which do not have a solver attached @@ -950,10 +911,6 @@ logic_output_t::logic_output_t(core_device_t &dev, const pstring &aname) state().setup().register_term(*this); } -logic_output_t::~logic_output_t() -{ -} - void logic_output_t::initial(const netlist_sig_t val) { if (has_net()) @@ -970,10 +927,6 @@ analog_input_t::analog_input_t(core_device_t &dev, const pstring &aname) state().setup().register_term(*this); } -analog_input_t::~analog_input_t() -{ -} - // ---------------------------------------------------------------------------------------- // analog_output_t // ---------------------------------------------------------------------------------------- @@ -989,10 +942,6 @@ analog_output_t::analog_output_t(core_device_t &dev, const pstring &aname) state().setup().register_term(*this); } -analog_output_t::~analog_output_t() -{ -} - void analog_output_t::initial(const nl_double val) { net().set_Q_Analog(val); @@ -1010,10 +959,6 @@ logic_input_t::logic_input_t(core_device_t &dev, const pstring &aname, state().setup().register_term(*this); } -logic_input_t::~logic_input_t() -{ -} - // ---------------------------------------------------------------------------------------- // Parameters ... // ---------------------------------------------------------------------------------------- @@ -1024,10 +969,6 @@ param_t::param_t(device_t &device, const pstring &name) device.setup().register_param(this->name(), *this); } -param_t::~param_t() -{ -} - param_t::param_type_t param_t::param_type() const { if (dynamic_cast(this) != nullptr) @@ -1074,10 +1015,6 @@ param_str_t::param_str_t(device_t &device, const pstring &name, const pstring &v m_param = device.setup().get_initial_param_val(this->name(),val); } -param_str_t::~param_str_t() -{ -} - void param_str_t::changed() { } diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 507eb42d367..58563c91610 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -13,18 +13,20 @@ #error "nl_base.h included. Please correct." #endif -#include "netlist_types.h" -#include "nl_errstr.h" -#include "nl_lists.h" -#include "nl_time.h" +#include +#include + #include "plib/palloc.h" // owned_ptr #include "plib/pdynlib.h" -#include "plib/pstate.h" #include "plib/pfmtlog.h" -#include "plib/pstream.h" #include "plib/ppmf.h" +#include "plib/pstate.h" +#include "plib/pstream.h" -#include +#include "netlist_types.h" +#include "nl_errstr.h" +#include "nl_lists.h" +#include "nl_time.h" //============================================================ // MACROS / New Syntax @@ -186,7 +188,7 @@ namespace netlist class NETLIB_NAME(base_proxy); class NETLIB_NAME(base_d_to_a_proxy); class NETLIB_NAME(base_a_to_d_proxy); - } + } // namespace devices namespace detail { class object_t; @@ -196,13 +198,12 @@ namespace netlist struct family_setter_t; class queue_t; class net_t; - } + } // namespace detail class logic_output_t; class logic_input_t; class analog_net_t; class logic_net_t; - class net_t; class setup_t; class netlist_t; class netlist_state_t; @@ -228,8 +229,7 @@ namespace netlist ) : plib::pexception(text) { } /*! Copy constructor. */ - nl_exception(const nl_exception &e) : plib::pexception(e) { } - virtual ~nl_exception(); + nl_exception(const nl_exception &e) = default; }; /*! Logic families descriptors are used to create proxy devices. @@ -240,7 +240,7 @@ namespace netlist { public: logic_family_desc_t(); - virtual ~logic_family_desc_t(); + virtual ~logic_family_desc_t() = default; virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const = 0; @@ -250,8 +250,8 @@ namespace netlist double fixed_V() const { return m_fixed_V; } double low_thresh_V(const double VN, const double VP) const { return VN + (VP - VN) * m_low_thresh_PCNT; } double high_thresh_V(const double VN, const double VP) const { return VN + (VP - VN) * m_high_thresh_PCNT; } - double low_V(const double VN, const double VP) const { return VN + m_low_VO; } - double high_V(const double VN, const double VP) const { return VP - m_high_VO; } + double low_V(const double VN, const double VP) const { plib::unused_var(VP); return VN + m_low_VO; } + double high_V(const double VN, const double VP) const { plib::unused_var(VN); return VP - m_high_VO; } double R_low() const { return m_R_low; } double R_high() const { return m_R_high; } @@ -285,7 +285,7 @@ namespace netlist void set_logic_family(const logic_family_desc_t *fam) { m_logic_family = fam; } protected: - ~logic_family_t() { } // prohibit polymorphic destruction + ~logic_family_t() = default; // prohibit polymorphic destruction const logic_family_desc_t *m_logic_family; }; @@ -391,7 +391,7 @@ namespace netlist * memory allocation to enhance locality. Please refer to \ref USE_MEMPOOL as * well. */ - class detail::object_t + class detail::object_t : public plib::nocopyassignmove { public: @@ -405,17 +405,22 @@ namespace netlist * * \returns name of the object. */ - const pstring &name() const; + pstring name() const; - void * operator new (size_t size, void *ptr) { return ptr; } - void operator delete (void *ptr, void *) { } + void * operator new (size_t size, void *ptr) { plib::unused_var(size); return ptr; } + void operator delete (void *ptr, void *) { plib::unused_var(ptr); } void * operator new (size_t size); void operator delete (void * mem); protected: - ~object_t(); // only childs should be destructible + ~object_t() = default; // only childs should be destructible private: - std::unique_ptr m_name; + //pstring m_name; + static std::unordered_map &name_hash() + { + static std::unordered_map lhash; + return lhash; + } }; struct detail::netlist_ref @@ -508,7 +513,7 @@ namespace netlist core_terminal_t(core_device_t &dev, const pstring &aname, const state_e state, nldelegate delegate = nldelegate()); - virtual ~core_terminal_t(); + virtual ~core_terminal_t() = default; /*! The object type. * \returns type of the object @@ -562,7 +567,6 @@ namespace netlist public: analog_t(core_device_t &dev, const pstring &aname, const state_e state); - virtual ~analog_t(); const analog_net_t & net() const NL_NOEXCEPT; analog_net_t & net() NL_NOEXCEPT; @@ -576,8 +580,7 @@ namespace netlist { public: - terminal_t(core_device_t &dev, const pstring &aname); - virtual ~terminal_t(); + terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm); nl_double operator ()() const NL_NOEXCEPT; @@ -593,36 +596,28 @@ namespace netlist void set(const nl_double GO, const nl_double GT, const nl_double I) noexcept { - set_ptr(m_Idr1, I); - set_ptr(m_go1, GO); - set_ptr(m_gt1, GT); + if (m_go1 != nullptr) + { + if (*m_Idr1 != I) *m_Idr1 = I; + if (*m_go1 != GO) *m_go1 = GO; + if (*m_gt1 != GT) *m_gt1 = GT; + } } void solve_now(); void schedule_solve_after(const netlist_time after); - void set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) noexcept - { - m_gt1 = gt; - m_go1 = go; - m_Idr1 = Idr; - } - - terminal_t *m_otherterm; + void set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) noexcept; + terminal_t *otherterm() const noexcept { return m_otherterm; } private: - void set_ptr(nl_double *ptr, const nl_double val) noexcept - { - if (ptr != nullptr && *ptr != val) - { - *ptr = val; - } - } nl_double *m_Idr1; // drive current nl_double *m_go1; // conductance for Voltage from other term nl_double *m_gt1; // conductance for total conductance + terminal_t *m_otherterm; + }; @@ -635,7 +630,6 @@ namespace netlist public: logic_t(core_device_t &dev, const pstring &aname, const state_e state, nldelegate delegate = nldelegate()); - virtual ~logic_t(); bool has_proxy() const { return (m_proxy != nullptr); } devices::nld_base_proxy *get_proxy() const { return m_proxy; } @@ -659,7 +653,6 @@ namespace netlist public: logic_input_t(core_device_t &dev, const pstring &aname, nldelegate delegate = nldelegate()); - virtual ~logic_input_t(); netlist_sig_t operator()() const NL_NOEXCEPT { @@ -691,9 +684,6 @@ namespace netlist const pstring &aname /*!< name of terminal */ ); - /*! Destructor */ - virtual ~analog_input_t(); - /*! returns voltage at terminal. * \returns voltage at terminal. */ @@ -796,7 +786,6 @@ namespace netlist public: logic_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); - virtual ~logic_net_t(); netlist_sig_t Q() const noexcept { return m_cur_Q; } void initial(const netlist_sig_t val) noexcept @@ -853,8 +842,6 @@ namespace netlist analog_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr); - virtual ~analog_net_t(); - nl_double Q_Analog() const NL_NOEXCEPT { return m_cur_Analog; } void set_Q_Analog(const nl_double v) NL_NOEXCEPT { m_cur_Analog = v; } nl_double *Q_Analog_state_ptr() NL_NOEXCEPT { return m_cur_Analog.ptr(); } @@ -877,7 +864,6 @@ namespace netlist public: logic_output_t(core_device_t &dev, const pstring &aname); - virtual ~logic_output_t(); void initial(const netlist_sig_t val); @@ -904,7 +890,6 @@ namespace netlist { public: analog_output_t(core_device_t &dev, const pstring &aname); - virtual ~analog_output_t(); void push(const nl_double val) NL_NOEXCEPT { set_Q(val); } void initial(const nl_double val); @@ -935,7 +920,7 @@ namespace netlist param_type_t param_type() const; protected: - virtual ~param_t(); /* not intended to be destroyed */ + virtual ~param_t() = default; /* not intended to be destroyed */ void update_param(); @@ -995,10 +980,9 @@ namespace netlist { public: param_str_t(device_t &device, const pstring &name, const pstring &val); - virtual ~param_str_t(); const pstring &operator()() const NL_NOEXCEPT { return Value(); } - void setTo(netlist_time time, const pstring ¶m) NL_NOEXCEPT + void setTo(const pstring ¶m) NL_NOEXCEPT { if (m_param != param) { @@ -1042,12 +1026,12 @@ namespace netlist const pstring model_value_str(const pstring &entity) /*const*/; const pstring model_type() /*const*/; + /* hide this */ + void setTo(const pstring ¶m) = delete; protected: - virtual void changed() override; + void changed() override; nl_double model_value(const pstring &entity) /*const*/; private: - /* hide this */ - void setTo(const pstring ¶m) = delete; detail::model_map_t m_map; }; @@ -1065,7 +1049,7 @@ namespace netlist std::unique_ptr stream(); protected: - virtual void changed() override { } + void changed() override { } }; // ----------------------------------------------------------------------------- @@ -1081,7 +1065,7 @@ namespace netlist const ST & operator[] (std::size_t n) NL_NOEXCEPT { return m_data[n]; } protected: - virtual void changed() override + void changed() override { stream()->read(reinterpret_cast(&m_data[0]),1<>; - using devices_collection_type = std::vector>; + + /* need to preserve order of device creation ... */ + using devices_collection_type = std::vector>>; netlist_state_t(const pstring &aname, std::unique_ptr &&callbacks, std::unique_ptr &&setup); @@ -1289,13 +1279,15 @@ namespace netlist plib::state_manager_t &run_state_manager() { return m_state; } - template void save(O &owner, C &state, const pstring &stname) + template + void save(O &owner, C &state, const pstring &module, const pstring &stname) { - this->run_state_manager().save_item(static_cast(&owner), state, owner.name() + pstring(".") + stname); + this->run_state_manager().save_item(static_cast(&owner), state, module + pstring(".") + stname); } - template void save(O &owner, C *state, const pstring &stname, const std::size_t count) + template + void save(O &owner, C *state, const pstring &module, const pstring &stname, const std::size_t count) { - this->run_state_manager().save_state_ptr(static_cast(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f::f(), count, state); + this->run_state_manager().save_state_ptr(static_cast(&owner), module + pstring(".") + stname, plib::state_manager_t::dtype(), count, state); } core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const; @@ -1312,33 +1304,31 @@ namespace netlist std::vector tmp; for (auto &d : m_devices) { - device_class *dev = dynamic_cast(d.get()); + auto dev = dynamic_cast(d.second.get()); if (dev != nullptr) tmp.push_back(dev); } return tmp; } - void add_dev(plib::owned_ptr dev) + template + void add_dev(const pstring &name, plib::owned_ptr &&dev) { for (auto & d : m_devices) - if (d->name() == dev->name()) - log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d->name()); - m_devices.push_back(std::move(dev)); + if (d.first == name) + log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d.first); + //m_devices.push_back(std::move(dev)); + m_devices.insert(m_devices.end(), { name, std::move(dev) }); } void remove_dev(core_device_t *dev) { - m_devices.erase( - std::remove_if( - m_devices.begin(), - m_devices.end(), - [&] (plib::owned_ptr const& p) - { - return p.get() == dev; - }), - m_devices.end() - ); + for (auto it = m_devices.begin(); it != m_devices.end(); it++) + if (it->second.get() == dev) + { + m_devices.erase(it); + return; + } } /* sole use is to manage lifetime of family objects */ @@ -1379,7 +1369,7 @@ namespace netlist public: explicit netlist_t(const pstring &aname, std::unique_ptr callbacks); - ~netlist_t(); + ~netlist_t() = default; /* run functions */ @@ -1407,6 +1397,7 @@ namespace netlist template nl_double gmin(X *solv = nullptr) const NL_NOEXCEPT { + plib::unused_var(solv); return static_cast(m_solver)->gmin(); } @@ -1486,7 +1477,7 @@ namespace netlist if (found) { bool err = false; - T vald = plib::pstonum_ne(p, err); + auto vald = plib::pstonum_ne(p, err); if (err) device.state().log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, p); m_param = vald; @@ -1494,7 +1485,7 @@ namespace netlist else m_param = val; - device.state().save(*this, m_param, "m_param"); + device.state().save(*this, m_param, this->name(), "m_param"); } template @@ -1613,6 +1604,18 @@ namespace netlist inline nl_double terminal_t::operator ()() const NL_NOEXCEPT { return net().Q_Analog(); } + inline void terminal_t::set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) noexcept + { + if (!(gt && go && Idr) && (gt || go || Idr)) + state().log().fatal("Inconsistent nullptrs for terminal {}", name()); + else + { + m_gt1 = gt; + m_go1 = go; + m_Idr1 = Idr; + } + } + inline logic_net_t & logic_t::net() NL_NOEXCEPT { return static_cast(core_terminal_t::net()); @@ -1674,18 +1677,18 @@ namespace netlist state_var::state_var(O &owner, const pstring &name, const T &value) : m_value(value) { - owner.state().save(owner, m_value, name); + owner.state().save(owner, m_value, owner.name(), name); } template template state_var::state_var(O &owner, const pstring &name, const T & value) { - owner.state().save(owner, m_value, name); + owner.state().save(owner, m_value, owner.name(), name); for (std::size_t i=0; i> : ptype_traits { }; -} +} // namespace plib diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index 69b5fad945c..de9a370db2f 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -62,8 +62,6 @@ // FIXME: Convert into solver parameter #define USE_LINEAR_PREDICTION (0) -#define NETLIST_GMIN_DEFAULT (1e-9) - //============================================================ // DEBUGGING //============================================================ @@ -98,16 +96,17 @@ #endif // !defined(USE_OPENMP) // Use nano-second resolution - Sufficient for now -#define NETLIST_INTERNAL_RES (UINT64_C(1000000000)) -#define NETLIST_CLOCK (NETLIST_INTERNAL_RES) + +static constexpr const auto NETLIST_INTERNAL_RES = 1000000000; +static constexpr const auto NETLIST_CLOCK = NETLIST_INTERNAL_RES; + +//#define NETLIST_INTERNAL_RES (UINT64_C(1000000000)) +//#define NETLIST_CLOCK (NETLIST_INTERNAL_RES) //#define NETLIST_INTERNAL_RES (UINT64_C(1000000000000)) //#define NETLIST_CLOCK (UINT64_C(1000000000)) //#define nl_double float -//#define NL_FCONST(x) (x ## f) - -#define NL_FCONST(x) x using nl_double = double; //============================================================ diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp index eca8de4d4b2..26ee33853e0 100644 --- a/src/lib/netlist/nl_factory.cpp +++ b/src/lib/netlist/nl_factory.cpp @@ -10,9 +10,9 @@ #include "nl_factory.h" #include "nl_base.h" +#include "nl_errstr.h" #include "nl_setup.h" #include "plib/putil.h" -#include "nl_errstr.h" namespace netlist { namespace factory { @@ -26,7 +26,7 @@ namespace netlist { namespace factory } protected: NETLIB_RESETI() { } - NETLIB_UPDATEI() { }; + NETLIB_UPDATEI() { } }; element_t::element_t(const pstring &name, const pstring &classname, @@ -43,10 +43,6 @@ namespace netlist { namespace factory { } - element_t::~element_t() - { - } - // ---------------------------------------------------------------------------------------- // net_device_t_base_factory // ---------------------------------------------------------------------------------------- @@ -98,4 +94,5 @@ namespace netlist { namespace factory } -} } +} // namespace factory + } // namespace netlist diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index a20ba400234..ca0c266739e 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -49,10 +49,14 @@ namespace factory { const pstring &def_param); element_t(const pstring &name, const pstring &classname, const pstring &def_param, const pstring &sourcefile); - virtual ~element_t(); + virtual ~element_t() = default; virtual plib::owned_ptr Create(netlist_state_t &anetlist, const pstring &name) = 0; - virtual void macro_actions(netlist_state_t &anetlist, const pstring &name) {} + virtual void macro_actions(netlist_state_t &anetlist, const pstring &name) + { + plib::unused_var(anetlist); + plib::unused_var(name); + } const pstring &name() const { return m_name; } const pstring &classname() const { return m_classname; } @@ -133,7 +137,11 @@ namespace factory { library_element_t(setup_t &setup, const pstring &name, const pstring &classname, const pstring &def_param, const pstring &source) - : element_t(name, classname, def_param, source) { } + : element_t(name, classname, def_param, source) + { + // FIXME: if it is not used, remove it + plib::unused_var(setup); + } plib::owned_ptr Create(netlist_state_t &anetlist, const pstring &name) override; @@ -142,11 +150,11 @@ namespace factory { private: }; - } + } // namespace factory namespace devices { void initialize_factory(factory::list_t &factory); - } -} + } // namespace devices +} // namespace netlist #endif /* NLFACTORY_H_ */ diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 042a823259f..0c5b25c1a1b 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -10,16 +10,16 @@ #ifndef NLLISTS_H_ #define NLLISTS_H_ -#include "nl_config.h" #include "netlist_types.h" -#include "plib/plists.h" +#include "nl_config.h" #include "plib/pchrono.h" +#include "plib/plists.h" #include "plib/ptypes.h" +#include #include -#include #include -#include +#include #include // ---------------------------------------------------------------------------------------- @@ -33,7 +33,7 @@ namespace netlist class pspin_mutex { public: - pspin_mutex() noexcept { } + pspin_mutex() noexcept = default; void lock() noexcept{ while (m_lock.test_and_set(std::memory_order_acquire)) { } } void unlock() noexcept { m_lock.clear(std::memory_order_release); } private: @@ -309,6 +309,6 @@ namespace netlist template using timed_queue = timed_queue_linear; -} +} // namespace netlist #endif /* NLLISTS_H_ */ diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index 460ff3819bf..f28eb822a09 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -6,9 +6,9 @@ */ #include "nl_parser.h" -#include "nl_factory.h" -#include "nl_errstr.h" #include "nl_base.h" +#include "nl_errstr.h" +#include "nl_factory.h" namespace netlist { @@ -395,7 +395,7 @@ void parser_t::device(const pstring &dev_type) // ---------------------------------------------------------------------------------------- -nl_double parser_t::eval_param(const token_t tok) +nl_double parser_t::eval_param(const token_t &tok) { static pstring macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"}; static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12}; @@ -423,4 +423,4 @@ nl_double parser_t::eval_param(const token_t tok) } -} +} // namespace netlist diff --git a/src/lib/netlist/nl_parser.h b/src/lib/netlist/nl_parser.h index f14250ea7d1..16075ca4914 100644 --- a/src/lib/netlist/nl_parser.h +++ b/src/lib/netlist/nl_parser.h @@ -18,7 +18,7 @@ namespace netlist public: template parser_t(T &&strm, setup_t &setup) - : plib::ptokenizer(std::move(strm)) + : plib::ptokenizer(std::forward(strm)) , m_setup(setup) { } @@ -45,10 +45,10 @@ namespace netlist /* for debugging messages */ netlist_state_t &netlist() { return m_setup.netlist(); } - virtual void verror(const pstring &msg, int line_num, const pstring &line) override; + void verror(const pstring &msg, int line_num, const pstring &line) override; private: - nl_double eval_param(const token_t tok); + nl_double eval_param(const token_t &tok); token_id_t m_tok_param_left; token_id_t m_tok_param_right; @@ -75,6 +75,6 @@ namespace netlist setup_t &m_setup; }; -} +} // namespace netlist #endif /* NL_PARSER_H_ */ diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index cef51f481db..d60074c0e47 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -6,16 +6,16 @@ */ #include "plib/palloc.h" -#include "plib/putil.h" +#include "analog/nld_twoterm.h" +#include "devices/nlid_proxy.h" +#include "devices/nlid_system.h" +#include "devices/nlid_truthtable.h" #include "nl_base.h" -#include "nl_setup.h" -#include "nl_parser.h" #include "nl_factory.h" -#include "devices/nlid_system.h" -#include "devices/nlid_proxy.h" -#include "analog/nld_twoterm.h" +#include "nl_parser.h" +#include "nl_setup.h" +#include "plib/putil.h" #include "solver/nld_solver.h" -#include "devices/nlid_truthtable.h" #include @@ -88,17 +88,24 @@ void setup_t::register_dev(const pstring &classname, const pstring &name) auto f = factory().factory_by_name(classname); if (f == nullptr) log().fatal(MF_1_CLASS_1_NOT_FOUND, classname); - /* make sure we parse macro library entries */ - f->macro_actions(netlist(), name); - pstring key = build_fqn(name); - if (device_exists(key)) - log().fatal(MF_1_DEVICE_ALREADY_EXISTS_1, name); - m_device_factory[key] = f; + else + { + /* make sure we parse macro library entries */ + f->macro_actions(netlist(), name); + pstring key = build_fqn(name); + if (device_exists(key)) + log().fatal(MF_1_DEVICE_ALREADY_EXISTS_1, name); + else + m_device_factory.insert(m_device_factory.end(), {key, f}); + } } bool setup_t::device_exists(const pstring &name) const { - return (m_device_factory.find(name) != m_device_factory.end()); + for (auto &d : m_device_factory) + if (d.first == name) + return true; + return false; } @@ -398,7 +405,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out) { nl_assert(out.is_logic()); - logic_output_t &out_cast = static_cast(out); + auto &out_cast = static_cast(out); devices::nld_base_proxy *proxy = out_cast.get_proxy(); if (proxy == nullptr) @@ -424,7 +431,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out) proxy = new_proxy.get(); - m_netlist.nlstate().add_dev(std::move(new_proxy)); + m_netlist.nlstate().add_dev(new_proxy->name(), std::move(new_proxy)); } return proxy; } @@ -433,7 +440,7 @@ devices::nld_base_proxy *setup_t::get_a_d_proxy(detail::core_terminal_t &inp) { nl_assert(inp.is_logic()); - logic_input_t &incast = dynamic_cast(inp); + auto &incast = dynamic_cast(inp); devices::nld_base_proxy *proxy = incast.get_proxy(); if (proxy != nullptr) @@ -463,7 +470,7 @@ devices::nld_base_proxy *setup_t::get_a_d_proxy(detail::core_terminal_t &inp) inp.net().m_core_terms.clear(); // clear the list } ret->out().net().add_terminal(inp); - m_netlist.nlstate().add_dev(std::move(new_proxy)); + m_netlist.nlstate().add_dev(new_proxy->name(), std::move(new_proxy)); return ret; } } @@ -598,7 +605,7 @@ static detail::core_terminal_t &resolve_proxy(detail::core_terminal_t &term) { if (term.is_logic()) { - logic_t &out = dynamic_cast(term); + auto &out = dynamic_cast(term); if (out.has_proxy()) return out.get_proxy()->proxy_term(); } @@ -765,7 +772,7 @@ void setup_t::register_dynamic_log_devices() auto nc = factory().factory_by_name("LOG")->Create(netlist(), name); register_link(name + ".I", ll); log().debug(" dynamic link {1}: <{2}>\n",ll, name); - m_netlist.nlstate().add_dev(std::move(nc)); + m_netlist.nlstate().add_dev(nc->name(), std::move(nc)); } } } @@ -858,7 +865,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) { pstring tmp = model_value_str(map, entity); - nl_double factor = NL_FCONST(1.0); + nl_double factor = plib::constants::one; auto p = std::next(tmp.begin(), static_cast(tmp.size() - 1)); switch (*p) { @@ -874,7 +881,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) if (*p < '0' || *p > '9') log().fatal(MF_1_UNKNOWN_NUMBER_FACTOR_IN_1, entity); } - if (factor != NL_FCONST(1.0)) + if (factor != plib::constants::one) tmp = plib::left(tmp, tmp.size() - 1); // FIXME: check for errors return plib::pstonum(tmp) * factor; @@ -883,10 +890,10 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity) class logic_family_std_proxy_t : public logic_family_desc_t { public: - logic_family_std_proxy_t() { } - virtual plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, + logic_family_std_proxy_t() = default; + plib::owned_ptr create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override; - virtual plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; + plib::owned_ptr create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override; }; plib::owned_ptr logic_family_std_proxy_t::create_d_a_proxy(netlist_base_t &anetlist, @@ -1017,8 +1024,7 @@ void setup_t::prepare_to_run() if ( factory().is_class(e.second) || factory().is_class(e.second)) { - auto dev = plib::owned_ptr(e.second->Create(netlist(), e.first)); - m_netlist.nlstate().add_dev(std::move(dev)); + m_netlist.nlstate().add_dev(e.first, plib::owned_ptr(e.second->Create(netlist(), e.first))); } } @@ -1036,7 +1042,22 @@ void setup_t::prepare_to_run() && !factory().is_class(e.second)) { auto dev = plib::owned_ptr(e.second->Create(netlist(), e.first)); - m_netlist.nlstate().add_dev(std::move(dev)); + m_netlist.nlstate().add_dev(dev->name(), std::move(dev)); + } + } + + log().debug("Looking for unknown parameters ...\n"); + for (auto &p : m_param_values) + { + auto f = m_params.find(p.first); + if (f == m_params.end()) + { + if (plib::endsWith(p.first, pstring(".HINT_NO_DEACTIVATE"))) + { + // FIXME: get device name, check for device + } + else + log().info("Unknown parameter: {}", p.first); } } @@ -1046,18 +1067,18 @@ void setup_t::prepare_to_run() { if (use_deactivate) { - auto p = m_param_values.find(d->name() + ".HINT_NO_DEACTIVATE"); + auto p = m_param_values.find(d.second->name() + ".HINT_NO_DEACTIVATE"); if (p != m_param_values.end()) { //FIXME: check for errors ... - double v = plib::pstonum(p->second); + auto v = plib::pstonum(p->second); if (std::abs(v - std::floor(v)) > 1e-6 ) log().fatal(MF_1_HND_VAL_NOT_SUPPORTED, p->second); - d->set_hint_deactivate(v == 0.0); + d.second->set_hint_deactivate(v == 0.0); } } else - d->set_hint_deactivate(false); + d.second->set_hint_deactivate(false); } /* resolve inputs */ @@ -1113,16 +1134,19 @@ bool source_t::parse(const pstring &name) std::unique_ptr source_string_t::stream(const pstring &name) { + plib::unused_var(name); return plib::make_unique_base(m_str.c_str(), std::strlen(m_str.c_str())); } std::unique_ptr source_mem_t::stream(const pstring &name) { + plib::unused_var(name); return plib::make_unique_base(m_str.c_str(), std::strlen(m_str.c_str())); } std::unique_ptr source_file_t::stream(const pstring &name) { + plib::unused_var(name); return plib::make_unique_base(m_filename); } @@ -1139,9 +1163,10 @@ bool source_proc_t::parse(const pstring &name) std::unique_ptr source_proc_t::stream(const pstring &name) { + plib::unused_var(name); std::unique_ptr p(nullptr); return p; } -} +} // namespace netlist diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index d0a5c002928..971f8d2e91d 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -8,20 +8,20 @@ #ifndef NLSETUP_H_ #define NLSETUP_H_ -#include "plib/pstring.h" -#include "plib/putil.h" -#include "plib/pstream.h" #include "plib/pparser.h" #include "plib/pstate.h" +#include "plib/pstream.h" +#include "plib/pstring.h" +#include "plib/putil.h" -#include "nl_factory.h" -#include "nl_config.h" #include "netlist_types.h" +#include "nl_config.h" #include "nl_errstr.h" +#include "nl_factory.h" +#include #include #include -#include //============================================================ // MACROS / inline netlist definitions @@ -100,10 +100,10 @@ void NETLIST_NAME(name)(netlist::setup_t &setup) \ desc.family = ""; #define TT_HEAD(x) \ - desc.desc.push_back(x); + desc.desc.emplace_back(x); #define TT_LINE(x) \ - desc.desc.push_back(x); + desc.desc.emplace_back(x); #define TT_FAMILY(x) \ desc.family = x; @@ -119,12 +119,12 @@ namespace netlist namespace detail { class core_terminal_t; class net_t; - } + } // namespace detail namespace devices { class nld_base_proxy; class nld_netlistparams; - } + } // namespace devices class core_device_t; class param_t; @@ -187,7 +187,7 @@ namespace netlist : m_setup(setup), m_type(type) {} - virtual ~source_t() { } + virtual ~source_t() = default; virtual bool parse(const pstring &name); setup_t &setup() { return m_setup; } @@ -339,8 +339,9 @@ namespace netlist devices::nld_base_proxy *get_d_a_proxy(detail::core_terminal_t &out); devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp); - //std::vector> m_device_factory; - std::unordered_map m_device_factory; + /* need to preserve order of device creation ... */ + std::vector> m_device_factory; + //std::unordered_map m_device_factory; std::unordered_map m_alias; std::unordered_map m_param_values; @@ -376,7 +377,7 @@ namespace netlist } protected: - virtual std::unique_ptr stream(const pstring &name) override; + std::unique_ptr stream(const pstring &name) override; private: pstring m_str; @@ -392,7 +393,7 @@ namespace netlist } protected: - virtual std::unique_ptr stream(const pstring &name) override; + std::unique_ptr stream(const pstring &name) override; private: pstring m_filename; @@ -407,7 +408,7 @@ namespace netlist } protected: - virtual std::unique_ptr stream(const pstring &name) override; + std::unique_ptr stream(const pstring &name) override; private: pstring m_str; @@ -423,10 +424,10 @@ namespace netlist { } - virtual bool parse(const pstring &name) override; + bool parse(const pstring &name) override; protected: - virtual std::unique_ptr stream(const pstring &name) override; + std::unique_ptr stream(const pstring &name) override; private: void (*m_setup_func)(setup_t &); @@ -437,7 +438,7 @@ namespace netlist // inline implementations // ----------------------------------------------------------------------------- -} +} // namespace netlist #endif /* NLSETUP_H_ */ diff --git a/src/lib/netlist/nl_time.h b/src/lib/netlist/nl_time.h index b8ed1bb5a33..76e572a4772 100644 --- a/src/lib/netlist/nl_time.h +++ b/src/lib/netlist/nl_time.h @@ -8,33 +8,25 @@ #define NLTIME_H_ #include "nl_config.h" -#include "plib/ptypes.h" #include "plib/pstate.h" +#include "plib/ptypes.h" #include -//============================================================ -// MACROS -//============================================================ - -#define NLTIME_FROM_NS(t) netlist_time::from_nsec(t) -#define NLTIME_FROM_US(t) netlist_time::from_usec(t) -#define NLTIME_FROM_MS(t) netlist_time::from_msec(t) -#define NLTIME_IMMEDIATE netlist_time::from_nsec(1) - // ---------------------------------------------------------------------------------------- // netlist_time // ---------------------------------------------------------------------------------------- namespace netlist { + template struct ptime final { public: using internal_type = TYPE; - using mult_type = std::uint64_t; + using mult_type = TYPE; constexpr ptime() noexcept : m_time(0) {} @@ -114,8 +106,9 @@ namespace netlist C14CONSTEXPR internal_type *get_internaltype_ptr() noexcept { return &m_time; } static constexpr ptime from_nsec(const internal_type ns) noexcept { return ptime(ns, UINT64_C(1000000000)); } - static constexpr ptime from_usec(const internal_type us) noexcept { return ptime(us, UINT64_C(1000000)); } - static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C(1000)); } + static constexpr ptime from_usec(const internal_type us) noexcept { return ptime(us, UINT64_C( 1000000)); } + static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C( 1000)); } + static constexpr ptime from_sec(const internal_type s) noexcept { return ptime(s, UINT64_C( 1)); } static constexpr ptime from_hz(const internal_type hz) noexcept { return ptime(1 , hz); } static constexpr ptime from_raw(const internal_type raw) noexcept { return ptime(raw); } static constexpr ptime from_double(const double t) noexcept { return ptime(static_cast( t * static_cast(RES)), RES); } @@ -125,6 +118,11 @@ namespace netlist static constexpr ptime never() noexcept { return ptime(plib::numeric_limits::max(), RES); } static constexpr internal_type resolution() noexcept { return RES; } + constexpr internal_type in_nsec() const noexcept { return m_time / (RES / UINT64_C(1000000000)); } + constexpr internal_type in_usec() const noexcept { return m_time / (RES / UINT64_C( 1000000)); } + constexpr internal_type in_msec() const noexcept { return m_time / (RES / UINT64_C( 1000)); } + constexpr internal_type in_sec() const noexcept { return m_time / (RES / UINT64_C( 1)); } + private: static constexpr const double inv_res = 1.0 / static_cast(RES); internal_type m_time; @@ -133,16 +131,26 @@ namespace netlist #if (PHAS_INT128) using netlist_time = ptime; #else - using netlist_time = ptime; + using netlist_time = ptime; static_assert(noexcept(netlist_time::from_nsec(1)) == true, "Not evaluated as constexpr"); #endif -} + + //============================================================ + // MACROS + //============================================================ + + template inline constexpr netlist_time NLTIME_FROM_NS(T &&t) { return netlist_time::from_nsec(t); } + template inline constexpr netlist_time NLTIME_FROM_US(T &&t) { return netlist_time::from_usec(t); } + template inline constexpr netlist_time NLTIME_FROM_MS(T &&t) { return netlist_time::from_msec(t); } + +} // namespace netlist namespace plib { -template<> inline void state_manager_t::save_item(const void *owner, netlist::netlist_time &nlt, const pstring &stname) -{ - save_state_ptr(owner, stname, datatype_t(sizeof(netlist::netlist_time::internal_type), true, false), 1, nlt.get_internaltype_ptr()); -} -} + + template<> inline void state_manager_t::save_item(const void *owner, netlist::netlist_time &nlt, const pstring &stname) + { + save_state_ptr(owner, stname, datatype_t(sizeof(netlist::netlist_time::internal_type), true, false), 1, nlt.get_internaltype_ptr()); + } +} // namespace plib #endif /* NLTIME_H_ */ diff --git a/src/lib/netlist/plib/gmres.h b/src/lib/netlist/plib/gmres.h index edda011dc19..352ce721722 100644 --- a/src/lib/netlist/plib/gmres.h +++ b/src/lib/netlist/plib/gmres.h @@ -8,9 +8,9 @@ #ifndef PLIB_GMRES_H_ #define PLIB_GMRES_H_ -#include "pconfig.h" #include "mat_cr.h" #include "parray.h" +#include "pconfig.h" #include "vector_ops.h" #include @@ -246,13 +246,13 @@ namespace plib if (rho < rho_delta) return itr_used + 1; - vec_set_scalar(RESTART+1, m_g, NL_FCONST(0.0)); + vec_set_scalar(RESTART+1, m_g, constants::zero); m_g[0] = rho; //for (std::size_t i = 0; i < mr + 1; i++) // vec_set_scalar(mr, m_ht[i], NL_FCONST(0.0)); - vec_mult_scalar(n, residual, NL_FCONST(1.0) / rho, m_v[0]); + vec_mult_scalar(n, residual, constants::one / rho, m_v[0]); for (std::size_t k = 0; k < RESTART; k++) { @@ -269,7 +269,7 @@ namespace plib m_ht[kp1][k] = std::sqrt(vec_mult2(n, m_v[kp1])); if (m_ht[kp1][k] != 0.0) - vec_scale(n, m_v[kp1], NL_FCONST(1.0) / m_ht[kp1][k]); + vec_scale(n, m_v[kp1], constants::one / m_ht[kp1][k]); for (std::size_t j = 0; j < k; j++) givens_mult(m_c[j], m_s[j], m_ht[j][k], m_ht[j+1][k]); diff --git a/src/lib/netlist/plib/mat_cr.h b/src/lib/netlist/plib/mat_cr.h index 9490a07f367..7bb81e3c8e4 100644 --- a/src/lib/netlist/plib/mat_cr.h +++ b/src/lib/netlist/plib/mat_cr.h @@ -11,16 +11,18 @@ #define MAT_CR_H_ #include -#include #include -#include #include #include +#include +#include -#include "pconfig.h" #include "palloc.h" -#include "pstate.h" #include "parray.h" +#include "pconfig.h" +#include "pomp.h" +#include "pstate.h" +#include "putil.h" namespace plib { @@ -62,9 +64,7 @@ namespace plib A[i] = 0; } - ~matrix_compressed_rows_t() - { - } + ~matrix_compressed_rows_t() = default; index_type size() const { return m_size; } @@ -285,7 +285,7 @@ namespace plib template - void mult_vec(VTR & RESTRICT res, const VTV & RESTRICT x) + void mult_vec(VTR & res, const VTV & x) { /* * res = A * x @@ -513,6 +513,6 @@ namespace plib index_type m_size; }; -} +} // namespace plib #endif /* MAT_CR_H_ */ diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp index 80fd2098a66..ab5b14d0618 100644 --- a/src/lib/netlist/plib/palloc.cpp +++ b/src/lib/netlist/plib/palloc.cpp @@ -7,8 +7,8 @@ #include "pconfig.h" #include "palloc.h" -#include "pfmtlog.h" #include "pexception.h" +#include "pfmtlog.h" #include @@ -37,7 +37,7 @@ mempool::~mempool() mempool::block * mempool::new_block() { - block *b = new block(); + auto *b = new block(); b->data = static_cast(::operator new(m_min_alloc)); b->cur_ptr = b->data; b->m_free = m_min_alloc; @@ -92,7 +92,7 @@ void mempool::free(void *ptr) auto i = reinterpret_cast(p - mininfosize()); block *b = i->m_block; if (b->m_num_alloc == 0) - plib::pexception("mempool::free - double free was called\n"); + throw plib::pexception("mempool::free - double free was called\n"); else { //b->m_free = m_min_alloc; @@ -101,4 +101,4 @@ void mempool::free(void *ptr) b->m_num_alloc--; } -} +} // namespace plib diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index de992b7bc50..e8d82277ed9 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -111,7 +111,7 @@ public: static owned_ptr Create(Args&&... args) { owned_ptr a; - DC *x = new DC(std::forward(args)...); + auto *x = new DC(std::forward(args)...); a.m_ptr = static_cast(x); return std::move(a); } @@ -176,6 +176,6 @@ public: }; -} +} // namespace plib #endif /* PALLOC_H_ */ diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index df3f85ea927..6fc9cc430b2 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -11,11 +11,11 @@ #include "pconfig.h" #include "pexception.h" +#include #include +#include #include #include -#include -#include namespace plib { @@ -112,6 +112,6 @@ namespace plib { base_type m_a; size_type m_size; }; -} +} // namespace plib #endif /* PARRAY_H_ */ diff --git a/src/lib/netlist/plib/pchrono.cpp b/src/lib/netlist/plib/pchrono.cpp index 971d19b3645..953d948e062 100644 --- a/src/lib/netlist/plib/pchrono.cpp +++ b/src/lib/netlist/plib/pchrono.cpp @@ -49,5 +49,5 @@ exact_ticks::type exact_ticks::per_second() #endif -} -} +} // namespace chrono +} // namespace plib diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h index c3ea4ba9535..76f18bf4a83 100644 --- a/src/lib/netlist/plib/pchrono.h +++ b/src/lib/netlist/plib/pchrono.h @@ -10,8 +10,8 @@ #include "pconfig.h" -#include #include +#include namespace plib { namespace chrono { @@ -174,7 +174,10 @@ namespace chrono { struct guard_t { - guard_t(timer &m) : m_m(m) { m_m.m_time -= T::start();; } + guard_t() = delete; + guard_t(const guard_t &g) noexcept = default; + guard_t(guard_t &&g) noexcept = default; + guard_t(timer &m) noexcept : m_m(m) { m_m.m_time -= T::start(); } ~guard_t() { m_m.m_time += T::stop(); ++m_m.m_count; } private: timer &m_m; @@ -208,8 +211,14 @@ namespace chrono { struct guard_t { - guard_t() {} - ~guard_t() {} + guard_t() = default; + guard_t(const guard_t &g) noexcept = default; + guard_t(guard_t &&g) noexcept = default; + /* using default constructor will trigger warning on + * unused local variable. + */ + // NOLINTNEXTLINE(modernize-use-equals-default) + ~guard_t() { } }; constexpr type operator()() const { return 0; } diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 731ae1f18fd..71a5f25e0e8 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -76,15 +76,6 @@ typedef __uint128_t UINT128; typedef __int128_t INT128; #endif -#if defined(__GNUC__) -#ifdef RESTRICT -#undef RESTRICT -#endif -#define RESTRICT __restrict__ -#else -#define RESTRICT -#endif - //============================================================ // Standard defines //============================================================ diff --git a/src/lib/netlist/plib/pdynlib.cpp b/src/lib/netlist/plib/pdynlib.cpp index 13827eaf24c..f30ddc5d59a 100644 --- a/src/lib/netlist/plib/pdynlib.cpp +++ b/src/lib/netlist/plib/pdynlib.cpp @@ -91,6 +91,8 @@ dynlib::dynlib(const pstring libname) dynlib::dynlib(const pstring path, const pstring libname) : m_isLoaded(false), m_lib(nullptr) { + // FIXME: implement path search + plib::unused_var(path); // printf("win: loading <%s>\n", libname.c_str()); #ifdef _WIN32 TCHAR *buffer = tstring_from_utf8(libname.c_str()); @@ -148,4 +150,4 @@ void *dynlib::getsym_p(const pstring name) #endif } -} +} // namespace plib diff --git a/src/lib/netlist/plib/pdynlib.h b/src/lib/netlist/plib/pdynlib.h index 7c9412593c9..0ab498436b3 100644 --- a/src/lib/netlist/plib/pdynlib.h +++ b/src/lib/netlist/plib/pdynlib.h @@ -64,6 +64,6 @@ private: calltype m_sym; }; -} +} // namespace plib #endif /* PSTRING_H_ */ diff --git a/src/lib/netlist/plib/pexception.cpp b/src/lib/netlist/plib/pexception.cpp index a4ed8f367e0..d26fc8fd12e 100644 --- a/src/lib/netlist/plib/pexception.cpp +++ b/src/lib/netlist/plib/pexception.cpp @@ -26,74 +26,48 @@ pexception::pexception(const pstring &text) { } -pexception::~pexception() noexcept -{ -} file_e::file_e(const pstring &fmt, const pstring &filename) : pexception(pfmt(fmt)(filename)) { } -file_e::~file_e() noexcept -{ -} file_open_e::file_open_e(const pstring &filename) : file_e("File open failed: {}", filename) { } -file_open_e::~file_open_e() noexcept -{ - -} file_read_e::file_read_e(const pstring &filename) : file_e("File read failed: {}", filename) { } -file_read_e::~file_read_e() noexcept -{ - -} file_write_e::file_write_e(const pstring &filename) : file_e("File write failed: {}", filename) { } -file_write_e::~file_write_e() noexcept -{ -} null_argument_e::null_argument_e(const pstring &argument) : pexception(pfmt("Null argument passed: {}")(argument)) { } -null_argument_e::~null_argument_e() noexcept -{ -} out_of_mem_e::out_of_mem_e(const pstring &location) : pexception(pfmt("Out of memory: {}")(location)) { } -out_of_mem_e::~out_of_mem_e() noexcept -{ -} fpexception_e::fpexception_e(const pstring &text) : pexception(pfmt("Out of memory: {}")(text)) { } -fpexception_e::~fpexception_e() noexcept -{ -} bool fpsignalenabler::m_enable = false; @@ -140,4 +114,4 @@ bool fpsignalenabler::global_enable(bool enable) } -} +} // namespace plib diff --git a/src/lib/netlist/plib/pexception.h b/src/lib/netlist/plib/pexception.h index 1a5957099fd..7c798112c69 100644 --- a/src/lib/netlist/plib/pexception.h +++ b/src/lib/netlist/plib/pexception.h @@ -8,10 +8,11 @@ #ifndef PEXCEPTION_H_ #define PEXCEPTION_H_ -#include "pstring.h" - #include +#include "pstring.h" +#include "ptypes.h" + namespace plib { //============================================================ // exception base @@ -21,9 +22,6 @@ class pexception : public std::exception { public: explicit pexception(const pstring &text); - pexception(const pexception &e) : std::exception(e), m_text(e.m_text) { } - - virtual ~pexception() noexcept override; const pstring &text() { return m_text; } const char* what() const noexcept override { return m_text.c_str(); } @@ -36,48 +34,36 @@ class file_e : public plib::pexception { public: file_e(const pstring &fmt, const pstring &filename); - file_e(const file_e &e) : pexception(e) { } - virtual ~file_e() noexcept; }; class file_open_e : public file_e { public: explicit file_open_e(const pstring &filename); - file_open_e(const file_open_e &e) : file_e(e) { } - virtual ~file_open_e() noexcept; }; class file_read_e : public file_e { public: explicit file_read_e(const pstring &filename); - file_read_e(const file_read_e &e) : file_e(e) { } - virtual ~file_read_e() noexcept; }; class file_write_e : public file_e { public: explicit file_write_e(const pstring &filename); - file_write_e(const file_write_e &e) : file_e(e) { } - virtual ~file_write_e() noexcept; }; class null_argument_e : public plib::pexception { public: explicit null_argument_e(const pstring &argument); - null_argument_e(const null_argument_e &e) : pexception(e) { } - virtual ~null_argument_e() noexcept; }; class out_of_mem_e : public plib::pexception { public: explicit out_of_mem_e(const pstring &location); - out_of_mem_e(const out_of_mem_e &e) : pexception(e) { } - virtual ~out_of_mem_e() noexcept; }; /* FIXME: currently only a stub for later use. More use could be added by @@ -88,8 +74,6 @@ class fpexception_e : public pexception { public: explicit fpexception_e(const pstring &text); - fpexception_e(const fpexception_e &e) : pexception(e) { } - virtual ~fpexception_e() noexcept; }; static constexpr unsigned FP_INEXACT = 0x0001; @@ -103,7 +87,7 @@ static constexpr unsigned FP_ALL = 0x0001f; * Catch SIGFPE on linux for debugging purposes. */ -class fpsignalenabler +class fpsignalenabler : public nocopyassignmove { public: explicit fpsignalenabler(unsigned fpexceptions); @@ -121,6 +105,6 @@ private: }; -} +} // namespace plib #endif /* PEXCEPTION_H_ */ diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp index 2c120f6b7a4..f142a0cd73f 100644 --- a/src/lib/netlist/plib/pfmtlog.cpp +++ b/src/lib/netlist/plib/pfmtlog.cpp @@ -8,18 +8,19 @@ #include "pfmtlog.h" #include "palloc.h" -#include -#include -#include #include -#include +#include +#include +#include #include +#include namespace plib { pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...) { va_list ap; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) va_start(ap, cfmt_spec); pstring fmt("%"); char buf[2048]; // FIXME @@ -87,4 +88,4 @@ pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...) return *this; } -} +} // namespace plib diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 9b7a85d8d8d..bf9d45fadd2 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -136,7 +136,6 @@ struct ptype_traits : ptype_traits_base static char32_t fmt_spec() { return 'f'; } }; - template<> struct ptype_traits : ptype_traits_base { @@ -144,6 +143,13 @@ struct ptype_traits : ptype_traits_base static char32_t fmt_spec() { return 's'; } }; +template<> +struct ptype_traits : ptype_traits_base +{ + static const char *cast(const std::string &x) { return x.c_str(); } + static char32_t fmt_spec() { return 's'; } +}; + class pfmt { public: @@ -151,44 +157,50 @@ public: : m_str(fmt), m_arg(0) { } - - pfmt(const pfmt &rhs) : m_str(rhs.m_str), m_arg(rhs.m_arg) { } - - ~pfmt() - { - } + pfmt(const pfmt &rhs) = default; + ~pfmt() = default; operator pstring() const { return m_str; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & e(const double &x) {return format_element("", 'e', x); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & g(const double &x) {return format_element("", 'g', x); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & e(const float &x) {return format_element("", 'e', static_cast(x)); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt & g(const float &x) {return format_element("", 'g', static_cast(x)); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt &operator ()(const void *x) {return format_element("", 'p', x); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) pfmt &operator ()(const pstring &x) {return format_element("", 's', x.c_str() ); } template pfmt &operator ()(const T &x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), ptype_traits::fmt_spec(), ptype_traits::cast(x)); } template pfmt &operator ()(const T *x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), ptype_traits::fmt_spec(), ptype_traits::cast(x)); } template pfmt &x(const T &x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), 'x', x); } template pfmt &o(const T &x) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits::size_spec(), 'o', x); } @@ -237,7 +249,7 @@ public: bool is_enabled() const { return m_enabled; } protected: - ~pfmt_writer_t() { } + ~pfmt_writer_t() = default; private: pfmt &xlog(pfmt &fmt) const { return fmt; } @@ -258,7 +270,7 @@ class plog_channel : public pfmt_writer_t, bui friend class pfmt_writer_t, build_enabled>; public: explicit plog_channel(T &b) : pfmt_writer_t(), m_base(b) { } - ~plog_channel() { } + ~plog_channel() = default; protected: void vdowrite(const pstring &ls) const @@ -283,7 +295,7 @@ public: error(proxy), fatal(proxy) {} - virtual ~plog_base() {} + virtual ~plog_base() = default; plog_channel debug; plog_channel info; @@ -293,7 +305,7 @@ public: plog_channel fatal; }; -} +} // namespace plib template plib::pfmt& operator<<(plib::pfmt &p, T&& val) { return p(std::forward(val)); } diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index 3a1ef9d841b..fc8f7248470 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -6,9 +6,9 @@ */ #include "pfunction.h" +#include "pexception.h" #include "pfmtlog.h" #include "putil.h" -#include "pexception.h" #include #include @@ -56,7 +56,7 @@ void pfunction::compile_postfix(const std::vector &inputs, { rc.m_cmd = RAND; stk += 1; } else { - for (unsigned i = 0; i < inputs.size(); i++) + for (std::size_t i = 0; i < inputs.size(); i++) { if (inputs[i] == cmd) { @@ -117,7 +117,7 @@ void pfunction::compile_infix(const std::vector &inputs, const pstring std::stack opstk; std::vector postfix; - for (unsigned i = 0; i < sexpr.size(); i++) + for (std::size_t i = 0; i < sexpr.size(); i++) { pstring &s = sexpr[i]; if (s=="(") @@ -181,14 +181,15 @@ void pfunction::compile_infix(const std::vector &inputs, const pstring #define OP(OP, ADJ, EXPR) \ case OP: \ - ptr-=ADJ; \ - stack[ptr-1] = EXPR; \ + ptr-= (ADJ); \ + stack[ptr-1] = (EXPR); \ break; double pfunction::evaluate(const std::vector &values) { double stack[20]; unsigned ptr = 0; + stack[0] = 0.0; for (auto &rc : m_precompiled) { switch (rc.m_cmd) @@ -214,4 +215,4 @@ double pfunction::evaluate(const std::vector &values) return stack[ptr-1]; } -} +} // namespace plib diff --git a/src/lib/netlist/plib/pfunction.h b/src/lib/netlist/plib/pfunction.h index 7d5984f9d15..fbb6c508333 100644 --- a/src/lib/netlist/plib/pfunction.h +++ b/src/lib/netlist/plib/pfunction.h @@ -8,8 +8,8 @@ #ifndef PFUNCTION_H_ #define PFUNCTION_H_ -#include "pstring.h" #include "pstate.h" +#include "pstring.h" #include @@ -112,6 +112,6 @@ namespace plib { }; -} +} // namespace plib #endif /* PEXCEPTION_H_ */ diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 19e65cb7cdc..3ba7dd2fb4f 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -32,9 +32,7 @@ public: typedef C* iterator; typedef const C* const_iterator; - uninitialised_array_t() - { - } + uninitialised_array_t() = default; ~uninitialised_array_t() { @@ -202,8 +200,8 @@ public: explicit constexpr iter_t(LC* x) noexcept : p(x) { } explicit constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { } iter_t(iter_t &&rhs) noexcept { std::swap(*this, rhs); } - iter_t& operator=(iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; } - iter_t& operator=(iter_t &&rhs) { std::swap(*this, rhs); return *this; } + iter_t& operator=(const iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; } + iter_t& operator=(iter_t &&rhs) noexcept { std::swap(*this, rhs); return *this; } iter_t& operator++() noexcept {p = p->next();return *this;} iter_t operator++(int) noexcept {iter_t tmp(*this); operator++(); return tmp;} constexpr bool operator==(const iter_t& rhs) const noexcept {return p == rhs.p;} @@ -265,6 +263,6 @@ private: LC *m_head; }; #endif -} +} // namespace plib #endif /* PLISTS_H_ */ diff --git a/src/lib/netlist/plib/pmain.cpp b/src/lib/netlist/plib/pmain.cpp index 30b4a1948bd..25022ed9734 100644 --- a/src/lib/netlist/plib/pmain.cpp +++ b/src/lib/netlist/plib/pmain.cpp @@ -43,11 +43,6 @@ namespace plib { } - app::~app() - { - - } - int app::main_utfX(int argc, char *argv[]) { auto r = this->parse(argc, argv); diff --git a/src/lib/netlist/plib/pmain.h b/src/lib/netlist/plib/pmain.h index e2f84b90de6..78e5213713f 100644 --- a/src/lib/netlist/plib/pmain.h +++ b/src/lib/netlist/plib/pmain.h @@ -11,12 +11,12 @@ #define PMAIN_H_ #include "poptions.h" +#include "pstream.h" #include "pstring.h" #include "putil.h" -#include "pstream.h" -#include #include +#include #ifdef _WIN32 #define PMAIN(appclass) \ @@ -36,7 +36,7 @@ namespace plib { { public: app(); - virtual ~app(); + virtual ~app() = default; virtual pstring usage() = 0; virtual int execute() = 0; @@ -62,7 +62,7 @@ namespace plib { }; -} +} // namespace plib diff --git a/src/lib/netlist/plib/pomp.h b/src/lib/netlist/plib/pomp.h index 19b39466025..d86326f4594 100644 --- a/src/lib/netlist/plib/pomp.h +++ b/src/lib/netlist/plib/pomp.h @@ -47,6 +47,8 @@ inline void set_num_threads(const std::size_t threads) { #if HAS_OPENMP && USE_OPENMP omp_set_num_threads(threads); +#else + plib::unused_var(threads); #endif } @@ -64,7 +66,7 @@ inline std::size_t get_max_threads() // pdynlib: dynamic loading of libraries ... // ---------------------------------------------------------------------------------------- -} -} +} // namespace omp +} // namespace plib #endif /* PSTRING_H_ */ diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index dcb8e3931f3..84e08715ec3 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -6,8 +6,8 @@ */ #include "poptions.h" -#include "ptypes.h" #include "pexception.h" +#include "ptypes.h" namespace plib { /*************************************************************************** @@ -20,28 +20,12 @@ namespace plib { parent.register_option(this); } - option_base::~option_base() - { - } - - option_group::~option_group() - { - } - - option_example::~option_example() - { - } - option::option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument) : option_base(parent, help), m_short(ashort), m_long(along), m_has_argument(has_argument), m_specified(false) { } - option::~option() - { - } - int option_str::parse(const pstring &argument) { m_val = argument; @@ -92,12 +76,12 @@ namespace plib { { for (auto &opt : m_opts) { - option *o = dynamic_cast