From ce612896a88be5a2cd6887f0ad569901fcbe0926 Mon Sep 17 00:00:00 2001 From: couriersud Date: Fri, 27 Sep 2019 22:30:33 +0200 Subject: [PATCH] netlist: Fix a number of minor issues. (nw) - lint warnings - remove const on return types --- src/lib/netlist/nl_setup.cpp | 7 ++-- src/lib/netlist/nl_setup.h | 2 +- src/lib/netlist/plib/pchrono.cpp | 28 +++++++++++++ src/lib/netlist/plib/pchrono.h | 34 ++++++++++++---- src/lib/netlist/plib/pparser.cpp | 8 +--- src/lib/netlist/plib/pparser.h | 12 +++--- src/lib/netlist/plib/pstream.h | 6 +-- src/lib/netlist/plib/putil.cpp | 4 +- src/lib/netlist/plib/putil.h | 4 +- src/lib/netlist/prg/nlwav.cpp | 63 +++++++++++++++++------------- src/lib/netlist/tools/nl_convert.h | 2 +- 11 files changed, 110 insertions(+), 60 deletions(-) diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 447e78cfe2e..3ffafe994e0 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -891,7 +891,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map) remainder = plib::left(remainder, remainder.size() - 1); std::vector pairs(plib::psplit(remainder," ", true)); - for (pstring &pe : pairs) + for (const pstring &pe : pairs) { auto pose = pe.find('='); if (pose == pstring::npos) @@ -900,9 +900,10 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map) } } -pstring models_t::model_string(model_map_t &map) +pstring models_t::model_string(const model_map_t &map) const { - pstring ret = map["COREMODEL"] + "("; + // operator [] has no const implementation + pstring ret = map.at("COREMODEL") + "("; for (auto & i : map) ret += (i.first + '=' + i.second + ' '); diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 3650b3756a9..e04b91c83f8 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -223,7 +223,7 @@ namespace netlist using model_map_t = std::unordered_map; void model_parse(const pstring &model, model_map_t &map); - pstring model_string(model_map_t &map); + pstring model_string(const model_map_t &map) const; std::unordered_map m_models; std::unordered_map m_cache; diff --git a/src/lib/netlist/plib/pchrono.cpp b/src/lib/netlist/plib/pchrono.cpp index f89df7dba07..354a2589851 100644 --- a/src/lib/netlist/plib/pchrono.cpp +++ b/src/lib/netlist/plib/pchrono.cpp @@ -1,14 +1,40 @@ // license:GPL-2.0+ // copyright-holders:Couriersud +#if 0 + #include "pchrono.h" namespace plib { namespace chrono { #if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)) +template +auto per_sec() -> typename T :: type +{ + using ret_type = typename T :: type; + static ret_type persec = 0; + if (persec == 0) + { + ret_type x = 0; + system_ticks::type t = system_ticks::start(); + system_ticks::type e; + x = - T :: start(); + do { + e = system_ticks::stop(); + } while (e - t < system_ticks::per_second() / 100 ); + x += T :: stop(); + persec = (ret_type)(double)((double) x * (double) system_ticks::per_second() / double (e - t)); + } + return persec; +} + + fast_ticks::type fast_ticks::per_second() { +#if 1 + return per_sec(); +#else static type persec = 0; if (persec == 0) { @@ -23,6 +49,7 @@ fast_ticks::type fast_ticks::per_second() persec = (type)(double)((double) x * (double) system_ticks::per_second() / double (e - t)); } return persec; +#endif } #if PUSE_ACCURATE_STATS && PHAS_RDTSCP @@ -49,3 +76,4 @@ exact_ticks::type exact_ticks::per_second() } // namespace chrono } // namespace plib +#endif diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h index 711e8908dfd..d6e98134f47 100644 --- a/src/lib/netlist/plib/pchrono.h +++ b/src/lib/netlist/plib/pchrono.h @@ -31,8 +31,32 @@ namespace chrono { #if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)) + template + struct base_ticks + { + using ret_type = R; + static ret_type per_second() + { + static ret_type persec = 0; + if (persec == 0) + { + ret_type x = 0; + system_ticks::type t = system_ticks::start(); + system_ticks::type e; + x = - T :: start(); + do { + e = system_ticks::stop(); + } while (e - t < system_ticks::per_second() / 100 ); + x += T :: stop(); + persec = (ret_type)(double)((double) x * (double) system_ticks::per_second() / double (e - t)); + } + return persec; + } + }; + + #if PHAS_RDTSCP - struct fast_ticks + struct fast_ticks : public base_ticks { typedef int64_t type; static inline type start() @@ -52,11 +76,10 @@ namespace chrono { { return start(); } - static type per_second(); }; #else - struct fast_ticks + struct fast_ticks : public base_ticks { typedef int64_t type; static inline type start() @@ -76,7 +99,6 @@ namespace chrono { { return start(); } - static type per_second(); }; #endif @@ -93,7 +115,7 @@ namespace chrono { * */ - struct exact_ticks + struct exact_ticks : public base_ticks { typedef int64_t type; @@ -129,8 +151,6 @@ namespace chrono { ); return v; } - - static type per_second(); }; #else using exact_ticks = fast_ticks; diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 2b365f22811..e567fc6e5be 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -253,12 +253,6 @@ ptokenizer::token_t ptokenizer::get_token_internal() } } -void ptokenizer::error(const pstring &errs) -{ - verror(errs, currentline_no(), currentline_str()); - //throw error; -} - // ---------------------------------------------------------------------------------------- // A simple preprocessor // ---------------------------------------------------------------------------------------- @@ -423,7 +417,7 @@ pstring ppreprocessor::process_comments(pstring line) return ret; } -pstring ppreprocessor::process_line(pstring line) +pstring ppreprocessor::process_line(pstring line) { bool line_cont = plib::right(line, 1) == "\\"; if (line_cont) diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 123786602e0..8949cf875d6 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -110,10 +110,10 @@ public: return ret; } - ptokenizer & identifier_chars(pstring s) { m_identifier_chars = std::move(s); return *this; } - ptokenizer & number_chars(pstring st, pstring rem) { m_number_chars_start = std::move(st); m_number_chars = std::move(rem); return *this; } + ptokenizer & identifier_chars(const pstring &s) { m_identifier_chars = s; return *this; } + ptokenizer & number_chars(const pstring &st, const 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 = std::move(s); return *this; } + ptokenizer & whitespace(const pstring & s) { m_whitespace = s; return *this; } ptokenizer & comment(const pstring &start, const pstring &end, const pstring &line) { m_tok_comment_start = register_token(start); @@ -123,7 +123,7 @@ public: } token_t get_token_internal(); - void error(const pstring &errs); + void error(const pstring &errs) { verror(errs, currentline_no(), currentline_str()); } putf8_reader &stream() { return m_strm; } protected: @@ -217,8 +217,8 @@ protected: class st : public std::streambuf { public: - st(ppreprocessor *strm) : m_strm(strm) { setg(nullptr, nullptr, nullptr); } - st(st &&rhs) noexcept : m_strm(rhs.m_strm) {} + st(ppreprocessor *strm) : m_strm(strm), m_buf() { setg(nullptr, nullptr, nullptr); } + st(st &&rhs) noexcept : m_strm(rhs.m_strm), m_buf() {} int_type underflow() override { //printf("here\n"); diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index ca21bca795a..27d157fbb1e 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -183,7 +183,7 @@ public: void write(const pstring &s) { const auto sm = reinterpret_cast(s.c_str()); - const std::streamsize sl(static_cast(pstring_mem_t_size(s))); + const auto sl(static_cast(pstring_mem_t_size(s))); write(sl); m_strm.write(sm, sl); } @@ -191,7 +191,7 @@ public: template void write(const std::vector &val) { - const std::streamsize sz(static_cast(val.size())); + const auto sz(static_cast(val.size())); write(sz); m_strm.write(reinterpret_cast(val.data()), sz * static_cast(sizeof(T))); } @@ -278,7 +278,7 @@ namespace filesystem return pstring(source); } -} +} // namespace filesystem } // namespace plib diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp index a9531006904..10f43cdb096 100644 --- a/src/lib/netlist/plib/putil.cpp +++ b/src/lib/netlist/plib/putil.cpp @@ -14,7 +14,7 @@ namespace plib { namespace util { - const pstring buildpath(std::initializer_list list ) + pstring buildpath(std::initializer_list list ) { pstring ret = ""; for( const auto &elem : list ) @@ -31,7 +31,7 @@ namespace plib return ret; } - const pstring environment(const pstring &var, const pstring &default_val) + pstring environment(const pstring &var, const pstring &default_val) { if (std::getenv(var.c_str()) == nullptr) return default_val; diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index e6e6153d840..e3dce29cdd8 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -26,8 +26,8 @@ namespace plib namespace util { - const pstring buildpath(std::initializer_list list ); - const pstring environment(const pstring &var, const pstring &default_val); + pstring buildpath(std::initializer_list list ); + pstring environment(const pstring &var, const pstring &default_val); } // namespace util namespace container diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 3974dde1f3a..a2f16adc922 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -396,16 +396,16 @@ public: opt_ex1(*this, "./nlwav -f vcdd -o x.vcd log_V*", "convert all files starting with \"log_V\" into a digital vcd file"), opt_ex2(*this, "./nlwav -f wav -o x.wav log_V*", - "convert all files starting with \"log_V\" into a multichannel wav file"), - m_outstrm(nullptr) + "convert all files starting with \"log_V\" into a multichannel wav file") {} int execute() override; pstring usage() override; private: - void convert_wav(); - void convert_vcd(vcdwriter::format_e format); + void convert_wav(std::ostream &ostrm); + void convert_vcd(std::ostream &ostrm, vcdwriter::format_e format); + void convert(std::ostream &ostrm); plib::option_str_limit opt_fmt; plib::option_str opt_out; @@ -421,15 +421,14 @@ private: plib::option_example opt_ex1; plib::option_example opt_ex2; std::vector> m_instrms; - std::ostream *m_outstrm; }; -void nlwav_app::convert_wav() +void nlwav_app::convert_wav(std::ostream &ostrm) { double dt = 1.0 / static_cast(opt_rate()); - plib::unique_ptr wo = plib::make_unique(*m_outstrm, opt_out() != "-", m_instrms.size(), opt_rate(), opt_amp()); + plib::unique_ptr wo = plib::make_unique(ostrm, opt_out() != "-", m_instrms.size(), opt_rate(), opt_amp()); plib::unique_ptr ago = plib::make_unique(m_instrms.size(), dt, aggregator::callback_type(&wavwriter::process, wo.get())); aggregator::callback_type agcb = log_processor::callback_type(&aggregator::process, ago.get()); @@ -448,10 +447,10 @@ void nlwav_app::convert_wav() } } -void nlwav_app::convert_vcd(vcdwriter::format_e format) +void nlwav_app::convert_vcd(std::ostream &ostrm, vcdwriter::format_e format) { - plib::unique_ptr wo = plib::make_unique(*m_outstrm, opt_args(), + plib::unique_ptr wo = plib::make_unique(ostrm, opt_args(), format, opt_high(), opt_low()); log_processor::callback_type agcb = log_processor::callback_type(&vcdwriter::process, wo.get()); @@ -476,6 +475,21 @@ pstring nlwav_app::usage() "nlwav [OPTION] ... [FILE] ..."); } +void nlwav_app::convert(std::ostream &ostrm) +{ + switch (opt_fmt()) + { + case 0: + convert_wav(ostrm); break; + case 1: + convert_vcd(ostrm, vcdwriter::ANALOG); break; + case 2: + convert_vcd(ostrm, vcdwriter::DIGITAL); break; + default: + // tease compiler - can't happen + break; + } +} int nlwav_app::execute() { @@ -499,11 +513,6 @@ int nlwav_app::execute() return 0; } - m_outstrm = (opt_out() == "-" ? &std::cout : plib::pnew(plib::filesystem::u8path(opt_out()))); - if (m_outstrm->fail()) - throw plib::file_open_e(opt_out()); - m_outstrm->imbue(std::locale::classic()); - for (auto &oi: opt_args()) { plib::unique_ptr fin; @@ -520,21 +529,19 @@ int nlwav_app::execute() m_instrms.push_back(std::move(fin)); } - switch (opt_fmt()) - { - case 0: - convert_wav(); break; - case 1: - convert_vcd(vcdwriter::ANALOG); break; - case 2: - convert_vcd(vcdwriter::DIGITAL); break; - default: - // tease compiler - can't happen - break; - } - if (opt_out() != "-") - plib::pdelete(m_outstrm); + { + auto outstrm(std::ofstream(plib::filesystem::u8path(opt_out()))); + if (outstrm.fail()) + throw plib::file_open_e(opt_out()); + outstrm.imbue(std::locale::classic()); + convert(outstrm); + } + else + { + std::cout.imbue(std::locale::classic()); + convert(std::cout); + } return 0; } diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index e070514d5ed..b47c5a82ce1 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -103,7 +103,7 @@ private: const pstring &name() { return m_name;} const pstring &type() { return m_type;} const pstring &model() { return m_model;} - const double &value() { return m_val;} + double value() { return m_val;} bool has_model() { return m_model != ""; } bool has_value() { return m_has_val; }