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
// -----------------------------------------------------------------------------
#ifndef NL_AUTO_DEVICES
#define QBJT_SW(name, model) \
NET_REGISTER_DEV(QBJT_SW, name) \
NETDEV_PARAMI(name, MODEL, model)
@ -23,6 +25,7 @@
NET_REGISTER_DEV(QBJT_EB, name) \
NETDEV_PARAMI(name, MODEL, model)
#endif
namespace netlist
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,6 @@
****************************************************************************/
#include "net_lib.h"
#include "nld_system.h"
#include "nl_factory.h"
#include "solver/nld_solver.h"
@ -54,7 +53,7 @@ static void initialize_factory(factory::list_t &factory)
ENTRYX(log, LOG, "+I")
ENTRYX(logD, LOGD, "+I,+I2")
ENTRYX(clock, CLOCK, "FREQ")
ENTRYX(extclock, EXTCLOCK, "FREQ")
ENTRYX(extclock, EXTCLOCK, "FREQ,PATTERN")
ENTRYX(mainclock, MAINCLOCK, "FREQ")
ENTRYX(gnd, GND, "")
ENTRYX(netlistparams, PARAMETER, "")
@ -62,7 +61,7 @@ static void initialize_factory(factory::list_t &factory)
ENTRYX(res_sw, RES_SWITCH, "+IN,+P1,+P2")
ENTRYX(switch1, SWITCH, "")
ENTRYX(switch2, SWITCH2, "")
ENTRYX(nicRSFF, NETDEV_RSFF, "+S,+R")
ENTRYX(nicRSFF, NETDEV_RSFF, "")
ENTRYX(nicDelay, NETDEV_DELAY, "")
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")

View File

@ -12,6 +12,27 @@
#define NET_LIB_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_2102A.h"
@ -75,6 +96,7 @@
#include "solver/nld_solver.h"
#include "nld_legacy.h"
#endif
namespace netlist {
void initialize_factory(factory::list_t &factory);

View File

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

View File

@ -54,9 +54,6 @@
NET_C(cG, name.G) \
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) \
NET_REGISTER_DEV(RES_SWITCH, name) \
NET_C(cIN, name.I) \
@ -72,4 +69,5 @@
PARAM(name.N, p_N) \
PARAM(name.FUNC, p_F)
#endif /* NLD_SYSTEM_H_ */

View File

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

View File

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

View File

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

View File

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

View File

@ -433,7 +433,8 @@ void netlist_t::stop()
log().debug("Printing statistics ...\n");
print_stats();
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)

View File

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

View File

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

View File

@ -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;

View File

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

View File

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