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]
This commit is contained in:
couriersud 2017-01-15 21:39:33 +01:00
parent 028fd8563a
commit 10a4ab4af1
20 changed files with 139 additions and 11 deletions

View File

@ -15,6 +15,8 @@
// Macros // Macros
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define QBJT_SW(name, model) \ #define QBJT_SW(name, model) \
NET_REGISTER_DEV(QBJT_SW, name) \ NET_REGISTER_DEV(QBJT_SW, name) \
NETDEV_PARAMI(name, MODEL, model) NETDEV_PARAMI(name, MODEL, model)
@ -23,6 +25,7 @@
NET_REGISTER_DEV(QBJT_EB, name) \ NET_REGISTER_DEV(QBJT_EB, name) \
NETDEV_PARAMI(name, MODEL, model) NETDEV_PARAMI(name, MODEL, model)
#endif
namespace netlist namespace netlist
{ {

View File

@ -15,6 +15,7 @@
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// Macros // Macros
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define VCCS(name) \ #define VCCS(name) \
NET_REGISTER_DEV(VCCS, name) NET_REGISTER_DEV(VCCS, name)
@ -28,6 +29,8 @@
#define LVCCS(name) \ #define LVCCS(name) \
NET_REGISTER_DEV(LVCCS, name) NET_REGISTER_DEV(LVCCS, name)
#endif
namespace netlist namespace netlist
{ {
namespace analog namespace analog

View File

@ -5,9 +5,10 @@
* *
*/ */
#include "nld_opamps.h"
#include "devices/net_lib.h" #include "devices/net_lib.h"
#include "nld_opamps.h"
namespace netlist namespace netlist
{ {

View File

@ -19,10 +19,13 @@
// Macros // Macros
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define OPAMP(name, model) \ #define OPAMP(name, model) \
NET_REGISTER_DEV(OPAMP, name) \ NET_REGISTER_DEV(OPAMP, name) \
NETDEV_PARAMI(name, MODEL, model) NETDEV_PARAMI(name, MODEL, model)
#endif
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// Devices ... // Devices ...
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------

View File

@ -17,11 +17,14 @@
// Macros // Macros
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define SWITCH(name) \ #define SWITCH(name) \
NET_REGISTER_DEV(SWITCH, name) NET_REGISTER_DEV(SWITCH, name)
#define SWITCH2(name) \ #define SWITCH2(name) \
NET_REGISTER_DEV(SWITCH2, name) NET_REGISTER_DEV(SWITCH2, name)
#endif
#endif /* NLD_SWITCHES_H_ */ #endif /* NLD_SWITCHES_H_ */

View File

@ -39,6 +39,8 @@
// Macros // Macros
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define RES(name, p_R) \ #define RES(name, p_R) \
NET_REGISTER_DEV(RES, name) \ NET_REGISTER_DEV(RES, name) \
NETDEV_PARAMI(name, R, p_R) NETDEV_PARAMI(name, R, p_R)
@ -74,6 +76,8 @@
NET_REGISTER_DEV(CS, name) \ NET_REGISTER_DEV(CS, name) \
NETDEV_PARAMI(name, I, pI) NETDEV_PARAMI(name, I, pI)
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Generic macros // Generic macros
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -9,7 +9,6 @@
****************************************************************************/ ****************************************************************************/
#include "net_lib.h" #include "net_lib.h"
#include "nld_system.h"
#include "nl_factory.h" #include "nl_factory.h"
#include "solver/nld_solver.h" #include "solver/nld_solver.h"
@ -54,7 +53,7 @@ static void initialize_factory(factory::list_t &factory)
ENTRYX(log, LOG, "+I") ENTRYX(log, LOG, "+I")
ENTRYX(logD, LOGD, "+I,+I2") ENTRYX(logD, LOGD, "+I,+I2")
ENTRYX(clock, CLOCK, "FREQ") ENTRYX(clock, CLOCK, "FREQ")
ENTRYX(extclock, EXTCLOCK, "FREQ") ENTRYX(extclock, EXTCLOCK, "FREQ,PATTERN")
ENTRYX(mainclock, MAINCLOCK, "FREQ") ENTRYX(mainclock, MAINCLOCK, "FREQ")
ENTRYX(gnd, GND, "") ENTRYX(gnd, GND, "")
ENTRYX(netlistparams, PARAMETER, "") ENTRYX(netlistparams, PARAMETER, "")
@ -62,7 +61,7 @@ static void initialize_factory(factory::list_t &factory)
ENTRYX(res_sw, RES_SWITCH, "+IN,+P1,+P2") ENTRYX(res_sw, RES_SWITCH, "+IN,+P1,+P2")
ENTRYX(switch1, SWITCH, "") ENTRYX(switch1, SWITCH, "")
ENTRYX(switch2, SWITCH2, "") ENTRYX(switch2, SWITCH2, "")
ENTRYX(nicRSFF, NETDEV_RSFF, "+S,+R") ENTRYX(nicRSFF, NETDEV_RSFF, "")
ENTRYX(nicDelay, NETDEV_DELAY, "") ENTRYX(nicDelay, NETDEV_DELAY, "")
ENTRYX(2716, EPROM_2716, "+GQ,+EPQ,+A0,+A1,+A2,+A3,+A4,+A5,+A6,+A7,+A8,+A9,+A10") ENTRYX(2716, EPROM_2716, "+GQ,+EPQ,+A0,+A1,+A2,+A3,+A4,+A5,+A6,+A7,+A8,+A9,+A10")
ENTRYX(2102A, RAM_2102A, "+CEQ,+A0,+A1,+A2,+A3,+A4,+A5,+A6,+A7,+A8,+A9,+RWQ,+DI") ENTRYX(2102A, RAM_2102A, "+CEQ,+A0,+A1,+A2,+A3,+A4,+A5,+A6,+A7,+A8,+A9,+RWQ,+DI")

View File

@ -12,6 +12,27 @@
#define NET_LIB_H #define NET_LIB_H
#include "nl_base.h" #include "nl_base.h"
//#define NL_AUTO_DEVICES 1
#ifdef NL_AUTO_DEVICES
#include "nld_devinc.h"
#include "analog/nld_bjt.h"
#include "analog/nld_fourterm.h"
#include "analog/nld_switches.h"
#include "analog/nld_twoterm.h"
#include "analog/nld_opamps.h"
#include "solver/nld_solver.h"
#include "macro/nlm_cd4xxx.h"
#include "macro/nlm_ttl74xx.h"
#include "macro/nlm_opamp.h"
#include "macro/nlm_other.h"
#include "nld_7448.h"
#else
#include "nld_system.h" #include "nld_system.h"
#include "nld_2102A.h" #include "nld_2102A.h"
@ -75,6 +96,7 @@
#include "solver/nld_solver.h" #include "solver/nld_solver.h"
#include "nld_legacy.h" #include "nld_legacy.h"
#endif
namespace netlist { namespace netlist {
void initialize_factory(factory::list_t &factory); void initialize_factory(factory::list_t &factory);

View File

@ -34,6 +34,8 @@
#define USE_TRUTHTABLE_7448 (0) #define USE_TRUTHTABLE_7448 (0)
#ifndef NL_AUTO_DEVICES
#define TTL_7448(name, cA0, cA1, cA2, cA3, cLTQ, cBIQ, cRBIQ) \ #define TTL_7448(name, cA0, cA1, cA2, cA3, cLTQ, cBIQ, cRBIQ) \
NET_REGISTER_DEV(TTL_7448, name) \ NET_REGISTER_DEV(TTL_7448, name) \
NET_CONNECT(name, A, cA0) \ NET_CONNECT(name, A, cA0) \
@ -47,4 +49,6 @@
#define TTL_7448_DIP(name) \ #define TTL_7448_DIP(name) \
NET_REGISTER_DEV(TTL_7448_DIP, name) NET_REGISTER_DEV(TTL_7448_DIP, name)
#endif
#endif /* NLD_7448_H_ */ #endif /* NLD_7448_H_ */

View File

@ -54,9 +54,6 @@
NET_C(cG, name.G) \ NET_C(cG, name.G) \
NET_C(cOUT, name.Q) NET_C(cOUT, name.Q)
#define OPTIMIZE_FRONTIER(attach, r_in, r_out) \
setup.register_frontier(# attach, r_in, r_out);
#define RES_SWITCH(name, cIN, cP1, cP2) \ #define RES_SWITCH(name, cIN, cP1, cP2) \
NET_REGISTER_DEV(RES_SWITCH, name) \ NET_REGISTER_DEV(RES_SWITCH, name) \
NET_C(cIN, name.I) \ NET_C(cIN, name.I) \
@ -72,4 +69,5 @@
PARAM(name.N, p_N) \ PARAM(name.N, p_N) \
PARAM(name.FUNC, p_F) PARAM(name.FUNC, p_F)
#endif /* NLD_SYSTEM_H_ */ #endif /* NLD_SYSTEM_H_ */

View File

@ -22,6 +22,8 @@
* Netlist Macros * Netlist Macros
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/
#ifndef NL_AUTO_DEVICES
#define CD4001_NOR(name) \ #define CD4001_NOR(name) \
NET_REGISTER_DEV(CD4001_NOR, name) NET_REGISTER_DEV(CD4001_NOR, name)
@ -44,6 +46,7 @@
#define CD4316_DIP(name) \ #define CD4316_DIP(name) \
NET_REGISTER_DEV(CD4016_DIP, name) NET_REGISTER_DEV(CD4016_DIP, name)
#endif
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* External declarations * External declarations
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/

View File

@ -11,6 +11,8 @@
* Netlist Macros * Netlist Macros
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/
#ifndef NL_AUTO_DEVICES
#define MB3614_DIP(name) \ #define MB3614_DIP(name) \
NET_REGISTER_DEV(MB3614_DIP, name) NET_REGISTER_DEV(MB3614_DIP, name)
@ -23,6 +25,8 @@
#define LM3900(name) \ #define LM3900(name) \
NET_REGISTER_DEV(LM3900, name) NET_REGISTER_DEV(LM3900, name)
#endif
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* External declarations * External declarations
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/

View File

@ -11,12 +11,15 @@
* Netlist Macros * Netlist Macros
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/
#ifndef NL_AUTO_DEVICES
#define MC14584B_GATE(name) \ #define MC14584B_GATE(name) \
NET_REGISTER_DEV(MC14584B_GATE, name) NET_REGISTER_DEV(MC14584B_GATE, name)
#define MC14584B_DIP(name) \ #define MC14584B_DIP(name) \
NET_REGISTER_DEV(MC14584B_DIP, name) NET_REGISTER_DEV(MC14584B_DIP, name)
#endif
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* External declarations * External declarations

View File

@ -11,6 +11,8 @@
* Netlist Macros * Netlist Macros
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/
#ifndef NL_AUTO_DEVICES
#define TTL_7400_GATE(name) \ #define TTL_7400_GATE(name) \
NET_REGISTER_DEV(TTL_7400_GATE, name) NET_REGISTER_DEV(TTL_7400_GATE, name)
@ -200,6 +202,8 @@
#define TTL_74260_DIP(name) \ #define TTL_74260_DIP(name) \
NET_REGISTER_DEV(TTL_74260_DIP, name) NET_REGISTER_DEV(TTL_74260_DIP, name)
#endif
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* External declarations * External declarations
* ---------------------------------------------------------------------------*/ * ---------------------------------------------------------------------------*/

View File

@ -433,7 +433,8 @@ void netlist_t::stop()
log().debug("Printing statistics ...\n"); log().debug("Printing statistics ...\n");
print_stats(); print_stats();
log().debug("Stopping solver device ...\n"); log().debug("Stopping solver device ...\n");
m_solver->stop(); if (m_solver != nullptr)
m_solver->stop();
} }
detail::net_t *netlist_t::find_net(const pstring &name) detail::net_t *netlist_t::find_net(const pstring &name)

View File

@ -7,8 +7,6 @@
#include <cstdio> #include <cstdio>
#include "solver/nld_solver.h"
#include "plib/palloc.h" #include "plib/palloc.h"
#include "plib/putil.h" #include "plib/putil.h"
#include "nl_base.h" #include "nl_base.h"

View File

@ -81,6 +81,9 @@ void NETLIST_NAME(name)(netlist::setup_t &setup) \
NETLIST_NAME(model)(setup); \ NETLIST_NAME(model)(setup); \
setup.namespace_pop(); setup.namespace_pop();
#define OPTIMIZE_FRONTIER(attach, r_in, r_out) \
setup.register_frontier(# attach, r_in, r_out);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// truthtable defines // truthtable defines
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -30,7 +30,7 @@ public:
tool_options_t() : tool_options_t() :
plib::options(), plib::options(),
opt_grp1(*this, "General options", "The following options apply to all commands."), 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_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_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"), 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 listdevices - list all known devices
-------------------------------------------------*/ -------------------------------------------------*/
@ -472,6 +538,8 @@ int main(int argc, char *argv[])
run(opts); run(opts);
else if (cmd == "static") else if (cmd == "static")
static_compile(opts); static_compile(opts);
else if (cmd == "header")
create_header(opts);
else if (cmd == "convert") else if (cmd == "convert")
{ {
pstring contents; pstring contents;

View File

@ -20,10 +20,13 @@
// Macros // Macros
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define SOLVER(name, freq) \ #define SOLVER(name, freq) \
NET_REGISTER_DEV(SOLVER, name) \ NET_REGISTER_DEV(SOLVER, name) \
PARAM(name.FREQ, freq) PARAM(name.FREQ, freq)
#endif
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// solver // solver
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------

View File

@ -87,6 +87,7 @@ CIRCUIT_LAYOUT( pongdoubles )
ANALOG_INPUT(V5, 5) ANALOG_INPUT(V5, 5)
#define VCC "V5", Q #define VCC "V5", Q
#undef GND
#define GND "GND", Q #define GND "GND", Q
CHIP("F9", 7493) CHIP("F9", 7493)