summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/netlist/devices/nld_truthtable.cpp4
-rw-r--r--src/lib/netlist/nl_base.h14
-rw-r--r--src/lib/netlist/nl_parser.cpp4
-rw-r--r--src/lib/netlist/nl_setup.cpp2
-rw-r--r--src/lib/netlist/plib/palloc.cpp37
-rw-r--r--src/lib/netlist/plib/palloc.h39
-rw-r--r--src/lib/netlist/plib/pparser.cpp7
-rw-r--r--src/lib/netlist/plib/pparser.h2
-rw-r--r--src/lib/netlist/plib/pstream.cpp123
-rw-r--r--src/lib/netlist/plib/pstream.h47
-rw-r--r--src/lib/netlist/plib/pstring.cpp3
-rw-r--r--src/lib/netlist/plib/pstring.h7
-rw-r--r--src/lib/netlist/prg/nltool.cpp90
-rw-r--r--src/lib/netlist/prg/nlwav.cpp26
14 files changed, 216 insertions, 189 deletions
diff --git a/src/lib/netlist/devices/nld_truthtable.cpp b/src/lib/netlist/devices/nld_truthtable.cpp
index be80b72fdce..d885ae3b1ca 100644
--- a/src/lib/netlist/devices/nld_truthtable.cpp
+++ b/src/lib/netlist/devices/nld_truthtable.cpp
@@ -156,7 +156,7 @@ void truthtable_desc_t::help(unsigned cur, plib::pstring_vector_t list,
{
// cutoff previous inputs and outputs for ignore
if (m_outs[nstate] != m_outs.adjust(all_set) && m_outs[nstate] != val)
- fatalerror_e(plib::pfmt("Error in truthtable: State {1} already set, {2} != {3}\n")
+ nl_exception(plib::pfmt("Error in truthtable: State {1} already set, {2} != {3}\n")
.x(nstate,"04")(m_outs[nstate])(val) );
m_outs.set(nstate, val);
for (unsigned j=0; j<m_NO; j++)
@@ -252,7 +252,7 @@ void truthtable_desc_t::setup(const plib::pstring_vector_t &truthtable, uint_lea
for (size_t i=0; i<m_size; i++)
{
if (m_outs[i] == m_outs.adjust(all_set))
- throw fatalerror_e(plib::pfmt("truthtable: found element not set {1}\n").x(i) );
+ throw nl_exception(plib::pfmt("truthtable: found element not set {1}\n").x(i) );
m_outs.set(i, m_outs[i] | ((ign[i] & ~disabled_ignore) << m_NO));;
}
*m_initialized = true;
diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h
index d31c39f2eda..9a0c9b824bf 100644
--- a/src/lib/netlist/nl_base.h
+++ b/src/lib/netlist/nl_base.h
@@ -238,11 +238,11 @@ class NETLIB_NAME(name) : public device_t
//============================================================
#if defined(MAME_DEBUG)
-#define nl_assert(x) do { if (1) if (!(x)) throw fatalerror_e(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
+#define nl_assert(x) do { if (1) if (!(x)) throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
#else
-#define nl_assert(x) do { if (0) if (!(x)) throw fatalerror_e(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
+#define nl_assert(x) do { if (0) if (!(x)) throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
#endif
-#define nl_assert_always(x, msg) do { if (!(x)) throw fatalerror_e(plib::pfmt("Fatal error: {1}\nCaused by assert: {2}:{3}: {4}")(msg)(__FILE__)(__LINE__)(#x)); } while (0)
+#define nl_assert_always(x, msg) do { if (!(x)) throw nl_exception(plib::pfmt("Fatal error: {1}\nCaused by assert: {2}:{3}: {4}")(msg)(__FILE__)(__LINE__)(#x)); } while (0)
// -----------------------------------------------------------------------------
@@ -270,12 +270,12 @@ namespace netlist
// Exceptions
//============================================================
- class fatalerror_e : public plib::pexception
+ class nl_exception : public plib::pexception
{
public:
- explicit fatalerror_e(const pstring text) : plib::pexception(text) { }
- fatalerror_e(const fatalerror_e &e) : plib::pexception(e) { }
- virtual ~fatalerror_e() noexcept {}
+ explicit nl_exception(const pstring text) : plib::pexception(text) { }
+ nl_exception(const nl_exception &e) : plib::pexception(e) { }
+ virtual ~nl_exception() noexcept {}
};
class logic_output_t;
diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp
index bc27913e6b0..c0b0b56bdf1 100644
--- a/src/lib/netlist/nl_parser.cpp
+++ b/src/lib/netlist/nl_parser.cpp
@@ -410,7 +410,7 @@ void parser_t::device(const pstring &dev_type)
tok = get_token();
}
if (cnt != termlist.size())
- m_setup.log().fatal("netlist: input count mismatch for {1} - expected {2} found {3}\n", devname, termlist.size(), cnt);
+ error(plib::pfmt("Input count mismatch for {1} - expected {2} found {3}")(devname)(termlist.size())(cnt));
require_token(tok, m_tok_param_right);
}
}
@@ -446,7 +446,7 @@ nl_double parser_t::eval_param(const token_t tok)
val = tok.str();
ret = val.as_double(&e);
if (e)
- error(plib::pfmt("Error with parameter {1}...\n")(val));
+ error(plib::pfmt("Parameter value <{1}> not double \n")(val));
}
return ret * facs[f];
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index afa4545e3b7..8aa30c9d945 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -975,7 +975,7 @@ nl_double setup_t::model_value(model_map_t &map, const pstring &entity)
case 'a': factor = 1e-18; break;
default:
if (numfac < "0" || numfac > "9")
- fatalerror_e(plib::pfmt("Unknown number factor <{1}> in: {2}")(numfac)(entity));
+ nl_exception(plib::pfmt("Unknown number factor <{1}> in: {2}")(numfac)(entity));
}
if (factor != NL_FCONST(1.0))
tmp = tmp.left(tmp.len() - 1);
diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp
index f7a9117f503..ef9e42dcba5 100644
--- a/src/lib/netlist/plib/palloc.cpp
+++ b/src/lib/netlist/plib/palloc.cpp
@@ -9,8 +9,10 @@
#include "pconfig.h"
#include "palloc.h"
+#include "pfmtlog.h"
namespace plib {
+
//============================================================
// Exceptions
//============================================================
@@ -18,9 +20,42 @@ namespace plib {
pexception::pexception(const pstring text)
{
m_text = text;
- fprintf(stderr, "%s\n", m_text.cstr());
}
+file_e::file_e(const pstring fmt, const pstring &filename)
+ : pexception(pfmt(fmt)(filename))
+{
+}
+
+file_open_e::file_open_e(const pstring &filename)
+ : file_e("File open failed: {}", filename)
+{
+}
+
+file_read_e::file_read_e(const pstring &filename)
+ : file_e("File read failed: {}", filename)
+{
+}
+
+file_write_e::file_write_e(const pstring &filename)
+ : file_e("File write failed: {}", filename)
+{
+}
+
+null_argument_e::null_argument_e(const pstring &argument)
+ : pexception(pfmt("Null argument passed: {}")(argument))
+{
+}
+
+out_of_mem_e::out_of_mem_e(const pstring &location)
+ : pexception(pfmt("Out of memory: {}")(location))
+{
+}
+
+//============================================================
+// Memory pool
+//============================================================
+
mempool::mempool(int min_alloc, int min_align)
: m_min_alloc(min_alloc), m_min_align(min_align)
{
diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h
index 5b734785145..cd21be0c91e 100644
--- a/src/lib/netlist/plib/palloc.h
+++ b/src/lib/netlist/plib/palloc.h
@@ -17,6 +17,7 @@
#include "pstring.h"
namespace plib {
+
//============================================================
// exception base
//============================================================
@@ -24,7 +25,7 @@ namespace plib {
class pexception : public std::exception
{
public:
- explicit pexception(const pstring text);
+ pexception(const pstring text);
pexception(const pexception &e) : std::exception(e) { m_text = e.m_text; }
virtual ~pexception() noexcept {}
@@ -35,6 +36,42 @@ private:
pstring m_text;
};
+class file_e : public plib::pexception
+{
+public:
+ explicit file_e(const pstring fmt, const pstring &filename);
+};
+
+class file_open_e : public file_e
+{
+public:
+ explicit file_open_e(const pstring &filename);
+};
+
+class file_read_e : public file_e
+{
+public:
+ explicit file_read_e(const pstring &filename);
+};
+
+class file_write_e : public file_e
+{
+public:
+ explicit file_write_e(const pstring &filename);
+};
+
+class null_argument_e : public plib::pexception
+{
+public:
+ explicit null_argument_e(const pstring &argument);
+};
+
+class out_of_mem_e : public plib::pexception
+{
+public:
+ explicit out_of_mem_e(const pstring &location);
+};
+
//============================================================
// Memory allocation
//============================================================
diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp
index 468fb90a1f6..cfa30669801 100644
--- a/src/lib/netlist/plib/pparser.cpp
+++ b/src/lib/netlist/plib/pparser.cpp
@@ -41,9 +41,11 @@ pstring::code_t ptokenizer::getc()
{
if (m_px >= m_cur_line.len())
{
+ m_lineno++;
if (m_strm.readline(m_cur_line))
{
- m_cur_line += "\n";
+ if (m_cur_line.right(1) != "\n")
+ m_cur_line += "\n";
m_px = 0;
}
else
@@ -245,7 +247,7 @@ ptokenizer::token_t ptokenizer::get_token_internal()
void ptokenizer::error(const pstring &errs)
{
- verror("Error: " + errs, currentline_no(), currentline_str());
+ verror(errs, currentline_no(), currentline_str());
//throw error;
}
@@ -459,7 +461,6 @@ pstring ppreprocessor::process_line(const pstring &line)
if (m_ifflag == 0)
{
ret.cat(lt);
- ret.cat("\n");
}
}
return ret;
diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h
index 30a00514840..463fdad9b76 100644
--- a/src/lib/netlist/plib/pparser.h
+++ b/src/lib/netlist/plib/pparser.h
@@ -25,7 +25,7 @@ public:
virtual ~ptokenizer() {}
explicit ptokenizer(pistream &strm)
- : m_strm(strm), m_lineno(1), m_px(0), m_string('"')
+ : m_strm(strm), m_lineno(0), m_px(0), m_string('"')
{}
enum token_type
diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp
index 40152408b0c..9fcede380d5 100644
--- a/src/lib/netlist/plib/pstream.cpp
+++ b/src/lib/netlist/plib/pstream.cpp
@@ -21,8 +21,8 @@ namespace plib {
bool pistream::readline(pstring &line)
{
char c = 0;
- pstringbuffer buf;
- if (!this->read(c))
+ m_linebuf.clear();
+ if (!this->readbyte(c))
{
line = "";
return false;
@@ -32,11 +32,11 @@ bool pistream::readline(pstring &line)
if (c == 10)
break;
else if (c != 13) /* ignore CR */
- buf += c;
- if (!this->read(c))
+ m_linebuf += c;
+ if (!this->readbyte(c))
break;
}
- line = buf;
+ line = m_linebuf;
return true;
}
@@ -48,7 +48,7 @@ void postream::write(pistream &strm)
{
char buf[1024];
unsigned r;
- while ( !bad() && ((r=strm.read(buf, 1024)) > 0))
+ while ((r=strm.read(buf, 1024)) > 0)
write(buf, r);
}
@@ -57,48 +57,39 @@ void postream::write(pistream &strm)
// -----------------------------------------------------------------------------
pifilestream::pifilestream(const pstring &fname)
-: pistream(0), m_pos(0), m_actually_close(true)
+: pistream(0)
+, m_file(fopen(fname.cstr(), "rb"))
+, m_pos(0)
+, m_actually_close(true)
+, m_filename(fname)
{
- init(fopen(fname.cstr(), "rb"));
+ if (m_file == nullptr)
+ throw file_open_e(fname);
+ init();
}
-pifilestream::pifilestream(void *file, const bool do_close)
-: pistream(0), m_pos(0), m_actually_close(do_close)
+pifilestream::pifilestream(void *file, const pstring name, const bool do_close)
+: pistream(0), m_file(file), m_pos(0), m_actually_close(do_close), m_filename(name)
{
- init(file);
+ if (m_file == nullptr)
+ throw null_argument_e(m_filename);
+ init();
}
-void pifilestream::init(void *file)
+void pifilestream::init()
{
- m_file = file;
- if (m_file == nullptr)
- {
- set_flag(FLAG_ERROR);
- set_flag(FLAG_EOF);
- set_flag(FLAG_CLOSED);
- }
- else
+ if (ftell((FILE *) m_file) >= 0)
{
- if (ftell((FILE *) m_file) >= 0)
- {
- if (fseek((FILE *) m_file, 0, SEEK_SET) >= 0)
- set_flag(FLAG_SEEKABLE);
- }
+ if (fseek((FILE *) m_file, 0, SEEK_SET) >= 0)
+ set_flag(FLAG_SEEKABLE);
}
}
pifilestream::~pifilestream()
{
- if (!closed())
- close();
-}
-
-void pifilestream::close()
-{
if (m_actually_close)
{
fclose((FILE *) m_file);
- set_flag(FLAG_CLOSED);
}
}
@@ -110,7 +101,7 @@ unsigned pifilestream::vread(void *buf, const unsigned n)
if (feof((FILE *) m_file))
set_flag(FLAG_EOF);
if (ferror((FILE *) m_file))
- set_flag(FLAG_ERROR);
+ throw file_read_e(m_filename);
}
m_pos += r;
return r;
@@ -118,9 +109,8 @@ unsigned pifilestream::vread(void *buf, const unsigned n)
void pifilestream::vseek(const pos_type n)
{
- check_seekable();
if (fseek((FILE *) m_file, SEEK_SET, n) < 0)
- set_flag(FLAG_ERROR);
+ throw file_e("File seek failed: {}", m_filename);
else
m_pos = n;
if (feof((FILE *) m_file))
@@ -128,7 +118,7 @@ void pifilestream::vseek(const pos_type n)
else
clear_flag(FLAG_EOF);
if (ferror((FILE *) m_file))
- set_flag(FLAG_ERROR);
+ throw file_e("Generic file operation failed: {}", m_filename);
}
pifilestream::pos_type pifilestream::vtell()
@@ -147,7 +137,7 @@ pifilestream::pos_type pifilestream::vtell()
// -----------------------------------------------------------------------------
pstdin::pstdin()
-: pifilestream(stdin, false)
+: pifilestream(stdin, "<stdin>", false)
{
/* nothing to do */
}
@@ -157,48 +147,32 @@ pstdin::pstdin()
// -----------------------------------------------------------------------------
pofilestream::pofilestream(const pstring &fname)
-: postream(0), m_pos(0), m_actually_close(true)
+: postream(0), m_file(fopen(fname.cstr(), "wb")), m_pos(0), m_actually_close(true), m_filename(fname)
{
- init(fopen(fname.cstr(), "wb"));
-}
-
-pofilestream::pofilestream(void *file, const bool do_close)
-: postream(0), m_pos(0), m_actually_close(do_close)
-{
- init(file);
+ if (m_file == nullptr)
+ throw file_open_e(m_filename);
+ init();
}
-void pofilestream::init(void *file)
+pofilestream::pofilestream(void *file, const pstring name, const bool do_close)
+: postream(0), m_file(file), m_pos(0), m_actually_close(do_close), m_filename(name)
{
- m_file = file;
if (m_file == nullptr)
- {
- set_flag(FLAG_ERROR);
- set_flag(FLAG_CLOSED);
- }
- else
- {
- if (ftell((FILE *) m_file) >= 0)
- {
- if (fseek((FILE *) m_file, 0, SEEK_SET) >= 0)
- set_flag(FLAG_SEEKABLE);
- }
- }
+ throw null_argument_e(m_filename);
+ init();
}
-pofilestream::~pofilestream()
+void pofilestream::init()
{
- if (!closed())
- close();
+ if (ftell((FILE *) m_file) >= 0)
+ if (fseek((FILE *) m_file, 0, SEEK_SET) >= 0)
+ set_flag(FLAG_SEEKABLE);
}
-void pofilestream::close()
+pofilestream::~pofilestream()
{
if (m_actually_close)
- {
fclose((FILE *) m_file);
- set_flag(FLAG_CLOSED);
- }
}
void pofilestream::vwrite(const void *buf, const unsigned n)
@@ -207,21 +181,20 @@ void pofilestream::vwrite(const void *buf, const unsigned n)
if (r < n)
{
if (ferror((FILE *) m_file))
- set_flag(FLAG_ERROR);
+ throw file_write_e(m_filename);
}
m_pos += r;
}
void pofilestream::vseek(const pos_type n)
{
- check_seekable();
if (fseek((FILE *) m_file, SEEK_SET, n) < 0)
- set_flag(FLAG_ERROR);
+ throw file_e("File seek failed: {}", m_filename);
else
{
m_pos = n;
if (ferror((FILE *) m_file))
- set_flag(FLAG_ERROR);
+ throw file_e("Generic file operation failed: {}", m_filename);
}
}
@@ -241,7 +214,7 @@ pstream::pos_type pofilestream::vtell()
// -----------------------------------------------------------------------------
pstderr::pstderr()
-: pofilestream(stderr, false)
+: pofilestream(stderr, "<stderr>", false)
{
}
@@ -250,7 +223,7 @@ pstderr::pstderr()
// -----------------------------------------------------------------------------
pstdout::pstdout()
-: pofilestream(stdout, false)
+: pofilestream(stdout, "<stdout>", false)
{
}
@@ -325,8 +298,7 @@ void pomemstream::vwrite(const void *buf, const unsigned n)
m_mem = palloc_array<char>(m_capacity);
if (m_mem == nullptr)
{
- set_flag(FLAG_ERROR);
- return;
+ throw out_of_mem_e("pomemstream::vwrite");
}
memcpy(m_mem, o, m_pos);
pfree_array(o);
@@ -349,8 +321,7 @@ void pomemstream::vseek(const pos_type n)
m_mem = palloc_array<char>(m_capacity);
if (m_mem == nullptr)
{
- set_flag(FLAG_ERROR);
- return;
+ throw out_of_mem_e("pomemstream::vseek");
}
memcpy(m_mem, o, m_pos);
pfree_array(o);
diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h
index 59406eab025..1e9a3ed6a1c 100644
--- a/src/lib/netlist/plib/pstream.h
+++ b/src/lib/netlist/plib/pstream.h
@@ -9,7 +9,6 @@
#include <cstdarg>
#include <cstddef>
-#include <stdexcept>
#include "pconfig.h"
#include "pstring.h"
@@ -28,7 +27,7 @@ public:
using pos_type = std::size_t;
- static const pos_type SEEK_EOF = (pos_type) -1;
+ static constexpr pos_type SEEK_EOF = (pos_type) -1;
explicit pstream(const unsigned flags) : m_flags(flags)
{
@@ -37,12 +36,10 @@ public:
{
}
- bool bad() const { return ((m_flags & FLAG_ERROR) != 0); }
bool seekable() const { return ((m_flags & FLAG_SEEKABLE) != 0); }
void seek(const pos_type n)
{
- check_seekable();
return vseek(n);
}
@@ -55,12 +52,8 @@ protected:
virtual void vseek(const pos_type n) = 0;
virtual pos_type vtell() = 0;
- static const unsigned FLAG_EOF = 0x01;
- static const unsigned FLAG_ERROR = 0x02;
- static const unsigned FLAG_SEEKABLE = 0x04;
- static const unsigned FLAG_CLOSED = 0x08; /* convenience flag */
-
- bool closed() { return ((m_flags & FLAG_CLOSED) != 0); }
+ static constexpr unsigned FLAG_EOF = 0x01;
+ static constexpr unsigned FLAG_SEEKABLE = 0x04;
void set_flag(const unsigned flag)
{
@@ -70,19 +63,6 @@ protected:
{
m_flags &= ~flag;
}
-
- void check_not_eof() const
- {
- if (m_flags & FLAG_EOF)
- throw pexception("unexpected eof");
- }
-
- void check_seekable() const
- {
- if (!(m_flags & FLAG_SEEKABLE))
- throw pexception("stream is not seekable");
- }
-
unsigned flags() const { return m_flags; }
private:
@@ -101,15 +81,15 @@ public:
explicit pistream(const unsigned flags) : pstream(flags) {}
virtual ~pistream() {}
- bool eof() const { return ((flags() & FLAG_EOF) != 0) || bad(); }
+ bool eof() const { return ((flags() & FLAG_EOF) != 0); }
/* this digests linux & dos/windows text files */
bool readline(pstring &line);
- bool read(char &c)
+ bool readbyte(char &b)
{
- return (read(&c, 1) == 1);
+ return (read(&b, 1) == 1);
}
unsigned read(void *buf, const unsigned n)
@@ -122,6 +102,7 @@ protected:
virtual unsigned vread(void *buf, const unsigned n) = 0;
private:
+ pstringbuffer m_linebuf;
};
// -----------------------------------------------------------------------------
@@ -232,10 +213,8 @@ public:
explicit pofilestream(const pstring &fname);
virtual ~pofilestream();
- void close();
-
protected:
- pofilestream(void *file, const bool do_close);
+ pofilestream(void *file, const pstring name, const bool do_close);
/* write n bytes to stream */
virtual void vwrite(const void *buf, const unsigned n) override;
virtual void vseek(const pos_type n) override;
@@ -245,8 +224,9 @@ private:
void *m_file;
pos_type m_pos;
bool m_actually_close;
+ pstring m_filename;
- void init(void *file);
+ void init();
};
// -----------------------------------------------------------------------------
@@ -283,10 +263,8 @@ public:
explicit pifilestream(const pstring &fname);
virtual ~pifilestream();
- void close();
-
protected:
- pifilestream(void *file, const bool do_close);
+ pifilestream(void *file, const pstring name, const bool do_close);
/* read up to n bytes from stream */
virtual unsigned vread(void *buf, const unsigned n) override;
@@ -297,8 +275,9 @@ private:
void *m_file;
pos_type m_pos;
bool m_actually_close;
+ pstring m_filename;
- void init(void *file);
+ void init();
};
// -----------------------------------------------------------------------------
diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp
index c85f18c260a..4db3de10503 100644
--- a/src/lib/netlist/plib/pstring.cpp
+++ b/src/lib/netlist/plib/pstring.cpp
@@ -25,7 +25,8 @@ pstr_t pstring_t<pu8_traits>::m_zero = pstr_t(0);
template<typename F>
pstring_t<F>::~pstring_t()
{
- sfree(m_ptr);
+ if (m_ptr != nullptr)
+ sfree(m_ptr);
}
template<typename F>
diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h
index 2490186566e..df4d79d587f 100644
--- a/src/lib/netlist/plib/pstring.h
+++ b/src/lib/netlist/plib/pstring.h
@@ -60,6 +60,7 @@ public:
// construction with copy
pstring_t(const mem_t *string) {init(); if (string != nullptr && *string != 0) pcopy(string); }
pstring_t(const pstring_t &string) {init(); pcopy(string); }
+ pstring_t(pstring_t &&string) : m_ptr(string.m_ptr) {string.m_ptr = nullptr; }
// assignment operators
pstring_t &operator=(const mem_t *string) { pcopy(string); return *this; }
@@ -115,7 +116,7 @@ public:
unsigned len() const
{
- return F::len(m_ptr);
+ return traits::len(m_ptr);
}
pstring_t& operator+=(const code_t c) { mem_t buf[F::MAXCODELEN+1] = { 0 }; F::encode(c, buf); pcat(buf); return *this; }
@@ -295,6 +296,8 @@ struct putf8_traits
}
};
+// FIXME: "using pstring = pstring_t<putf8_traits>" is not understood by eclipse
+
struct pstring : public pstring_t<putf8_traits>
{
public:
@@ -357,6 +360,8 @@ public:
void cat(const char *s) { pcat(s); }
void cat(const void *m, unsigned l) { pcat(m, l); }
+ void clear() { m_len = 0; *m_ptr = 0; }
+
private:
void init()
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index fdfd5ed7a94..31cb8af00f6 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -145,9 +145,10 @@ protected:
void vlog(const plib::plog_level &l, const pstring &ls) const override
{
- pout("{}: {}\n", l.name().cstr(), ls.cstr());
+ pstring err = plib::pfmt("{}: {}\n")(l.name())(ls.cstr());
+ pout("{}", err);
if (l == plib::plog_level::FATAL)
- throw std::exception();
+ throw netlist::nl_exception(err);
}
private:
@@ -179,7 +180,7 @@ struct input_t
double t;
int e = sscanf(line.cstr(), "%lf,%[^,],%lf", &t, buf, &m_value);
if ( e!= 3)
- throw netlist::fatalerror_e(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
+ throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
m_time = netlist::netlist_time::from_double(t);
m_param = setup.find_param(buf, true);
}
@@ -190,7 +191,7 @@ struct input_t
{
case netlist::param_t::MODEL:
case netlist::param_t::STRING:
- throw netlist::fatalerror_e(plib::pfmt("param {1} is not numeric\n")(m_param->name()));
+ throw netlist::nl_exception(plib::pfmt("param {1} is not numeric\n")(m_param->name()));
case netlist::param_t::DOUBLE:
static_cast<netlist::param_double_t*>(m_param)->setTo(m_value);
break;
@@ -432,50 +433,61 @@ int main(int argc, char *argv[])
return 0;
}
- pstring cmd = opts.opt_cmd();
- if (cmd == "listdevices")
- listdevices(opts);
- else if (cmd == "run")
- run(opts);
- else if (cmd == "static")
- static_compile(opts);
- else if (cmd == "convert")
+ try
{
- pstring contents;
- plib::postringstream ostrm;
- if (opts.opt_file() == "-")
+ pstring cmd = opts.opt_cmd();
+ if (cmd == "listdevices")
+ listdevices(opts);
+ else if (cmd == "run")
+ run(opts);
+ else if (cmd == "static")
+ static_compile(opts);
+ else if (cmd == "convert")
{
- plib::pstdin f;
- ostrm.write(f);
- }
- else
- {
- plib::pifilestream f(opts.opt_file());
- ostrm.write(f);
- }
- contents = ostrm.str();
+ pstring contents;
+ plib::postringstream ostrm;
+ if (opts.opt_file() == "-")
+ {
+ plib::pstdin f;
+ ostrm.write(f);
+ }
+ else
+ {
+ plib::pifilestream f(opts.opt_file());
+ ostrm.write(f);
+ }
+ contents = ostrm.str();
- pstring result;
- if (opts.opt_type().equals("spice"))
- {
- nl_convert_spice_t c;
- c.convert(contents);
- result = c.result();
+ pstring result;
+ if (opts.opt_type().equals("spice"))
+ {
+ nl_convert_spice_t c;
+ c.convert(contents);
+ result = c.result();
+ }
+ else
+ {
+ nl_convert_eagle_t c;
+ c.convert(contents);
+ result = c.result();
+ }
+ /* present result */
+ pout_strm.write(result.cstr());
}
else
{
- nl_convert_eagle_t c;
- c.convert(contents);
- result = c.result();
+ perr("Unknown command {}\n", cmd.cstr());
+ usage(opts);
+ return 1;
}
- /* present result */
- pout_strm.write(result.cstr());
}
- else
+ catch (netlist::nl_exception &e)
{
- perr("Unknown command {}\n", cmd.cstr());
- usage(opts);
- return 1;
+ perr("Netlist exception caught: {}\n", e.text());
+ }
+ catch (plib::pexception &e)
+ {
+ perr("plib exception caught: {}\n", e.text());
}
pstring::resetmem();
diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp
index 0937f70470d..a48323f265f 100644
--- a/src/lib/netlist/prg/nlwav.cpp
+++ b/src/lib/netlist/prg/nlwav.cpp
@@ -49,7 +49,12 @@ public:
}
~wav_t()
{
- close();
+ m_f.seek(0);
+ m_f.write(&m_fh, sizeof(m_fh));
+ m_f.write(&m_fmt, sizeof(m_fmt));
+
+ //data.len = fmt.block_align * n;
+ m_f.write(&m_data, sizeof(m_data));
}
unsigned channels() { return m_fmt.channels; }
@@ -62,15 +67,6 @@ public:
m_f.write(&ps, sizeof(ps));
}
- void close()
- {
- m_f.seek(0);
- m_f.write(&m_fh, sizeof(m_fh));
- m_f.write(&m_fmt, sizeof(m_fmt));
-
- //data.len = fmt.block_align * n;
- m_f.write(&m_data, sizeof(m_data));
- }
private:
struct riff_chunk_t
{
@@ -129,15 +125,9 @@ private:
static void convert(nlwav_options_t &opts)
{
plib::pofilestream fo(opts.opt_out());
- if (fo.bad())
- {
- throw netlist::fatalerror_e("Error opening output file: " + opts.opt_out());
- }
wav_t wo(fo, 48000);
plib::pifilestream fin(opts.opt_inp());
- if (fin.bad())
- throw netlist::fatalerror_e("Error opening input file: " + opts.opt_inp());
double dt = 1.0 / (double) wo.sample_rate();
double ct = dt;
@@ -208,10 +198,6 @@ static void convert(nlwav_options_t &opts)
pout("Mean (static): {}\n", means / (double) n);
pout("Amp + {}\n", 32000.0 / (maxsam- mean));
pout("Amp - {}\n", -32000.0 / (minsam- mean));
- wo.close();
- fo.close();
- fin.close();
-
}
static void usage(plib::pstream_fmt_writer_t &fw, nlwav_options_t &opts)