summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/prg/nltool.cpp
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2017-01-15 21:39:33 +0100
committer couriersud <couriersud@gmx.org>2017-01-16 19:49:43 +0100
commit10a4ab4af1d71d4c9eee2af68f872db00e718db7 (patch)
treee6318391fdfffee20c58166b7e581a568dcd25ce /src/lib/netlist/prg/nltool.cpp
parent028fd8563a76965e5dbbdea54c042b15d82583ca (diff)
Preparation work for automatically generated include file for devices.
nltool now is able to create all defines from the factory definitions. This will reduce the number of places needed to touch when adding devices and always ensure that the parser and statically compiled netlist code use the same syntax. This will enable us to delete most device include files, e.g. nld_74107.h. Netlist usage to create this header file: ./nltool -c header > src/lib/netlist/devices/nld_devinc.h This is not yet used in production. It will be enabled after additional tests. [Couriersud]
Diffstat (limited to 'src/lib/netlist/prg/nltool.cpp')
-rw-r--r--src/lib/netlist/prg/nltool.cpp70
1 files changed, 69 insertions, 1 deletions
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index 91f9fc7c1ae..3850dd935e4 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -30,7 +30,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"),
@@ -325,6 +325,72 @@ static void static_compile(tool_options_t &opts)
}
+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");
+
+ for (auto &e : nt.setup().factory())
+ {
+ auto v = plib::pstring_vector_t(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
-------------------------------------------------*/
@@ -472,6 +538,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;