diff --git a/cli/cmd/io/read.hpp b/cli/cmd/io/read.hpp index b7b655c4d..40af5d29d 100644 --- a/cli/cmd/io/read.hpp +++ b/cli/cmd/io/read.hpp @@ -44,7 +44,9 @@ class read_command : public command "In a directory, only files with extension '.v', '.aig', '.blif' are considered.") { add_option("filename", filename, "Filename or directory")->required(); - add_option("topology", topology, "Topology for gate-level layouts"); + add_option("topology", topology, + "Topology for gate-level layouts. Can be 'cartesian' or of the form " + "'__"); add_flag("--aig,-a", "Parse file as AIG"); add_flag("--xag,-x", "Parse file as XAG"); add_flag("--mig,-m", "Parse file as MIG"); @@ -112,130 +114,127 @@ class read_command : public command store_ntks(reader); } - if (is_set("fgl")) + if (is_set("fgl") || is_set("qca")) { - if (!topology.empty()) + if (std::filesystem::exists(filename)) { - if (std::filesystem::exists(filename)) + if (std::filesystem::is_regular_file(filename)) { - if (std::filesystem::is_regular_file(filename)) + if (is_set("fgl")) { - try + if (!topology.empty()) { - if (topology == "cartesian") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); - } - else if (topology == "odd_row_cartesian") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); - } - else if (topology == "even_row_cartesian") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout( - filename)); - } - else if (topology == "odd_column_cartesian") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); - } - else if (topology == "even_column_cartesian") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout( - filename)); - } - else if (topology == "odd_row_hex") + try { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); + if (topology == "cartesian") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout(filename)); + } + else if (topology == "odd_row_cartesian") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "even_row_cartesian") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "odd_column_cartesian") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "even_column_cartesian") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "odd_row_hex") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "even_row_hex") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "odd_column_hex") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else if (topology == "even_column_hex") + { + store().extend() = + std::make_shared( + fiction::read_fgl_layout( + filename)); + } + else + { + env->out() << fmt::format("[e] given topology does not exist: {}", topology) + << std::endl; + } } - else if (topology == "even_row_hex") + catch (const fiction::fgl_parsing_error& e) { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); - } - else if (topology == "odd_column_hex") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); - } - else if (topology == "even_column_hex") - { - store().extend() = - std::make_shared( - fiction::read_fgl_layout(filename)); - } - else - { - env->out() << fmt::format("[e] given topology does not exist: {}", topology) - << std::endl; + env->out() << e.what() << std::endl; } } - catch (const fiction::fgl_parsing_error& e) + else { - env->out() << e.what() << std::endl; + env->out() << "[e] for reading gate-level layouts, the topology has to be set" + << std::endl; } } - else - { - env->out() << "[e] given file name does not point to a regular file" << std::endl; - } - } - else - { - env->out() << "[e] given file name does not exist" << std::endl; - } - } - else - { - env->out() << "[e] for reading gate-level layouts, the topology has to be set" << std::endl; - } - } - if (is_set("qca")) - { - if (std::filesystem::exists(filename)) - { - if (std::filesystem::is_regular_file(filename)) - { - try + if (is_set("qca")) { - const auto layout_name = std::filesystem::path{filename}.stem().string(); + try + { + const auto layout_name = std::filesystem::path{filename}.stem().string(); - store().extend() = - std::make_shared( - fiction::read_fqca_layout(filename, - layout_name)); - } - catch (const fiction::unsupported_character_exception& e) - { - env->out() - << fmt::format("character '{}' is not supported as a cell designator", e.which()) - << std::endl; - } - catch (const fiction::undefined_cell_label_exception& e) - { - env->out() << fmt::format("cell label '{}' was used in the cell definition section but " - "never defined above", - e.which()) - << std::endl; - } - catch (const fiction::unrecognized_cell_definition_exception& e) - { - env->out() - << fmt::format("unsupported cell definition in line {}", e.where()) << std::endl; + store().extend() = + std::make_shared( + fiction::read_fqca_layout(filename, + layout_name)); + } + catch (const fiction::unsupported_character_exception& e) + { + env->out() << fmt::format("character '{}' is not supported as a cell designator", + e.which()) + << std::endl; + } + catch (const fiction::undefined_cell_label_exception& e) + { + env->out() + << fmt::format("cell label '{}' was used in the cell definition section but " + "never defined above", + e.which()) + << std::endl; + } + catch (const fiction::unrecognized_cell_definition_exception& e) + { + env->out() << fmt::format("unsupported cell definition in line {}", e.where()) + << std::endl; + } } } else diff --git a/include/fiction/io/read_fgl_layout.hpp b/include/fiction/io/read_fgl_layout.hpp index 0a7668084..6f540eac4 100644 --- a/include/fiction/io/read_fgl_layout.hpp +++ b/include/fiction/io/read_fgl_layout.hpp @@ -27,9 +27,6 @@ #include #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" - namespace fiction { @@ -114,8 +111,8 @@ class read_fgl_layout_impl throw fgl_parsing_error("Error parsing FGL file: Lyt is not a cartesian layout"); } } - else if (std::find(shifted_cartesian.begin(), shifted_cartesian.end(), topology_name) != - shifted_cartesian.end()) + else if (std::find(shifted_cartesian.cbegin(), shifted_cartesian.cend(), topology_name) != + shifted_cartesian.cend()) { if constexpr (is_shifted_cartesian_layout_v) { @@ -155,7 +152,7 @@ class read_fgl_layout_impl throw fgl_parsing_error("Error parsing FGL file: Lyt is not a shifted_cartesian layout"); } } - else if (std::find(hex.begin(), hex.end(), topology_name) != hex.end()) + else if (std::find(hex.cbegin(), hex.cend(), topology_name) != hex.cend()) { if constexpr (is_hexagonal_layout_v) { @@ -303,9 +300,9 @@ class read_fgl_layout_impl lyt.assign_clock_number({x_coord, y_coord}, clock); } } - else if (std::find(std::begin(open_clocking_schemes), std::end(open_clocking_schemes), + else if (std::find(open_clocking_schemes.cbegin(), open_clocking_schemes.cend(), static_cast(clocking_scheme_name->GetText())) != - open_clocking_schemes.end()) + open_clocking_schemes.cend()) { throw fgl_parsing_error("Error parsing FGL file: no element 'zones' in 'clocking'"); } @@ -375,6 +372,8 @@ class read_fgl_layout_impl throw fgl_parsing_error("Error parsing FGL file: no element 'loc'"); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" // get x-coordinate auto* const loc_x = loc->FirstChildElement("x"); if (loc_x != nullptr && loc_x->GetText()) @@ -452,6 +451,7 @@ class read_fgl_layout_impl gate.incoming.push_back(incoming); } } +#pragma GCC diagnostic pop gates.push_back(gate); } @@ -714,7 +714,7 @@ class read_fgl_layout_impl /** * Reads a gate-level layout from an FGL file provided as an input stream. * - * May throw a `fgl_parsing_exception` if the FGL file is malformed. + * May throw an `fgl_parsing_exception` if the FGL file is malformed. * * @tparam Lyt The layout type to be created from an input. * @param is The input stream to read from. @@ -723,9 +723,6 @@ class read_fgl_layout_impl template [[nodiscard]] Lyt read_fgl_layout(std::istream& is, const std::string_view& name = "") { - static_assert(is_coordinate_layout_v, "Lyt is not a coordinate layout"); - static_assert(is_tile_based_layout_v, "Lyt is not a tile-based layout"); - static_assert(is_clocked_layout_v, "Lyt is not a clocked layout"); static_assert(is_gate_level_layout_v, "Lyt is not a gate-level layout"); detail::read_fgl_layout_impl p{is, name}; @@ -737,7 +734,7 @@ template /** * Reads a gate-level layout from an FGL file provided as an input stream. * - * May throw a `fgl_parsing_exception` if the FGL file is malformed. + * May throw an `fgl_parsing_exception` if the FGL file is malformed. * * This is an in-place version of read_fgl_layout that utilizes the given layout as a target to write to. * @@ -748,9 +745,6 @@ template template void read_fgl_layout(Lyt& lyt, std::istream& is) { - static_assert(is_coordinate_layout_v, "Lyt is not a coordinate layout"); - static_assert(is_tile_based_layout_v, "Lyt is not a tile-based layout"); - static_assert(is_clocked_layout_v, "Lyt is not a clocked layout"); static_assert(is_gate_level_layout_v, "Lyt is not a gate-level layout"); detail::read_fgl_layout_impl p{lyt, is}; @@ -760,7 +754,7 @@ void read_fgl_layout(Lyt& lyt, std::istream& is) /** * Reads a gate-level layout from an FGL file provided as an input stream. * - * May throw a `fgl_parsing_exception` if the FGL file is malformed. + * May throw an `fgl_parsing_exception` if the FGL file is malformed. * * @tparam Lyt The layout type to be created from an input. * @param filename The file name to open and read from. @@ -784,7 +778,7 @@ template /** * Reads a gate-level layout from an FGL file provided as an input stream. * - * May throw a `fgl_parsing_exception` if the FGL file is malformed. + * May throw an `fgl_parsing_exception` if the FGL file is malformed. * * This is an in-place version of `read_fgl_layout` that utilizes the given layout as a target to write to. * @@ -807,6 +801,5 @@ void read_fgl_layout(Lyt& lyt, const std::string_view& filename) } } // namespace fiction -#pragma GCC diagnostic pop #endif // FICTION_READ_FGL_LAYOUT_HPP diff --git a/include/fiction/io/write_fgl_layout.hpp b/include/fiction/io/write_fgl_layout.hpp index 4869e7cdc..ba93260c7 100644 --- a/include/fiction/io/write_fgl_layout.hpp +++ b/include/fiction/io/write_fgl_layout.hpp @@ -23,8 +23,6 @@ #include #include #include -#include -#include namespace fiction { @@ -328,9 +326,6 @@ class write_fgl_layout_impl template void write_fgl_layout(const Lyt& lyt, std::ostream& os) { - static_assert(is_coordinate_layout_v, "Lyt is not a coordinate layout"); - static_assert(is_tile_based_layout_v, "Lyt is not a tile-based layout"); - static_assert(is_clocked_layout_v, "Lyt is not a clocked layout"); static_assert(is_gate_level_layout_v, "Lyt is not a gate-level layout"); detail::write_fgl_layout_impl p{lyt, os}; diff --git a/test/io/read_fgl_layout.cpp b/test/io/read_fgl_layout.cpp index bfa787a22..cb6e30f6b 100644 --- a/test/io/read_fgl_layout.cpp +++ b/test/io/read_fgl_layout.cpp @@ -1775,4 +1775,4 @@ TEST_CASE("Parsing error: no element 'z' in 'signal'", "[read-fgl-layout]") using gate_layout = gate_level_layout>>>; CHECK_THROWS_AS(read_fgl_layout(layout_stream), fgl_parsing_error); -} \ No newline at end of file +}