From fceee50c8bd6d930fc1f152ede4185ce7dc44c40 Mon Sep 17 00:00:00 2001 From: couriersud Date: Wed, 29 Jan 2020 19:00:10 +0100 Subject: netlist: Parameters evaluated when netlist is created. [Couriersud] Parameters are now passed to the netlist core as strings. During netlist creation they are evaluated as functions. This opens the path to parameters on subdevice level. Examples: PARAM(device.XY, (1+2*0.005)) RES(R1, 2.05*RES_K(1)+1) In addition the commit contains dead code removal. --- src/lib/netlist/nl_parser.cpp | 60 ++++++------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) (limited to 'src/lib/netlist/nl_parser.cpp') diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index 7f4d7bd4e7e..04cfd43c635 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -237,10 +237,10 @@ void parser_t::frontier() pstring attachat = get_identifier(); require_token(m_tok_comma); auto tok = get_token(); - nl_fptype r_IN = eval_param(tok); + auto r_IN = stringify_expression(tok); require_token(tok, m_tok_comma); tok = get_token(); - nl_fptype r_OUT = eval_param(tok); + auto r_OUT = stringify_expression(tok); require_token(tok, m_tok_paren_right); m_setup.register_frontier(attachat, r_IN, r_OUT); @@ -341,7 +341,7 @@ void parser_t::netdev_param() } else { - nl_fptype val = eval_param(tok); + auto val = stringify_expression(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); @@ -354,7 +354,7 @@ void parser_t::netdev_hint() pstring dev(get_identifier()); require_token(m_tok_comma); pstring hint(get_identifier()); - m_setup.register_param(dev + ".HINT_" + hint, 1); + m_setup.register_param_val(dev + ".HINT_" + hint, 1); require_token(m_tok_paren_right); } @@ -379,13 +379,8 @@ void parser_t::device(const pstring &dev_type) } else { - // FIXME: Do we really need this? - nl_fptype value = eval_param(tok); - if (plib::abs(value - plib::floor(value)) > nlconst::magic(1e-30) - || plib::abs(value) > nlconst::magic(1e9)) - params.push_back(plib::pfmt("{1:.9}").e(value)); - else - params.push_back(plib::pfmt("{1}")(static_cast(value))); + auto value = stringify_expression(tok); + params.push_back(value); } } @@ -398,9 +393,8 @@ void parser_t::device(const pstring &dev_type) // private // ---------------------------------------------------------------------------------------- -nl_fptype parser_t::eval_param(token_t &tok) +pstring parser_t::stringify_expression(token_t &tok) { -#if USE_EVAL int pc(0); pstring ret; while (!tok.is(m_tok_comma)) @@ -416,45 +410,7 @@ nl_fptype parser_t::eval_param(token_t &tok) ret += tok.str(); tok = get_token(); } - // FIXME: Not necessary here, should be done if parameter is read by devices - plib::pfunction func; - func.compile_infix(ret, {}); - return func.evaluate(); - -#else - static std::array macs = {"", "RES_R", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"}; - - static std::array facs = { - nlconst::magic(1.0), - nlconst::magic(1.0), - nlconst::magic(1e3), - nlconst::magic(1e6), - nlconst::magic(1e-6), - nlconst::magic(1e-9), - nlconst::magic(1e-12) - }; - std::size_t f=0; - nl_fptype ret(0); - - for (std::size_t i=1; i0) - { - require_token(m_tok_paren_left); - ret = static_cast(get_number_double()); - require_token(m_tok_paren_right); - } - else - { - bool err(false); - ret = plib::pstonum_ne(tok.str(), err); - if (err) - error(MF_PARAM_NOT_FP_1(tok.str())); - } - tok = get_token(); - return ret * facs[f]; -#endif + return ret; } } // namespace netlist -- cgit v1.2.3