summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/nl_setup.cpp
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2020-08-05 21:43:54 +0200
committer couriersud <couriersud@gmx.org>2020-08-06 09:44:59 +0200
commitd524688df1535b2825773cbdf430bf5377aff189 (patch)
treee7494fd21962fc50ee27e296c9d9f3104301b278 /src/lib/netlist/nl_setup.cpp
parentbca7016758229428934398a13406847604d77152 (diff)
netlist: Refactored pokenizer.
* Separated tokenizing and reading of tokens. * This enables caching of parsing results on the token level. * Implemented caching of token stream. * Overall this significantly improves parsing performance (~10x) * Next step towards a bare-bone nltool which does not depend on macro devices.
Diffstat (limited to 'src/lib/netlist/nl_setup.cpp')
-rw-r--r--src/lib/netlist/nl_setup.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index 46b04d902dc..aed7a509d5e 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -16,6 +16,8 @@
#include "solver/nld_solver.h"
+#include <sstream>
+
namespace netlist
{
// ----------------------------------------------------------------------------------------
@@ -352,10 +354,26 @@ namespace netlist
bool nlparse_t::parse_stream(plib::psource_t::stream_ptr &&istrm, const pstring &name)
{
- auto y = std::make_unique<plib::ppreprocessor>(m_includes, &m_defines);
- y->process(std::move(istrm), "<stream>");
- return parser_t(std::move(y), *this).parse(name);
- //return parser_t(std::move(plib::ppreprocessor(&m_defines).process(std::move(istrm))), *this).parse(name);
+ auto key = istrm.filename();
+
+ if (m_source_cache.find(key) != m_source_cache.end())
+ {
+ return parser_t(*this).parse(m_source_cache[key], name);
+ }
+ else
+ {
+ //printf("searching %s\n", name.c_str());
+ plib::ppreprocessor y(m_includes, &m_defines);
+ y.process(std::move(istrm), istrm.filename());
+
+ auto abc = std::make_unique<std::stringstream>();
+ plib::copystream(*abc, y);
+
+ parser_t::token_store &st = m_source_cache[key];
+ parser_t parser(*this);
+ parser.parse_tokens(plib::psource_t::stream_ptr(std::move(abc), key), st);
+ return parser.parse(st, name);
+ }
}
void nlparse_t::add_define(const pstring &defstr)
@@ -1690,6 +1708,19 @@ source_file_t::stream_ptr source_file_t::stream(const pstring &name)
return stream_ptr();
}
+source_file_t::stream_ptr source_pattern_t::stream(const pstring &name)
+{
+ pstring filename = plib::pfmt(m_pattern)(name);
+ auto f = std::make_unique<plib::ifstream>(plib::filesystem::u8path(filename));
+ if (f->is_open())
+ {
+ return stream_ptr(std::move(f), filename);
+ }
+ else
+ return stream_ptr();
+}
+
+
bool source_proc_t::parse(nlparse_t &setup, const pstring &name)
{
if (name == m_setup_func_name)