passes/hierarchy: Reduce code duplication in expand_module
authorSergi Granell <xerpi.g.12@gmail.com>
Tue, 27 Mar 2018 07:35:20 +0000 (09:35 +0200)
committerSergi Granell <xerpi.g.12@gmail.com>
Tue, 27 Mar 2018 07:35:20 +0000 (09:35 +0200)
This also makes it easier to add new file extensions support.

Signed-off-by: Sergi Granell <xerpi.g.12@gmail.com>
passes/hierarchy/hierarchy.cc

index 71b0cf6227da32d5ea2bc13bfd0326188142184d..21a232572e2d9453a2d2630e35a9998d334ebca8 100644 (file)
@@ -173,22 +173,20 @@ bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check
 
                        for (auto &dir : libdirs)
                        {
-                               filename = dir + "/" + RTLIL::unescape_id(cell->type) + ".v";
-                               if (check_file_exists(filename)) {
-                                       Frontend::frontend_call(design, NULL, filename, "verilog");
-                                       goto loaded_module;
-                               }
-
-                               filename = dir + "/" + RTLIL::unescape_id(cell->type) + ".sv";
-                               if (check_file_exists(filename)) {
-                                       Frontend::frontend_call(design, NULL, filename, "verilog -sv");
-                                       goto loaded_module;
-                               }
+                               static const std::map<std::string, std::string> extensions_map =
+                               {
+                                       {".v", "verilog"},
+                                       {".sv", "verilog -sv"},
+                                       {".il", "ilang"}
+                               };
 
-                               filename = dir + "/" + RTLIL::unescape_id(cell->type) + ".il";
-                               if (check_file_exists(filename)) {
-                                       Frontend::frontend_call(design, NULL, filename, "ilang");
-                                       goto loaded_module;
+                               for (auto &ext : extensions_map)
+                               {
+                                       filename = dir + "/" + RTLIL::unescape_id(cell->type) + ext.first;
+                                       if (check_file_exists(filename)) {
+                                               Frontend::frontend_call(design, NULL, filename, ext.second);
+                                               goto loaded_module;
+                                       }
                                }
                        }