netlist: Code maintenance. (nw)

- Fixed some clang lint warnings
- Removed dead code
- Experimental parser code to allow calculations in parameter value.
  This already works for compiled netlists. These changes are
  currently disabled. Updated pong netlist (and CRC/SHA) to work
  with this new code.
This commit is contained in:
couriersud 2020-01-27 21:47:41 +01:00
parent 8c2bb62367
commit f7d8a10da5
26 changed files with 148 additions and 73 deletions

View File

@ -476,7 +476,11 @@ namespace analog
const nl_fptype Vctrl = (is_forward ? Vgs : Vgd) - Vth;
nl_fptype Ids(0), gm(0), gds(0), gmb(0);
nl_fptype Ids(0);
nl_fptype gm(0);
nl_fptype gds(0);
nl_fptype gmb(0);
const nl_fptype absVds = plib::abs(Vds);
if (Vctrl <= nlconst::zero())

View File

@ -162,7 +162,7 @@ namespace devices
void parseline(unsigned cur, std::vector<pstring> list,
tt_bitset state, std::uint_least64_t val, std::vector<uint_least8_t> &timing_index);
tt_bitset calculate_ignored_inputs(tt_bitset i) const;
tt_bitset calculate_ignored_inputs(tt_bitset state) const;
unsigned m_NO;
unsigned m_NI;

View File

@ -75,11 +75,11 @@ NETLIST_END()
* ---------------------------------------------------------------------------*/
static NETLIST_START(family_models)
NET_MODEL("FAMILY _(TYPE=CUSTOM FV=5 IVL=0.16 IVH=0.4 OVL=0.1 OVH=1.0 ORL=1.0 ORH=130.0)")
NET_MODEL("FAMILY _(TYPE=CUSTOM IVL=0.16 IVH=0.4 OVL=0.1 OVH=1.0 ORL=1.0 ORH=130.0)")
NET_MODEL("OPAMP _()")
NET_MODEL("SCHMITT_TRIGGER _()")
NET_MODEL("74XXOC FAMILY(FV=5 IVL=0.16 IVH=0.4 OVL=0.1 OVH=0.05 ORL=10.0 ORH=1.0e8)")
NET_MODEL("74XXOC FAMILY(IVL=0.16 IVH=0.4 OVL=0.1 OVH=0.05 ORL=10.0 ORH=1.0e8)")
NET_MODEL("74XX FAMILY(TYPE=TTL)")
NET_MODEL("CD4XXX FAMILY(TYPE=CD4XXX)")
NETLIST_END()

View File

@ -48,7 +48,7 @@ NETLIST_START(otheric_lib)
TT_LINE(" 0 | 1 |100")
TT_LINE(" 1 | 0 |100")
// 2.1V negative going and 2.7V positive going at 5V
TT_FAMILY("FAMILY(FV=0 IVL=0.42 IVH=0.54 OVL=0.05 OVH=0.05 ORL=10.0 ORH=10.0)")
TT_FAMILY("FAMILY(IVL=0.42 IVH=0.54 OVL=0.05 OVH=0.05 ORL=10.0 ORH=10.0)")
TRUTHTABLE_END()
LOCAL_LIB_ENTRY(MC14584B_DIP)

View File

@ -897,7 +897,7 @@ NETLIST_START(TTL74XX_lib)
NET_MODEL("DM7414 SCHMITT_TRIGGER(VTP=1.7 VTM=0.9 VI=4.35 RI=6.15k VOH=3.5 ROH=120 VOL=0.1 ROL=37.5 TPLH=15 TPHL=15)")
NET_MODEL("TTL_7414_GATE SCHMITT_TRIGGER(VTP=1.7 VTM=0.9 VI=4.35 RI=6.15k VOH=3.5 ROH=120 VOL=0.1 ROL=37.5 TPLH=15 TPHL=15)")
NET_MODEL("DM74LS14 SCHMITT_TRIGGER(VTP=1.6 VTM=0.8 VI=4.4 RI=19.3k VOH=3.45 ROH=130 VOL=0.1 ROL=31.2 TPLH=15 TPHL=15)")
//NET_MODEL("DM7414 FAMILY(FV=5 IVL=0.16 IVH=0.4 OVL=0.1 OVH=0.05 ORL=10.0 ORH=1.0e8)")
//NET_MODEL("DM7414 FAMILY(IVL=0.16 IVH=0.4 OVL=0.1 OVH=0.05 ORL=10.0 ORH=1.0e8)")
TRUTHTABLE_START(TTL_7400_GATE, 2, 1, "")

View File

@ -35,7 +35,6 @@ namespace netlist
public:
logic_family_ttl_t() : logic_family_desc_t()
{
m_fixed_V = nlconst::magic(5.0);
m_low_thresh_PCNT = nlconst::magic(0.8 / 5.0);
m_high_thresh_PCNT = nlconst::magic(2.0 / 5.0);
// m_low_V - these depend on sinked/sourced current. Values should be suitable for typical applications.
@ -62,7 +61,6 @@ namespace netlist
public:
logic_family_cd4xxx_t() : logic_family_desc_t()
{
m_fixed_V = nlconst::magic(0.0);
m_low_thresh_PCNT = nlconst::magic(1.5 / 5.0);
m_high_thresh_PCNT = nlconst::magic(3.5 / 5.0);
// m_low_V - these depend on sinked/sourced current. Values should be suitable for typical applications.
@ -214,6 +212,24 @@ namespace netlist
// Initialize factory
devices::initialize_factory(m_setup->factory());
// Add default include file
using a = plib::psource_str_t<plib::psource_t>;
#if USE_EVAL
const pstring content =
"#define RES_R(res) (res) \n"
"#define RES_K(res) ((res) * 1e3) \n"
"#define RES_M(res) ((res) * 1e6) \n"
"#define CAP_U(cap) ((cap) * 1e-6) \n"
"#define CAP_N(cap) ((cap) * 1e-9) \n"
"#define CAP_P(cap) ((cap) * 1e-12) \n"
"#define IND_U(ind) ((ind) * 1e-6) \n"
"#define IND_N(ind) ((ind) * 1e-9) \n"
"#define IND_P(ind) ((ind) * 1e-12) \n";
setup().add_include(plib::make_unique<a>("netlist/devices/net_lib.h", content));
#else
setup().add_include(plib::make_unique<a>("netlist/devices/net_lib.h",""));
#endif
NETLIST_NAME(base)(*m_setup);
}

View File

@ -265,8 +265,6 @@ namespace netlist
virtual unique_pool_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_state_t &anetlist, const pstring &name,
logic_input_t *proxied) const = 0;
// FIXME: remove fixed_V()
nl_fptype fixed_V() const noexcept{return m_fixed_V; }
nl_fptype low_thresh_V(nl_fptype VN, nl_fptype VP) const noexcept{ return VN + (VP - VN) * m_low_thresh_PCNT; }
nl_fptype high_thresh_V(nl_fptype VN, nl_fptype VP) const noexcept{ return VN + (VP - VN) * m_high_thresh_PCNT; }
nl_fptype low_offset_V() const noexcept{ return m_low_VO; }
@ -280,7 +278,6 @@ namespace netlist
bool is_below_low_thresh_V(nl_fptype V, nl_fptype VN, nl_fptype VP) const noexcept
{ return (V - VN) < low_thresh_V(VN, VP); }
nl_fptype m_fixed_V; //!< For variable voltage families, specify 0. For TTL this would be 5.
nl_fptype m_low_thresh_PCNT; //!< low input threshhold offset. If the input voltage is below this value times supply voltage, a "0" input is signalled
nl_fptype m_high_thresh_PCNT; //!< high input threshhold offset. If the input voltage is above the value times supply voltage, a "0" input is signalled
nl_fptype m_low_VO; //!< low output voltage offset. This voltage is output if the ouput is "0"

View File

@ -10,6 +10,9 @@
#include "plib/pconfig.h"
#include "plib/pexception.h"
// FIXME: Remove this again after testing
#define USE_EVAL (0)
///
/// \brief Version - Major.
///

View File

@ -236,10 +236,12 @@ void parser_t::frontier()
// don't do much
pstring attachat = get_identifier();
require_token(m_tok_comma);
nl_fptype r_IN = eval_param(get_token());
require_token(m_tok_comma);
nl_fptype r_OUT = eval_param(get_token());
require_token(m_tok_paren_right);
auto tok = get_token();
nl_fptype r_IN = eval_param(tok);
require_token(tok, m_tok_comma);
tok = get_token();
nl_fptype r_OUT = eval_param(tok);
require_token(tok, m_tok_paren_right);
m_setup.register_frontier(attachat, r_IN, r_OUT);
}
@ -335,14 +337,15 @@ void parser_t::netdev_param()
{
m_setup.log().debug("Parser: Param: {1} {2}\n", param, tok.str());
m_setup.register_param(param, tok.str());
require_token(m_tok_paren_right);
}
else
{
nl_fptype val = eval_param(tok);
m_setup.log().debug("Parser: Param: {1} {2}\n", param, val);
m_setup.register_param(param, val);
require_token(tok, m_tok_paren_right);
}
require_token(m_tok_paren_right);
}
void parser_t::netdev_hint()
@ -370,7 +373,10 @@ void parser_t::device(const pstring &dev_type)
{
tok = get_token();
if (tok.is_type(token_type::IDENTIFIER) || tok.is_type(token_type::STRING))
{
params.push_back(tok.str());
tok = get_token();
}
else
{
// FIXME: Do we really need this?
@ -381,7 +387,6 @@ void parser_t::device(const pstring &dev_type)
else
params.push_back(plib::pfmt("{1}")(static_cast<long>(value)));
}
tok = get_token();
}
require_token(tok, m_tok_paren_right);
@ -393,9 +398,32 @@ void parser_t::device(const pstring &dev_type)
// private
// ----------------------------------------------------------------------------------------
nl_fptype parser_t::eval_param(const token_t &tok)
nl_fptype parser_t::eval_param(token_t &tok)
{
#if USE_EVAL
int pc(0);
pstring ret;
while (!tok.is(m_tok_comma))
{
if (tok.is(m_tok_paren_left))
pc++;
else if (tok.is(m_tok_paren_right))
{
if (pc<=0)
break;
pc--;
}
ret += tok.str();
tok = get_token();
}
// FIXME: Not necessary here, should be done if parameter is read by devices
plib::pfunction<nl_fptype> func;
func.compile_infix(ret, {});
return func.evaluate();
#else
static std::array<pstring, 7> macs = {"", "RES_R", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
static std::array<nl_fptype, 7> facs = {
nlconst::magic(1.0),
nlconst::magic(1.0),
@ -424,8 +452,9 @@ nl_fptype parser_t::eval_param(const token_t &tok)
if (err)
error(MF_PARAM_NOT_FP_1(tok.str()));
}
tok = get_token();
return ret * facs[f];
#endif
}
} // namespace netlist

View File

@ -44,7 +44,7 @@ namespace netlist
void verror(const pstring &msg) override;
private:
nl_fptype eval_param(const token_t &tok);
nl_fptype eval_param(token_t &tok);
token_id_t m_tok_paren_left;
token_id_t m_tok_paren_right;

View File

@ -1150,7 +1150,6 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model)
auto ret = plib::make_unique<logic_family_std_proxy_t>();
ret->m_fixed_V = m_models.value(model, "FV");
ret->m_low_thresh_PCNT = m_models.value(model, "IVL");
ret->m_high_thresh_PCNT = m_models.value(model, "IVH");
ret->m_low_VO = m_models.value(model, "OVL");

View File

@ -367,8 +367,8 @@ namespace plib {
return true;
}
size_type cur_alloc() const noexcept { return m_stat_cur_alloc(); }
size_type max_alloc() const noexcept { return m_stat_max_alloc(); }
size_type cur_alloc() const noexcept { return m_stat_cur_alloc(); } // NOLINT(readability-convert-member-functions-to-static)
size_type max_alloc() const noexcept { return m_stat_max_alloc(); } // NOLINT(readability-convert-member-functions-to-static)
private:
static size_t &m_stat_cur_alloc() noexcept { static size_t val = 0; return val; }
static size_t &m_stat_max_alloc() noexcept { static size_t val = 0; return val; }

View File

@ -76,7 +76,7 @@ namespace plib
/// later.
///
template <typename V>
static inline constexpr const T magic(V &&v) noexcept { return static_cast<T>(v); }
static inline constexpr T magic(V &&v) noexcept { return static_cast<T>(v); }
};
/// \brief typesafe reciprocal function
@ -415,7 +415,7 @@ namespace plib
return (m != 0 && n != 0) ? (plib::abs(m) / gcd(m, n)) * plib::abs(n) : 0;
}
static_assert(noexcept(constants<double>::one()) == true, "Not evaluated as constexpr");
static_assert(noexcept(constants<double>::one()), "Not evaluated as constexpr");
} // namespace plib

View File

@ -56,7 +56,7 @@ namespace plib {
pstring e = plib::pfmt("{1}:{2}:0: error: {3}\n")
(m_stack.back().m_name, m_stack.back().m_lineno, err);
m_stack.pop_back();
while (m_stack.size() > 0)
while (!m_stack.empty())
{
if (m_stack.size() == 1)
trail = trail_first;
@ -236,38 +236,51 @@ namespace plib {
tmpret.push_back(s);
}
else
if (!remove_ws || (tmp[pi] != " " && tmp[pi] != "\t"))
tmpret.push_back(tmp[pi]);
{
pstring tok=tmp[pi];
if (tok.size() >= 2 && pi < tmp.size() - 2 )
{
auto sc=tok.substr(0,1);
auto ec=tok.substr(tok.size()-1, 1);
if ((sc == "." || (sc>="0" && sc<="9")) && (ec=="e" || ec=="E"))
{
// looks like an incomplete float due splitting by - or +
tok = tok + tmp[pi+1] + tmp[pi+2];
pi += 2;
}
}
if (!remove_ws || (tok != " " && tok != "\t"))
tmpret.push_back(tok);
}
pi++;
}
if (!concat)
return tmpret;
else
// FIXME: error if concat at beginning or end
string_list ret;
pi = 0;
while (pi<tmpret.size())
{
// FIXME: error if concat at beginning or end
string_list ret;
pi = 0;
while (pi<tmpret.size())
if (tmpret[pi] == "##")
{
if (tmpret[pi] == "##")
{
while (ret.back() == " " || ret.back() == "\t")
ret.pop_back();
pstring cc = ret.back();
while (ret.back() == " " || ret.back() == "\t")
ret.pop_back();
pi++;
while (pi < tmpret.size() && (tmpret[pi] == " " || tmpret[pi] == "\t"))
pi++;
if (pi == tmpret.size())
error("## found at end of sequence");
ret.push_back(cc + tmpret[pi]);
}
else
ret.push_back(tmpret[pi]);
pstring cc = ret.back();
ret.pop_back();
pi++;
while (pi < tmpret.size() && (tmpret[pi] == " " || tmpret[pi] == "\t"))
pi++;
if (pi == tmpret.size())
error("## found at end of sequence");
ret.push_back(cc + tmpret[pi]);
}
return ret;
else
ret.push_back(tmpret[pi]);
pi++;
}
return ret;
}
bool ppreprocessor::is_valid_token(const pstring &str)

View File

@ -29,9 +29,9 @@ int pstring_t<F>::compare(const pstring_t &right) const noexcept
if (si != this->end() && ri != right.end())
return static_cast<int>(*si) - static_cast<int>(*ri);
else if (this->mem_t_size() > right.mem_t_size())
if (this->mem_t_size() > right.mem_t_size())
return 1;
else if (this->mem_t_size() < right.mem_t_size())
if (this->mem_t_size() < right.mem_t_size())
return -1;
return 0;
}

View File

@ -186,8 +186,8 @@ public:
pstring_t& operator+=(const pstring_t &string) { m_str.append(string.m_str); return *this; }
pstring_t& operator+=(const code_t c) { traits_type::encode(c, m_str); return *this; }
friend pstring_t operator+(const pstring_t &lhs, const pstring_t &rhs) { return pstring_t(lhs) += rhs; }
friend pstring_t operator+(const pstring_t &lhs, const code_t rhs) { return pstring_t(lhs) += rhs; }
friend pstring_t operator+(const code_t lhs, const pstring_t &rhs) { return pstring_t(1, lhs) += rhs; }
friend pstring_t operator+(const pstring_t &lhs, code_t rhs) { return pstring_t(lhs) += rhs; }
friend pstring_t operator+(code_t lhs, const pstring_t &rhs) { return pstring_t(1, lhs) += rhs; }
// comparison operators
bool operator==(const pstring_t &string) const noexcept { return (compare(string) == 0); }

View File

@ -292,7 +292,7 @@ namespace plib {
pstring e = plib::pfmt("{1}:{2}:0: error: {3}\n")
(m_source_location.back().file_name(), m_source_location.back().line(), errs());
m_source_location.pop_back();
while (m_source_location.size() > 0)
while (!m_source_location.empty())
{
if (m_source_location.size() == 1)
trail = trail_first;

View File

@ -218,8 +218,24 @@ public:
for (auto & r : roms)
setup().register_source(plib::make_unique<netlist_data_folder_t>(r));
#if 0
using a = plib::psource_str_t<plib::psource_t>;
#if USE_EVAL
const pstring content =
"#define RES_R(res) (res) \n"
"#define RES_K(res) ((res) * 1e3) \n"
"#define RES_M(res) ((res) * 1e6) \n"
"#define CAP_U(cap) ((cap) * 1e-6) \n"
"#define CAP_N(cap) ((cap) * 1e-9) \n"
"#define CAP_P(cap) ((cap) * 1e-12) \n"
"#define IND_U(ind) ((ind) * 1e-6) \n"
"#define IND_N(ind) ((ind) * 1e-9) \n"
"#define IND_P(ind) ((ind) * 1e-12) \n";
setup().add_include(plib::make_unique<a>("netlist/devices/net_lib.h", content));
#else
setup().add_include(plib::make_unique<a>("netlist/devices/net_lib.h",""));
#endif
#endif
for (auto & i : includes)
setup().add_include(plib::make_unique<netlist_data_folder_t>(i));

View File

@ -433,7 +433,7 @@ namespace solver
d->timestep(dd);
}
const netlist_time matrix_solver_t::solve(netlist_time_ext now)
netlist_time matrix_solver_t::solve(netlist_time_ext now)
{
const netlist_time_ext delta = now - m_last_step();
@ -561,10 +561,8 @@ namespace solver
{
m_terms[net_idx].add_terminal(term, ot, true);
}
// Should this be allowed ?
else
{
m_rails_temp[net_idx].add_terminal(term, ot, true);
log().fatal(MF_FOUND_TERM_WITH_MISSING_OTHERNET(term->name()));
throw nl_exception(MF_FOUND_TERM_WITH_MISSING_OTHERNET(term->name()));
}

View File

@ -177,7 +177,7 @@ namespace solver
// after every call to solve, update inputs must be called.
// this can be done as well as a batch to ease parallel processing.
const netlist_time solve(netlist_time_ext now);
netlist_time solve(netlist_time_ext now);
void update_inputs();
bool has_dynamic_devices() const noexcept { return !m_dynamic_devices.empty(); }

View File

@ -30,7 +30,7 @@ namespace solver
matrix_solver_direct_t(netlist_state_t &anetlist, const pstring &name,
const analog_net_t::list_t &nets,
const solver_parameters_t *params, const std::size_t size);
const solver_parameters_t *params, std::size_t size);
void reset() override { matrix_solver_t::reset(); }
@ -184,7 +184,7 @@ namespace solver
matrix_solver_direct_t<FT, SIZE>::matrix_solver_direct_t(netlist_state_t &anetlist, const pstring &name,
const analog_net_t::list_t &nets,
const solver_parameters_t *params,
const std::size_t size)
std::size_t size)
: matrix_solver_ext_t<FT, SIZE>(anetlist, name, nets, params, size)
, m_pitch(m_pitch_ABS ? m_pitch_ABS : (((size + 0) + 7) / 8) * 8)
, m_A(size, m_pitch)

View File

@ -146,7 +146,7 @@ namespace solver
{
const auto &nzbd = this->m_terms[i].m_nzbd;
if (nzbd.size() > 0)
if (!nzbd.empty())
{
std::size_t pi = mat.diag[i];

View File

@ -291,7 +291,7 @@ namespace devices
// process all terminals connected to this net
for (auto &term : n.core_terms())
{
netlist.log().verbose("Term {} {}", term->name(), (int) term->type());
netlist.log().verbose("Term {} {}", term->name(), static_cast<int>(term->type()));
// only process analog terminals
if (term->is_type(detail::terminal_type::TERMINAL))
{

View File

@ -485,18 +485,18 @@ void nl_convert_spice_t::process_line(const pstring &line)
}
else
{
int sce(4);
int scoeff(5 + n);
if ((tt.size() != 5 + 2 * n) || (tt[scoeff-1] != "0"))
unsigned sce(4);
auto scoeff(static_cast<unsigned>(5 + n));
if ((tt.size() != 5 + 2 * static_cast<unsigned>(n)) || (tt[scoeff-1] != "0"))
{
out("// IGNORED {}: {}\n", tt[0].c_str(), line.c_str());
break;
}
pstring lastnet = tt[1];
for (int i=0; i<n; i++)
for (std::size_t i=0; i < static_cast<std::size_t>(n); i++)
{
pstring devname = tt[0] + plib::pfmt("{}")(i);
pstring nextnet = (i<n-1) ? tt[1] + "a" + plib::pfmt("{}")(i) : tt[2];
pstring nextnet = (i<static_cast<std::size_t>(n)-1) ? tt[1] + "a" + plib::pfmt("{}")(i) : tt[2];
auto net2 = plib::psplit(plib::replace_all(plib::replace_all(tt[sce+i],")",""),"(",""),",");
add_device("VCVS", devname);
add_term(lastnet, devname, 0);
@ -519,8 +519,8 @@ void nl_convert_spice_t::process_line(const pstring &line)
case 'F':
{
auto n=npoly(tt[3]);
int sce(4);
int scoeff(5 + n);
unsigned sce(4);
unsigned scoeff(5 + static_cast<unsigned>(n));
if (n<0)
{
sce = 3;
@ -529,13 +529,13 @@ void nl_convert_spice_t::process_line(const pstring &line)
}
else
{
if ((tt.size() != 5 + 2 * n) || (tt[scoeff-1] != "0"))
if ((tt.size() != 5 + 2 * static_cast<unsigned>(n)) || (tt[scoeff-1] != "0"))
{
out("// IGNORED {}: {}\n", tt[0].c_str(), line.c_str());
break;
}
}
for (int i=0; i<n; i++)
for (std::size_t i=0; i < static_cast<std::size_t>(n); i++)
{
pstring devname = tt[0] + plib::pfmt("{}")(i);
add_device("CCCS", devname);

View File

@ -666,7 +666,7 @@ void rebound_state::rebound(machine_config &config)
ROM_START( pong ) /* dummy to satisfy game entry*/
ROM_REGION( 0x10000, "maincpu", 0 ) /* enough for netlist */
ROM_LOAD( "pong.netlist", 0x000000, 0x00473b, CRC(eadaf087) SHA1(4cb9a79f5cb53502105974be61b99ff16ee930e9) )
ROM_LOAD( "pong.netlist", 0x000000, 18273, CRC(d249ce49) SHA1(e1d2cfca74b75f0520965639e6947a351650fc3e) )
ROM_END
ROM_START( breakout )

View File

@ -7,10 +7,10 @@
***************************************************************************/
#ifndef __PLIB_PREPROCESSOR__
//#ifndef __PLIB_PREPROCESSOR__
#define NL_PROHIBIT_BASEH_INCLUDE 1
#include "netlist/devices/net_lib.h"
#endif
//#endif
#define FAST_CLOCK (1)