netlist: code maintenance.

* more handler alignment
* dead code removal
* remove update calls which do nothing
This commit is contained in:
couriersud 2020-07-16 09:55:15 +02:00
parent 0dfa500a4a
commit 8cd6774cac
11 changed files with 129 additions and 115 deletions

View File

@ -176,9 +176,9 @@ namespace analog
{
NETLIB_CONSTRUCTOR(QBJT_switch)
, m_modacc(m_model)
, m_RB(*this, "m_RB", true)
, m_RC(*this, "m_RC", true)
, m_BC(*this, "m_BC", true)
, m_RB(*this, "m_RB", NETLIB_DELEGATE(termhandler))
, m_RC(*this, "m_RC", NETLIB_DELEGATE(termhandler))
, m_BC(*this, "m_BC", NETLIB_DELEGATE(termhandler))
, m_gB(nlconst::cgmin())
, m_gC(nlconst::cgmin())
, m_V(nlconst::zero())
@ -194,7 +194,19 @@ namespace analog
}
NETLIB_RESETI();
NETLIB_UPDATEI();
NETLIB_UPDATEI()
{
termhandler();
}
NETLIB_HANDLERI(termhandler)
{
auto *solv(m_RB.solver());
if (solv != nullptr)
solv->solve_now();
else
m_RC.solver()->solve_now();
}
NETLIB_UPDATE_PARAMI();
NETLIB_UPDATE_TERMINALSI();
@ -223,9 +235,9 @@ namespace analog
, m_modacc(m_model)
, m_gD_BC(*this, "m_D_BC")
, m_gD_BE(*this, "m_D_BE")
, m_D_CB(*this, "m_D_CB", true)
, m_D_EB(*this, "m_D_EB", true)
, m_D_EC(*this, "m_D_EC", true)
, m_D_CB(*this, "m_D_CB", NETLIB_DELEGATE(termhandler))
, m_D_EB(*this, "m_D_EB", NETLIB_DELEGATE(termhandler))
, m_D_EC(*this, "m_D_EC", NETLIB_DELEGATE(termhandler))
, m_alpha_f(0)
, m_alpha_r(0)
{
@ -256,7 +268,20 @@ namespace analog
protected:
NETLIB_RESETI();
NETLIB_UPDATEI();
NETLIB_UPDATEI()
{
termhandler();
}
NETLIB_HANDLERI(termhandler)
{
auto *solv(m_D_EB.solver());
if (solv != nullptr)
solv->solve_now();
else
m_D_CB.solver()->solve_now();
}
NETLIB_UPDATE_PARAMI();
NETLIB_UPDATE_TERMINALSI();
@ -307,16 +332,6 @@ namespace analog
}
NETLIB_UPDATE(QBJT_switch)
{
auto *solv(m_RB.solver());
if (solv != nullptr)
solv->solve_now();
else
m_RC.solver()->solve_now();
}
NETLIB_UPDATE_PARAM(QBJT_switch)
{
nl_fptype IS = m_modacc.m_IS;
@ -371,15 +386,6 @@ namespace analog
// nld_Q - Ebers Moll
// ----------------------------------------------------------------------------------------
NETLIB_UPDATE(QBJT_EB)
{
auto *solv(m_D_EB.solver());
if (solv != nullptr)
solv->solve_now();
else
m_D_CB.solver()->solve_now();
}
NETLIB_RESET(QBJT_EB)
{
if (m_D_EB.solver() == nullptr && m_D_CB.solver() == nullptr)

View File

@ -182,9 +182,9 @@ namespace analog
{
public:
NETLIB_CONSTRUCTOR(MOSFET)
, m_DG(*this, "m_DG", true)
, m_SG(*this, "m_SG", true)
, m_SD(*this, "m_SD", true)
, m_DG(*this, "m_DG", NETLIB_DELEGATE(termhandler))
, m_SG(*this, "m_SG", NETLIB_DELEGATE(termhandler))
, m_SD(*this, "m_SD", NETLIB_DELEGATE(termhandler))
, m_D_BD(*this, "m_D_BD")
#if (!BODY_CONNECTED_TO_SOURCE)
, m_D_BS(*this, "m_D_BS")
@ -332,7 +332,20 @@ namespace analog
#endif
}
NETLIB_UPDATEI();
NETLIB_UPDATEI()
{
termhandler();
}
NETLIB_HANDLERI(termhandler)
{
// FIXME: This should never be called
if (!m_SG.P().net().is_rail_net())
m_SG.P().solve_now(); // Basis
else if (!m_SG.N().net().is_rail_net())
m_SG.N().solve_now(); // Emitter
else
m_DG.N().solve_now(); // Collector
}
NETLIB_UPDATE_PARAMI();
NETLIB_UPDATE_TERMINALSI();
@ -438,17 +451,6 @@ namespace analog
// MOSFET
// ----------------------------------------------------------------------------------------
NETLIB_UPDATE(MOSFET)
{
// FIXME: This should never be called
if (!m_SG.P().net().is_rail_net())
m_SG.P().solve_now(); // Basis
else if (!m_SG.N().net().is_rail_net())
m_SG.N().solve_now(); // Emitter
else
m_DG.N().solve_now(); // Collector
}
NETLIB_UPDATE_TERMINALS(MOSFET)
{
nl_fptype Vgd = -m_DG.deltaV() * m_polarity; // Gate - Drain

View File

@ -31,6 +31,11 @@ NETLIB_RESET(VCCS)
}
NETLIB_UPDATE(VCCS)
{
termhandler();
}
NETLIB_HANDLER(VCCS, termhandler)
{
// only called if connected to a rail net ==> notify the solver to recalculate
if (!m_IP.net().is_rail_net())

View File

@ -39,12 +39,12 @@ namespace analog {
NETLIB_CONSTRUCTOR_EX(VCCS, nl_fptype ri = nlconst::magic(1e9))
, m_G(*this, "G", nlconst::one())
, m_RI(*this, "RI", ri)
, m_OP(*this, "OP", &m_IP)
, m_ON(*this, "ON", &m_IP)
, m_IP(*this, "IP", &m_IN) // <= this should be NULL and terminal be filtered out prior to solving...
, m_IN(*this, "IN", &m_IP) // <= this should be NULL and terminal be filtered out prior to solving...
, m_OP1(*this, "_OP1", &m_IN)
, m_ON1(*this, "_ON1", &m_IN)
, m_OP(*this, "OP", &m_IP, NETLIB_DELEGATE(termhandler))
, m_ON(*this, "ON", &m_IP, NETLIB_DELEGATE(termhandler))
, m_IP(*this, "IP", &m_IN, NETLIB_DELEGATE(termhandler)) // <= this should be NULL and terminal be filtered out prior to solving...
, m_IN(*this, "IN", &m_IP, NETLIB_DELEGATE(termhandler)) // <= this should be NULL and terminal be filtered out prior to solving...
, m_OP1(*this, "_OP1", &m_IN, NETLIB_DELEGATE(termhandler))
, m_ON1(*this, "_ON1", &m_IN, NETLIB_DELEGATE(termhandler))
, m_gfac(nlconst::one())
{
connect(m_OP, m_OP1);
@ -58,6 +58,7 @@ namespace analog {
protected:
NETLIB_UPDATEI();
NETLIB_HANDLERI(termhandler);
NETLIB_UPDATE_PARAMI()
{
NETLIB_NAME(VCCS)::reset();
@ -181,8 +182,8 @@ namespace analog {
public:
NETLIB_CONSTRUCTOR(VCVS)
, m_RO(*this, "RO", nlconst::one())
, m_OP2(*this, "_OP2", &m_ON2)
, m_ON2(*this, "_ON2", &m_OP2)
, m_OP2(*this, "_OP2", &m_ON2, NETLIB_DELEGATE(termhandler))
, m_ON2(*this, "_ON2", &m_OP2, NETLIB_DELEGATE(termhandler))
{
connect(m_OP2, m_OP1);
connect(m_ON2, m_ON1);
@ -193,8 +194,15 @@ namespace analog {
param_fp_t m_RO;
private:
//NETLIB_UPDATEI();
NETLIB_UPDATEI()
{
termhandler();
}
//NETLIB_UPDATE_PARAMI();
NETLIB_HANDLERI(termhandler)
{
NETLIB_NAME(VCCS) :: termhandler();
}
terminal_t m_OP2;
terminal_t m_ON2;
@ -233,8 +241,8 @@ namespace analog {
public:
NETLIB_CONSTRUCTOR_PASS(CCVS, nlconst::one())
, m_RO(*this, "RO", nlconst::one())
, m_OP2(*this, "_OP2", &m_ON2)
, m_ON2(*this, "_ON2", &m_OP2)
, m_OP2(*this, "_OP2", &m_ON2, NETLIB_DELEGATE(termhandler))
, m_ON2(*this, "_ON2", &m_OP2, NETLIB_DELEGATE(termhandler))
{
connect(m_OP2, m_OP1);
connect(m_ON2, m_ON1);
@ -245,9 +253,17 @@ namespace analog {
param_fp_t m_RO;
private:
//NETLIB_UPDATEI();
NETLIB_UPDATEI()
{
termhandler();
}
//NETLIB_UPDATE_PARAMI();
NETLIB_HANDLERI(termhandler)
{
NETLIB_NAME(VCCS) :: termhandler();
}
terminal_t m_OP2;
terminal_t m_ON2;
};

View File

@ -32,22 +32,16 @@ namespace analog
}
NETLIB_UPDATE(twoterm)
{
termhandler();
}
NETLIB_HANDLER(twoterm, termhandler)
{
// only called if connected to a rail net ==> notify the solver to recalculate
//printf("%s update\n", this->name().c_str());
solve_now();
}
// ----------------------------------------------------------------------------------------
// nld_R_base
// ----------------------------------------------------------------------------------------
NETLIB_RESET(R_base)
{
// FIXME: this reset is causing issues. Remove.
NETLIB_NAME(twoterm)::reset();
set_R(plib::reciprocal(exec().gmin()));
}
// ----------------------------------------------------------------------------------------
// nld_POT
// ----------------------------------------------------------------------------------------

View File

@ -70,10 +70,17 @@ namespace analog
NETLIB_BASE_OBJECT(twoterm)
{
// FIXME locate use case of owned = true and eliminate them if possible
NETLIB_CONSTRUCTOR_EX(twoterm, bool terminals_owned = false)
, m_P(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "1", &m_N)
, m_N(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "2", &m_P)
NETLIB_CONSTRUCTOR(twoterm)
, m_P(*this, "1", &m_N, NETLIB_DELEGATE(termhandler))
, m_N(*this, "2", &m_P, NETLIB_DELEGATE(termhandler))
{
}
//NETLIB_CONSTRUCTOR_EX(twoterm, nldelegate owner_delegate)
template <class C>
NETLIB_NAME(twoterm)(C &owner, const pstring &name, nldelegate owner_delegate) \
: base_type(owner, name)
, m_P(owner, name + ".1", &m_N, owner_delegate)
, m_N(owner, name + ".2", &m_P, owner_delegate)
{
}
@ -83,6 +90,7 @@ namespace analog
public:
NETLIB_UPDATEI();
NETLIB_HANDLERI(termhandler);
solver::matrix_solver_t *solver() const noexcept;
@ -196,7 +204,7 @@ namespace analog
-G, G, nlconst::zero());
}
NETLIB_RESETI();
//NETLIB_RESETI();
protected:
//NETLIB_UPDATEI();

View File

@ -33,7 +33,7 @@ namespace devices
, m_max_link_loops(*this, "MAX_LINK_RESOLVE_LOOPS", 100)
{
}
NETLIB_UPDATEI() { }
//NETLIB_UPDATEI() { }
//NETLIB_RESETI() { }
//NETLIB_UPDATE_PARAMI() { }
public:
@ -261,7 +261,7 @@ namespace devices
{
}
NETLIB_UPDATEI() { }
//NETLIB_UPDATEI() { }
NETLIB_RESETI() { m_Q.initial(0); }
NETLIB_UPDATE_PARAMI()
{
@ -286,7 +286,7 @@ namespace devices
{
}
NETLIB_UPDATEI() { }
//NETLIB_UPDATEI() { }
NETLIB_RESETI() { for (auto &q : m_Q) q.initial(0); }
NETLIB_UPDATE_PARAMI()
{
@ -310,7 +310,7 @@ namespace devices
{
}
NETLIB_UPDATEI() { }
//NETLIB_UPDATEI() { }
NETLIB_RESETI() { m_Q.initial(nlconst::zero()); }
NETLIB_UPDATE_PARAMI() { m_Q.push(m_IN()); }
@ -329,11 +329,14 @@ namespace devices
, m_Q(*this, "Q")
{
}
NETLIB_UPDATEI()
//NETLIB_UPDATEI() { }
NETLIB_UPDATE_PARAMI()
{
m_Q.push(nlconst::zero());
}
NETLIB_RESETI() { }
//NETLIB_RESETI() { }
protected:
analog_output_t m_Q;
};
@ -351,8 +354,8 @@ namespace devices
}
protected:
NETLIB_RESETI() { }
NETLIB_UPDATEI() { }
//NETLIB_RESETI() { }
//NETLIB_UPDATEI() { }
private:
NETLIB_HANDLERI(noop)
@ -371,8 +374,8 @@ namespace devices
{
public:
NETLIB_CONSTRUCTOR(frontier)
, m_RIN(*this, "m_RIN", true)
, m_ROUT(*this, "m_ROUT", true)
, m_RIN(*this, "m_RIN", NETLIB_DELEGATE(input))
, m_ROUT(*this, "m_ROUT", NETLIB_DELEGATE(input))
, m_I(*this, "_I", NETLIB_DELEGATE(input))
, m_Q(*this, "_Q")
, m_p_RIN(*this, "RIN", nlconst::magic(1.0e6))

View File

@ -507,12 +507,6 @@ namespace netlist
m_stats = owner.state().make_pool_object<stats_t>();
}
void core_device_t::set_default_delegate(detail::core_terminal_t &term)
{
if (!term.delegate().is_set())
term.set_delegate(nldelegate(&core_device_t::update, this));
}
log_type & core_device_t::log()
{
return state().log();
@ -716,8 +710,8 @@ namespace netlist
// terminal_t
// ----------------------------------------------------------------------------------------
terminal_t::terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm)
: analog_t(dev, aname, STATE_BIDIR, nldelegate())
terminal_t::terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm, nldelegate delegate)
: analog_t(dev, aname, STATE_BIDIR, delegate)
, m_Idr(nullptr)
, m_go(nullptr)
, m_gt(nullptr)
@ -771,8 +765,10 @@ namespace netlist
logic_input_t::logic_input_t(device_t &dev, const pstring &aname,
nldelegate delegate)
: logic_t(dev, aname, STATE_INP_ACTIVE, delegate.is_set() ? delegate : dev.default_delegate())
: logic_t(dev, aname, STATE_INP_ACTIVE, delegate)
{
if (!delegate.is_set())
throw nl_exception("delegate not set for {1}", this->name());
state().setup().register_term(*this);
}

View File

@ -836,7 +836,7 @@ namespace netlist
/// @param dev core_devict_t object owning the terminal
/// @param aname name of this terminal
/// @param otherterm pointer to the sibling terminal
terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm);
terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm, nldelegate delegate);
/// \brief Returns voltage of connected net
///
@ -906,10 +906,6 @@ namespace netlist
logic_input_t(device_t &dev, const pstring &aname,
nldelegate delegate);
#if 0
template <class D>
logic_input_t(D &dev, const pstring &aname);
#endif
inline netlist_sig_t operator()() const noexcept;
void inactivate() noexcept;
@ -1386,8 +1382,6 @@ namespace netlist
// Has to be set in device reset
void set_active_outputs(int n) noexcept { m_active_outputs = n; }
void set_default_delegate(detail::core_terminal_t &term);
// stats
struct stats_t
{
@ -1477,8 +1471,6 @@ namespace netlist
~device_t() noexcept override = default;
//nldelegate default_delegate() { return nldelegate(&device_t::update, this); }
nldelegate default_delegate() { return { &core_device_t::update, dynamic_cast<core_device_t *>(this) }; }
protected:
//NETLIB_UPDATEI() { }
@ -2146,14 +2138,6 @@ namespace netlist
{
}
#if 0
explicit nld_power_pins(device_t &owner, const pstring &sVCC,
const pstring &sGND)
: m_VCC(owner, sVCC, NETLIB_DELEGATE(noop))
, m_GND(owner, sGND, NETLIB_DELEGATE(noop))
{
}
#endif
const analog_input_t &VCC() const noexcept
{
return m_VCC;

View File

@ -15,8 +15,6 @@ namespace netlist
static constexpr const char sHINT_NO_DEACTIVATE[] = ".HINT_NO_DEACTIVATE"; // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
static constexpr const char sHINT_NC[] = ".HINT_NC"; // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
static constexpr const char sPowerGND[] = "GND"; // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
static constexpr const char sPowerVCC[] = "VCC"; // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
// nl_base.cpp
@ -27,7 +25,6 @@ namespace netlist
PERRMSGV(MF_REMOVE_TERMINAL_1_FROM_NET_2, 2, "Can not remove terminal {1} from net {2}.")
PERRMSGV(MF_UNKNOWN_PARAM_TYPE, 1, "Can not determine param_type for {1}")
PERRMSGV(MF_ERROR_CONNECTING_1_TO_2, 2, "Error connecting {1} to {2}")
PERRMSGV(MF_NO_SOLVER, 0, "No solver found for this netlist although analog elements are present")
PERRMSGV(ME_HND_VAL_NOT_SUPPORTED, 1, "HINT_NO_DEACTIVATE value not supported: <{1}>")
PERRMSGV(MW_ROM_NOT_FOUND, 1, "Rom {1} not found")
@ -122,6 +119,9 @@ namespace netlist
PERRMSGV(ME_UNKNOWN_PARAMETER, 1, "Unknown parameter {1}")
PERRMSGV(MF_ERRORS_FOUND, 1, "Counted {1} errors which need to be fixed")
PERRMSGV(MF_NO_SOLVER, 0, "No solver found for this netlist although analog elements are present")
PERRMSGV(MF_DELEGATE_NOT_SET_1, 1, "delegate not set for terminal {1}")
// nlid_proxy.cpp
PERRMSGV(MF_NO_POWER_TERMINALS_ON_DEVICE_2, 2, "D/A Proxy {1}: Found no valid combination of power terminals on device {2}")

View File

@ -1629,11 +1629,11 @@ void setup_t::prepare_to_run()
for (auto &n : m_nlstate.nets())
for (auto & term : n->core_terms())
{
core_device_t *dev = &term->device();
dev->set_default_delegate(*term);
}
if (!term->delegate().is_set())
{
log().fatal(MF_DELEGATE_NOT_SET_1(term->name()));
throw nl_exception(MF_DELEGATE_NOT_SET_1(term->name()));
}
}
// ----------------------------------------------------------------------------------------