From caafc0f7823054c21a67f096650b2f4a333469c3 Mon Sep 17 00:00:00 2001 From: couriersud Date: Fri, 1 Jul 2016 02:09:14 +0200 Subject: [PATCH] Netlist improvements: - nltool now accepts -Ddefine=value to pass on to netlists - improved option handling and added "dummy" options to add grouping and examples in help output. - improved --cmd=listdevices output - Fix dynamic timestepping. This will work with breakout using real capacitor modelling instead of delay devices. Really slow, but very useful to calibrate timings. - Fix an awful bug in timing for delay devices. - Switched to clang 3.8 and made code compile with -Weverything -Werror -Wno-old-style-cast -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wno-conversion -Wno-c++98-compat -Wno-float-equal -Wno-cast-align -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-exit-time-destructors -Wno-format-nonliteral -Wno-weak-template-vtables This was a helpful exercise since it brought forward some serious issues with implicit constructors. [Couriersud] --- nl_examples/cdelay.c | 17 ++- src/devices/machine/netlist.cpp | 6 +- src/lib/netlist/build/makefile | 28 +++-- src/lib/netlist/devices/net_lib.cpp | 3 +- src/lib/netlist/devices/nld_4066.cpp | 2 +- src/lib/netlist/devices/nld_74123.cpp | 3 - src/lib/netlist/devices/nld_9310.cpp | 2 +- src/lib/netlist/devices/nld_9316.cpp | 2 +- src/lib/netlist/devices/nld_system.cpp | 2 +- src/lib/netlist/devices/nld_truthtable.cpp | 2 +- src/lib/netlist/devices/nlid_cmos.h | 4 +- src/lib/netlist/macro/nlm_cd4xxx.cpp | 8 +- src/lib/netlist/macro/nlm_opamp.cpp | 10 +- src/lib/netlist/macro/nlm_other.cpp | 2 +- src/lib/netlist/macro/nlm_ttl74xx.cpp | 28 ++--- src/lib/netlist/nl_base.h | 26 ++-- src/lib/netlist/nl_dice_compat.h | 26 +++- src/lib/netlist/nl_setup.cpp | 36 +++--- src/lib/netlist/nl_setup.h | 13 +- src/lib/netlist/plib/palloc.cpp | 2 +- src/lib/netlist/plib/palloc.h | 6 +- src/lib/netlist/plib/pfmtlog.h | 2 +- src/lib/netlist/plib/poptions.cpp | 138 ++++++++++++++------- src/lib/netlist/plib/poptions.h | 65 ++++++++-- src/lib/netlist/plib/pparser.cpp | 9 +- src/lib/netlist/plib/pparser.h | 3 +- src/lib/netlist/plib/pstate.h | 2 +- src/lib/netlist/plib/pstring.cpp | 59 +++------ src/lib/netlist/plib/pstring.h | 27 ++-- src/lib/netlist/prg/nltool.cpp | 130 ++++++++++++------- src/lib/netlist/prg/nlwav.cpp | 8 +- src/lib/netlist/solver/nld_matrix_solver.h | 11 +- src/lib/netlist/solver/nld_ms_direct.h | 2 +- src/lib/netlist/solver/nld_ms_direct_lu.h | 4 +- src/lib/netlist/solver/nld_ms_sm.h | 2 +- src/lib/netlist/solver/nld_ms_w.h | 2 +- src/lib/netlist/solver/nld_solver.cpp | 40 +++--- src/lib/netlist/tools/nl_convert.h | 6 +- src/mame/machine/nl_breakout.cpp | 8 +- 39 files changed, 455 insertions(+), 291 deletions(-) diff --git a/nl_examples/cdelay.c b/nl_examples/cdelay.c index 927a7cfe0a4..d6d3f614478 100644 --- a/nl_examples/cdelay.c +++ b/nl_examples/cdelay.c @@ -17,8 +17,15 @@ NETLIST_START(perf) NETLIST_END() +#ifndef P_FREQ +#define P_FREQ 4800 +#endif -NETLIST_START(7400_astable) +#ifndef P_DTS +#define P_DTS 1 +#endif + +NETLIST_START(cap_delay) /* * delay circuit @@ -27,18 +34,20 @@ NETLIST_START(7400_astable) /* Standard stuff */ - SOLVER(Solver, 48000) + SOLVER(Solver, P_FREQ) PARAM(Solver.ACCURACY, 1e-20) + PARAM(Solver.DYNAMIC_TS, P_DTS) + PARAM(Solver.MIN_TIMESTEP, 1e-6) CLOCK(clk, 5000) TTL_7400_NAND(n1,clk,clk) - CAP(C, 1e-9) + CAP(C, 1e-6) NET_C(n1.Q, C.2) NET_C(GND, C.1) TTL_7400_NAND(n2,n1.Q, n1.Q) LOG(logclk, clk) LOG(logn1Q, C.2) - LOG(logn2Q, n2.Q) + LOG(logn2Q, n1.Q) NETLIST_END() diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index b924e052e50..0fa446aa897 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -676,11 +676,7 @@ void netlist_mame_sound_device_t::sound_stream_update(sound_stream &stream, stre bool netlist_source_memregion_t::parse(netlist::setup_t &setup, const pstring &name) { - // FIXME: preprocessor should be a stream! memory_region *mem = downcast(setup.netlist()).machine().root_device().memregion(m_name.cstr()); plib::pimemstream istrm(mem->base(),mem->bytes() ); - plib::pomemstream ostrm; - - plib::pimemstream istrm2(plib::ppreprocessor().process(istrm, ostrm)); - return netlist::parser_t(istrm2, setup).parse(name); + return setup.parse_stream(istrm, name); } diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 7a5e88a5e4c..8b7bc4b2c12 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -14,14 +14,15 @@ SRC = .. #-fuse-ld=gold -Wpedantic -march=native -march=native -LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr +# LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr -CDEFS = -DPSTANDALONE=1 -DPTR64=1 #-Werror #CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I.. #LDFLAGS = $(LTO) -g -O3 -std=c++98 -CFLAGS = $(LTO) -g -O3 -std=c++11 -march=native -I.. -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter -LDFLAGS = $(LTO) -g -O3 -std=c++11 -lpthread -ldl + +CFLAGS = $(CEXTRAFLAGS) $(LTO) -g -O3 -std=c++11 -march=native -I.. -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter +LDFLAGS = $(LTO) -g -O3 -std=c++11 +LIBS = -lpthread -ldl CC = g++-5 LD = @g++-5 @@ -125,11 +126,11 @@ clean: nltool: $(OBJ)/prg/nltool.o $(OBJS) @echo Linking $@... - $(LD) -o $@ $(LDFLAGS) $^ $(LIBS) + @$(LD) -o $@ $(LDFLAGS) $^ $(LIBS) nlwav: $(OBJ)/prg/nlwav.o $(OBJS) @echo Linking $@... - $(LD) -o $@ $(LDFLAGS) $^ $(LIBS) + @$(LD) -o $@ $(LDFLAGS) $^ $(LIBS) #------------------------------------------------- # directories @@ -155,6 +156,17 @@ depend: .depend -include .depend +#------------------------------------------------- +# Special targets +#------------------------------------------------- + +.PHONY: clang +clang: + $(MAKE) CC=clang++ LD=clang++ CEXTRAFLAGS="-Weverything -Werror -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wno-conversion -Wno-c++98-compat -Wno-float-equal -Wno-cast-align -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-exit-time-destructors -Wno-format-nonliteral -Wno-weak-template-vtables" + +# -Wno-old-style-cast +# FIX: -Wno-weak-vtables -Wno-missing-variable-declarations -Wno-conversion -Wno-old-style-cast -Wno-exit-time-destructors + #------------------------------------------------- # generic rules #------------------------------------------------- @@ -163,11 +175,11 @@ $(OBJ)/%.o: $(SRC)/%.cpp @echo Compiling $<... @$(CC) $(CDEFS) $(CFLAGS) -c $< -o $@ -$(OBJ)/%.pp: $(SRC)/%.cpp | $(OSPREBUILD) +$(OBJ)/%.pp: $(SRC)/%.cpp @echo Compiling $<... @$(CC) $(CDEFS) $(CFLAGS) -E $< -o $@ -$(OBJ)/%.s: $(SRC)/%.cpp | $(OSPREBUILD) +$(OBJ)/%.s: $(SRC)/%.cpp @echo Compiling $<... @$(CC) $(CDEFS) $(CFLAGS) -S $< -o $@ diff --git a/src/lib/netlist/devices/net_lib.cpp b/src/lib/netlist/devices/net_lib.cpp index 701bcd8dbbc..3f41d6b9daf 100644 --- a/src/lib/netlist/devices/net_lib.cpp +++ b/src/lib/netlist/devices/net_lib.cpp @@ -71,7 +71,8 @@ namespace netlist { namespace devices { -void initialize_factory(factory_list_t &factory) + +static void initialize_factory(factory_list_t &factory) { ENTRY(R, RES, "R") ENTRY(POT, POT, "R") diff --git a/src/lib/netlist/devices/nld_4066.cpp b/src/lib/netlist/devices/nld_4066.cpp index 4fc78357e84..33b78ddf1b7 100644 --- a/src/lib/netlist/devices/nld_4066.cpp +++ b/src/lib/netlist/devices/nld_4066.cpp @@ -55,7 +55,7 @@ namespace netlist if (R > NL_FCONST(0.0)) { // We only need to update the net first if this is a time stepping net - if (1) // m_R.m_P.net().as_analog().solver().is_timestep()) + if ((1)) // m_R.m_P.net().as_analog().solver().is_timestep()) { m_R.update_dev(); m_R.set_R(R); diff --git a/src/lib/netlist/devices/nld_74123.cpp b/src/lib/netlist/devices/nld_74123.cpp index 8aa623ffd1e..5f45b330b61 100644 --- a/src/lib/netlist/devices/nld_74123.cpp +++ b/src/lib/netlist/devices/nld_74123.cpp @@ -10,9 +10,6 @@ #include "nlid_system.h" #include "analog/nld_twoterm.h" -#define R_OFF (1E20) -#define R_ON (m_RI.Value()) - namespace netlist { namespace devices diff --git a/src/lib/netlist/devices/nld_9310.cpp b/src/lib/netlist/devices/nld_9310.cpp index 66d3a6ddaf4..e7b95549d47 100644 --- a/src/lib/netlist/devices/nld_9310.cpp +++ b/src/lib/netlist/devices/nld_9310.cpp @@ -159,7 +159,7 @@ namespace netlist { if (m_loadq) { - switch (m_cnt) + switch (m_cnt()) { case MAXCNT - 1: m_cnt = MAXCNT; diff --git a/src/lib/netlist/devices/nld_9316.cpp b/src/lib/netlist/devices/nld_9316.cpp index 3775cc90902..6af7ef2eda9 100644 --- a/src/lib/netlist/devices/nld_9316.cpp +++ b/src/lib/netlist/devices/nld_9316.cpp @@ -162,7 +162,7 @@ namespace netlist { if (m_loadq) { - switch (m_cnt) + switch (m_cnt()) { case MAXCNT - 1: m_cnt = MAXCNT; diff --git a/src/lib/netlist/devices/nld_system.cpp b/src/lib/netlist/devices/nld_system.cpp index 90364c58a6a..b692b60506a 100644 --- a/src/lib/netlist/devices/nld_system.cpp +++ b/src/lib/netlist/devices/nld_system.cpp @@ -133,7 +133,7 @@ namespace netlist const nl_double R = state ? m_RON.Value() : m_ROFF.Value(); // We only need to update the net first if this is a time stepping net - if (0) // m_R->m_P.net().as_analog().solver()->is_timestep()) + if ((0)) // m_R->m_P.net().as_analog().solver()->is_timestep()) { m_R.update_dev(); m_R.set_R(R); diff --git a/src/lib/netlist/devices/nld_truthtable.cpp b/src/lib/netlist/devices/nld_truthtable.cpp index 22520b61882..be80b72fdce 100644 --- a/src/lib/netlist/devices/nld_truthtable.cpp +++ b/src/lib/netlist/devices/nld_truthtable.cpp @@ -229,7 +229,7 @@ void truthtable_desc_t::setup(const plib::pstring_vector_t &truthtable, uint_lea if (ign[i] == all_set) { int tign; - if (0) + if ((0)) { tign = get_ignored_simple(i); ign[i] = tign; diff --git a/src/lib/netlist/devices/nlid_cmos.h b/src/lib/netlist/devices/nlid_cmos.h index 74482c85046..758cafa3029 100644 --- a/src/lib/netlist/devices/nlid_cmos.h +++ b/src/lib/netlist/devices/nlid_cmos.h @@ -22,8 +22,8 @@ namespace netlist { } - NETLIB_UPDATEI() {}; - NETLIB_RESETI() {}; + NETLIB_UPDATEI() {} + NETLIB_RESETI() {} public: inline nl_double vdd() { return INPANALOG(m_vdd); } diff --git a/src/lib/netlist/macro/nlm_cd4xxx.cpp b/src/lib/netlist/macro/nlm_cd4xxx.cpp index d622881abb4..95fff085b9e 100644 --- a/src/lib/netlist/macro/nlm_cd4xxx.cpp +++ b/src/lib/netlist/macro/nlm_cd4xxx.cpp @@ -22,7 +22,7 @@ * */ -NETLIST_START(CD4001_DIP) +static NETLIST_START(CD4001_DIP) CD4001_NOR(s1) CD4001_NOR(s2) CD4001_NOR(s3) @@ -63,7 +63,7 @@ NETLIST_END() * This needs a cmos d-a/a-d proxy implementation. */ -NETLIST_START(CD4020_DIP) +static NETLIST_START(CD4020_DIP) CD4020(s1) DIPPINS( /* +--------------+ */ @@ -101,7 +101,7 @@ NETLIST_END() * */ -NETLIST_START(CD4066_DIP) +static NETLIST_START(CD4066_DIP) CD4066_GATE(A) CD4066_GATE(B) CD4066_GATE(C) @@ -127,7 +127,7 @@ NETLIST_START(CD4066_DIP) ) NETLIST_END() -NETLIST_START(CD4016_DIP) +static NETLIST_START(CD4016_DIP) CD4066_GATE(A) CD4066_GATE(B) CD4066_GATE(C) diff --git a/src/lib/netlist/macro/nlm_opamp.cpp b/src/lib/netlist/macro/nlm_opamp.cpp index c3a932c0a35..e7571dfd910 100644 --- a/src/lib/netlist/macro/nlm_opamp.cpp +++ b/src/lib/netlist/macro/nlm_opamp.cpp @@ -9,7 +9,7 @@ * Generic layout with 4 opamps, VCC on pint 4 and GND on pin 11 */ -NETLIST_START(opamp_layout_4_4_11) +static NETLIST_START(opamp_layout_4_4_11) DIPPINS( /* +--------------+ */ A.OUT, /* |1 ++ 14| */ D.OUT, A.MINUS, /* |2 13| */ D.MINUS, @@ -28,7 +28,7 @@ NETLIST_END() * Generic layout with 2 opamps, VCC on pint 8 and GND on pin 4 */ -NETLIST_START(opamp_layout_2_8_4) +static NETLIST_START(opamp_layout_2_8_4) DIPPINS( /* +--------------+ */ A.OUT, /* |1 ++ 8| */ A.VCC, A.MINUS, /* |2 7| */ B.OUT, @@ -40,7 +40,7 @@ NETLIST_START(opamp_layout_2_8_4) NET_C(A.VCC, B.VCC) NETLIST_END() -NETLIST_START(MB3614_DIP) +static NETLIST_START(MB3614_DIP) OPAMP(A, "MB3614") OPAMP(B, "MB3614") OPAMP(C, "MB3614") @@ -50,7 +50,7 @@ NETLIST_START(MB3614_DIP) NETLIST_END() -NETLIST_START(LM324_DIP) +static NETLIST_START(LM324_DIP) OPAMP(A, "LM324") OPAMP(B, "LM324") OPAMP(C, "LM324") @@ -60,7 +60,7 @@ NETLIST_START(LM324_DIP) NETLIST_END() -NETLIST_START(LM358_DIP) +static NETLIST_START(LM358_DIP) OPAMP(A, "LM358") OPAMP(B, "LM358") diff --git a/src/lib/netlist/macro/nlm_other.cpp b/src/lib/netlist/macro/nlm_other.cpp index 6fd73a29fe8..68c0ea57d36 100644 --- a/src/lib/netlist/macro/nlm_other.cpp +++ b/src/lib/netlist/macro/nlm_other.cpp @@ -21,7 +21,7 @@ * */ -NETLIST_START(MC14584B_DIP) +static NETLIST_START(MC14584B_DIP) MC14584B_GATE(s1) MC14584B_GATE(s2) MC14584B_GATE(s3) diff --git a/src/lib/netlist/macro/nlm_ttl74xx.cpp b/src/lib/netlist/macro/nlm_ttl74xx.cpp index 314ba84062c..646ae44a86b 100644 --- a/src/lib/netlist/macro/nlm_ttl74xx.cpp +++ b/src/lib/netlist/macro/nlm_ttl74xx.cpp @@ -24,7 +24,7 @@ * */ -NETLIST_START(TTL_7400_DIP) +static NETLIST_START(TTL_7400_DIP) TTL_7400_GATE(s1) TTL_7400_GATE(s2) TTL_7400_GATE(s3) @@ -62,7 +62,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7402_DIP) +static NETLIST_START(TTL_7402_DIP) TTL_7402_GATE(s1) TTL_7402_GATE(s2) TTL_7402_GATE(s3) @@ -98,7 +98,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7404_DIP) +static NETLIST_START(TTL_7404_DIP) TTL_7404_GATE(s1) TTL_7404_GATE(s2) TTL_7404_GATE(s3) @@ -139,7 +139,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7408_DIP) +static NETLIST_START(TTL_7408_DIP) TTL_7408_GATE(s1) TTL_7408_GATE(s2) TTL_7408_GATE(s3) @@ -177,7 +177,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7410_DIP) +static NETLIST_START(TTL_7410_DIP) TTL_7410_GATE(s1) TTL_7410_GATE(s2) TTL_7410_GATE(s3) @@ -214,7 +214,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7411_DIP) +static NETLIST_START(TTL_7411_DIP) TTL_7411_GATE(s1) TTL_7411_GATE(s2) TTL_7411_GATE(s3) @@ -240,7 +240,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7416_DIP) +static NETLIST_START(TTL_7416_DIP) TTL_7416_GATE(s1) TTL_7416_GATE(s2) TTL_7416_GATE(s3) @@ -281,7 +281,7 @@ NETLIST_END() * Naming conventions follow National Semiconductor datasheet * */ -NETLIST_START(TTL_7420_DIP) +static NETLIST_START(TTL_7420_DIP) TTL_7420_GATE(s1) TTL_7420_GATE(s2) @@ -323,7 +323,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7425_DIP) +static NETLIST_START(TTL_7425_DIP) TTL_7425_GATE(s1) TTL_7425_GATE(s2) @@ -361,7 +361,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7427_DIP) +static NETLIST_START(TTL_7427_DIP) TTL_7427_GATE(s1) TTL_7427_GATE(s2) TTL_7427_GATE(s3) @@ -402,7 +402,7 @@ NETLIST_END() * Naming conventions follow National Semiconductor datasheet */ -NETLIST_START(TTL_7430_DIP) +static NETLIST_START(TTL_7430_DIP) TTL_7430_GATE(s1) DUMMY_INPUT(GND) @@ -439,7 +439,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7432_DIP) +static NETLIST_START(TTL_7432_DIP) TTL_7432_GATE(s1) TTL_7432_GATE(s2) TTL_7432_GATE(s3) @@ -481,7 +481,7 @@ NETLIST_END() * Netlist currently does not model over currents (should it ever?) */ -NETLIST_START(TTL_7437_DIP) +static NETLIST_START(TTL_7437_DIP) TTL_7437_GATE(s1) TTL_7437_GATE(s2) TTL_7437_GATE(s3) @@ -519,7 +519,7 @@ NETLIST_END() * */ -NETLIST_START(TTL_7486_DIP) +static NETLIST_START(TTL_7486_DIP) TTL_7486_GATE(s1) TTL_7486_GATE(s2) TTL_7486_GATE(s3) diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index b08ce88eb02..d31c39f2eda 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -273,8 +273,9 @@ namespace netlist class fatalerror_e : public plib::pexception { public: - fatalerror_e(const pstring &text) : plib::pexception(text) { } - virtual ~fatalerror_e() throw() {} + explicit fatalerror_e(const pstring text) : plib::pexception(text) { } + fatalerror_e(const fatalerror_e &e) : plib::pexception(e) { } + virtual ~fatalerror_e() noexcept {} }; class logic_output_t; @@ -663,6 +664,7 @@ namespace netlist bool is_analog() const; void toggle_new_Q() { m_new_Q ^= 1; } + void force_queue_execution() { m_new_Q = (m_cur_Q ^ 1); } void push_to_queue(const netlist_time delay) NOEXCEPT; void reschedule_in_queue(const netlist_time delay) NOEXCEPT; @@ -711,7 +713,7 @@ namespace netlist public: logic_net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr = nullptr); - virtual ~logic_net_t() { }; + virtual ~logic_net_t() { } netlist_sig_t Q() const { return m_cur_Q; } netlist_sig_t new_Q() const { return m_new_Q; } @@ -755,7 +757,7 @@ namespace netlist analog_net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr = nullptr); - virtual ~analog_net_t() { }; + virtual ~analog_net_t() { } nl_double Q_Analog() const { return m_cur_Analog; } nl_double &Q_Analog_state_ptr() { return m_cur_Analog; } @@ -1139,11 +1141,11 @@ namespace netlist template void save(O &owner, C &state, const pstring &stname) { - this->state().save_item((void *)&owner, state, pstring(owner.name()) + "." + stname); + this->state().save_item(static_cast(&owner), state, pstring(owner.name()) + "." + stname); } template void save(O &owner, C *state, const pstring &stname, const int count) { - this->state().save_state_ptr((void *)&owner, pstring(owner.name()) + "." + stname, plib::state_manager_t::datatype_f::f(), count, state); + this->state().save_state_ptr(static_cast(&owner), pstring(owner.name()) + "." + stname, plib::state_manager_t::datatype_f::f(), count, state); } virtual void reset(); @@ -1160,13 +1162,6 @@ namespace netlist /* sole use is to manage lifetime of family objects */ std::vector>> m_family_cache; - protected: - - // performance - nperfcount_t m_perf_out_processed; - nperfcount_t m_perf_inp_processed; - nperfcount_t m_perf_inp_active; - private: plib::state_manager_t m_state; /* mostly rw */ @@ -1185,6 +1180,11 @@ namespace netlist setup_t *m_setup; plib::plog_base m_log; plib::dynlib *m_lib; // external lib needs to be loaded as long as netlist exists + + // performance + nperfcount_t m_perf_out_processed; + nperfcount_t m_perf_inp_processed; + nperfcount_t m_perf_inp_active; }; // ----------------------------------------------------------------------------- diff --git a/src/lib/netlist/nl_dice_compat.h b/src/lib/netlist/nl_dice_compat.h index e163b637f4c..5923ebdd10c 100644 --- a/src/lib/netlist/nl_dice_compat.h +++ b/src/lib/netlist/nl_dice_compat.h @@ -105,7 +105,7 @@ public: }; #else -#define CHIP(n, t) TTL_ ## t ## DIP(n) +#define CHIP(n, t) TTL_ ## t ## _DIP(n) #define OHM(x) x #define K_OHM(x) RES_K(X) @@ -200,8 +200,8 @@ inline int CAPACITOR_tc_hl(const double c, const double r) * Vt = (VH-VL)*exp(-t/RC) * ln(Vt/(VH-VL))*RC = -t */ - static const double TIME_CONSTANT = -std::log(2.0 / (3.7-0.3)); - int ret = (int) (TIME_CONSTANT * (130.0 + r) * c * 1e9); + static const double TIME_CONSTANT = -std::log(0.8 / (4.0-0.1)); + int ret = (int) (TIME_CONSTANT * (1.0 + r) * c * 1e9); return ret; } @@ -211,14 +211,30 @@ inline int CAPACITOR_tc_lh(const double c, const double r) * Vt = (VH-VL)*(1-exp(-t/RC)) * -t=ln(1-Vt/(VH-VL))*RC */ - static const double TIME_CONSTANT = -std::log(1.0 - 0.8 / (3.7-0.3)); - int ret = (int) (TIME_CONSTANT * (1.0 + r) * c * 1e9); + static const double TIME_CONSTANT = -std::log(1.0 - 2.0 / (4.0-0.1)); + int ret = (int) (TIME_CONSTANT * (130.0 + r) * c * 1e9); return ret; } +#if 1 #define CHIP_CAPACITOR(name, pdesc) \ NETDEV_DELAY(name) \ NETDEV_PARAMI(name, L_TO_H, CAPACITOR_tc_lh((pdesc)->c, (pdesc)->r)) \ NETDEV_PARAMI(name, H_TO_L, CAPACITOR_tc_hl((pdesc)->c, (pdesc)->r)) +#elif 1 +// slow, very slow +#define CHIP_CAPACITOR(name, pdesc) \ + CAP(name ## _C, (pdesc)->c) \ + ALIAS(name.1, name ## _C.1 ) \ + ALIAS(name.2, name ## _C.1) \ + NET_C(GND, name ## _C.2) +#else +// fast, might work +#define CHIP_CAPACITOR(name, pdesc) \ + RES(name ## _C, RES_K(1000)) \ + ALIAS(name.1, name ## _C.1 ) \ + ALIAS(name.2, name ## _C.1) \ + NET_C(GND, name ## _C.2) +#endif #endif /* NL_DICE_COMPAT_H_ */ diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 99fb8962546..afa4545e3b7 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -223,8 +223,8 @@ void setup_t::register_and_set_param(pstring name, param_t ¶m) static_cast(param).initial(val); } break; - default: - log().fatal("Parameter is not supported {1} : {2}\n", name, val); + //default: + // log().fatal("Parameter is not supported {1} : {2}\n", name, val); } } if (!m_params.insert({param.name(), param_ref_t(param.name(), param.device(), param)}).second) @@ -1002,6 +1002,23 @@ void setup_t::include(const pstring &netlist_name) log().fatal("unable to find {1} in source collection", netlist_name); } +bool setup_t::parse_stream(plib::pistream &istrm, const pstring &name) +{ + plib::pomemstream ostrm; + + plib::pimemstream istrm2(plib::ppreprocessor(&m_defines).process(istrm, ostrm)); + return parser_t(istrm2, *this).parse(name); +} + +void setup_t::register_define(pstring defstr) +{ + auto p = defstr.find("="); + if (p>0) + register_define(defstr.left(p), defstr.substr(p+1)); + else + register_define(defstr, "1"); +} + // ---------------------------------------------------------------------------------------- // base sources // ---------------------------------------------------------------------------------------- @@ -1009,28 +1026,19 @@ void setup_t::include(const pstring &netlist_name) bool source_string_t::parse(setup_t &setup, const pstring &name) { plib::pimemstream istrm(m_str.cstr(), m_str.len()); - plib::pomemstream ostrm; - - plib::pimemstream istrm2(plib::ppreprocessor().process(istrm, ostrm)); - return parser_t(istrm2, setup).parse(name); + return setup.parse_stream(istrm, name); } bool source_mem_t::parse(setup_t &setup, const pstring &name) { plib::pimemstream istrm(m_str.cstr(), m_str.len()); - plib::pomemstream ostrm; - - plib::pimemstream istrm2(plib::ppreprocessor().process(istrm, ostrm)); - return parser_t(istrm2, setup).parse(name); + return setup.parse_stream(istrm, name); } bool source_file_t::parse(setup_t &setup, const pstring &name) { plib::pifilestream istrm(m_filename); - plib::pomemstream ostrm; - - plib::pimemstream istrm2(plib::ppreprocessor().process(istrm, ostrm)); - return parser_t(istrm2, setup).parse(name); + return setup.parse_stream(istrm, name); } } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index a4e0c7ade05..85dc1eb4fd5 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -16,7 +16,9 @@ #include "plib/pstring.h" #include "plib/palloc.h" #include "plib/pfmtlog.h" +#include "plib/pstream.h" #include "plib/putil.h" +#include "plib/pparser.h" #include "nl_config.h" #include "nl_base.h" #include "nl_factory.h" @@ -156,6 +158,7 @@ namespace netlist virtual ~source_t() { } virtual bool parse(setup_t &setup, const pstring &name) = 0; + private: }; @@ -222,6 +225,8 @@ namespace netlist void include(const pstring &netlist_name); + bool parse_stream(plib::pistream &istrm, const pstring &name); + /* register a source */ void register_source(std::unique_ptr &&src) @@ -229,6 +234,9 @@ namespace netlist m_sources.push_back(std::move(src)); } + void register_define(pstring def, pstring val) { m_defines.push_back(plib::ppreprocessor::define_t(def, val)); } + void register_define(pstring defstr); + factory_list_t &factory() { return m_factory; } const factory_list_t &factory() const { return m_factory; } @@ -251,6 +259,9 @@ namespace netlist void tt_factory_create(tt_desc &desc); + /* helper - also used by nltool */ + const pstring resolve_alias(const pstring &name) const; + protected: private: @@ -267,7 +278,6 @@ namespace netlist // helpers pstring objtype_as_str(device_object_t &in) const; - const pstring resolve_alias(const pstring &name) const; devices::nld_base_proxy *get_d_a_proxy(core_terminal_t &out); netlist_t &m_netlist; @@ -290,6 +300,7 @@ namespace netlist std::stack m_namespace_stack; source_t::list_t m_sources; + std::vector m_defines; std::vector m_lib; }; diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp index 557e285bf6b..f7a9117f503 100644 --- a/src/lib/netlist/plib/palloc.cpp +++ b/src/lib/netlist/plib/palloc.cpp @@ -15,7 +15,7 @@ namespace plib { // Exceptions //============================================================ -pexception::pexception(const pstring &text) +pexception::pexception(const pstring text) { m_text = text; fprintf(stderr, "%s\n", m_text.cstr()); diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index 8b49d4367b1..5b734785145 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -24,8 +24,10 @@ namespace plib { class pexception : public std::exception { public: - pexception(const pstring &text); - virtual ~pexception() throw() {} + explicit pexception(const pstring text); + pexception(const pexception &e) : std::exception(e) { m_text = e.m_text; } + + virtual ~pexception() noexcept {} const pstring &text() { return m_text; } diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 79fa94da2aa..6fa7ac55776 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -277,7 +277,7 @@ public: error(proxy), fatal(proxy) {} - virtual ~plog_base() {}; + virtual ~plog_base() {} plog_channel debug; plog_channel info; diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index e01169f5264..e6bc45d15eb 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -12,17 +12,18 @@ namespace plib { Options ***************************************************************************/ - option::option() - : m_short(""), m_long(""), m_help(""), m_has_argument(false) - {} - - option::option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument) - : m_short(ashort), m_long(along), m_help(help), m_has_argument(has_argument) + option_base::option_base(options &parent, pstring help) + : m_help(help) { parent.register_option(this); } - option::~option() + option_base::~option_base() + { + } + + option::option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument) + : option_base(parent, help), m_short(ashort), m_long(along), m_has_argument(has_argument) { } @@ -56,6 +57,13 @@ namespace plib { return (err ? 1 : 0); } + int option_vec::parse(pstring argument) + { + bool err = false; + m_val.push_back(argument); + return (err ? 1 : 0); + } + options::options() { } @@ -75,7 +83,7 @@ namespace plib { m_opts.clear(); } - void options::register_option(option *opt) + void options::register_option(option_base *opt) { m_opts.push_back(opt); } @@ -96,11 +104,21 @@ namespace plib { auto v = pstring_vector_t(arg.substr(2),"="); opt = getopt_long(v[0]); has_equal_arg = (v.size() > 1); - if (has_equal_arg) opt_arg = v[1]; + if (has_equal_arg) + { + for (unsigned j = 1; j < v.size() - 1; j++) + opt_arg = opt_arg + v[j] + "="; + opt_arg += v[v.size()-1]; + } } else if (arg.startsWith("-")) { - opt = getopt_short(arg.substr(1)); + opt = getopt_short(arg.substr(1,1)); + if (arg.len() > 2) + { + has_equal_arg = true; + opt_arg = arg.substr(2); + } } else return i; @@ -131,21 +149,21 @@ namespace plib { return argc; } - pstring options::split_paragraphs(pstring text, unsigned width, unsigned ident, - unsigned firstline_ident) + pstring options::split_paragraphs(pstring text, unsigned width, unsigned indent, + unsigned firstline_indent) { auto paragraphs = pstring_vector_t(text,"\n"); pstring ret(""); for (auto &p : paragraphs) { - pstring line = pstring("").rpad(" ", firstline_ident); + pstring line = pstring("").rpad(" ", firstline_indent); for (auto &s : pstring_vector_t(p, " ")) { if (line.len() + s.len() > width) { ret += line + "\n"; - line = pstring("").rpad(" ", ident); + line = pstring("").rpad(" ", indent); } line += s + " "; } @@ -155,67 +173,91 @@ namespace plib { } pstring options::help(pstring description, pstring usage, - unsigned width, unsigned ident) + unsigned width, unsigned indent) { pstring ret; ret = split_paragraphs(description, width, 0, 0) + "\n"; - ret += "Usage:\t" + usage + "\n\nOptions:\n"; + ret += "Usage:\t" + usage + "\n\nOptions:\n\n"; - for (auto & opt : m_opts ) + for (auto & optbase : m_opts ) { - pstring line = ""; - if (opt->short_opt() != "") - line += " -" + opt->short_opt(); - if (opt->long_opt() != "") + if (auto opt = dynamic_cast