From b09fa00cca1a9baa0327a33d865fc970f77d4db0 Mon Sep 17 00:00:00 2001 From: couriersud Date: Fri, 18 Oct 2019 17:57:55 +0200 Subject: Netlist: code maintenance and improvements. [Couriersud] - Added support for line markers to the preprocessor and parser. - Added support for include processing to the preprocessor. - Moved sources base type to plib to be used for preprocessor includes. This enables to include e.g. from rom memory regions. - Renamed some defines --- src/lib/netlist/prg/nltool.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/lib/netlist/prg/nltool.cpp') diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 11ca83c9aa5..f34c83d5382 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -31,6 +31,7 @@ public: opt_grp1(*this, "General options", "The following options apply to all commands."), opt_cmd (*this, "c", "cmd", 0, std::vector({"run","validate","convert","listdevices","static","header","docheader"}), "run|validate|convert|listdevices|static|header|docheader"), opt_file(*this, "f", "file", "-", "file to process (default is stdin)"), + opt_includes(*this, "I", "include", "Add the directory to the list of directories to be searched for header files. This option may be specified repeatedly."), opt_defines(*this, "D", "define", "predefine value as macro, e.g. -Dname=value. If '=value' is omitted predefine it as 1. This option may be specified repeatedly."), opt_rfolders(*this, "r", "rom", "where to look for data files"), opt_verb(*this, "v", "verbose", "be verbose - this produces lots of output"), @@ -76,6 +77,7 @@ public: plib::option_group opt_grp1; plib::option_str_limit opt_cmd; plib::option_str opt_file; + plib::option_vec opt_includes; plib::option_vec opt_defines; plib::option_vec opt_rfolders; plib::option_bool opt_verb; @@ -140,21 +142,21 @@ NETLIST_END() CORE IMPLEMENTATION ***************************************************************************/ -class netlist_data_folder_t : public netlist::source_t +class netlist_data_folder_t : public netlist::source_data_t { public: netlist_data_folder_t(const pstring &folder) - : netlist::source_t(netlist::source_t::DATA) + : netlist::source_data_t() , m_folder(folder) { } - plib::unique_ptr stream(const pstring &file) override + stream_ptr stream(const pstring &file) override { pstring name = m_folder + "/" + file; auto strm(plib::make_unique(plib::filesystem::u8path(name))); if (strm->fail()) - return plib::unique_ptr(nullptr); + return stream_ptr(nullptr); else { strm->imbue(std::locale::classic()); @@ -198,7 +200,8 @@ public: void read_netlist(const pstring &filename, const pstring &name, const std::vector &logs, const std::vector &defines, - const std::vector &roms) + const std::vector &roms, + const std::vector &includes) { // read the netlist ... @@ -208,6 +211,11 @@ public: for (auto & r : roms) setup().register_source(plib::make_unique(r)); + using a = plib::psource_str_t; + setup().add_include(plib::make_unique("netlist/devices/net_lib.h","")); + for (auto & i : includes) + setup().add_include(plib::make_unique(i)); + setup().register_source(plib::make_unique(filename)); setup().include(name); create_dynamic_logs(logs); @@ -377,7 +385,7 @@ void tool_app_t::run() nt.read_netlist(opt_file(), opt_name(), opt_logs(), - m_options, opt_rfolders()); + m_options, opt_rfolders(), opt_includes()); nt.reset(); @@ -473,7 +481,7 @@ void tool_app_t::validate() nt.read_netlist(opt_file(), opt_name(), opt_logs(), - m_options, opt_rfolders()); + m_options, opt_rfolders(), opt_includes()); } catch (netlist::nl_exception &e) { @@ -507,7 +515,7 @@ void tool_app_t::static_compile() nt.read_netlist(opt_file(), opt_name(), opt_logs(), - m_options, opt_rfolders()); + m_options, opt_rfolders(), opt_includes()); // need to reset ... @@ -824,8 +832,6 @@ int tool_app_t::execute() if (opt_help()) { - pout(plib::pfmt("{:10.3}\n").f(20.0)); - //pout(plib::pfmt("{10.3}\n").f(20)); pout(usage()); return 0; } -- cgit v1.2.3-70-g09d2