summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/prg/nltool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/prg/nltool.cpp')
-rw-r--r--src/lib/netlist/prg/nltool.cpp117
1 files changed, 97 insertions, 20 deletions
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index 91f9fc7c1ae..6eec3d0e6dc 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -8,21 +8,12 @@
****************************************************************************/
-#include <cstdio>
-#include <cstdlib>
-
#include "plib/poptions.h"
-#include "plib/pstring.h"
-#include "plib/plists.h"
-#include "plib/ptypes.h"
-#include "plib/pexception.h"
#include "nl_setup.h"
-#include "nl_factory.h"
#include "nl_parser.h"
#include "devices/net_lib.h"
#include "tools/nl_convert.h"
-
-#include <cfenv>
+#include "solver/nld_solver.h"
class tool_options_t : public plib::options
{
@@ -30,7 +21,7 @@ public:
tool_options_t() :
plib::options(),
opt_grp1(*this, "General options", "The following options apply to all commands."),
- opt_cmd (*this, "c", "cmd", "run", "run:convert:listdevices:static", "run|convert|listdevices|static"),
+ opt_cmd (*this, "c", "cmd", "run", "run:convert:listdevices:static:header", "run|convert|listdevices|static|header"),
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 files"),
@@ -77,8 +68,8 @@ public:
static plib::pstdout pout_strm;
static plib::pstderr perr_strm;
-static plib::pstream_fmt_writer_t pout(pout_strm);
-static plib::pstream_fmt_writer_t perr(perr_strm);
+static plib::putf8_fmt_writer pout(pout_strm);
+static plib::putf8_fmt_writer perr(perr_strm);
static NETLIST_START(dummy)
/* Standard stuff */
@@ -211,7 +202,7 @@ struct input_t
if (e != 3)
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);
+ m_param = setup.find_param(pstring(buf, pstring::UTF8), true);
}
void setparam()
@@ -244,8 +235,9 @@ static std::vector<input_t> read_input(const netlist::setup_t &setup, pstring fn
if (fname != "")
{
plib::pifilestream f(fname);
+ plib::putf8_reader r(f);
pstring l;
- while (f.readline(l))
+ while (r.readline(l))
{
if (l != "")
{
@@ -319,12 +311,95 @@ static void static_compile(tool_options_t &opts)
opts.opt_logs(),
opts.opt_defines(), opts.opt_rfolders());
- nt.solver()->create_solver_code(pout_strm);
+ plib::putf8_writer w(pout_strm);
+ std::map<pstring, pstring> mp;
+
+ nt.solver()->create_solver_code(mp);
+
+ for (auto &e : mp)
+ {
+ w.write(e.second);
+ }
nt.stop();
}
+static void mac_out(const pstring s, const bool cont = true)
+{
+ static const unsigned RIGHT = 72;
+ if (cont)
+ {
+ unsigned adj = 0;
+ for (auto x : s)
+ adj += (x == '\t' ? 3 : 0);
+ pout("{1}\\\n", s.rpad(" ", RIGHT-1-adj));
+ }
+ else
+ pout("{1}\n", s);
+}
+
+static void create_header(tool_options_t &opts)
+{
+ netlist_tool_t nt("netlist");
+
+ nt.init();
+
+ nt.log().verbose.set_enabled(false);
+ nt.log().warning.set_enabled(false);
+
+ nt.setup().register_source(plib::make_unique_base<netlist::source_t,
+ netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy));
+ nt.setup().include("dummy");
+
+ pout("// license:GPL-2.0+\n");
+ pout("// copyright-holders:Couriersud\n");
+ pout("#ifndef NLD_DEVINC_H\n");
+ pout("#define NLD_DEVINC_H\n");
+ pout("\n");
+ pout("#include \"nl_setup.h\"\n");
+ pout("#ifndef __PLIB_PREPROCESSOR__\n");
+ pout("\n");
+ pout("/* ----------------------------------------------------------------------------\n");
+ pout(" * Netlist Macros\n");
+ pout(" * ---------------------------------------------------------------------------*/\n");
+ pout("\n");
+
+ pstring last_source("");
+
+ for (auto &e : nt.setup().factory())
+ {
+ if (last_source != e->sourcefile())
+ {
+ last_source = e->sourcefile();
+ pout("{1}\n", pstring("// ").rpad("-", 72));
+ pout("{1}\n", pstring("// Source: ").cat(e->sourcefile().replace("../","")));
+ pout("{1}\n", pstring("// ").rpad("-", 72));
+ }
+ auto v = plib::psplit(e->param_desc(), ",");
+ pstring vs;
+ for (auto s : v)
+ vs += ", p" + s.replace("+","").replace(".","_");
+ mac_out("#define " + e->name() + "(name" + vs + ")");
+ mac_out("\tNET_REGISTER_DEV(" + e->name() +", name)"); \
+
+ for (auto s : v)
+ {
+ pstring r(s.replace("+","").replace(".","_"));
+ if (s.startsWith("+"))
+ mac_out("\tNET_CONNECT(name, " + r + ", p" + r + ")");
+ else
+ mac_out("\tNETDEV_PARAMI(name, " + r + ", p" + r + ")");
+ }
+ mac_out("", false);
+ }
+ pout("#endif // __PLIB_PREPROCESSOR__\n");
+ pout("#endif\n");
+ nt.stop();
+
+}
+
+
/*-------------------------------------------------
listdevices - list all known devices
-------------------------------------------------*/
@@ -390,7 +465,7 @@ static void listdevices(tool_options_t &opts)
}
out += "," + f->param_desc();
- for (auto p : plib::pstring_vector_t(f->param_desc(),",") )
+ for (auto p : plib::psplit(f->param_desc(),",") )
{
if (p.startsWith("+"))
{
@@ -417,7 +492,7 @@ static void listdevices(tool_options_t &opts)
-------------------------------------------------*/
#if 0
-static const char *pmf_verbose[] =
+static const pstring pmf_verbose[] =
{
"NL_PMF_TYPE_VIRTUAL",
"NL_PMF_TYPE_GNUC_PMF",
@@ -455,7 +530,7 @@ int main(int argc, char *argv[])
{
pout(
"nltool (netlist) 0.1\n"
- "Copyright (C) 2016 Couriersud\n"
+ "Copyright (C) 2017 Couriersud\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n\n"
@@ -472,6 +547,8 @@ int main(int argc, char *argv[])
run(opts);
else if (cmd == "static")
static_compile(opts);
+ else if (cmd == "header")
+ create_header(opts);
else if (cmd == "convert")
{
pstring contents;
@@ -508,7 +585,7 @@ int main(int argc, char *argv[])
result = c.result();
}
/* present result */
- pout_strm.write(result.c_str());
+ pout.write(result);
}
else
{