From b3f6072cfddb8d012f7065587330d94ad846c9b4 Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 7 Jun 2016 19:31:59 +0200 Subject: [PATCH] Fix standalone build. Refactor ptypes.h. (nw) --- src/lib/netlist/build/makefile | 7 +- src/lib/netlist/nl_base.cpp | 2 + src/lib/netlist/nl_factory.cpp | 1 + src/lib/netlist/nl_factory.h | 1 + src/lib/netlist/plib/plists.h | 69 ------------------ src/lib/netlist/plib/poptions.h | 3 +- src/lib/netlist/plib/pparser.h | 5 +- src/lib/netlist/plib/ptypes.h | 68 +++--------------- src/lib/netlist/plib/putil.cpp | 122 +++++++++++++++++++++++++++++++- src/lib/netlist/plib/putil.h | 13 ++++ 10 files changed, 155 insertions(+), 136 deletions(-) diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index af65492711c..c1729cc0c39 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -14,7 +14,7 @@ SRC = .. #-fuse-ld=gold -Wpedantic -march=native -march=native -# LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr +LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr CDEFS = -DPSTANDALONE=1 -DPTR64=1 #-Werror @@ -49,11 +49,12 @@ OBJS = $(POBJS) $(NLOBJS) POBJS := \ $(POBJ)/pstring.o \ $(POBJ)/palloc.o \ + $(POBJ)/pdynlib.o \ + $(POBJ)/pfmtlog.o \ $(POBJ)/pparser.o \ $(POBJ)/pstate.o \ $(POBJ)/pstream.o \ - $(POBJ)/pfmtlog.o \ - $(POBJ)/pdynlib.o \ + $(POBJ)/putil.o \ NLOBJS := \ $(NLOBJ)/nl_base.o \ diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index b39a41cdcaa..6c1df62290d 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -5,6 +5,8 @@ * */ +#include + #include "solver/nld_matrix_solver.h" #include "solver/nld_solver.h" diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp index 6d9d8e9bfd5..43f83b39374 100644 --- a/src/lib/netlist/nl_factory.cpp +++ b/src/lib/netlist/nl_factory.cpp @@ -10,6 +10,7 @@ #include "nl_factory.h" #include "nl_setup.h" +#include "plib/putil.h" namespace netlist { diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index d1bd0b6f728..780408cd285 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -13,6 +13,7 @@ #include "nl_config.h" #include "plib/plists.h" +#include "plib/putil.h" #include "nl_base.h" #define NETLIB_DEVICE_IMPL(chip) factory_creator_ptr_t decl_ ## chip = factory_creator_t< NETLIB_NAME(chip) >; diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 93d6be60f07..be36dd8fb2d 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -190,75 +190,6 @@ public: LC *m_head; }; -// ---------------------------------------------------------------------------------------- -// string list -// ---------------------------------------------------------------------------------------- - -class pstring_vector_t : public pvector_t -{ -public: - pstring_vector_t() : pvector_t() { } - - pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty = false) - : pvector_t() - { - int p = 0; - int pn; - - pn = str.find(onstr, p); - while (pn>=0) - { - pstring t = str.substr(p, pn - p); - if (!ignore_empty || t.len() != 0) - this->push_back(t); - p = pn + onstr.len(); - pn = str.find(onstr, p); - } - if (p < (int) str.len()) - { - pstring t = str.substr(p); - if (!ignore_empty || t.len() != 0) - this->push_back(t); - } - } - - pstring_vector_t(const pstring &str, const pstring_vector_t &onstrl) - : pvector_t() - { - pstring col = ""; - - unsigned i = 0; - while (i=0) - { - if (col != "") - this->push_back(col); - - col = ""; - this->push_back(onstrl[p]); - i += onstrl[p].blen(); - } - else - { - pstring::traits::code_t c = pstring::traits::code(str.cstr() + i); - col += c; - i+=pstring::traits::codelen(c); - } - } - if (col != "") - this->push_back(col); - } -}; // ---------------------------------------------------------------------------------------- // hashmap list diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index dbcf3ba30d4..8a66000053c 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -14,6 +14,7 @@ #include "pstring.h" #include "plists.h" +#include "putil.h" namespace plib { @@ -82,7 +83,7 @@ public: pstring operator ()() { return m_val; } private: pstring m_val; - pstring_vector_t m_limit; + plib::pstring_vector_t m_limit; }; class option_bool : public option diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index dd08d781313..610f524b5e3 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -11,6 +11,7 @@ #include "pconfig.h" #include "pstring.h" #include "plists.h" +#include "putil.h" #include "pstream.h" namespace plib { @@ -176,7 +177,7 @@ protected: postream &process_i(pistream &istrm, postream &ostrm); - double expr(const pstring_vector_t &sexpr, std::size_t &start, int prio); + double expr(const plib::pstring_vector_t &sexpr, std::size_t &start, int prio); define_t *get_define(const pstring &name); @@ -189,7 +190,7 @@ private: pstring process_line(const pstring &line); hashmap_t m_defines; - pstring_vector_t m_expr_sep; + plib::pstring_vector_t m_expr_sep; //pstringbuffer m_ret; UINT32 m_ifflag; // 31 if levels diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index 06246846d0e..af8e16a2253 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -13,68 +13,16 @@ namespace plib { -//============================================================ -// penum - strongly typed enumeration -//============================================================ + //============================================================ + // penum - strongly typed enumeration + //============================================================ -struct enum_base -{ -protected: - static int from_string_int(const char *str, const char *x) + struct enum_base { - int cnt = 0; - const char *cur = str; - int lx = strlen(x); - while (*str) - { - if (*str == ',') - { - int l = str-cur; - if (l == lx) - if (strncmp(cur, x, lx) == 0) - return cnt; - } - else if (*str == ' ') - { - cur = str + 1; - cnt++; - } - str++; - } - int l = str-cur; - if (l == lx) - if (strncmp(cur, x, lx) == 0) - return cnt; - return -1; - } - static pstring nthstr(int n, const char *str) - { - char buf[64]; - char *bufp = buf; - int cur = 0; - while (*str) - { - if (cur == n) - { - if (*str == ',') - { - *bufp = 0; - return pstring(buf); - } - else if (*str != ' ') - *bufp++ = *str; - } - else - { - if (*str == ',') - cur++; - } - str++; - } - *bufp = 0; - return pstring(buf); - } -}; + protected: + static int from_string_int(const char *str, const char *x); + static pstring nthstr(int n, const char *str); + }; } diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp index 3e77cdf19c0..3e5cecc0081 100644 --- a/src/lib/netlist/plib/putil.cpp +++ b/src/lib/netlist/plib/putil.cpp @@ -7,6 +7,7 @@ #include #include "plib/putil.h" +#include "plib/ptypes.h" #include "plib/plists.h" namespace plib @@ -38,4 +39,123 @@ namespace plib return pstring(getenv(var.cstr())); } } -} + + pstring_vector_t::pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty) + : pvector_t() + { + int p = 0; + int pn; + + pn = str.find(onstr, p); + while (pn>=0) + { + pstring t = str.substr(p, pn - p); + if (!ignore_empty || t.len() != 0) + this->push_back(t); + p = pn + onstr.len(); + pn = str.find(onstr, p); + } + if (p < (int) str.len()) + { + pstring t = str.substr(p); + if (!ignore_empty || t.len() != 0) + this->push_back(t); + } + } + + pstring_vector_t::pstring_vector_t(const pstring &str, const pstring_vector_t &onstrl) + : pvector_t() + { + pstring col = ""; + + unsigned i = 0; + while (i=0) + { + if (col != "") + this->push_back(col); + + col = ""; + this->push_back(onstrl[p]); + i += onstrl[p].blen(); + } + else + { + pstring::traits::code_t c = pstring::traits::code(str.cstr() + i); + col += c; + i+=pstring::traits::codelen(c); + } + } + if (col != "") + this->push_back(col); + } + + + int enum_base::from_string_int(const char *str, const char *x) + { + int cnt = 0; + const char *cur = str; + int lx = strlen(x); + while (*str) + { + if (*str == ',') + { + int l = str-cur; + if (l == lx) + if (strncmp(cur, x, lx) == 0) + return cnt; + } + else if (*str == ' ') + { + cur = str + 1; + cnt++; + } + str++; + } + int l = str-cur; + if (l == lx) + if (strncmp(cur, x, lx) == 0) + return cnt; + return -1; + } + pstring enum_base::nthstr(int n, const char *str) + { + char buf[64]; + char *bufp = buf; + int cur = 0; + while (*str) + { + if (cur == n) + { + if (*str == ',') + { + *bufp = 0; + return pstring(buf); + } + else if (*str != ' ') + *bufp++ = *str; + } + else + { + if (*str == ',') + cur++; + } + str++; + } + *bufp = 0; + return pstring(buf); + } +} // namespace plib + + + diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 59aaee9d557..db5510178c0 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -20,6 +20,19 @@ namespace plib const pstring buildpath(std::initializer_list list ); const pstring environment(const pstring &var, const pstring &default_val = ""); } + + // ---------------------------------------------------------------------------------------- + // string list + // ---------------------------------------------------------------------------------------- + + class pstring_vector_t : public pvector_t + { + public: + pstring_vector_t() : pvector_t() { } + pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty = false); + pstring_vector_t(const pstring &str, const pstring_vector_t &onstrl); + }; + } #endif /* P_UTIL_H_ */