summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-01-19 18:17:35 +0100
committer couriersud <couriersud@gmx.org>2019-01-19 18:17:35 +0100
commit17d32e0bd5b98761fea3e1f42f73bdb8d197ea69 (patch)
tree66b7ceebccce0c6cf07c2d1095652a5a96d8cdf4 /src/lib
parentb685850e01b89c6ea14c9890ec2c885ee56d679e (diff)
netlist: pstream and ppreprocessor (now a pistream) refactoring. (nw)
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/netlist/nl_parser.cpp11
-rw-r--r--src/lib/netlist/nl_parser.h8
-rw-r--r--src/lib/netlist/nl_setup.cpp21
-rw-r--r--src/lib/netlist/nl_setup.h2
-rw-r--r--src/lib/netlist/plib/pparser.cpp33
-rw-r--r--src/lib/netlist/plib/pparser.h53
-rw-r--r--src/lib/netlist/plib/pstream.cpp20
-rw-r--r--src/lib/netlist/plib/pstream.h128
-rw-r--r--src/lib/netlist/prg/nlwav.cpp27
-rw-r--r--src/lib/netlist/tools/nl_convert.cpp26
10 files changed, 182 insertions, 147 deletions
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<char>(9) + static_cast<char>(10) + static_cast<char>(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<char>(9) + static_cast<char>(10) + static_cast<char>(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 <typename T>
+ 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<plib::pistream> 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<plib::pistream> setup_t::get_data_stream(const pstring &name)
return std::unique_ptr<plib::pistream>(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<plib::pistream> get_data_stream(const pstring &name);
- bool parse_stream(plib::putf8_reader &&istrm, const pstring &name);
+ bool parse_stream(std::unique_ptr<plib::pistream> 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<define_t> *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 <typename T>
+ 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<define_t> *defines = nullptr);
- virtual ~ppreprocessor() {}
+ virtual ~ppreprocessor() override {}
- void process(putf8_reader &istrm, putf8_writer &ostrm);
+ template <typename T>
+ 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<char>(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<pstring> &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<pu8_traits> 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<FILE *>(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<FILE *>(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<char *>(buf));
+ std::copy(m_mem + m_pos, m_mem + m_pos + ret, reinterpret_cast<char *>(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<const char *>(buf), static_cast<const char *>(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 <typename T>
+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<std::uint8_t> pistream;
+
// -----------------------------------------------------------------------------
// postream: output stream
// -----------------------------------------------------------------------------
#if !USE_CSTREAM
-class postream : public pstream
+template <typename T>
+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<std::uint8_t> 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<const char *>(buf), n);
+ m_buf += pstring(reinterpret_cast<const pstring::mem_t *>(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 <typename T>
+struct constructor_helper
+{
+ std::unique_ptr<pistream> operator()(T &&s) { return std::move(plib::make_unique<T>(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<pimemstream>(std::move(strm))),
- m_stream_owned(true)
- {}
-
- putf8_reader(pifilestream &&strm)
- : m_strm(palloc<pifilestream>(std::move(strm))),
- m_stream_owned(true)
- {}
+ template <typename T>
+ friend struct constructor_helper;
- putf8_reader(pistringstream &&strm)
- : m_strm(palloc<pistringstream>(std::move(strm))),
- m_stream_owned(true)
+ template <typename T>
+ putf8_reader(T &&strm)
+ : m_strm(std::move(constructor_helper<T>()(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<putf8string::traits_type::mem_t *>(&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<putf8string::traits_type::mem_t *>(&b));
return true;
}
private:
- pistream *m_strm;
- bool m_stream_owned;
+ std::unique_ptr<pistream> m_strm;
putf8string m_linebuf;
};
+template <>
+struct constructor_helper<putf8_reader>
+{
+ std::unique_ptr<pistream> operator()(putf8_reader &&s) { return std::move(s.m_strm); }
+};
+
+template <>
+struct constructor_helper<std::unique_ptr<pistream>>
+{
+ std::unique_ptr<pistream> operator()(std::unique_ptr<pistream> &&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<const pistream::value_type *>(conv_utf8.c_str()), conv_utf8.mem_t_size());
}
void write(const pstring::value_type c) const
@@ -516,13 +532,13 @@ public:
template <typename T>
void write(const T &val)
{
- m_strm.write(reinterpret_cast<const char *>(&val), sizeof(T));
+ m_strm.write(reinterpret_cast<const postream::value_type *>(&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<const postream::value_type *>(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<const postream::value_type *>(val.data()), sizeof(T) * sz);
}
private:
@@ -549,7 +565,7 @@ public:
template <typename T>
void read(T &val)
{
- m_strm.read(&val, sizeof(T));
+ m_strm.read(reinterpret_cast<pistream::value_type *>(&val), sizeof(T));
}
void read( pstring &s)
@@ -557,7 +573,7 @@ public:
std::size_t sz = 0;
read(sz);
plib::string_info<pstring>::mem_t *buf = new plib::string_info<pstring>::mem_t[sz+1];
- m_strm.read(buf, sz);
+ m_strm.read(reinterpret_cast<pistream::value_type *>(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<pistream::value_type *>(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 <typename T>
void write(const T &val)
{
- m_f.write(reinterpret_cast<const char *>(&val), sizeof(T));
+ m_f.write(reinterpret_cast<const plib::postream::value_type *>(&val), sizeof(T));
}
void write_sample(int sample)
@@ -153,11 +153,11 @@ class log_processor
{
public:
typedef plib::pmfp<void, double, double> 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<plib::pistream> &&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<plib::pofilestream>(opt_out()));
- plib::pistream *fin = (opt_inp() == "-" ? &pin_strm : plib::palloc<plib::pifilestream>(opt_inp()));
- plib::putf8_reader reader(fin);
+ std::unique_ptr<plib::pistream> fin = (opt_inp() == "-" ?
+ plib::make_unique<plib::pstdin>()
+ : plib::make_unique<plib::pifilestream>(opt_inp()));
+ plib::putf8_reader reader(std::move(fin));
wav_t *wo = plib::palloc<wav_t>(*fo, static_cast<unsigned>(sample_rate));
double dt = 1.0 / static_cast<double>(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<plib::pofilestream>(opt_out()));
- plib::pistream *fin = (opt_inp() == "-" ? &pin_strm : plib::palloc<plib::pifilestream>(opt_inp()));
+ std::unique_ptr<plib::pistream> fin = (opt_inp() == "-" ?
+ plib::make_unique<plib::pstdin>()
+ : plib::make_unique<plib::pifilestream>(opt_inp()));
double dt = 1.0 / static_cast<double>(sample_rate);
wavwriter *wo = plib::palloc<wavwriter>(*fo, static_cast<unsigned>(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<char>(9) + static_cast<char>(10) + static_cast<char>(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<char>(9) + static_cast<char>(10) + static_cast<char>(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<char>(9) + static_cast<char>(10) + static_cast<char>(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<char>(9) + static_cast<char>(10) + static_cast<char>(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");