summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/nl_parser.cpp
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2020-01-29 19:00:10 +0100
committer couriersud <couriersud@gmx.org>2020-01-29 19:00:10 +0100
commitfceee50c8bd6d930fc1f152ede4185ce7dc44c40 (patch)
tree71a0f8d6d43ddbe1fc98a078d3baddecd6e5d953 /src/lib/netlist/nl_parser.cpp
parentd7fd89afe1a384e268cb8a9fbd0f6c4c994e195d (diff)
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.
Diffstat (limited to 'src/lib/netlist/nl_parser.cpp')
-rw-r--r--src/lib/netlist/nl_parser.cpp60
1 files changed, 8 insertions, 52 deletions
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<long>(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<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),
- 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; i<macs.size();i++)
- if (tok.str() == macs[i])
- f = i;
- if (f>0)
- {
- require_token(m_tok_paren_left);
- ret = static_cast<nl_fptype>(get_number_double());
- require_token(m_tok_paren_right);
- }
- else
- {
- bool err(false);
- ret = plib::pstonum_ne<nl_fptype>(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