From 4be6e7568ed3964fc88ad6eb6fec6b6aec61ae18 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 23 Aug 2015 13:42:03 +0200 Subject: [PATCH] Created a separate logging class. Netlist code should now be at least 98% type safe. No more fuzzing around with SIZEFMT and friends. Changed formatting to use python style format strings. (nw) --- src/emu/machine/netlist.c | 43 +++--- src/emu/machine/netlist.h | 12 +- src/emu/netlist/analog/nld_fourterm.c | 3 - src/emu/netlist/analog/nld_opamps.c | 3 +- src/emu/netlist/analog/nld_twoterm.c | 1 - src/emu/netlist/analog/nld_twoterm.h | 1 - src/emu/netlist/devices/nld_74123.c | 1 - src/emu/netlist/devices/nld_74ls629.c | 3 +- src/emu/netlist/devices/nld_log.c | 9 +- src/emu/netlist/devices/nld_r2r_dac.c | 2 - src/emu/netlist/devices/nld_system.c | 4 +- src/emu/netlist/devices/nld_system.h | 3 +- src/emu/netlist/devices/nld_truthtable.c | 8 +- src/emu/netlist/devices/nld_truthtable.h | 1 - src/emu/netlist/nl_base.c | 65 +++----- src/emu/netlist/nl_base.h | 41 ++--- src/emu/netlist/nl_config.h | 22 +-- src/emu/netlist/nl_factory.c | 4 +- src/emu/netlist/nl_parser.c | 39 +++-- src/emu/netlist/nl_setup.c | 174 +++++++++++----------- src/emu/netlist/nl_setup.h | 3 + src/emu/netlist/plib/palloc.h | 2 - src/emu/netlist/plib/pconfig.h | 14 +- src/emu/netlist/plib/pparser.c | 25 ++-- src/emu/netlist/plib/pstream.h | 47 +++++- src/emu/netlist/plib/pstring.c | 63 +++++++- src/emu/netlist/plib/pstring.h | 163 +++++++++++++++++--- src/emu/netlist/solver/nld_ms_direct.h | 24 +-- src/emu/netlist/solver/nld_ms_direct1.h | 2 +- src/emu/netlist/solver/nld_ms_direct_lu.h | 31 +--- src/emu/netlist/solver/nld_ms_gmres.h | 3 - src/emu/netlist/solver/nld_ms_sor_mat.h | 21 --- src/emu/netlist/solver/nld_solver.c | 63 ++++---- src/emu/netlist/solver/nld_solver.h | 1 + src/emu/netlist/tools/nl_convert.c | 66 ++++---- src/emu/netlist/tools/nl_convert.h | 11 +- src/tools/nltool.c | 35 +++-- 37 files changed, 543 insertions(+), 470 deletions(-) diff --git a/src/emu/machine/netlist.c b/src/emu/machine/netlist.c index 2f782802151..cdbfe89d91b 100644 --- a/src/emu/machine/netlist.c +++ b/src/emu/machine/netlist.c @@ -175,11 +175,11 @@ void netlist_mame_stream_input_t::custom_netlist_additions(netlist::setup_t &set if (snd_in == NULL) snd_in = dynamic_cast(setup.register_dev("NETDEV_SOUND_IN", "STREAM_INPUT")); - pstring sparam = pformat("STREAM_INPUT.CHAN%1")(m_channel); + pstring sparam = pfmt("STREAM_INPUT.CHAN{1}")(m_channel); setup.register_param(sparam, m_param_name); - sparam = pformat("STREAM_INPUT.MULT%1")(m_channel); + sparam = pfmt("STREAM_INPUT.MULT{1}")(m_channel); setup.register_param(sparam, m_mult); - sparam = pformat("STREAM_INPUT.OFFSET%1")(m_channel); + sparam = pfmt("STREAM_INPUT.OFFSET{1}")(m_channel); setup.register_param(sparam, m_offset); } @@ -210,7 +210,7 @@ void netlist_mame_stream_output_t::device_start() void netlist_mame_stream_output_t::custom_netlist_additions(netlist::setup_t &setup) { //NETLIB_NAME(sound_out) *snd_out; - pstring sname = pformat("STREAM_OUT_%1")(m_channel); + pstring sname = pfmt("STREAM_OUT_{1}")(m_channel); //snd_out = dynamic_cast(setup.register_dev("nld_sound_out", sname)); setup.register_dev("NETDEV_SOUND_OUT", sname); @@ -226,19 +226,28 @@ void netlist_mame_stream_output_t::custom_netlist_additions(netlist::setup_t &se // netlist_mame_t // ---------------------------------------------------------------------------------------- -void netlist_mame_t::verror(const loglevel_e level, const char *format, va_list ap) const +void netlist_mame_t::vlog(const plog_level &l, const pstring &ls) const { - pstring errstr = pstring(format).vprintf(ap); + pstring errstr = ls; - switch (level) + switch (l) { - case NL_WARNING: + case DEBUG: + logerror("netlist DEBUG: %s\n", errstr.cstr()); + break; + case INFO: + logerror("netlist INFO: %s\n", errstr.cstr()); + break; + case VERBOSE: + logerror("netlist VERBOSE: %s\n", errstr.cstr()); + break; + case WARNING: logerror("netlist WARNING: %s\n", errstr.cstr()); break; - case NL_LOG: - logerror("netlist LOG: %s\n", errstr.cstr()); + case ERROR: + logerror("netlist ERROR: %s\n", errstr.cstr()); break; - case NL_ERROR: + case FATAL: emu_fatalerror error("netlist ERROR: %s\n", errstr.cstr()); throw error; } @@ -328,12 +337,8 @@ void netlist_mame_device_t::device_start() void netlist_mame_device_t::device_clock_changed() { - //printf("device_clock_changed\n"); m_div = netlist::netlist_time::from_hz(clock()); - //m_rem = 0; - //NL_VERBOSE_OUT(("Setting clock %" I64FMT "d and divisor %d\n", clock(), m_div)); - NL_VERBOSE_OUT(("Setting clock %d and divisor %f\n", clock(), m_div.as_double())); - //printf("Setting clock %d and divisor %d\n", clock(), m_div); + netlist().log().debug("Setting clock {1} and divisor {2}\n", clock(), m_div.as_double()); } @@ -398,7 +403,7 @@ ATTR_COLD void netlist_mame_device_t::save_state() for (int i=0; i< netlist().save_list().size(); i++) { pstate_entry_t *s = netlist().save_list()[i]; - NL_VERBOSE_OUT(("saving state for %s\n", s->m_name.cstr())); + netlist().log().debug("saving state for {1}\n", s->m_name.cstr()); switch (s->m_dt) { case DT_DOUBLE: @@ -438,7 +443,7 @@ ATTR_COLD void netlist_mame_device_t::save_state() break; case NOT_SUPPORTED: default: - netlist().error("found unsupported save element %s\n", s->m_name.cstr()); + netlist().log().fatal("found unsupported save element %s\n", s->m_name); break; } } @@ -575,7 +580,7 @@ void netlist_mame_sound_device_t::device_start() { int chan = outdevs[i]->m_channel.Value(); - netlist().log("Output %d on channel %d", i, chan); + netlist().log().verbose("Output %d on channel %d", i, chan); if (chan < 0 || chan >= MAX_OUT || chan >= outdevs.size()) fatalerror("illegal channel number"); diff --git a/src/emu/machine/netlist.h b/src/emu/machine/netlist.h index d3818ab1955..32b19070d4e 100644 --- a/src/emu/machine/netlist.h +++ b/src/emu/machine/netlist.h @@ -97,7 +97,7 @@ public: protected: - void verror(const loglevel_e level, const char *format, va_list ap) const; + void vlog(const plog_level &l, const pstring &ls) const; private: netlist_mame_device_t &m_parent; @@ -583,7 +583,7 @@ public: { int pos = (upto - m_last_buffer) / m_sample; if (pos >= BUFSIZE) - netlist().error("sound %s: exceeded BUFSIZE\n", name().cstr()); + netlist().log().fatal("sound {1}: exceeded BUFSIZE\n", name().cstr()); while (m_last_pos < pos ) { m_buffer[m_last_pos++] = (stream_sample_t) m_cur; @@ -648,9 +648,9 @@ public: for (int i = 0; i < MAX_INPUT_CHANNELS; i++) { - register_param(pformat("CHAN%1")(i), m_param_name[i], ""); - register_param(pformat("MULT%1")(i), m_param_mult[i], 1.0); - register_param(pformat("OFFSET%1")(i), m_param_offset[i], 0.0); + register_param(pfmt("CHAN{1}")(i), m_param_name[i], ""); + register_param(pfmt("MULT{1}")(i), m_param_mult[i], 1.0); + register_param(pfmt("OFFSET{1}")(i), m_param_offset[i], 0.0); } m_num_channel = 0; } @@ -670,7 +670,7 @@ public: if (m_param_name[i].Value() != "") { if (i != m_num_channel) - netlist().error("sound input numbering has to be sequential!"); + netlist().log().fatal("sound input numbering has to be sequential!"); m_num_channel++; m_param[i] = dynamic_cast(setup().find_param(m_param_name[i].Value(), true)); } diff --git a/src/emu/netlist/analog/nld_fourterm.c b/src/emu/netlist/analog/nld_fourterm.c index b217ff21f3a..d7fd828e1f3 100644 --- a/src/emu/netlist/analog/nld_fourterm.c +++ b/src/emu/netlist/analog/nld_fourterm.c @@ -52,7 +52,6 @@ NETLIB_RESET(VCCS) const nl_double m_mult = m_G.Value() * m_gfac; // 1.0 ==> 1V ==> 1A const nl_double GI = NL_FCONST(1.0) / m_RI.Value(); - //printf("VCCS %s RI %f\n", name().cstr(), m_RI.Value()); m_IP.set(GI); m_IN.set(GI); @@ -127,8 +126,6 @@ NETLIB_UPDATE_TERMINALS(LVCCS) m_ON.set(-beta, NL_FCONST(0.0), -I); m_ON1.set(beta, NL_FCONST(0.0)); - //printf("vi %f beta %f I %f\n", vi, beta, I); - } // ---------------------------------------------------------------------------------------- diff --git a/src/emu/netlist/analog/nld_opamps.c b/src/emu/netlist/analog/nld_opamps.c index d0b9e5da023..38a32b0d211 100644 --- a/src/emu/netlist/analog/nld_opamps.c +++ b/src/emu/netlist/analog/nld_opamps.c @@ -103,7 +103,7 @@ NETLIB_START(OPAMP) connect_late("EBUF.IP", "RP1.1"); } else - netlist().error("Unknown opamp type: %d", m_type); + netlist().log().fatal("Unknown opamp type: {1}", m_type); } /* .model abc OPAMP(VLH=2.0 VLL=0.2 FPF=5 UGF=10k SLEW=0.6u RI=1000k RO=50 DAB=0.002) @@ -150,7 +150,6 @@ NETLIB_RESET(OPAMP) double RP = 0.5 / 3.1459 / CP / m_model.model_value("FPF"); double G = m_model.model_value("UGF") / m_model.model_value("FPF") / RP; - //printf("CP=%e RP=%f G=%f\n", CP, RP, G); m_CP.m_C.setTo(CP); m_RP.set_R(RP); m_G1.m_G.setTo(G); diff --git a/src/emu/netlist/analog/nld_twoterm.c b/src/emu/netlist/analog/nld_twoterm.c index cb5bc5f5ab3..7c54910612f 100644 --- a/src/emu/netlist/analog/nld_twoterm.c +++ b/src/emu/netlist/analog/nld_twoterm.c @@ -333,7 +333,6 @@ NETLIB_START(CS) NETLIB_RESET(CS) { NETLIB_NAME(twoterm)::reset(); - printf("m_I %f\n", m_I.Value()); this->set(0.0, 0.0, m_I); } diff --git a/src/emu/netlist/analog/nld_twoterm.h b/src/emu/netlist/analog/nld_twoterm.h index c38242cd90f..27da8ba258e 100644 --- a/src/emu/netlist/analog/nld_twoterm.h +++ b/src/emu/netlist/analog/nld_twoterm.h @@ -257,7 +257,6 @@ public: m_Id = m_Is * (eVDVt - NL_FCONST(1.0)); m_G = m_Is * m_VtInv * eVDVt + m_gmin; #endif - //printf("%p nVd %f m_Vd %f Vcrit %f\n", this, nVd, m_Vd, m_Vcrit); } ATTR_COLD void set_param(const nl_double Is, const nl_double n, nl_double gmin); diff --git a/src/emu/netlist/devices/nld_74123.c b/src/emu/netlist/devices/nld_74123.c index 59a9ed16ce4..ccd8eba012e 100644 --- a/src/emu/netlist/devices/nld_74123.c +++ b/src/emu/netlist/devices/nld_74123.c @@ -77,7 +77,6 @@ NETLIB_UPDATE(74123) //res = res | INPLOGIC(m_A) | (INPLOGIC(m_B) ^ 1); t_AB_to_Q = NLTIME_FROM_NS(300); t_C_to_Q = NLTIME_FROM_NS(250); - //printf("m_trig %d res %d\n", m_trig, res); } if (res) diff --git a/src/emu/netlist/devices/nld_74ls629.c b/src/emu/netlist/devices/nld_74ls629.c index ce8a0dd3b79..a659fef032b 100644 --- a/src/emu/netlist/devices/nld_74ls629.c +++ b/src/emu/netlist/devices/nld_74ls629.c @@ -150,7 +150,7 @@ NETLIB_UPDATE(SN74LS629) m_clock.m_inc = netlist_time::from_double(0.5 / (double) freq); //m_clock.update(); - //NL_VERBOSE_OUT(("%s %f %f %f\n", name().cstr(), v_freq, v_rng, freq)); + //NL_VERBOSE_OUT(("{1} {2} {3} {4}\n", name(), v_freq, v_rng, freq)); } if (!m_clock.m_enableq && INPLOGIC(m_ENQ)) @@ -169,7 +169,6 @@ NETLIB_UPDATE(SN74LS629) NETLIB_UPDATE_PARAM(SN74LS629) { - //printf("updating %s to %f\n", name().cstr(), m_R.Value()); update_dev(); } diff --git a/src/emu/netlist/devices/nld_log.c b/src/emu/netlist/devices/nld_log.c index ac8a3fdbbc6..db96664661b 100644 --- a/src/emu/netlist/devices/nld_log.c +++ b/src/emu/netlist/devices/nld_log.c @@ -16,7 +16,7 @@ NETLIB_START(log) { register_input("I", m_I); - pstring filename = pformat("%1.log")(name()); + pstring filename = pfmt("{1}.log")(name()); m_strm = palloc(pofilestream(filename)); } @@ -27,8 +27,7 @@ NETLIB_RESET(log) NETLIB_UPDATE(log) { /* use pstring::sprintf, it is a LOT faster */ -// m_strm->writeline(pstring::sprintf("%20.9e %e", netlist().time().as_double(), (nl_double) INPANALOG(m_I)).cstr()); - m_strm->writeline(pformat("%1 %2").e(netlist().time().as_double(),".9").e((nl_double) INPANALOG(m_I)).cstr()); + m_strm->writeline(pfmt("{1} {2}").e(netlist().time().as_double(),".9").e((nl_double) INPANALOG(m_I))); } NETLIB_NAME(log)::~NETLIB_NAME(log)() @@ -49,11 +48,11 @@ NETLIB_RESET(logD) NETLIB_UPDATE(logD) { - m_strm->writeline(pstring::sprintf("%e %e", netlist().time().as_double(), (nl_double) (INPANALOG(m_I) - INPANALOG(m_I2))).cstr()); + m_strm->writeline(pfmt("{1} {2}").e(netlist().time().as_double(),".9").e((nl_double) (INPANALOG(m_I) - INPANALOG(m_I2)))); } // FIXME: Implement wav later, this must be clock triggered device where the input to be written -// is on a subdevice ... +// is on a subdevice .. #if 0 NETLIB_START(wav) { diff --git a/src/emu/netlist/devices/nld_r2r_dac.c b/src/emu/netlist/devices/nld_r2r_dac.c index c1f05837d4c..8ad59dfc9f8 100644 --- a/src/emu/netlist/devices/nld_r2r_dac.c +++ b/src/emu/netlist/devices/nld_r2r_dac.c @@ -32,8 +32,6 @@ NETLIB_UPDATE(r2r_dac) NETLIB_UPDATE_PARAM(r2r_dac) { - //printf("updating %s to %f\n", name().cstr(), m_R.Value()); - update_dev(); nl_double V = m_VIN.Value() / (nl_double) (1 << m_num.Value()) * (nl_double) m_val.Value(); diff --git a/src/emu/netlist/devices/nld_system.c b/src/emu/netlist/devices/nld_system.c index 565b1c81dd1..628ec617cb1 100644 --- a/src/emu/netlist/devices/nld_system.c +++ b/src/emu/netlist/devices/nld_system.c @@ -299,7 +299,7 @@ NETLIB_START(function) register_output("Q", m_Q); for (int i=0; i < m_N; i++) - register_input(pformat("A%1")(i), m_I[i]); + register_input(pfmt("A{1}")(i), m_I[i]); pstring_list_t cmds(m_func.Value(), " "); m_precompiled.clear(); @@ -329,7 +329,7 @@ NETLIB_START(function) rc.m_cmd = PUSH_CONST; rc.m_param = cmd.as_double(&err); if (err) - netlist().error("nld_function: unknown/misformatted token <%s> in <%s>", cmd.cstr(), m_func.Value().cstr()); + netlist().log().fatal("nld_function: unknown/misformatted token <{1}> in <{2}>", cmd, m_func.Value()); } m_precompiled.add(rc); } diff --git a/src/emu/netlist/devices/nld_system.h b/src/emu/netlist/devices/nld_system.h index d3f1aff8935..2ea6fbed4d4 100644 --- a/src/emu/netlist/devices/nld_system.h +++ b/src/emu/netlist/devices/nld_system.h @@ -403,7 +403,6 @@ protected: ATTR_HOT void update() { - //printf("%s: %f\n", name().cstr(), m_I.Q_Analog()); if (m_I.Q_Analog() > logic_family().m_high_thresh_V) OUTLOGIC(m_Q, 1, NLTIME_FROM_NS(1)); else if (m_I.Q_Analog() < logic_family().m_low_thresh_V) @@ -478,7 +477,7 @@ public: ATTR_COLD factory_lib_entry_t(setup_t &setup, const pstring &name, const pstring &classname, const pstring &def_param) - : base_factory_t(name, classname, def_param), m_setup(setup) { printf("devname %s\n", classname.cstr()); } + : base_factory_t(name, classname, def_param), m_setup(setup) { } class dummy : public device_t { diff --git a/src/emu/netlist/devices/nld_truthtable.c b/src/emu/netlist/devices/nld_truthtable.c index 1f6a9a19117..1f671b23108 100644 --- a/src/emu/netlist/devices/nld_truthtable.c +++ b/src/emu/netlist/devices/nld_truthtable.c @@ -135,7 +135,7 @@ void truthtable_desc_t::help(unsigned cur, pstring_list_t list, { // cutoff previous inputs and outputs for ignore if (m_outs[nstate] != ~0U && m_outs[nstate] != val) - fatalerror_e(pformat("Error in truthtable: State %1 already set, %2 != %3\n") + fatalerror_e(pfmt("Error in truthtable: State {1} already set, {2} != {3}\n") .x(nstate,"04")(m_outs[nstate])(val) ); m_outs[nstate] = val; for (unsigned j=0; j")(ni)(no)(has_state); - nl_assert_always(false, msg.cstr()); + pstring msg = pfmt("unable to create truthtable<{1},{2},{3}>")(ni)(no)(has_state); + nl_assert_always(false, msg); } return NULL; } diff --git a/src/emu/netlist/devices/nld_truthtable.h b/src/emu/netlist/devices/nld_truthtable.h index 1044d58e9b2..b5a90d8125c 100644 --- a/src/emu/netlist/devices/nld_truthtable.h +++ b/src/emu/netlist/devices/nld_truthtable.h @@ -157,7 +157,6 @@ public: const int idx = inout.indexof(tmp); if (idx>=0) { - //printf("connecting %s %d\n", out[i].cstr(), idx); connect_late(m_Q[i], m_I[idx]); // disable ignore for this inputs altogether. // FIXME: This shouldn't be necessary diff --git a/src/emu/netlist/nl_base.c b/src/emu/netlist/nl_base.c index e7ef9d66a64..31fc8983d6c 100644 --- a/src/emu/netlist/nl_base.c +++ b/src/emu/netlist/nl_base.c @@ -85,7 +85,7 @@ queue_t::queue_t(netlist_t &nl) void queue_t::register_state(pstate_manager_t &manager, const pstring &module) { - NL_VERBOSE_OUT(("register_state\n")); + netlist().log().debug("register_state\n"); manager.save_item(m_qsize, this, module + "." + "qsize"); manager.save_item(&m_times[0], this, module + "." + "times", m_times.size()); manager.save_item(&(m_names[0].m_buf[0]), this, module + "." + "names", m_names.size() * sizeof(names_t)); @@ -93,9 +93,9 @@ void queue_t::register_state(pstate_manager_t &manager, const pstring &module) void queue_t::on_pre_save() { - NL_VERBOSE_OUT(("on_pre_save\n")); + netlist().log().debug("on_pre_save\n"); m_qsize = this->count(); - NL_VERBOSE_OUT(("current time %f qsize %d\n", netlist().time().as_double(), m_qsize)); + netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize); for (int i = 0; i < m_qsize; i++ ) { m_times[i] = this->listptr()[i].exec_time().as_raw(); @@ -111,12 +111,12 @@ void queue_t::on_pre_save() void queue_t::on_post_load() { this->clear(); - NL_VERBOSE_OUT(("current time %f qsize %d\n", netlist().time().as_double(), m_qsize)); + netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize); for (int i = 0; i < m_qsize; i++ ) { net_t *n = netlist().find_net(m_names[i].m_buf); - //NL_VERBOSE_OUT(("Got %s ==> %p\n", qtemp[i].m_name, n)); - //NL_VERBOSE_OUT(("schedule time %f (%f)\n", n->time().as_double(), netlist_time::from_raw(m_times[i]).as_double())); + //log().debug("Got {1} ==> {2}\n", qtemp[i].m_name, n)); + //log().debug("schedule time {1} ({2})\n", n->time().as_double(), netlist_time::from_raw(m_times[i]).as_double())); this->push(queue_t::entry_t(netlist_time::from_raw(m_times[i]), n)); } } @@ -145,7 +145,7 @@ ATTR_COLD void object_t::init_object(netlist_t &nl, const pstring &aname) ATTR_COLD const pstring &object_t::name() const { if (m_name == "") - netlist().error("object not initialized"); + netlist().log().fatal("object not initialized"); return m_name; } @@ -180,7 +180,8 @@ netlist_t::netlist_t() m_mainclock(NULL), m_solver(NULL), m_gnd(NULL), - m_setup(NULL) + m_setup(NULL), + m_log(this) { } @@ -217,7 +218,7 @@ ATTR_COLD void netlist_t::start() { /* find the main clock and solver ... */ - NL_VERBOSE_OUT(("Searching for mainclock and solver ...\n")); + log().debug("Searching for mainclock and solver ...\n"); m_mainclock = get_single_device("mainclock"); m_solver = get_single_device("solver"); @@ -236,7 +237,7 @@ ATTR_COLD void netlist_t::start() m_use_deactivate = (m_params->m_use_deactivate.Value() ? true : false); - NL_VERBOSE_OUT(("Initializing devices ...\n")); + log().debug("Initializing devices ...\n"); for (std::size_t i = 0; i < m_devices.size(); i++) { device_t *dev = m_devices[i]; @@ -250,7 +251,7 @@ ATTR_COLD void netlist_t::stop() { /* find the main clock and solver ... */ - NL_VERBOSE_OUT(("Stopping all devices ...\n")); + log().debug("Stopping all devices ...\n"); // Step all devices once ! for (std::size_t i = 0; i < m_devices.size(); i++) @@ -360,31 +361,6 @@ ATTR_HOT void netlist_t::process_queue(const netlist_time &delta) } } -ATTR_COLD void netlist_t::error(const char *format, ...) const -{ - va_list ap; - va_start(ap, format); - verror(NL_ERROR, format, ap); - va_end(ap); -} - -ATTR_COLD void netlist_t::warning(const char *format, ...) const -{ - va_list ap; - va_start(ap, format); - verror(NL_WARNING, format, ap); - va_end(ap); -} - -ATTR_COLD void netlist_t::log(const char *format, ...) const -{ - va_list ap; - va_start(ap, format); - verror(NL_LOG, format, ap); - va_end(ap); -} - - // ---------------------------------------------------------------------------------------- // Default netlist elements ... // ---------------------------------------------------------------------------------------- @@ -473,7 +449,7 @@ device_t::device_t(const family_t afamily) device_t::~device_t() { - //NL_VERBOSE_OUT(("~net_device_t\n"); + //log().debug("~net_device_t\n"); } ATTR_COLD setup_t &device_t::setup() @@ -563,7 +539,7 @@ ATTR_COLD void device_t::connect_late(const pstring &t1, const pstring &t2) ATTR_COLD void device_t::connect_direct(core_terminal_t &t1, core_terminal_t &t2) { if (!setup().connect(t1, t2)) - netlist().error("Error connecting %s to %s\n", t1.name().cstr(), t2.name().cstr()); + netlist().log().fatal("Error connecting {1} to {2}\n", t1.name(), t2.name()); } @@ -670,8 +646,6 @@ ATTR_COLD void net_t::rebuild_list() m_list_active.add(*m_core_terms[i]); cnt++; } - //if (cnt != m_active) - //printf("ARgh %s ==> %d != %d\n", name().cstr(), cnt, m_active); m_active = cnt; } @@ -784,22 +758,22 @@ ATTR_COLD void net_t::move_connections(net_t *dest_net) ATTR_COLD void net_t::merge_net(net_t *othernet) { - NL_VERBOSE_OUT(("merging nets ...\n")); + netlist().log().debug("merging nets ...\n"); if (othernet == NULL) return; // Nothing to do if (othernet == this) { - netlist().warning("Connecting %s to itself. This may be right, though\n", this->name().cstr()); + netlist().log().warning("Connecting {1} to itself. This may be right, though\n", this->name()); return; // Nothing to do } if (this->isRailNet() && othernet->isRailNet()) - netlist().error("Trying to merge two rail nets: %s and %s\n", this->name().cstr(), othernet->name().cstr()); + netlist().log().fatal("Trying to merge two rail nets: {1} and {2}\n", this->name(), othernet->name()); if (othernet->isRailNet()) { - NL_VERBOSE_OUT(("othernet is railnet\n")); + netlist().log().debug("othernet is railnet\n"); othernet->merge_net(this); } else @@ -870,15 +844,12 @@ ATTR_COLD void analog_net_t::process_net(list_t *groups, int &cur_group) if (num_cons() == 0) return; /* add the net */ - //SOLVER_VERBOSE_OUT(("add %d - %s\n", cur_group, name().cstr())); groups[cur_group].add(this); for (std::size_t i = 0; i < m_core_terms.size(); i++) { core_terminal_t *p = m_core_terms[i]; - //SOLVER_VERBOSE_OUT(("terminal %s\n", p->name().cstr())); if (p->isType(terminal_t::TERMINAL)) { - //SOLVER_VERBOSE_OUT(("isterminal\n")); terminal_t *pt = static_cast(p); analog_net_t *other_net = &pt->m_otherterm->net().as_analog(); if (!other_net->already_processed(groups, cur_group)) diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h index bfaaee9b44f..9e4b90df9ba 100644 --- a/src/emu/netlist/nl_base.h +++ b/src/emu/netlist/nl_base.h @@ -252,11 +252,11 @@ virtual logic_family_desc_t *default_logic_family() //============================================================ #if defined(MAME_DEBUG) -#define nl_assert(x) do { if (1) if (!(x)) throw fatalerror_e(pformat("assert: %1:%2: %3")(__FILE__)(__LINE__)(#x) ); } while (0) +#define nl_assert(x) do { if (1) if (!(x)) throw fatalerror_e(pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0) #else -#define nl_assert(x) do { if (0) if (!(x)) throw fatalerror_e(pformat("assert: %1:%2: %3")(__FILE__)(__LINE__)(#x) ); } while (0) +#define nl_assert(x) do { if (0) if (!(x)) throw fatalerror_e(pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0) #endif -#define nl_assert_always(x, msg) do { if (!(x)) throw fatalerror_e(pformat("Fatal error: %1\nCaused by assert: %2:%3: %4")(msg)(__FILE__)(__LINE__)(#x)); } while (0) +#define nl_assert_always(x, msg) do { if (!(x)) throw fatalerror_e(pfmt("Fatal error: {1}\nCaused by assert: {2}:{3}: {4}")(msg)(__FILE__)(__LINE__)(#x)); } while (0) // ----------------------------------------------------------------------------- @@ -444,7 +444,7 @@ namespace netlist ATTR_COLD void init_object(core_device_t &dev, const pstring &aname); - core_device_t &device() const { return *m_device; } + ATTR_HOT core_device_t &device() const { return *m_device; } private: core_device_t * m_device; }; @@ -1019,7 +1019,6 @@ namespace netlist ATTR_HOT netlist_sig_t INPLOGIC(const logic_input_t &inp) const { - //printf("%s %d\n", inp.name().cstr(), inp.state()); nl_assert(inp.state() != logic_t::STATE_INP_PASSIVE); return inp.Q(); } @@ -1152,7 +1151,7 @@ namespace netlist // ----------------------------------------------------------------------------- - class netlist_t : public object_t, public pstate_manager_t + class netlist_t : public object_t, public pstate_manager_t, public plog_dispatch_intf { P_PREVENT_COPYING(netlist_t) public: @@ -1185,12 +1184,8 @@ namespace netlist ATTR_COLD net_t *find_net(const pstring &name); - ATTR_COLD void error(const char *format, ...) const ATTR_PRINTF(2,3); - ATTR_COLD void warning(const char *format, ...) const ATTR_PRINTF(2,3); - ATTR_COLD void log(const char *format, ...) const ATTR_PRINTF(2,3); - template - plist_t<_C *> get_device_list() + ATTR_COLD plist_t<_C *> get_device_list() { plist_t<_C *> tmp; for (std::size_t i = 0; i < m_devices.size(); i++) @@ -1203,7 +1198,7 @@ namespace netlist } template - _C *get_first_device() + ATTR_COLD _C *get_first_device() { for (std::size_t i = 0; i < m_devices.size(); i++) { @@ -1215,7 +1210,7 @@ namespace netlist } template - _C *get_single_device(const char *classname) + ATTR_COLD _C *get_single_device(const char *classname) { _C *ret = NULL; for (std::size_t i = 0; i < m_devices.size(); i++) @@ -1224,7 +1219,7 @@ namespace netlist if (dev != NULL) { if (ret != NULL) - this->error("more than one %s device found", classname); + this->log().fatal("more than one {1} device found", classname); else ret = dev; } @@ -1238,18 +1233,12 @@ namespace netlist pnamedlist_t m_started_devices; #endif + ATTR_COLD const plog_base &log() const { return m_log; } + protected: - enum loglevel_e - { - NL_ERROR, - NL_WARNING, - NL_LOG - }; - - // any derived netlist must override this ... - virtual void verror(const loglevel_e level, - const char *format, va_list ap) const = 0; + // any derived netlist must override vlog inherited from plog_base + // virtual void vlog(const plog_level &l, const pstring &ls) = 0; /* from netlist_object */ virtual void reset(); @@ -1267,7 +1256,7 @@ namespace netlist netlist_time m_time; bool m_use_deactivate; - queue_t m_queue; + queue_t m_queue; devices::NETLIB_NAME(mainclock) * m_mainclock; @@ -1277,6 +1266,7 @@ namespace netlist devices::NETLIB_NAME(netlistparams) *m_params; setup_t *m_setup; + plog_base m_log; }; // ----------------------------------------------------------------------------- @@ -1325,7 +1315,6 @@ namespace netlist { if (EXPECTED(!is_state(STATE_INP_PASSIVE))) { - //printf("inactivate %s\n", name().cstr()); set_state(STATE_INP_PASSIVE); net().as_logic().dec_active(*this); } diff --git a/src/emu/netlist/nl_config.h b/src/emu/netlist/nl_config.h index 77759c349b0..41d2989bd2f 100644 --- a/src/emu/netlist/nl_config.h +++ b/src/emu/netlist/nl_config.h @@ -47,7 +47,7 @@ */ // This will be autodetected -//#define NL_PMF_TYPE 3 +// #define NL_PMF_TYPE 2 #define NL_PMF_TYPE_VIRTUAL 0 #define NL_PMF_TYPE_GNUC_PMF 1 @@ -66,18 +66,6 @@ #pragma GCC diagnostic ignored "-Wpmf-conversions" #endif -/* - * This increases performance in circuits with a lot of gates - * but is not guaranteed to be absolutely timing correct. - * - * Performance increase about 10% (breakout) to 20% (pong) - * - */ - - -// moved to parameter NETLIST.USE_DEACTIVATE -// #define USE_DEACTIVE_DEVICE (0) - #define USE_TRUTHTABLE (1) // The following adds about 10% performance ... @@ -116,15 +104,9 @@ // DEBUGGING //============================================================ -#define NL_VERBOSE (0) +#define NL_DEBUG (false) #define NL_KEEP_STATISTICS (0) -#if (NL_VERBOSE) - #define NL_VERBOSE_OUT(x) netlist().log x -#else - #define NL_VERBOSE_OUT(x) do { if(0) netlist().log x ; } while (0) -#endif - //============================================================ // General Macros //============================================================ diff --git a/src/emu/netlist/nl_factory.c b/src/emu/netlist/nl_factory.c index edc55af9732..5f6762c4d05 100644 --- a/src/emu/netlist/nl_factory.c +++ b/src/emu/netlist/nl_factory.c @@ -68,7 +68,7 @@ device_t *factory_list_t::new_device_by_classname(const pstring &classname) cons void factory_list_t::error(const pstring &s) { - m_setup.netlist().error("%s", s.cstr()); + m_setup.log().fatal("{1}", s); } device_t *factory_list_t::new_device_by_name(const pstring &name) @@ -83,7 +83,7 @@ base_factory_t * factory_list_t::factory_by_name(const pstring &name) return (*this)[name]; else { - m_setup.netlist().error("Class %s not found!\n", name.cstr()); + m_setup.log().fatal("Class {1} not found!\n", name); return NULL; // appease code analysis } } diff --git a/src/emu/netlist/nl_parser.c b/src/emu/netlist/nl_parser.c index f77b97a2741..32609079ba6 100644 --- a/src/emu/netlist/nl_parser.c +++ b/src/emu/netlist/nl_parser.c @@ -16,9 +16,6 @@ #pragma GCC diagnostic ignored "-Wformat-extra-args" #endif -//#undef NL_VERBOSE_OUT -//#define NL_VERBOSE_OUT(x) printf x - namespace netlist { // ---------------------------------------------------------------------------------------- @@ -27,8 +24,8 @@ namespace netlist ATTR_COLD void parser_t::verror(const pstring &msg, int line_num, const pstring &line) { - m_setup.netlist().error("line %d: error: %s\n\t\t%s\n", line_num, - msg.cstr(), line.cstr()); + m_setup.log().fatal("line {1}: error: {2}\n\t\t{3}\n", line_num, + msg, line); //throw error; } @@ -77,7 +74,7 @@ bool parser_t::parse(const pstring nlname) if (token.is_type(ENDOFFILE)) { return false; - //error("EOF while searching for <%s>", nlname.cstr()); + //error("EOF while searching for <{1}>", nlname); } if (token.is(m_tok_NETLIST_END)) @@ -118,7 +115,7 @@ void parser_t::parse_netlist(ATTR_UNUSED const pstring &nlname) return; require_token(m_tok_param_left); - NL_VERBOSE_OUT(("Parser: Device: %s\n", token.str().cstr())); + m_setup.log().debug("Parser: Device: {1}\n", token.str()); if (token.is(m_tok_ALIAS)) net_alias(); @@ -279,7 +276,7 @@ void parser_t::net_alias() require_token(m_tok_param_right); - NL_VERBOSE_OUT(("Parser: Alias: %s %s\n", alias.cstr(), out.cstr())); + m_setup.log().debug("Parser: Alias: {1} {2}\n", alias, out); m_setup.register_alias(alias, out); } @@ -292,12 +289,12 @@ void parser_t::net_c() { pstring t1 = get_identifier(); m_setup.register_link(first , t1); - NL_VERBOSE_OUT(("Parser: Connect: %s %s\n", first.cstr(), t1.cstr())); + m_setup.log().debug("Parser: Connect: {1} {2}\n", first, t1); token_t n = get_token(); if (n.is(m_tok_param_right)) break; if (!n.is(m_tok_comma)) - error(pformat("expected a comma, found <%1>")(n.str()) ); + error(pfmt("expected a comma, found <{1}>")(n.str()) ); } } @@ -317,15 +314,15 @@ void parser_t::dippins() if (n.is(m_tok_param_right)) break; if (!n.is(m_tok_comma)) - error(pformat("expected a comma, found <%1>")(n.str()) ); + error(pfmt("expected a comma, found <{1}>")(n.str()) ); } if ((pins.size() % 2) == 1) error("You must pass an equal number of pins to DIPPINS"); unsigned n = pins.size(); for (unsigned i = 0; i < n / 2; i++) { - m_setup.register_alias(pformat("%1")(i+1), pins[i*2]); - m_setup.register_alias(pformat("%1")(n-i), pins[i*2 + 1]); + m_setup.register_alias(pfmt("{1}")(i+1), pins[i*2]); + m_setup.register_alias(pfmt("{1}")(n-i), pins[i*2 + 1]); } } @@ -337,14 +334,14 @@ void parser_t::netdev_param() token_t tok = get_token(); if (tok.is_type(STRING)) { - NL_VERBOSE_OUT(("Parser: Param: %s %s\n", param.cstr(), tok.str().cstr())); + m_setup.log().debug("Parser: Param: {1} {2}\n", param, tok.str()); m_setup.register_param(param, tok.str()); } else { nl_double val = eval_param(tok); - NL_VERBOSE_OUT(("Parser: Param: %s %f\n", param.cstr(), val)); - m_setup.register_param(param, val); + m_setup.log().debug("Parser: Param: {1} {2}\n", param, val); + m_setup.register_param(param, val); } require_token(m_tok_param_right); } @@ -373,14 +370,14 @@ void parser_t::device(const pstring &dev_type) dev = f->Create(); m_setup.register_dev(dev, devname); - NL_VERBOSE_OUT(("Parser: IC: %s\n", devname.cstr())); + m_setup.log().debug("Parser: IC: {1}\n", devname); cnt = 0; while (cnt < def_params.size()) { pstring paramfq = devname + "." + def_params[cnt]; - NL_VERBOSE_OUT(("Defparam: %s\n", paramfq.cstr())); + m_setup.log().debug("Defparam: {1}\n", paramfq); require_token(m_tok_comma); token_t tok = get_token(); if (tok.is_type(STRING)) @@ -407,7 +404,7 @@ void parser_t::device(const pstring &dev_type) tok = get_token(); } if (cnt != termlist.size()) - m_setup.netlist().error("netlist: input count mismatch for %s - expected %" SIZETFMT " found %" SIZETFMT "\n", devname.cstr(), SIZET_PRINTF(termlist.size()), SIZET_PRINTF(cnt)); + m_setup.log().fatal("netlist: input count mismatch for {1} - expected {2} found {3}\n", devname, termlist.size(), cnt); require_token(tok, m_tok_param_right); } } @@ -428,7 +425,7 @@ nl_double parser_t::eval_param(const token_t tok) nl_double ret; pstring val; - //printf("param %s\n", tok.m_token.cstr()); + //printf("param {1}\n", tok.m_token); for (i=1; i<6;i++) if (tok.str().equals(macs[i])) f = i; @@ -460,7 +457,7 @@ nl_double parser_t::eval_param(const token_t tok) ret = val.as_double(&e); if (e) - error("Error with parameter ...\n"); + fatal("Error with parameter ...\n"); if (f>0) require_token(m_tok_param_right); return ret * facs[f]; diff --git a/src/emu/netlist/nl_setup.c b/src/emu/netlist/nl_setup.c index a25566d3d85..fc74e9f3908 100644 --- a/src/emu/netlist/nl_setup.c +++ b/src/emu/netlist/nl_setup.c @@ -107,14 +107,14 @@ device_t *setup_t::register_dev(device_t *dev, const pstring &name) dev->init(netlist(), fqn); if (!(netlist().m_devices.add(dev, false)==true)) - netlist().error("Error adding %s to device list\n", name.cstr()); + log().fatal("Error adding {1} to device list\n", name); return dev; } void setup_t::register_lib_entry(const pstring &name) { if (m_lib.contains(name)) - netlist().warning("Lib entry collection already contains %s. IGNORED", name.cstr()); + log().warning("Lib entry collection already contains {1}. IGNORED", name); else m_lib.add(name); } @@ -133,7 +133,7 @@ device_t *setup_t::register_dev(const pstring &classname, const pstring &name) device_t *dev = factory().new_device_by_name(classname); //device_t *dev = factory().new_device_by_classname(classname); if (dev == NULL) - netlist().error("Class %s not found!\n", classname.cstr()); + log().fatal("Class {1} not found!\n", classname); return register_dev(dev, name); } } @@ -142,17 +142,17 @@ void setup_t::register_model(const pstring &model_in) { int pos = model_in.find(" "); if (pos < 0) - netlist().error("Unable to parse model: %s", model_in.cstr()); + log().fatal("Unable to parse model: {1}", model_in); pstring model = model_in.left(pos).trim().ucase(); pstring def = model_in.substr(pos + 1).trim(); if (!m_models.add(model, def)) - netlist().error("Model already exists: %s", model_in.cstr()); + log().fatal("Model already exists: {1}", model_in); } void setup_t::register_alias_nofqn(const pstring &alias, const pstring &out) { if (!m_alias.add(alias, out)) - netlist().error("Error adding alias %s to alias list\n", alias.cstr()); + log().fatal("Error adding alias {1} to alias list\n", alias); } void setup_t::register_alias(const pstring &alias, const pstring &out) @@ -166,12 +166,12 @@ void setup_t::register_dippins_arr(const pstring &terms) { pstring_list_t list(terms,", "); if (list.size() == 0 || (list.size() % 2) == 1) - netlist().error("You must pass an equal number of pins to DIPPINS"); + log().fatal("You must pass an equal number of pins to DIPPINS"); unsigned n = list.size(); for (unsigned i = 0; i < n / 2; i++) { - register_alias(pformat("%1")(i+1), list[i * 2]); - register_alias(pformat("%1")(n-i), list[i * 2 + 1]); + register_alias(pfmt("{1}")(i+1), list[i * 2]); + register_alias(pfmt("{1}")(n-i), list[i * 2 + 1]); } } @@ -197,7 +197,7 @@ pstring setup_t::objtype_as_astr(object_t &in) const return "QUEUE"; } // FIXME: noreturn - netlist().error("Unknown object type %d\n", in.type()); + log().fatal("Unknown object type {1}\n", (unsigned) in.type()); return "Error"; } @@ -218,14 +218,14 @@ void setup_t::register_object(device_t &dev, const pstring &name, object_t &obj) else if (obj.isFamily(terminal_t::ANALOG)) dynamic_cast(term).init_object(dev, dev.name() + "." + name); else - netlist().error("Error adding %s %s to terminal list, neither LOGIC nor ANALOG\n", objtype_as_astr(term).cstr(), term.name().cstr()); + log().fatal("Error adding {1} {2} to terminal list, neither LOGIC nor ANALOG\n", objtype_as_astr(term), term.name()); } else term.init_object(dev, dev.name() + "." + name); if (!m_terminals.add(term.name(), &term)) - netlist().error("Error adding %s %s to terminal list\n", objtype_as_astr(term).cstr(), term.name().cstr()); - NL_VERBOSE_OUT(("%s %s\n", objtype_as_astr(term).cstr(), name.cstr())); + log().fatal("Error adding {1} {2} to terminal list\n", objtype_as_astr(term), term.name()); + log().debug("{1} {2}\n", objtype_as_astr(term), name); } break; case terminal_t::NET: @@ -233,7 +233,7 @@ void setup_t::register_object(device_t &dev, const pstring &name, object_t &obj) case terminal_t::PARAM: { param_t ¶m = dynamic_cast(obj); - //printf("name: %s\n", name.cstr()); + //printf("name: {1}\n", name); if (m_params_temp.contains(name)) { const pstring val = m_params_temp[name]; @@ -241,20 +241,20 @@ void setup_t::register_object(device_t &dev, const pstring &name, object_t &obj) { case param_t::DOUBLE: { - NL_VERBOSE_OUT(("Found parameter ... %s : %s\n", name.cstr(), val.cstr())); + log().debug("Found parameter ... {1} : {1}\n", name, val); double vald = 0; if (sscanf(val.cstr(), "%lf", &vald) != 1) - netlist().error("Invalid number conversion %s : %s\n", name.cstr(), val.cstr()); + log().fatal("Invalid number conversion {1} : {2}\n", name, val); dynamic_cast(param).initial(vald); } break; case param_t::INTEGER: case param_t::LOGIC: { - NL_VERBOSE_OUT(("Found parameter ... %s : %s\n", name.cstr(), val.cstr())); + log().debug("Found parameter ... {1} : {2}\n", name, val); double vald = 0; if (sscanf(val.cstr(), "%lf", &vald) != 1) - netlist().error("Invalid number conversion %s : %s\n", name.cstr(), val.cstr()); + log().fatal("Invalid number conversion {1} : {2}\n", name, val); dynamic_cast(param).initial((int) vald); } break; @@ -268,21 +268,21 @@ void setup_t::register_object(device_t &dev, const pstring &name, object_t &obj) dynamic_cast(param).initial(val); break; default: - netlist().error("Parameter is not supported %s : %s\n", name.cstr(), val.cstr()); + log().fatal("Parameter is not supported {1} : {2}\n", name, val); } } if (!m_params.add(param.name(), ¶m)) - netlist().error("Error adding parameter %s to parameter list\n", name.cstr()); + log().fatal("Error adding parameter {1} to parameter list\n", name); } break; case terminal_t::DEVICE: - netlist().error("Device registration not yet supported - %s\n", name.cstr()); + log().fatal("Device registration not yet supported - {1}\n", name); break; case terminal_t::NETLIST: - netlist().error("Netlist registration not yet supported - %s\n", name.cstr()); + log().fatal("Netlist registration not yet supported - {1}\n", name); break; case terminal_t::QUEUE: - netlist().error("QUEUE registration not yet supported - %s\n", name.cstr()); + log().fatal("QUEUE registration not yet supported - {1}\n", name); break; } } @@ -291,7 +291,7 @@ void setup_t::register_link_arr(const pstring &terms) { pstring_list_t list(terms,", "); if (list.size() < 2) - netlist().error("You must pass at least 2 terminals to NET_C"); + log().fatal("You must pass at least 2 terminals to NET_C"); for (std::size_t i = 1; i < list.size(); i++) { register_link(list[0], list[i]); @@ -302,7 +302,7 @@ void setup_t::register_link_arr(const pstring &terms) void setup_t::register_link_fqn(const pstring &sin, const pstring &sout) { link_t temp = link_t(sin, sout); - NL_VERBOSE_OUT(("link %s <== %s\n", sin.cstr(), sout.cstr())); + log().debug("link {1} <== {2}\n", sin, sout); m_links.add(temp); } @@ -319,20 +319,20 @@ void setup_t::remove_connections(const pstring pin) { if ((m_links[i].e1 == pinfn) || (m_links[i].e2 == pinfn)) { - netlist().log("removing connection: %s <==> %s\n", m_links[i].e1.cstr(), m_links[i].e2.cstr()); + log().verbose("removing connection: {1} <==> {2}\n", m_links[i].e1, m_links[i].e2); m_links.remove_at(i); found = true; } } if (!found) - netlist().error("remove_connections: found no occurrence of %s\n", pin.cstr()); + log().fatal("remove_connections: found no occurrence of {1}\n", pin); } void setup_t::register_frontier(const pstring attach, const double r_IN, const double r_OUT) { static int frontier_cnt = 0; - pstring frontier_name = pformat("frontier_%1")(frontier_cnt); + pstring frontier_name = pfmt("frontier_{1}")(frontier_cnt); frontier_cnt++; device_t *front = register_dev("FRONTIER_DEV", frontier_name); register_param(frontier_name + ".RIN", r_IN); @@ -354,7 +354,7 @@ void setup_t::register_frontier(const pstring attach, const double r_IN, const d } } if (!found) - netlist().error("Frontier setup: found no occurrence of %s\n", attach.cstr()); + log().fatal("Frontier setup: found no occurrence of {1}\n", attach); register_link(attach, frontier_name + ".Q"); } @@ -362,7 +362,7 @@ void setup_t::register_frontier(const pstring attach, const double r_IN, const d void setup_t::register_param(const pstring ¶m, const double value) { // FIXME: there should be a better way - register_param(param, pformat("%1").e(value,".9")); + register_param(param, pfmt("{1}").e(value,".9")); } void setup_t::register_param(const pstring ¶m, const pstring &value) @@ -373,11 +373,11 @@ void setup_t::register_param(const pstring ¶m, const pstring &value) if (idx < 0) { if (!m_params_temp.add(fqn, value)) - netlist().error("Unexpected error adding parameter %s to parameter list\n", param.cstr()); + log().fatal("Unexpected error adding parameter {1} to parameter list\n", param); } else { - netlist().warning("Overwriting %s old <%s> new <%s>\n", fqn.cstr(), m_params_temp.value_at(idx).cstr(), value.cstr()); + log().warning("Overwriting {1} old <{2}> new <{3}>\n", fqn, m_params_temp.value_at(idx), value); m_params_temp[fqn] = value; } } @@ -394,7 +394,7 @@ const pstring setup_t::resolve_alias(const pstring &name) const temp = (p>=0 ? m_alias.value_at(p) : ""); } while (temp != ""); - NL_VERBOSE_OUT(("%s==>%s\n", name.cstr(), ret.cstr())); + log().debug("{1}==>{2}\n", name, ret); return ret; } @@ -414,9 +414,9 @@ core_terminal_t *setup_t::find_terminal(const pstring &terminal_in, bool require core_terminal_t *term = (ret < 0 ? NULL : m_terminals.value_at(ret)); if (term == NULL && required) - netlist().error("terminal %s(%s) not found!\n", terminal_in.cstr(), tname.cstr()); + log().fatal("terminal {1}({2}) not found!\n", terminal_in, tname); if (term != NULL) - NL_VERBOSE_OUT(("Found input %s\n", tname.cstr())); + log().debug("Found input {1}\n", tname); return term; } @@ -433,19 +433,19 @@ core_terminal_t *setup_t::find_terminal(const pstring &terminal_in, object_t::ty ret = m_terminals.index_of(tname + ".Q"); } if (ret < 0 && required) - netlist().error("terminal %s(%s) not found!\n", terminal_in.cstr(), tname.cstr()); + log().fatal("terminal {1}({2}) not found!\n", terminal_in, tname); core_terminal_t *term = (ret < 0 ? NULL : m_terminals.value_at(ret)); if (term != NULL && term->type() != atype) { if (required) - netlist().error("object %s(%s) found but wrong type\n", terminal_in.cstr(), tname.cstr()); + log().fatal("object {1}({2}) found but wrong type\n", terminal_in, tname); else term = NULL; } if (term != NULL) - NL_VERBOSE_OUT(("Found input %s\n", tname.cstr())); + log().debug("Found input {1}\n", tname); return term; } @@ -459,9 +459,9 @@ param_t *setup_t::find_param(const pstring ¶m_in, bool required) ret = m_params.index_of(outname); if (ret < 0 && required) - netlist().error("parameter %s(%s) not found!\n", param_in_fqn.cstr(), outname.cstr()); + log().fatal("parameter {1}({2}) not found!\n", param_in_fqn, outname); if (ret != -1) - NL_VERBOSE_OUT(("Found parameter %s\n", outname.cstr())); + log().debug("Found parameter {1}\n", outname); return (ret == -1 ? NULL : m_params.value_at(ret)); } @@ -470,7 +470,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(core_terminal_t &out) { nl_assert(out.isFamily(terminal_t::LOGIC)); - //printf("proxy for %s\n", out.name().cstr());; + //printf("proxy for {1}\n", out.name());; logic_output_t &out_cast = dynamic_cast(out); devices::nld_base_proxy *proxy = out_cast.get_proxy(); @@ -478,7 +478,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(core_terminal_t &out) { // create a new one ... devices::nld_base_d_to_a_proxy *new_proxy = out_cast.logic_family()->create_d_a_proxy(&out_cast); - pstring x = pformat("proxy_da_%1_%2")(out.name())(m_proxy_cnt); + pstring x = pfmt("proxy_da_{1}_{2}")(out.name())(m_proxy_cnt); m_proxy_cnt++; register_dev(new_proxy, x); @@ -492,7 +492,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(core_terminal_t &out) core_terminal_t *p = out.net().m_core_terms[i]; p->clear_net(); // de-link from all nets ... if (!connect(new_proxy->proxy_term(), *p)) - netlist().error("Error connecting %s to %s\n", new_proxy->proxy_term().name().cstr(), (*p).name().cstr()); + log().fatal("Error connecting {1} to {2}\n", new_proxy->proxy_term().name(), (*p).name()); } out.net().m_core_terms.clear(); // clear the list #endif @@ -510,7 +510,7 @@ void setup_t::connect_input_output(core_terminal_t &in, core_terminal_t &out) logic_input_t &incast = dynamic_cast(in); devices::nld_a_to_d_proxy *proxy = palloc(devices::nld_a_to_d_proxy(&incast)); incast.set_proxy(proxy); - pstring x = pformat("proxy_ad_%1_%2")(in.name())( m_proxy_cnt); + pstring x = pfmt("proxy_ad_{1}_{2}")(in.name())( m_proxy_cnt); m_proxy_cnt++; register_dev(proxy, x); @@ -546,10 +546,10 @@ void setup_t::connect_terminal_input(terminal_t &term, core_terminal_t &inp) else if (inp.isFamily(terminal_t::LOGIC)) { logic_input_t &incast = dynamic_cast(inp); - NL_VERBOSE_OUT(("connect_terminal_input: connecting proxy\n")); + log().debug("connect_terminal_input: connecting proxy\n"); devices::nld_a_to_d_proxy *proxy = palloc(devices::nld_a_to_d_proxy(&incast)); incast.set_proxy(proxy); - pstring x = pformat("proxy_ad_%1_%2")(inp.name())(m_proxy_cnt); + pstring x = pfmt("proxy_ad_{1}_{2}")(inp.name())(m_proxy_cnt); m_proxy_cnt++; register_dev(proxy, x); @@ -565,7 +565,7 @@ void setup_t::connect_terminal_input(terminal_t &term, core_terminal_t &inp) } else { - netlist().error("Netlist: Severe Error"); + log().fatal("Netlist: Severe Error"); } } @@ -573,7 +573,7 @@ void setup_t::connect_terminal_output(terminal_t &in, core_terminal_t &out) { if (out.isFamily(terminal_t::ANALOG)) { - NL_VERBOSE_OUT(("connect_terminal_output: %s %s\n", in.name().cstr(), out.name().cstr())); + log().debug("connect_terminal_output: {1} {2}\n", in.name(), out.name()); /* no proxy needed, just merge existing terminal net */ if (in.has_net()) out.net().merge_net(&in.net()); @@ -582,14 +582,14 @@ void setup_t::connect_terminal_output(terminal_t &in, core_terminal_t &out) } else if (out.isFamily(terminal_t::LOGIC)) { - NL_VERBOSE_OUT(("connect_terminal_output: connecting proxy\n")); + log().debug("connect_terminal_output: connecting proxy\n"); devices::nld_base_proxy *proxy = get_d_a_proxy(out); connect_terminals(proxy->proxy_term(), in); } else { - netlist().error("Netlist: Severe Error"); + log().fatal("Netlist: Severe Error"); } } @@ -600,22 +600,22 @@ void setup_t::connect_terminals(core_terminal_t &t1, core_terminal_t &t2) if (t1.has_net() && t2.has_net()) { - NL_VERBOSE_OUT(("T2 and T1 have net\n")); + log().debug("T2 and T1 have net\n"); t1.net().merge_net(&t2.net()); } else if (t2.has_net()) { - NL_VERBOSE_OUT(("T2 has net\n")); + log().debug("T2 has net\n"); t2.net().register_con(t1); } else if (t1.has_net()) { - NL_VERBOSE_OUT(("T1 has net\n")); + log().debug("T1 has net\n"); t1.net().register_con(t2); } else { - NL_VERBOSE_OUT(("adding net ...\n")); + log().debug("adding net ...\n"); analog_net_t *anet = palloc(analog_net_t); t1.set_net(*anet); //m_netlist.solver()->m_nets.add(anet); @@ -683,7 +683,7 @@ bool setup_t::connect_input_input(core_terminal_t &t1, core_terminal_t &t2) bool setup_t::connect(core_terminal_t &t1_in, core_terminal_t &t2_in) { - NL_VERBOSE_OUT(("Connecting %s to %s\n", t1_in.name().cstr(), t2_in.name().cstr())); + log().debug("Connecting {1} to {2}\n", t1_in.name(), t2_in.name()); core_terminal_t &t1 = resolve_proxy(t1_in); core_terminal_t &t2 = resolve_proxy(t2_in); bool ret = true; @@ -691,13 +691,13 @@ bool setup_t::connect(core_terminal_t &t1_in, core_terminal_t &t2_in) if (t1.isType(core_terminal_t::OUTPUT) && t2.isType(core_terminal_t::INPUT)) { if (t2.has_net() && t2.net().isRailNet()) - netlist().error("Input %s already connected\n", t2.name().cstr()); + log().fatal("Input {1} already connected\n", t2.name()); connect_input_output(t2, t1); } else if (t1.isType(core_terminal_t::INPUT) && t2.isType(core_terminal_t::OUTPUT)) { if (t1.has_net() && t1.net().isRailNet()) - netlist().error("Input %s already connected\n", t1.name().cstr()); + log().fatal("Input {1} already connected\n", t1.name()); connect_input_output(t1, t2); } else if (t1.isType(core_terminal_t::OUTPUT) && t2.isType(core_terminal_t::TERMINAL)) @@ -726,7 +726,7 @@ bool setup_t::connect(core_terminal_t &t1_in, core_terminal_t &t2_in) } else ret = false; - //netlist().error("Connecting %s to %s not supported!\n", t1.name().cstr(), t2.name().cstr()); + //netlist().error("Connecting {1} to {2} not supported!\n", t1.name(), t2.name()); return ret; } @@ -734,7 +734,7 @@ void setup_t::resolve_inputs() { bool has_twoterms = false; - netlist().log("Resolving inputs ..."); + log().verbose("Resolving inputs ..."); /* Netlist can directly connect input to input. * We therefore first park connecting inputs and retry @@ -761,12 +761,12 @@ void setup_t::resolve_inputs() if (tries == 0) { for (std::size_t i = 0; i < m_links.size(); i++ ) - netlist().warning("Error connecting %s to %s\n", m_links[i].e1.cstr(), m_links[i].e2.cstr()); + log().warning("Error connecting {1} to {2}\n", m_links[i].e1, m_links[i].e2); - netlist().error("Error connecting -- bailing out\n"); + log().fatal("Error connecting -- bailing out\n"); } - netlist().log("deleting empty nets ..."); + log().verbose("deleting empty nets ..."); // delete empty nets ... and save m_list ... @@ -786,7 +786,7 @@ void setup_t::resolve_inputs() for (std::size_t i=0; i < todelete.size(); i++) { - netlist().log("Deleting net %s ...", todelete[i]->name().cstr()); + log().verbose("Deleting net {1} ...", todelete[i]->name()); netlist().m_nets.remove(todelete[i]); if (!todelete[i]->isRailNet()) pfree(todelete[i]); @@ -794,21 +794,21 @@ void setup_t::resolve_inputs() pstring errstr(""); - netlist().log("looking for terminals not connected ..."); + log().verbose("looking for terminals not connected ..."); for (std::size_t i = 0; i < m_terminals.size(); i++) { core_terminal_t *term = m_terminals.value_at(i); if (!term->has_net()) - errstr += pformat("Found terminal %1 without a net\n")(term->name()); + errstr += pfmt("Found terminal {1} without a net\n")(term->name()); else if (term->net().num_cons() == 0) - netlist().warning("Found terminal %s without connections", - term->name().cstr()); + log().warning("Found terminal {1} without connections", + term->name()); } if (errstr != "") - netlist().error("%s", errstr.cstr()); + log().fatal("{1}", errstr); - netlist().log("looking for two terms connected to rail nets ...\n"); + log().verbose("looking for two terms connected to rail nets ...\n"); // FIXME: doesn't find internal devices. This needs to be more clever for (std::size_t i=0; i < netlist().m_devices.size(); i++) { @@ -818,21 +818,21 @@ void setup_t::resolve_inputs() has_twoterms = true; if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet()) #if 0 - netlist().error("Found device %s connected only to railterminals %s/%s\n", - t->name().cstr(), t->m_N.net().name().cstr(), t->m_P.net().name().cstr()); + netlist().fatal("Found device {1} connected only to railterminals {2}/{3}\n", + t->name(), t->m_N.net().name(), t->m_P.net().name()); #else - netlist().warning("Found device %s connected only to railterminals %s/%s\n", - t->name().cstr(), t->m_N.net().name().cstr(), t->m_P.net().name().cstr()); + log().warning("Found device {1} connected only to railterminals {2}/{3}\n", + t->name(), t->m_N.net().name(), t->m_P.net().name()); #endif } } - netlist().log("initialize solver ...\n"); + log().verbose("initialize solver ...\n"); if (netlist().solver() == NULL) { if (has_twoterms) - netlist().error("No solver found for this net although analog elements are present\n"); + log().fatal("No solver found for this net although analog elements are present\n"); } else netlist().solver()->post_start(); @@ -845,12 +845,12 @@ void setup_t::start_devices() if (env != "") { - NL_VERBOSE_OUT(("Creating dynamic logs ...\n")); + log().debug("Creating dynamic logs ...\n"); pstring_list_t ll(env, ":"); for (unsigned i=0; i < ll.size(); i++) { - NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr())); - NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr())); + log().debug("{1}: <{2}>\n",i, ll[i]); + log().debug("{1}: <{2}>\n",i, ll[i]); device_t *nc = factory().new_device_by_name("LOG"); pstring name = "log_" + ll[i]; register_dev(nc, name); @@ -868,7 +868,7 @@ void setup_t::print_stats() const for (std::size_t i = 0; i < netlist().m_started_devices.size(); i++) { core_device_t *entry = netlist().m_started_devices[i]; - printf("Device %20s : %12d %12d %15ld\n", entry->name().cstr(), entry->stat_call_count, entry->stat_update_count, (long int) entry->stat_total_time / (entry->stat_update_count + 1)); + printf("Device %20s : %12d %12d %15ld\n", entry->name(), entry->stat_call_count, entry->stat_update_count, (long int) entry->stat_total_time / (entry->stat_update_count + 1)); } printf("Queue Pushes %15d\n", netlist().queue().m_prof_call); printf("Queue Moves %15d\n", netlist().queue().m_prof_sortmove); @@ -935,7 +935,7 @@ void setup_t::model_parse(const pstring &model_in, model_map_t &map) key = model.ucase(); if (!m_models.contains(key)) - netlist().error("Model %s not found\n", model.cstr()); + log().fatal("Model {1} not found\n", model); model = m_models[key]; } pstring xmodel = model.left(pos); @@ -947,12 +947,12 @@ void setup_t::model_parse(const pstring &model_in, model_map_t &map) if (m_models.contains(xmodel)) model_parse(xmodel, map); else - netlist().error("Model doesn't exist %s\n", xmodel.cstr()); + log().fatal("Model doesn't exist {1}\n", xmodel); } pstring remainder=model.substr(pos+1).trim(); if (!remainder.endsWith(")")) - netlist().error("Model error %s\n", model.cstr()); + log().fatal("Model error {1}\n", model); remainder = remainder.left(remainder.len() - 1); pstring_list_t pairs(remainder," ", true); @@ -960,7 +960,7 @@ void setup_t::model_parse(const pstring &model_in, model_map_t &map) { int pose = pairs[i].find("="); if (pose < 0) - netlist().error("Model error on pair %s\n", model.cstr()); + log().fatal("Model error on pair {1}\n", model); map[pairs[i].left(pose).ucase()] = pairs[i].substr(pose+1); } } @@ -970,9 +970,9 @@ const pstring setup_t::model_value_str(model_map_t &map, const pstring &entity) pstring ret; if (entity != entity.ucase()) - netlist().error("model parameters should be uppercase:%s %s\n", entity.cstr(), model_string(map).cstr()); + log().fatal("model parameters should be uppercase:{1} {2}\n", entity, model_string(map)); if (!map.contains(entity)) - netlist().error("Entity %s not found in model %s\n", entity.cstr(), model_string(map).cstr()); + log().fatal("Entity {1} not found in model {2}\n", entity, model_string(map)); else ret = map[entity]; @@ -997,7 +997,7 @@ nl_double setup_t::model_value(model_map_t &map, const pstring &entity) case 'a': factor = 1e-18; break; default: if (numfac < "0" || numfac > "9") - fatalerror_e(pformat("Unknown number factor <%1> in: %2")(numfac)(entity)); + fatalerror_e(pfmt("Unknown number factor <{1}> in: {2}")(numfac)(entity)); } if (factor != NL_FCONST(1.0)) tmp = tmp.left(tmp.len() - 1); @@ -1015,7 +1015,7 @@ void setup_t::include(const pstring &netlist_name) if (m_sources[i]->parse(*this, netlist_name)) return; } - netlist().error("unable to find %s in source collection", netlist_name.cstr()); + log().fatal("unable to find {1} in source collection", netlist_name); } // ---------------------------------------------------------------------------------------- diff --git a/src/emu/netlist/nl_setup.h b/src/emu/netlist/nl_setup.h index 9f1fbdb9e6f..adb3ccebb5d 100644 --- a/src/emu/netlist/nl_setup.h +++ b/src/emu/netlist/nl_setup.h @@ -197,6 +197,9 @@ namespace netlist nl_double model_value(model_map_t &map, const pstring &entity); void model_parse(const pstring &model, model_map_t &map); + + const plog_base &log() const { return netlist().log(); } + protected: private: diff --git a/src/emu/netlist/plib/palloc.h b/src/emu/netlist/plib/palloc.h index 26f76255e76..01193998392 100644 --- a/src/emu/netlist/plib/palloc.h +++ b/src/emu/netlist/plib/palloc.h @@ -68,7 +68,6 @@ inline void pfree_t(T *p) template inline T *palloc_array_t(size_t N) { - //printf("here palloc_array %d\n", (unsigned) N); char *buf = reinterpret_cast(palloc_raw(N * sizeof(T) + 64*2)); size_t *s = reinterpret_cast(buf); *s = N; @@ -86,7 +85,6 @@ inline void pfree_array_t(T *p) buf -= 64; size_t *s = reinterpret_cast(buf); size_t N = *s; - //printf("here pfree_array %d\n", (unsigned) N); while (N > 0) { p->~T(); diff --git a/src/emu/netlist/plib/pconfig.h b/src/emu/netlist/plib/pconfig.h index 021bb7ff72d..61af16a17db 100644 --- a/src/emu/netlist/plib/pconfig.h +++ b/src/emu/netlist/plib/pconfig.h @@ -63,13 +63,8 @@ typedef __int128_t INT128; #if !(PSTANDALONE) -#undef ATTR_COLD -#define ATTR_COLD - -static inline std::size_t SIZET_PRINTF(const std::size_t &v) -{ - return (unsigned) v; -} +//#undef ATTR_COLD +//#define ATTR_COLD /* use MAME */ #if (USE_DELEGATE_TYPE == DELEGATE_TYPE_INTERNAL) @@ -171,11 +166,6 @@ typedef int64_t INT64; #endif #endif -static inline std::size_t SIZET_PRINTF(const std::size_t &v) -{ - return (unsigned) v; -} - #endif /* diff --git a/src/emu/netlist/plib/pparser.c b/src/emu/netlist/plib/pparser.c index 7e05c8a29e0..aa11c30cfa9 100644 --- a/src/emu/netlist/plib/pparser.c +++ b/src/emu/netlist/plib/pparser.c @@ -16,9 +16,6 @@ #pragma GCC diagnostic ignored "-Wformat-extra-args" #endif -//#undef NL_VERBOSE_OUT -//#define NL_VERBOSE_OUT(x) printf x - // ---------------------------------------------------------------------------------------- // A simple tokenizer // ---------------------------------------------------------------------------------------- @@ -75,7 +72,7 @@ void ptokenizer::require_token(const token_t tok, const token_id_t &token_num) { if (!tok.is(token_num)) { - error(pformat("Expected token <%1> got <%2>")(m_tokens[token_num.id()])(tok.str()) ); + error(pfmt("Expected token <{1}> got <{2}>")(m_tokens[token_num.id()])(tok.str()) ); } } @@ -84,7 +81,7 @@ pstring ptokenizer::get_string() token_t tok = get_token(); if (!tok.is_type(STRING)) { - error(pformat("Expected a string, got <%1>")(tok.str()) ); + error(pfmt("Expected a string, got <{1}>")(tok.str()) ); } return tok.str(); } @@ -94,7 +91,7 @@ pstring ptokenizer::get_identifier() token_t tok = get_token(); if (!tok.is_type(IDENTIFIER)) { - error(pformat("Expected an identifier, got <%1>")(tok.str()) ); + error(pfmt("Expected an identifier, got <{1}>")(tok.str()) ); } return tok.str(); } @@ -104,7 +101,7 @@ pstring ptokenizer::get_identifier_or_number() token_t tok = get_token(); if (!(tok.is_type(IDENTIFIER) || tok.is_type(NUMBER))) { - error(pformat("Expected an identifier, got <%1>")(tok.str()) ); + error(pfmt("Expected an identifier, got <{1}>")(tok.str()) ); } return tok.str(); } @@ -114,12 +111,12 @@ double ptokenizer::get_number_double() token_t tok = get_token(); if (!tok.is_type(NUMBER)) { - error(pformat("Expected a number, got <%1>")(tok.str()) ); + error(pfmt("Expected a number, got <{1}>")(tok.str()) ); } bool err = false; double ret = tok.str().as_double(&err); if (err) - error(pformat("Expected a number, got <%1>")(tok.str()) ); + error(pfmt("Expected a number, got <{1}>")(tok.str()) ); return ret; } @@ -128,12 +125,12 @@ long ptokenizer::get_number_long() token_t tok = get_token(); if (!tok.is_type(NUMBER)) { - error(pformat("Expected a long int, got <%1>")(tok.str()) ); + error(pfmt("Expected a long int, got <{1}>")(tok.str()) ); } bool err = false; long ret = tok.str().as_long(&err); if (err) - error(pformat("Expected a long int, got <%1>")(tok.str()) ); + error(pfmt("Expected a long int, got <{1}>")(tok.str()) ); return ret; } @@ -388,7 +385,7 @@ static pstring catremainder(const pstring_list_t &elems, std::size_t start, pstr ret.cat(elems[i]); ret.cat(sep); } - return pstring(ret.cstr()); + return ret; } pstring ppreprocessor::process_line(const pstring &line) @@ -448,12 +445,12 @@ pstring ppreprocessor::process_line(const pstring &line) if (m_ifflag == 0) { if (lti.size() != 3) - error("PREPRO: only simple defines allowed: %s" + line); + error("PREPRO: only simple defines allowed: " + line); m_defines.add(lti[1], define_t(lti[1], lti[2])); } } else - error(pformat("unknown directive on line %1: %2")(m_lineno)(line)); + error(pfmt("unknown directive on line {1}: {2}")(m_lineno)(line)); } else { diff --git a/src/emu/netlist/plib/pstream.h b/src/emu/netlist/plib/pstream.h index d0cfd8e21d8..fdf3c0687d6 100644 --- a/src/emu/netlist/plib/pstream.h +++ b/src/emu/netlist/plib/pstream.h @@ -158,7 +158,7 @@ public: void writeline(const pstring &line) { - write(line.cstr(), line.blen()); + write(line); write(10); } @@ -212,6 +212,30 @@ private: char *m_mem; }; +class postringstream : public postream +{ + P_PREVENT_COPYING(postringstream ); + +public: + + postringstream() : postream(0) { } + virtual ~postringstream() { } + + const pstringbuffer &str() { return m_buf; } + +protected: + /* write n bytes to stream */ + virtual void vwrite(const void *buf, unsigned n) + { + m_buf.cat(buf, n); + } + virtual void vseek(pos_type n) { } + virtual pos_type vtell() { return m_buf.len(); } + +private: + pstringbuffer m_buf; +}; + // ----------------------------------------------------------------------------- // pofilestream: file output stream // ----------------------------------------------------------------------------- @@ -303,5 +327,26 @@ private: pstring m_str; }; +// ----------------------------------------------------------------------------- +// pstream_fmt_writer_t: writer on top of ostream +// ----------------------------------------------------------------------------- + +class pstream_fmt_writer_t : public pfmt_writer_t<> +{ + P_PREVENT_COPYING(pstream_fmt_writer_t); +public: + + pstream_fmt_writer_t(postream &strm) : m_strm(strm) {} + virtual ~pstream_fmt_writer_t() { } + +protected: + virtual void vdowrite(const pstring &ls) const + { + m_strm.write(ls); + } + +private: + postream &m_strm; +}; #endif /* _PSTREAM_H_ */ diff --git a/src/emu/netlist/plib/pstring.c b/src/emu/netlist/plib/pstring.c index f2583787f3e..47e1c8743e6 100644 --- a/src/emu/netlist/plib/pstring.c +++ b/src/emu/netlist/plib/pstring.c @@ -494,6 +494,15 @@ void pstringbuffer::pcat(const char *s) m_len += slen; } +void pstringbuffer::pcat(const void *m, unsigned l) +{ + const std::size_t nl = m_len + l + 1; + resize(nl); + std::memcpy(m_ptr + m_len, m, l); + m_len += l; + *(m_ptr + m_len) = 0; +} + void pstringbuffer::pcat(const pstring &s) { const std::size_t slen = s.blen(); @@ -504,19 +513,20 @@ void pstringbuffer::pcat(const pstring &s) m_ptr[m_len] = 0; } -pformat::pformat(const pstring &fmt) +pfmt::pfmt(const pstring &fmt) : m_arg(0) { memcpy(m_str, fmt.cstr(), fmt.blen() + 1); } -pformat::pformat(const char *fmt) +pfmt::pfmt(const char *fmt) : m_arg(0) { strncpy(m_str, fmt, sizeof(m_str) - 1); m_str[sizeof(m_str) - 1] = 0; } +#if 0 void pformat::format_element(const char *f, const char *l, const char *fmt_spec, ...) { va_list ap; @@ -539,7 +549,54 @@ void pformat::format_element(const char *f, const char *l, const char *fmt_spec, } va_end(ap); } - +#else +void pfmt::format_element(const char *f, const char *l, const char *fmt_spec, ...) +{ + va_list ap; + va_start(ap, fmt_spec); + char fmt[30] = "%"; + char search[10] = ""; + char buf[1024]; + m_arg++; + int sl = sprintf(search, "{%d:", m_arg); + char *p = strstr(m_str, search); + if (p == NULL) + { + sl = sprintf(search, "{%d}", m_arg); + p = strstr(m_str, search); + if (p == NULL) + { + sl = 2; + p = strstr(m_str, "{}"); + } + strcat(fmt, f); + } + else + { + char *p1 = strstr(p, "}"); + if (p1 != NULL) + { + sl = p1 - p + 1; + if (m_arg>=10) + strncat(fmt, p+4, p1 - p - 4); + else + strncat(fmt, p+3, p1 - p - 3); + } + else + strcat(fmt, f); + } + strcat(fmt, l); + strcat(fmt, fmt_spec); + int nl = vsprintf(buf, fmt, ap); + if (p != NULL) + { + // Make room + memmove(p+nl, p+sl, strlen(p) + 1 - sl); + memcpy(p, buf, nl); + } + va_end(ap); +} +#endif template struct pstring_t; template struct pstring_t; diff --git a/src/emu/netlist/plib/pstring.h b/src/emu/netlist/plib/pstring.h index f59cefb9341..023e0775b5e 100644 --- a/src/emu/netlist/plib/pstring.h +++ b/src/emu/netlist/plib/pstring.h @@ -356,6 +356,7 @@ public: void cat(const pstring &s) { pcat(s); } void cat(const char *s) { pcat(s); } + void cat(const void *m, unsigned l) { pcat(m, l); } private: @@ -372,6 +373,7 @@ private: void pcopy(const pstring &from); void pcat(const char *s); void pcat(const pstring &s); + void pcat(const void *m, unsigned l); char *m_ptr; std::size_t m_size; @@ -387,7 +389,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef short cast_type; + static short cast(char x) { return x; } static const bool is_signed = true; static const char *size_specifier() { return "h"; } }; @@ -395,7 +397,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef short cast_type; + static short cast(short x) { return x; } static const bool is_signed = true; static const char *size_specifier() { return "h"; } }; @@ -403,7 +405,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef int cast_type; + static int cast(int x) { return x; } static const bool is_signed = true; static const char *size_specifier() { return ""; } }; @@ -411,7 +413,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef long cast_type; + static long cast(long x) { return x; } static const bool is_signed = true; static const char *size_specifier() { return "l"; } }; @@ -419,7 +421,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef long long cast_type; + static long long cast(long long x) { return x; } static const bool is_signed = true; static const char *size_specifier() { return "ll"; } }; @@ -427,7 +429,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef unsigned short cast_type; + static unsigned short cast(unsigned char x) { return x; } static const bool is_signed = false; static const char *size_specifier() { return "h"; } }; @@ -435,7 +437,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef unsigned short cast_type; + static unsigned short cast(unsigned short x) { return x; } static const bool is_signed = false; static const char *size_specifier() { return "h"; } }; @@ -443,7 +445,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef unsigned int cast_type; + static unsigned int cast(unsigned int x) { return x; } static const bool is_signed = false; static const char *size_specifier() { return ""; } }; @@ -451,7 +453,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef unsigned long cast_type; + static unsigned long cast(unsigned long x) { return x; } static const bool is_signed = false; static const char *size_specifier() { return "l"; } }; @@ -459,7 +461,7 @@ struct ptype_treats template<> struct ptype_treats { - typedef unsigned long long cast_type; + static unsigned long long cast(unsigned long long x) { return x; } static const bool is_signed = false; static const char *size_specifier() { return "ll"; } }; @@ -471,33 +473,34 @@ public: virtual ~pformat_base() { } - P &operator ()(const double x, const char *f = "") { format_element(f, "", "g", x); return static_cast

(*this); } - P & e(const double x, const char *f = "") { format_element(f, "", "e", x); return static_cast

(*this); } - P & f(const double x, const char *f = "") { format_element(f, "", "f", x); return static_cast

(*this); } + ATTR_COLD P &operator ()(const double x, const char *f = "") { format_element(f, "", "f", x); return static_cast

(*this); } + ATTR_COLD P & e(const double x, const char *f = "") { format_element(f, "", "e", x); return static_cast

(*this); } + ATTR_COLD P & g(const double x, const char *f = "") { format_element(f, "", "g", x); return static_cast

(*this); } - P &operator ()(const char *x, const char *f = "") { format_element(f, "", "s", x); return static_cast

(*this); } - P &operator ()(const void *x, const char *f = "") { format_element(f, "", "p", x); return static_cast

(*this); } - P &operator ()(const pstring &x, const char *f = "") { format_element(f, "", "s", x.cstr() ); return static_cast

(*this); } + ATTR_COLD P &operator ()(const char *x, const char *f = "") { format_element(f, "", "s", x); return static_cast

(*this); } + ATTR_COLD P &operator ()(char *x, const char *f = "") { format_element(f, "", "s", x); return static_cast

(*this); } + ATTR_COLD P &operator ()(const void *x, const char *f = "") { format_element(f, "", "p", x); return static_cast

(*this); } + ATTR_COLD P &operator ()(const pstring &x, const char *f = "") { format_element(f, "", "s", x.cstr() ); return static_cast

(*this); } template - P &operator ()(const T x, const char *f = "") + ATTR_COLD P &operator ()(const T x, const char *f = "") { if (ptype_treats::is_signed) - format_element(f, ptype_treats::size_specifier(), "d", (typename ptype_treats::cast_type) x); + format_element(f, ptype_treats::size_specifier(), "d", ptype_treats::cast(x)); else - format_element(f, ptype_treats::size_specifier(), "u", (typename ptype_treats::cast_type) x); + format_element(f, ptype_treats::size_specifier(), "u", ptype_treats::cast(x)); return static_cast

(*this); } template - P &x(const T x, const char *f = "") + ATTR_COLD P &x(const T x, const char *f = "") { format_element(f, ptype_treats::size_specifier(), "x", x); return static_cast

(*this); } template - P &o(const T x, const char *f = "") + ATTR_COLD P &o(const T x, const char *f = "") { format_element(f, ptype_treats::size_specifier(), "o", x); return static_cast

(*this); @@ -509,11 +512,11 @@ protected: }; -class pformat : public pformat_base +class pfmt : public pformat_base { public: - pformat(const pstring &fmt); - pformat(const char *fmt); + ATTR_COLD pfmt(const pstring &fmt); + ATTR_COLD pfmt(const char *fmt); operator pstring() const { return m_str; } @@ -529,5 +532,117 @@ private: unsigned m_arg; }; +enum plog_level +{ + DEBUG, + INFO, + VERBOSE, + WARNING, + ERROR, + FATAL +}; + +class plog_dispatch_intf; + +template +class pfmt_writer_t +{ +public: + pfmt_writer_t() { } + virtual ~pfmt_writer_t() { } + + ATTR_COLD void operator ()(const char *fmt) const + { + if (build_enabled) vdowrite(fmt); + } + + template + ATTR_COLD void operator ()(const char *fmt, const T1 &v1) const + { + if (build_enabled) vdowrite(pfmt(fmt)(v1)); + } + + template + ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2) const + { + if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)); + } + + template + ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2, const T3 &v3) const + { + if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)); + } + + template + ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) const + { + if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)(v4)); + } + + template + ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5) const + { + if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)(v4)(v5)); + } + +protected: + virtual void vdowrite(const pstring &ls) const {} + +}; + +template +class plog_channel : public pfmt_writer_t +{ +public: + plog_channel(plog_dispatch_intf *b) : pfmt_writer_t(), m_base(b) { } + virtual ~plog_channel() { } + +protected: + virtual void vdowrite(const pstring &ls) const; + +private: + plog_dispatch_intf *m_base; +}; + +class plog_dispatch_intf +{ + template friend class plog_channel; + +public: + virtual ~plog_dispatch_intf() { } +protected: + virtual void vlog(const plog_level &l, const pstring &ls) const = 0; +}; + +template +class plog_base +{ +public: + + plog_base(plog_dispatch_intf *proxy) + : debug(proxy), + info(proxy), + verbose(proxy), + warning(proxy), + error(proxy), + fatal(proxy) + {} + virtual ~plog_base() {}; + + plog_channel debug; + plog_channel info; + plog_channel verbose; + plog_channel warning; + plog_channel error; + plog_channel fatal; +}; + + +template +void plog_channel::vdowrite(const pstring &ls) const +{ + m_base->vlog(L, ls); +} #endif /* _PSTRING_H_ */ diff --git a/src/emu/netlist/solver/nld_ms_direct.h b/src/emu/netlist/solver/nld_ms_direct.h index f23d5fdba49..d05480b2715 100644 --- a/src/emu/netlist/solver/nld_ms_direct.h +++ b/src/emu/netlist/solver/nld_ms_direct.h @@ -142,13 +142,12 @@ ATTR_COLD void matrix_solver_direct_t::add_term(int k, terminal if (ot>=0) { m_terms[k]->add(term, ot, true); - SOLVER_VERBOSE_OUT(("Net %d Term %s %f %f\n", k, terms[i]->name().cstr(), terms[i]->m_gt, terms[i]->m_go)); } /* Should this be allowed ? */ else // if (ot<0) { m_rails_temp[k].add(term, ot, true); - netlist().error("found term with missing othernet %s\n", term->name().cstr()); + log().fatal("found term with missing othernet {1}\n", term->name()); } } } @@ -158,7 +157,7 @@ template ATTR_COLD void matrix_solver_direct_t::vsetup(analog_net_t::list_t &nets) { if (m_dim < nets.size()) - netlist().error("Dimension %d less than %" SIZETFMT, m_dim, SIZET_PRINTF(nets.size())); + log().fatal("Dimension {1} less than {2}", m_dim, nets.size()); for (unsigned k = 0; k < N(); k++) { @@ -295,10 +294,10 @@ ATTR_COLD void matrix_solver_direct_t::vsetup(analog_net_t::lis if (0) for (unsigned k = 0; k < N(); k++) { - pstring line = pformat("%1")(k, "3"); + pstring line = pfmt("{1}")(k, "3"); for (unsigned j = 0; j < m_terms[k]->m_nzrd.size(); j++) - line += pformat(" %1")(m_terms[k]->m_nzrd[j], "3"); - netlist().log("%s", line.cstr()); + line += pfmt(" {1}")(m_terms[k]->m_nzrd[j], "3"); + log().verbose("{1}", line); } /* @@ -310,7 +309,7 @@ ATTR_COLD void matrix_solver_direct_t::vsetup(analog_net_t::lis for (unsigned k = 0; k < N(); k++) { - pstring num = pformat("%1")(k); + pstring num = pfmt("{1}")(k); save(m_terms[k]->go(),"GO" + num, m_terms[k]->count()); save(m_terms[k]->gt(),"GT" + num, m_terms[k]->count()); @@ -509,17 +508,6 @@ ATTR_HOT void matrix_solver_direct_t::LE_back_subst_full( x[i] = sum / A(i,i); } -#if 0 - printf("Solution:\n"); - for (unsigned i = 0; i < N(); i++) - { - for (unsigned k = 0; k < N(); k++) - printf("%f ", m_A[i][k]); - printf("| %f = %f \n", x[i], m_RHS[i]); - } - printf("\n"); -#endif - } template diff --git a/src/emu/netlist/solver/nld_ms_direct1.h b/src/emu/netlist/solver/nld_ms_direct1.h index 6c915c4a413..9f895a6c3f3 100644 --- a/src/emu/netlist/solver/nld_ms_direct1.h +++ b/src/emu/netlist/solver/nld_ms_direct1.h @@ -41,7 +41,7 @@ ATTR_HOT inline int matrix_solver_direct1_t::vsolve_non_dynamic(ATTR_UNUSED cons analog_net_t *net = m_nets[0]; this->build_LE_A(); this->build_LE_RHS(m_RHS); - //NL_VERBOSE_OUT(("%f %f\n", new_val, m_RHS[0] / m_A[0][0]); + //NL_VERBOSE_OUT(("{1} {2}\n", new_val, m_RHS[0] / m_A[0][0]); nl_double new_val = m_RHS[0] / A(0,0); diff --git a/src/emu/netlist/solver/nld_ms_direct_lu.h b/src/emu/netlist/solver/nld_ms_direct_lu.h index 809ba97c18e..633e135cbe4 100644 --- a/src/emu/netlist/solver/nld_ms_direct_lu.h +++ b/src/emu/netlist/solver/nld_ms_direct_lu.h @@ -222,13 +222,12 @@ ATTR_COLD void matrix_solver_direct_t::add_term(int k, terminal if (ot>=0) { m_terms[k]->add(term, ot, true); - SOLVER_VERBOSE_OUT(("Net %d Term %s %f %f\n", k, terms[i]->name().cstr(), terms[i]->m_gt, terms[i]->m_go)); } /* Should this be allowed ? */ else // if (ot<0) { m_rails_temp[k].add(term, ot, true); - netlist().error("found term with missing othernet %s\n", term->name().cstr()); + netlist().error("found term with missing othernet {1}\n", term->name()); } } } @@ -238,7 +237,7 @@ template ATTR_COLD void matrix_solver_direct_t::vsetup(analog_net_t::list_t &nets) { if (m_dim < nets.size()) - netlist().error("Dimension %d less than %" SIZETFMT, m_dim, SIZET_PRINTF(nets.size())); + netlist().error("Dimension {1} less than {2}", m_dim, SIZET_PRINTF(nets.size())); for (unsigned k = 0; k < N(); k++) { @@ -348,9 +347,9 @@ ATTR_COLD void matrix_solver_direct_t::vsetup(analog_net_t::lis if(0) for (unsigned k = 0; k < N(); k++) { - netlist().log("%3d: ", k); + netlist().log("{1:3}: ", k); for (unsigned j = 0; j < m_terms[k]->m_nzrd.size(); j++) - netlist().log(" %3d", m_terms[k]->m_nzrd[j]); + netlist().log(" {1:3}", m_terms[k]->m_nzrd[j]); netlist().log("\n"); } @@ -363,7 +362,7 @@ ATTR_COLD void matrix_solver_direct_t::vsetup(analog_net_t::lis for (unsigned k = 0; k < N(); k++) { - pstring num = pformat("%1")(k); + pstring num = pfmt("{1}")(k); save(m_terms[k]->go(),"GO" + num, m_terms[k]->count()); save(m_terms[k]->gt(),"GT" + num, m_terms[k]->count()); @@ -430,15 +429,6 @@ ATTR_HOT void matrix_solver_direct_t::build_LE_RHS(nl_double * template ATTR_HOT void matrix_solver_direct_t::LE_solve() { -#if 0 - for (int i = 0; i < N(); i++) - { - for (int k = 0; k < N(); k++) - printf("%f ", m_A[i][k]); - printf("| %f = %f \n", x[i], m_RHS[i]); - } - printf("\n"); -#endif const unsigned kN = N(); @@ -551,17 +541,6 @@ ATTR_HOT void matrix_solver_direct_t::LE_back_subst( x[i] = sum / A(i,i); } -#if 0 - printf("Solution:\n"); - for (unsigned i = 0; i < N(); i++) - { - for (unsigned k = 0; k < N(); k++) - printf("%f ", m_A[i][k]); - printf("| %f = %f \n", x[i], m_RHS[i]); - } - printf("\n"); -#endif - } template diff --git a/src/emu/netlist/solver/nld_ms_gmres.h b/src/emu/netlist/solver/nld_ms_gmres.h index 2410bf2f91b..ab6b17a08e4 100644 --- a/src/emu/netlist/solver/nld_ms_gmres.h +++ b/src/emu/netlist/solver/nld_ms_gmres.h @@ -218,7 +218,6 @@ ATTR_HOT inline int matrix_solver_GMRES_t::vsolve_non_dynamic(c for (unsigned k = 0; k < iN; k++) err = std::max(nl_math::abs(l_V[k] - new_V[k]), err); - //printf("here %s\n", this->name().cstr()); for (unsigned k = 0; k < iN; k++) this->m_nets[k]->m_cur_Analog += 1.0 * (new_V[k] - this->m_nets[k]->m_cur_Analog); if (err > accuracy) @@ -297,8 +296,6 @@ int matrix_solver_GMRES_t::solve_ilu_gmres (nl_double * RESTRIC const nl_double rho_to_accuracy = std::sqrt(vecmult2(n, Ax)) / accuracy; - //printf("rho/accuracy = %f\n", rho_to_accuracy); - rho_delta = accuracy * rho_to_accuracy; } else diff --git a/src/emu/netlist/solver/nld_ms_sor_mat.h b/src/emu/netlist/solver/nld_ms_sor_mat.h index e57322e157e..bbf8706a139 100644 --- a/src/emu/netlist/solver/nld_ms_sor_mat.h +++ b/src/emu/netlist/solver/nld_ms_sor_mat.h @@ -35,7 +35,6 @@ public: virtual ~matrix_solver_SOR_mat_t() {} - virtual void log_stats(); virtual void vsetup(analog_net_t::list_t &nets); ATTR_HOT inline int vsolve_non_dynamic(const bool newton_raphson); @@ -55,26 +54,6 @@ private: // matrix_solver - Gauss - Seidel // ---------------------------------------------------------------------------------------- -template -void matrix_solver_SOR_mat_t::log_stats() -{ - if (this->m_stat_calculations != 0 && this->m_params.m_log_stats) - { - this->netlist().log("=============================================="); - this->netlist().log("Solver %s", this->name().cstr()); - this->netlist().log(" ==> %d nets", this->N()); //, (*(*groups[i].first())->m_core_terms.first())->name().cstr()); - this->netlist().log(" has %s elements", this->is_dynamic() ? "dynamic" : "no dynamic"); - this->netlist().log(" has %s elements", this->is_timestep() ? "timestep" : "no timestep"); - this->netlist().log(" %6.3f average newton raphson loops", (double) this->m_stat_newton_raphson / (double) this->m_stat_vsolver_calls); - this->netlist().log(" %10d invocations (%6d Hz) %10d gs fails (%6.2f%%) %6.3f average", - this->m_stat_calculations, - this->m_stat_calculations * 10 / (int) (this->netlist().time().as_double() * 10.0), - this->m_gs_fail, - 100.0 * (double) this->m_gs_fail / (double) this->m_stat_calculations, - (double) this->m_gs_total / (double) this->m_stat_calculations); - } -} - template void matrix_solver_SOR_mat_t::vsetup(analog_net_t::list_t &nets) { diff --git a/src/emu/netlist/solver/nld_solver.c b/src/emu/netlist/solver/nld_solver.c index 9aae218d3ff..a3877b7eaa7 100644 --- a/src/emu/netlist/solver/nld_solver.c +++ b/src/emu/netlist/solver/nld_solver.c @@ -113,7 +113,7 @@ ATTR_COLD matrix_solver_t::~matrix_solver_t() ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) { - NL_VERBOSE_OUT(("New solver setup\n")); + log().debug("New solver setup\n"); m_nets.clear(); @@ -124,7 +124,7 @@ ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) for (std::size_t k = 0; k < nets.size(); k++) { - NL_VERBOSE_OUT(("setting up net\n")); + log().debug("setting up net\n"); analog_net_t *net = nets[k]; @@ -133,7 +133,7 @@ ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) for (std::size_t i = 0; i < net->m_core_terms.size(); i++) { core_terminal_t *p = net->m_core_terms[i]; - NL_VERBOSE_OUT(("%s %s %d\n", p->name().cstr(), net->name().cstr(), (int) net->isRailNet())); + log().debug("{1} {2} {3}\n", p->name(), net->name(), (int) net->isRailNet()); switch (p->type()) { case terminal_t::TERMINAL: @@ -147,7 +147,7 @@ ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) case device_t::DIODE: case device_t::LVCCS: case device_t::BJT_SWITCH: - NL_VERBOSE_OUT(("found BJT/Diode/LVCCS\n")); + log().debug("found BJT/Diode/LVCCS\n"); if (!m_dynamic_devices.contains(&p->device())) m_dynamic_devices.add(&p->device()); break; @@ -158,7 +158,7 @@ ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) terminal_t *pterm = dynamic_cast(p); add_term(k, pterm); } - NL_VERBOSE_OUT(("Added terminal\n")); + log().debug("Added terminal\n"); break; case terminal_t::INPUT: { @@ -173,22 +173,22 @@ ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) if (net_proxy_output == NULL) { net_proxy_output = palloc(analog_output_t); - net_proxy_output->init_object(*this, this->name() + "." + pformat("m%1")(m_inps.size())); + net_proxy_output->init_object(*this, this->name() + "." + pfmt("m{1}")(m_inps.size())); m_inps.add(net_proxy_output); net_proxy_output->m_proxied_net = &p->net().as_analog(); } net_proxy_output->net().register_con(*p); // FIXME: repeated net_proxy_output->net().rebuild_list(); - NL_VERBOSE_OUT(("Added input\n")); + log().debug("Added input\n"); } break; default: - netlist().error("unhandled element found\n"); + log().fatal("unhandled element found\n"); break; } } - NL_VERBOSE_OUT(("added net with %" SIZETFMT " populated connections\n", net->m_core_terms.size())); + log().debug("added net with {1} populated connections\n", net->m_core_terms.size()); } } @@ -199,7 +199,6 @@ ATTR_HOT void matrix_solver_t::update_inputs() // avoid recursive calls. Inputs are updated outside this call for (std::size_t i=0; iset_Q(m_inps[i]->m_proxied_net->m_cur_Analog); - } ATTR_HOT void matrix_solver_t::update_dynamic() @@ -273,7 +272,7 @@ void matrix_solver_t::solve_base(C *p) // reschedule .... if (this_resched > 1 && !m_Q_sync.net().is_queued()) { - netlist().warning("NEWTON_LOOPS exceeded on net %s... reschedule", this->name().cstr()); + log().warning("NEWTON_LOOPS exceeded on net {1}... reschedule", this->name()); m_Q_sync.net().reschedule_in_queue(m_params.m_nt_sync_delay); } } @@ -317,13 +316,13 @@ void matrix_solver_t::log_stats() { if (this->m_stat_calculations != 0 && this->m_params.m_log_stats) { - this->netlist().log("=============================================="); - this->netlist().log("Solver %s", this->name().cstr()); - this->netlist().log(" ==> %d nets", (unsigned) this->m_nets.size()); //, (*(*groups[i].first())->m_core_terms.first())->name().cstr()); - this->netlist().log(" has %s elements", this->is_dynamic() ? "dynamic" : "no dynamic"); - this->netlist().log(" has %s elements", this->is_timestep() ? "timestep" : "no timestep"); - this->netlist().log(" %6.3f average newton raphson loops", (double) this->m_stat_newton_raphson / (double) this->m_stat_vsolver_calls); - this->netlist().log(" %10d invocations (%6d Hz) %10d gs fails (%6.2f%%) %6.3f average", + log().verbose("=============================================="); + log().verbose("Solver {1}", this->name()); + log().verbose(" ==> {1} nets", this->m_nets.size()); //, (*(*groups[i].first())->m_core_terms.first())->name()); + log().verbose(" has {1} elements", this->is_dynamic() ? "dynamic" : "no dynamic"); + log().verbose(" has {1} elements", this->is_timestep() ? "timestep" : "no timestep"); + log().verbose(" {1:6.3} average newton raphson loops", (double) this->m_stat_newton_raphson / (double) this->m_stat_vsolver_calls); + log().verbose(" {1:10} invocations ({2:6} Hz) {3:10} gs fails ({4:6.2} %) {5:6.3} average", this->m_stat_calculations, this->m_stat_calculations * 10 / (int) (this->netlist().time().as_double() * 10.0), this->m_iterative_fail, @@ -479,7 +478,7 @@ matrix_solver_t * NETLIB_NAME(solver)::create_solver(int size, const bool use_sp } else { - netlist().error("Unknown solver type: %s\n", m_iterative_solver.Value().cstr()); + netlist().log().fatal("Unknown solver type: {1}\n", m_iterative_solver.Value()); return NULL; } } @@ -525,14 +524,14 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start() else m_params.m_log_stats = (bool) m_log_stats.Value(); - netlist().log("Scanning net groups ..."); + netlist().log().verbose("Scanning net groups ..."); // determine net groups for (std::size_t i=0; iname().cstr())); + netlist().log().debug("processing {1}\n", netlist().m_nets[i]->name()); if (!netlist().m_nets[i]->isRailNet()) { - SOLVER_VERBOSE_OUT((" ==> not a rail net\n")); + netlist().log().debug(" ==> not a rail net\n"); analog_net_t *n = &netlist().m_nets[i]->as_analog(); if (!n->already_processed(groups, cur_group)) { @@ -543,7 +542,7 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start() } // setup the solvers - netlist().log("Found %d net groups in %" SIZETFMT " nets\n", cur_group + 1, SIZET_PRINTF(netlist().m_nets.size())); + netlist().log().verbose("Found {1} net groups in {2} nets\n", cur_group + 1, netlist().m_nets.size()); for (int i = 0; i <= cur_group; i++) { matrix_solver_t *ms; @@ -599,7 +598,7 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start() break; #endif default: - netlist().warning("No specific solver found for netlist of size %d", (unsigned) net_count); + netlist().log().warning("No specific solver found for netlist of size {1}", (unsigned) net_count); if (net_count <= 16) { ms = create_solver<0,16>(net_count, use_specific); @@ -619,31 +618,31 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start() } else { - netlist().error("Encountered netgroup with > 128 nets"); + netlist().log().fatal("Encountered netgroup with > 128 nets"); ms = NULL; /* tease compilers */ } break; } - register_sub(pformat("Solver_%1")(m_mat_solvers.size()), *ms); + register_sub(pfmt("Solver_{1}")(m_mat_solvers.size()), *ms); ms->vsetup(groups[i]); m_mat_solvers.add(ms); - netlist().log("Solver %s", ms->name().cstr()); - netlist().log(" # %d ==> %" SIZETFMT " nets", i, SIZET_PRINTF(groups[i].size())); //, (*(*groups[i].first())->m_core_terms.first())->name().cstr()); - netlist().log(" has %s elements", ms->is_dynamic() ? "dynamic" : "no dynamic"); - netlist().log(" has %s elements", ms->is_timestep() ? "timestep" : "no timestep"); + netlist().log().verbose("Solver {1}", ms->name()); + netlist().log().verbose(" # {1} ==> {2} nets", i, groups[i].size()); + netlist().log().verbose(" has {1} elements", ms->is_dynamic() ? "dynamic" : "no dynamic"); + netlist().log().verbose(" has {1} elements", ms->is_timestep() ? "timestep" : "no timestep"); for (std::size_t j=0; jname().cstr()); + netlist().log().verbose("Net {1}: {2}", j, groups[i][j]->name()); net_t *n = groups[i][j]; for (std::size_t k = 0; k < n->m_core_terms.size(); k++) { const core_terminal_t *p = n->m_core_terms[k]; - netlist().log(" %s", p->name().cstr()); + netlist().log().verbose(" {1}", p->name()); } } } diff --git a/src/emu/netlist/solver/nld_solver.h b/src/emu/netlist/solver/nld_solver.h index cf03708582f..6da438b19cb 100644 --- a/src/emu/netlist/solver/nld_solver.h +++ b/src/emu/netlist/solver/nld_solver.h @@ -135,6 +135,7 @@ public: ATTR_COLD int get_net_idx(net_t *net); inline eSolverType type() const { return m_type; } + const plog_base &log() const { return netlist().log(); } virtual void log_stats(); diff --git a/src/emu/netlist/tools/nl_convert.c b/src/emu/netlist/tools/nl_convert.c index 85490bab5b6..dae68968445 100644 --- a/src/emu/netlist/tools/nl_convert.c +++ b/src/emu/netlist/tools/nl_convert.c @@ -42,15 +42,6 @@ static plist_t bubble(const pnamedlist_t &sl) convert - convert a spice netlist -------------------------------------------------*/ - -void nl_convert_base_t::out(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - m_buf += pstring(format).vprintf(ap); - va_end(ap); -} - void nl_convert_base_t::add_pin_alias(const pstring &devname, const pstring &name, const pstring &alias) { m_pins.add(palloc(pin_alias_t(devname + "." + name, devname + "." + alias)), false); @@ -98,7 +89,7 @@ void nl_convert_base_t::dump_nl() { net_t *net = m_nets.find_by_name(m_ext_alias[i]); // use the first terminal ... - out("ALIAS(%s, %s)\n", m_ext_alias[i].cstr(), net->terminals()[0].cstr()); + out("ALIAS({}, {})\n", m_ext_alias[i].cstr(), net->terminals()[0].cstr()); // if the aliased net only has this one terminal connected ==> don't dump if (net->terminals().size() == 1) net->set_no_export(); @@ -109,13 +100,13 @@ void nl_convert_base_t::dump_nl() std::size_t j = sorted[i]; if (m_devs[j]->has_value()) - out("%s(%s, %s)\n", m_devs[j]->type().cstr(), + out("{}({}, {})\n", m_devs[j]->type().cstr(), m_devs[j]->name().cstr(), get_nl_val(m_devs[j]->value()).cstr()); else if (m_devs[j]->has_model()) - out("%s(%s, \"%s\")\n", m_devs[j]->type().cstr(), + out("{}({}, \"{}\")\n", m_devs[j]->type().cstr(), m_devs[j]->name().cstr(), m_devs[j]->model().cstr()); else - out("%s(%s)\n", m_devs[j]->type().cstr(), + out("{}({})\n", m_devs[j]->type().cstr(), m_devs[j]->name().cstr()); } // print nets @@ -124,11 +115,11 @@ void nl_convert_base_t::dump_nl() net_t * net = m_nets[i]; if (!net->is_no_export()) { - //printf("Net %s\n", net->name().cstr()); - out("NET_C(%s", net->terminals()[0].cstr() ); + //printf("Net {}\n", net->name().cstr()); + out("NET_C({}", net->terminals()[0].cstr() ); for (std::size_t j=1; jterminals().size(); j++) { - out(", %s", net->terminals()[j].cstr() ); + out(", {}", net->terminals()[j].cstr() ); } out(")\n"); } @@ -149,7 +140,7 @@ const pstring nl_convert_base_t::get_nl_val(const double val) break; i++; } - return pformat(m_units[i].m_func.cstr())(val / m_units[i].m_mult); + return pfmt(m_units[i].m_func.cstr())(val / m_units[i].m_mult); } } double nl_convert_base_t::get_sp_unit(const pstring &unit) @@ -174,28 +165,27 @@ double nl_convert_base_t::get_sp_val(const pstring &sin) pstring unit = sin.substr(p + 1); double ret = get_sp_unit(unit) * val.as_double(); - //printf("<%s> %s %d ==> %f\n", sin.cstr(), unit.cstr(), p, ret); return ret; } nl_convert_base_t::unit_t nl_convert_base_t::m_units[] = { {"T", "", 1.0e12 }, {"G", "", 1.0e9 }, - {"MEG", "RES_M(%1)", 1.0e6 }, - {"k", "RES_K(%1)", 1.0e3 }, /* eagle */ - {"K", "RES_K(%1)", 1.0e3 }, - {"", "%1", 1.0e0 }, - {"M", "CAP_M(%1)", 1.0e-3 }, - {"u", "CAP_U(%1)", 1.0e-6 }, /* eagle */ - {"U", "CAP_U(%1)", 1.0e-6 }, - {"??", "CAP_U(%1)", 1.0e-6 }, - {"N", "CAP_N(%1)", 1.0e-9 }, - {"P", "CAP_P(%1)", 1.0e-12}, - {"F", "%1e-15", 1.0e-15}, + {"MEG", "RES_M({1})", 1.0e6 }, + {"k", "RES_K({1})", 1.0e3 }, /* eagle */ + {"K", "RES_K({1})", 1.0e3 }, + {"", "{1}", 1.0e0 }, + {"M", "CAP_M({1})", 1.0e-3 }, + {"u", "CAP_U({1})", 1.0e-6 }, /* eagle */ + {"U", "CAP_U({1})", 1.0e-6 }, + {"??", "CAP_U({1})", 1.0e-6 }, + {"N", "CAP_N({1})", 1.0e-9 }, + {"P", "CAP_P({1})", 1.0e-12}, + {"F", "{1}e-15", 1.0e-15}, - {"MIL", "%1", 25.4e-6}, + {"MIL", "{1}", 25.4e-6}, - {"-", "%1", 1.0 } + {"-", "{1}", 1.0 } }; @@ -238,15 +228,15 @@ void nl_convert_spice_t::process_line(const pstring &line) switch (tt[0].code_at(0)) { case ';': - out("// %s\n", line.substr(1).cstr()); + out("// {}\n", line.substr(1).cstr()); break; case '*': - out("// %s\n", line.substr(1).cstr()); + out("// {}\n", line.substr(1).cstr()); break; case '.': if (tt[0].equals(".SUBCKT")) { - out("NETLIST_START(%s)\n", tt[1].cstr()); + out("NETLIST_START({})\n", tt[1].cstr()); for (std::size_t i=2; i m_devs; pnamedlist_t m_nets; @@ -198,7 +199,7 @@ public: void verror(const pstring &msg, int line_num, const pstring &line) { - m_convert.out("%s (line %d): %s\n", msg.cstr(), line_num, line.cstr()); + m_convert.out("{} (line {}): {}\n", msg.cstr(), line_num, line.cstr()); } diff --git a/src/tools/nltool.c b/src/tools/nltool.c index ed9473efc02..7ee742e307b 100644 --- a/src/tools/nltool.c +++ b/src/tools/nltool.c @@ -209,7 +209,7 @@ public: void log_setup() { - NL_VERBOSE_OUT(("Creating dynamic logs ...\n")); + log().debug("Creating dynamic logs ...\n"); pstring_list_t ll(m_opts ? m_opts->opt_logs() : "" , ":"); for (int i=0; i < ll.size(); i++) { @@ -223,27 +223,30 @@ public: protected: - void verror(const loglevel_e level, const char *format, va_list ap) const + void vlog(const plog_level &l, const pstring &ls) const { - switch (level) + switch (l) { - case NL_LOG: + case DEBUG: + case INFO: + break; + case VERBOSE: if (m_opts ? m_opts->opt_verb() : false) { - vprintf(format, ap); - printf("\n"); + printf("%s\n", ls.cstr()); } break; - case NL_WARNING: + case WARNING: if (!(m_opts ? m_opts->opt_quiet() : false)) { - vprintf(format, ap); - printf("\n"); + printf("%s\n", ls.cstr()); } break; - case NL_ERROR: - vprintf(format, ap); - printf("\n"); + case ERROR: + printf("%s\n", ls.cstr()); + break; + case FATAL: + printf("%s\n", ls.cstr()); throw; } } @@ -277,7 +280,7 @@ struct input_t double t; int e = sscanf(line.cstr(), "%lf,%[^,],%lf", &t, buf, &m_value); if ( e!= 3) - throw netlist::fatalerror_e(pformat("error %1 scanning line %2\n")(e)(line)); + throw netlist::fatalerror_e(pfmt("error {1} scanning line {2}\n")(e)(line)); m_time = netlist::netlist_time::from_double(t); m_param = netlist->setup().find_param(buf, true); } @@ -288,7 +291,7 @@ struct input_t { case netlist::param_t::MODEL: case netlist::param_t::STRING: - throw netlist::fatalerror_e(pformat("param %1 is not numeric\n")(m_param->name())); + throw netlist::fatalerror_e(pfmt("param {1} is not numeric\n")(m_param->name())); case netlist::param_t::DOUBLE: static_cast(m_param)->setTo(m_value); break; @@ -380,11 +383,11 @@ static void listdevices() for (int i=0; i < list.size(); i++) { netlist::base_factory_t *f = list.value_at(i); - pstring out = pformat("%1 %2(")(f->classname(),"-20")(f->name()); + pstring out = pfmt("{1} {2}(")(f->classname(),"-20")(f->name()); pstring terms(""); netlist::device_t *d = f->Create(); - d->init(nt, pformat("dummy%1")(i)); + d->init(nt, pfmt("dummy{1}")(i)); d->start_dev(); // get the list of terminals ...