netlist: Fix a number of minor issues. (nw)

- lint warnings
- remove const on return types
This commit is contained in:
couriersud 2019-09-27 22:30:33 +02:00
parent 28192a5a65
commit ce612896a8
11 changed files with 110 additions and 60 deletions

View File

@ -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<pstring> 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 + ' ');

View File

@ -223,7 +223,7 @@ namespace netlist
using model_map_t = std::unordered_map<pstring, pstring>;
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<pstring, pstring> m_models;
std::unordered_map<pstring, model_map_t> m_cache;

View File

@ -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 <typename T>
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<fast_ticks>();
#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

View File

@ -31,8 +31,32 @@ namespace chrono {
#if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
template <typename T, typename R>
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<fast_ticks, int64_t>
{
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<fast_ticks, int64_t>
{
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<exact_ticks, int64_t>
{
typedef int64_t type;
@ -129,8 +151,6 @@ namespace chrono {
);
return v;
}
static type per_second();
};
#else
using exact_ticks = fast_ticks;

View File

@ -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)

View File

@ -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");

View File

@ -183,7 +183,7 @@ public:
void write(const pstring &s)
{
const auto sm = reinterpret_cast<const std::ostream::char_type *>(s.c_str());
const std::streamsize sl(static_cast<std::streamsize>(pstring_mem_t_size(s)));
const auto sl(static_cast<std::streamsize>(pstring_mem_t_size(s)));
write(sl);
m_strm.write(sm, sl);
}
@ -191,7 +191,7 @@ public:
template <typename T>
void write(const std::vector<T> &val)
{
const std::streamsize sz(static_cast<std::streamsize>(val.size()));
const auto sz(static_cast<std::streamsize>(val.size()));
write(sz);
m_strm.write(reinterpret_cast<const std::ostream::char_type *>(val.data()), sz * static_cast<std::streamsize>(sizeof(T)));
}
@ -278,7 +278,7 @@ namespace filesystem
return pstring(source);
}
}
} // namespace filesystem
} // namespace plib

View File

@ -14,7 +14,7 @@ namespace plib
{
namespace util
{
const pstring buildpath(std::initializer_list<pstring> list )
pstring buildpath(std::initializer_list<pstring> 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;

View File

@ -26,8 +26,8 @@ namespace plib
namespace util
{
const pstring buildpath(std::initializer_list<pstring> list );
const pstring environment(const pstring &var, const pstring &default_val);
pstring buildpath(std::initializer_list<pstring> list );
pstring environment(const pstring &var, const pstring &default_val);
} // namespace util
namespace container

View File

@ -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<unsigned> opt_fmt;
plib::option_str opt_out;
@ -421,15 +421,14 @@ private:
plib::option_example opt_ex1;
plib::option_example opt_ex2;
std::vector<plib::unique_ptr<std::istream>> 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<double>(opt_rate());
plib::unique_ptr<wavwriter> wo = plib::make_unique<wavwriter>(*m_outstrm, opt_out() != "-", m_instrms.size(), opt_rate(), opt_amp());
plib::unique_ptr<wavwriter> wo = plib::make_unique<wavwriter>(ostrm, opt_out() != "-", m_instrms.size(), opt_rate(), opt_amp());
plib::unique_ptr<aggregator> ago = plib::make_unique<aggregator>(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<vcdwriter> wo = plib::make_unique<vcdwriter>(*m_outstrm, opt_args(),
plib::unique_ptr<vcdwriter> wo = plib::make_unique<vcdwriter>(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<std::ofstream>(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<std::istream> 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;
}

View File

@ -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; }