diff options
Diffstat (limited to 'src/lib/netlist/nl_parser.cpp')
-rw-r--r-- | src/lib/netlist/nl_parser.cpp | 89 |
1 files changed, 50 insertions, 39 deletions
diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index 02c7d11f2b2..3e4ecd0937c 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -1,16 +1,17 @@ // license:BSD-3-Clause // copyright-holders:Couriersud +#include "nl_parser.h" + #include "nl_errstr.h" #include "nl_factory.h" -#include "nl_parser.h" #include "nl_setup.h" namespace netlist { - // ---------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------- // A netlist parser - // ---------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------- void parser_t::verror(const pstring &msg) { @@ -19,12 +20,16 @@ namespace netlist } parser_t::parser_t(nlparse_t &setup) - : m_setup(setup) - , m_cur_local(nullptr) + : m_setup(setup) + , m_cur_local(nullptr) { - m_tokenizer.identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-$@") - .number_chars(".0123456789", "0123456789eE-.") //FIXME: processing of numbers - .whitespace(pstring("") + ' ' + static_cast<char>(9) + static_cast<char>(10) + static_cast<char>(13)) + m_tokenizer + .identifier_chars( + "abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-$@") + .number_chars(".0123456789", "0123456789eE-.") // FIXME: processing + // of numbers + .whitespace(pstring("") + ' ' + static_cast<char>(9) + + static_cast<char>(10) + static_cast<char>(13)) .comment("/*", "*/", "//"); m_tok_paren_left = m_tokenizer.register_token("("); m_tok_paren_right = m_tokenizer.register_token(")"); @@ -43,7 +48,8 @@ namespace netlist m_tok_INCLUDE = m_tokenizer.register_token("INCLUDE"); m_tok_LOCAL_SOURCE = m_tokenizer.register_token("LOCAL_SOURCE"); m_tok_LOCAL_LIB_ENTRY = m_tokenizer.register_token("LOCAL_LIB_ENTRY"); - m_tok_EXTERNAL_LIB_ENTRY = m_tokenizer.register_token("EXTERNAL_LIB_ENTRY"); + m_tok_EXTERNAL_LIB_ENTRY = m_tokenizer.register_token( + "EXTERNAL_LIB_ENTRY"); m_tok_SUBMODEL = m_tokenizer.register_token("SUBMODEL"); m_tok_NETLIST_START = m_tokenizer.register_token("NETLIST_START"); m_tok_NETLIST_END = m_tokenizer.register_token("NETLIST_END"); @@ -62,7 +68,6 @@ namespace netlist m_tokenizer.register_token("CAP_U"); m_tokenizer.register_token("CAP_N"); m_tokenizer.register_token("CAP_P"); - } bool parser_t::parse(plib::istream_uptr &&strm, const pstring &nlname) @@ -72,15 +77,16 @@ namespace netlist return parse(tokstor, nlname); } - void parser_t::parse_tokens(plib::istream_uptr &&strm, token_store_t &tokstor) + void parser_t::parse_tokens(plib::istream_uptr &&strm, + token_store_t & tokstor) { plib::putf8_reader u8reader(strm.release_stream()); m_tokenizer.append_to_store(&u8reader, tokstor); } - bool parser_t::parse(const token_store_t &tokstor, const pstring &nlname) + bool parser_t::parse(const token_store_t &store, const pstring &nlname) { - set_token_source(&tokstor); + set_token_source(&store); bool in_nl = false; @@ -97,7 +103,7 @@ namespace netlist if (token.is(m_tok_NETLIST_END) || token.is(m_tok_TRUTHTABLE_END)) { if (!in_nl) - error (MF_PARSER_UNEXPECTED_1(token.str())); + error(MF_PARSER_UNEXPECTED_1(token.str())); else { in_nl = false; @@ -108,15 +114,16 @@ namespace netlist m_cur_local->push_back(token); m_cur_local->push_back(token_t(m_tok_paren_left)); m_cur_local->push_back(token_t(m_tok_paren_right)); - } - else if (token.is(m_tok_NETLIST_START) || token.is(m_tok_TRUTHTABLE_START)) + else if (token.is(m_tok_NETLIST_START) + || token.is(m_tok_TRUTHTABLE_START)) { if (in_nl) - error (MF_PARSER_UNEXPECTED_1(token.str())); + error(MF_PARSER_UNEXPECTED_1(token.str())); require_token(m_tok_paren_left); token_t name = get_token(); - if (token.is(m_tok_NETLIST_START) && (name.str() == nlname || nlname.empty())) + if (token.is(m_tok_NETLIST_START) + && (name.str() == nlname || nlname.empty())) { require_token(m_tok_paren_right); parse_netlist(); @@ -132,29 +139,32 @@ namespace netlist m_local.emplace(name.str(), token_store_t()); m_cur_local = &m_local[name.str()]; auto sl = location(); - auto li = plib::pfmt("# {1} \"{2}\"")(sl.line(), sl.file_name()); + auto li = plib::pfmt( + "# {1} \"{2}\"")(sl.line(), sl.file_name()); m_cur_local->push_back(token_t(token_type::LINEMARKER, li)); m_cur_local->push_back(token); m_cur_local->push_back(token_t(m_tok_paren_left)); m_cur_local->push_back(name); - //m_cur_local->push_back(token_t(m_tok_paren_right)); + // m_cur_local->push_back(token_t(m_tok_paren_right)); in_nl = true; } - // FIXME: do we really need this going forward ? there should be no need + // FIXME: do we really need this going forward ? there should be no + // need // for NETLIST_EXTERNAL in netlist files else if (token.is(m_tok_NETLIST_EXTERNAL)) { if (in_nl) - error (MF_UNEXPECTED_NETLIST_EXTERNAL()); + error(MF_UNEXPECTED_NETLIST_EXTERNAL()); require_token(m_tok_paren_left); token_t name = get_token(); require_token(m_tok_paren_right); } else if (!in_nl) { - if (!token.is(m_tok_static) && !token.is_type(token_type::SOURCELINE) - && !token.is_type(token_type::LINEMARKER)) + if (!token.is(m_tok_static) + && !token.is_type(token_type::SOURCELINE) + && !token.is_type(token_type::LINEMARKER)) error(MF_EXPECTED_NETLIST_START_1(token.str())); } else @@ -171,7 +181,7 @@ namespace netlist token_t token = get_token(); if (token.is_type(token_type::ENDOFFILE)) - error (MF_UNEXPECTED_END_OF_FILE()); + error(MF_UNEXPECTED_END_OF_FILE()); m_setup.log().debug("Parser: Device: {1}\n", token.str()); @@ -237,7 +247,8 @@ namespace netlist else if (m_local.find(name) != m_local.end()) error(MF_EXTERNAL_SOURCE_IS_LOCAL_1(name)); - // FIXME: Need to pass in parameter definition FIXME: get line number right + // FIXME: Need to pass in parameter definition FIXME: get line number + // right m_setup.register_lib_entry(name, "", location()); require_token(m_tok_paren_right); } @@ -376,7 +387,6 @@ namespace netlist require_token(m_tok_paren_left); pstring name(get_identifier()); require_token(m_tok_paren_right); - } void parser_t::net_alias() @@ -403,7 +413,7 @@ namespace netlist while (true) { pstring t1 = get_identifier(); - m_setup.register_link(first , t1); + m_setup.register_link(first, t1); m_setup.log().debug("Parser: Connect: {1} {2}\n", first, t1); token_t n = get_token(); if (n.is(m_tok_paren_right)) @@ -411,7 +421,6 @@ namespace netlist if (!n.is(m_tok_comma)) error(MF_EXPECTED_COMMA_OR_RP_1(n.str())); } - } void parser_t::dip_pins() @@ -437,8 +446,8 @@ namespace netlist std::size_t n = pins.size(); for (std::size_t i = 0; i < n / 2; i++) { - m_setup.register_alias(plib::pfmt("{1}")(i+1), pins[i*2]); - m_setup.register_alias(plib::pfmt("{1}")(n-i), pins[i*2 + 1]); + m_setup.register_alias(plib::pfmt("{1}")(i + 1), pins[i * 2]); + m_setup.register_alias(plib::pfmt("{1}")(n - i), pins[i * 2 + 1]); } } @@ -471,7 +480,8 @@ namespace netlist token_t tok = get_token(); if (tok.is_type(token_type::STRING)) { - m_setup.log().debug("Parser: DefParam: {1} {2}\n", param, tok.str()); + m_setup.log().debug("Parser: DefParam: {1} {2}\n", param, + tok.str()); m_setup.register_default_param(param, tok.str()); require_token(m_tok_paren_right); } @@ -535,13 +545,13 @@ namespace netlist m_setup.register_dev(dev_type, devname, params); } - // ---------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------- // private - // ---------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------- pstring parser_t::stringify_expression(token_t &tok) { - int pc(0); + int pc(0); pstring ret; while (!tok.is(m_tok_comma)) { @@ -549,7 +559,7 @@ namespace netlist pc++; else if (tok.is(m_tok_paren_right)) { - if (pc<=0) + if (pc <= 0) break; pc--; } @@ -559,9 +569,9 @@ namespace netlist return ret; } - // ---------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------- // source_token_t - // ---------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------- bool source_token_t::parse(nlparse_t &setup, const pstring &name) { @@ -574,7 +584,8 @@ namespace netlist return false; } - plib::istream_uptr source_token_t::stream([[maybe_unused]] const pstring &name) + plib::istream_uptr source_token_t::stream( + [[maybe_unused]] const pstring &name) { return plib::istream_uptr(); } |