From 0eeeb8b6a33c2305c8a28192c0bad28200ba6a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Wed, 16 Mar 2022 23:32:24 +0100 Subject: [PATCH] Bd enhancements (#1034) * Added ability to join files for strmxor * Joined input files also for strm2txt strmclip and strmcmp. Output options for strmxor. --- src/buddies/src/bd/bdConverterMain.cc | 36 +------------------------ src/buddies/src/bd/bdReaderOptions.cc | 38 +++++++++++++++++++++++++++ src/buddies/src/bd/bdReaderOptions.h | 7 +++++ src/buddies/src/bd/strm2txt.cc | 5 +--- src/buddies/src/bd/strmclip.cc | 5 +--- src/buddies/src/bd/strmcmp.cc | 10 ++----- src/buddies/src/bd/strmxor.cc | 15 +++++------ 7 files changed, 57 insertions(+), 59 deletions(-) diff --git a/src/buddies/src/bd/bdConverterMain.cc b/src/buddies/src/bd/bdConverterMain.cc index 1190e1377..215740cca 100644 --- a/src/buddies/src/bd/bdConverterMain.cc +++ b/src/buddies/src/bd/bdConverterMain.cc @@ -31,33 +31,6 @@ namespace bd { -static std::string::size_type find_file_sep (const std::string &s, std::string::size_type from) -{ - std::string::size_type p1 = s.find ("+", from); - std::string::size_type p2 = s.find (",", from); - - if (p1 == std::string::npos) { - return p2; - } else if (p2 == std::string::npos) { - return p1; - } else { - return p1 < p2 ? p1 : p2; - } -} - -static std::vector split_file_list (const std::string &infile) -{ - std::vector files; - - size_t p = 0; - for (size_t pp = 0; (pp = find_file_sep (infile, p)) != std::string::npos; p = pp + 1) { - files.push_back (std::string (infile, p, pp - p)); - } - files.push_back (std::string (infile, p)); - - return files; -} - int converter_main (int argc, char *argv[], const std::string &format) { bd::GenericWriterOptions generic_writer_options; @@ -83,14 +56,7 @@ int converter_main (int argc, char *argv[], const std::string &format) { db::LoadLayoutOptions load_options; generic_reader_options.configure (load_options); - - std::vector files = split_file_list (infile); - - for (std::vector::const_iterator f = files.begin (); f != files.end (); ++f) { - tl::InputStream stream (*f); - db::Reader reader (stream); - reader.read (layout, load_options); - } + read_files (layout, infile, load_options); } { diff --git a/src/buddies/src/bd/bdReaderOptions.cc b/src/buddies/src/bd/bdReaderOptions.cc index 8209f2924..2cc09cd22 100644 --- a/src/buddies/src/bd/bdReaderOptions.cc +++ b/src/buddies/src/bd/bdReaderOptions.cc @@ -833,4 +833,42 @@ GenericReaderOptions::configure (db::LoadLayoutOptions &load_options) load_options.set_option_by_name ("lefdef_config.macro_layouts", lef_layout_ptrs); } +static std::string::size_type find_file_sep (const std::string &s, std::string::size_type from) +{ + std::string::size_type p1 = s.find ("+", from); + std::string::size_type p2 = s.find (",", from); + + if (p1 == std::string::npos) { + return p2; + } else if (p2 == std::string::npos) { + return p1; + } else { + return p1 < p2 ? p1 : p2; + } +} + +static std::vector split_file_list (const std::string &infile) +{ + std::vector files; + + size_t p = 0; + for (size_t pp = 0; (pp = find_file_sep (infile, p)) != std::string::npos; p = pp + 1) { + files.push_back (std::string (infile, p, pp - p)); + } + files.push_back (std::string (infile, p)); + + return files; +} + +void read_files (db::Layout &layout, const std::string &infile, const db::LoadLayoutOptions &options) +{ + std::vector files = split_file_list (infile); + + for (std::vector::const_iterator f = files.begin (); f != files.end (); ++f) { + tl::InputStream stream (*f); + db::Reader reader (stream); + reader.read (layout, options); + } +} + } diff --git a/src/buddies/src/bd/bdReaderOptions.h b/src/buddies/src/bd/bdReaderOptions.h index 8cd4383b4..3569fe617 100644 --- a/src/buddies/src/bd/bdReaderOptions.h +++ b/src/buddies/src/bd/bdReaderOptions.h @@ -195,6 +195,13 @@ private: tl::shared_collection m_lef_layouts; }; +/** + * @brief A function to load a sequence of files into the layout with the given options + * + * "file_path" is a "+" or "," separated list of files read "into" a single layout. + */ +BD_PUBLIC void read_files (db::Layout &layout, const std::string &infile, const db::LoadLayoutOptions &options); + } #endif diff --git a/src/buddies/src/bd/strm2txt.cc b/src/buddies/src/bd/strm2txt.cc index f1e5264ea..a8135b832 100644 --- a/src/buddies/src/bd/strm2txt.cc +++ b/src/buddies/src/bd/strm2txt.cc @@ -47,10 +47,7 @@ BD_PUBLIC int strm2txt (int argc, char *argv[]) { db::LoadLayoutOptions load_options; generic_reader_options.configure (load_options); - - tl::InputStream stream (infile); - db::Reader reader (stream); - reader.read (layout, load_options); + bd::read_files (layout, infile, load_options); } { diff --git a/src/buddies/src/bd/strmclip.cc b/src/buddies/src/bd/strmclip.cc index 72b97cce0..629042372 100644 --- a/src/buddies/src/bd/strmclip.cc +++ b/src/buddies/src/bd/strmclip.cc @@ -71,10 +71,7 @@ void clip (ClipData &data) { db::LoadLayoutOptions load_options; data.reader_options.configure (load_options); - - tl::InputStream stream (data.file_in); - db::Reader reader (stream); - reader.read (layout, load_options); + bd::read_files (layout, data.file_in, load_options); } // create the layers in the target layout as well diff --git a/src/buddies/src/bd/strmcmp.cc b/src/buddies/src/bd/strmcmp.cc index d441221c3..2e71a5505 100644 --- a/src/buddies/src/bd/strmcmp.cc +++ b/src/buddies/src/bd/strmcmp.cc @@ -142,19 +142,13 @@ BD_PUBLIC int strmcmp (int argc, char *argv[]) { db::LoadLayoutOptions load_options; generic_reader_options_a.configure (load_options); - - tl::InputStream stream (infile_a); - db::Reader reader (stream); - reader.read (layout_a, load_options); + bd::read_files (layout_a, infile_a, load_options); } { db::LoadLayoutOptions load_options; generic_reader_options_b.configure (load_options); - - tl::InputStream stream (infile_b); - db::Reader reader (stream); - reader.read (layout_b, load_options); + bd::read_files (layout_b, infile_b, load_options); } unsigned int flags = 0; diff --git a/src/buddies/src/bd/strmxor.cc b/src/buddies/src/bd/strmxor.cc index 9c20d77d2..03de6cf80 100644 --- a/src/buddies/src/bd/strmxor.cc +++ b/src/buddies/src/bd/strmxor.cc @@ -21,6 +21,7 @@ */ #include "bdReaderOptions.h" +#include "bdWriterOptions.h" #include "dbLayout.h" #include "dbTilingProcessor.h" #include "dbReader.h" @@ -327,6 +328,9 @@ BD_PUBLIC int strmxor (int argc, char *argv[]) generic_reader_options_a.add_options (cmd); generic_reader_options_b.add_options (cmd); + bd::GenericWriterOptions writer_options; + writer_options.add_options (cmd); + cmd << tl::arg ("input_a", &infile_a, "The first input file (any format, may be gzip compressed)") << tl::arg ("input_b", &infile_b, "The second input file (any format, may be gzip compressed)") << tl::arg ("?output", &output, "The output file to which the XOR differences are written", @@ -408,10 +412,7 @@ BD_PUBLIC int strmxor (int argc, char *argv[]) db::LoadLayoutOptions load_options; generic_reader_options_a.configure (load_options); - - tl::InputStream stream (infile_a); - db::Reader reader (stream); - reader.read (layout_a, load_options); + bd::read_files (layout_a, infile_a, load_options); } { @@ -419,10 +420,7 @@ BD_PUBLIC int strmxor (int argc, char *argv[]) db::LoadLayoutOptions load_options; generic_reader_options_b.configure (load_options); - - tl::InputStream stream (infile_b); - db::Reader reader (stream); - reader.read (layout_b, load_options); + bd::read_files (layout_b, infile_b, load_options); } if (top_a.empty ()) { @@ -512,6 +510,7 @@ BD_PUBLIC int strmxor (int argc, char *argv[]) db::SaveLayoutOptions save_options; save_options.set_format_from_filename (output); + writer_options.configure (save_options, *output_layout); tl::OutputStream stream (output); db::Writer writer (save_options);