proc_clean: remove any empty cases at the end of the switch.
authorwhitequark <whitequark@whitequark.org>
Sat, 22 Dec 2018 08:58:37 +0000 (08:58 +0000)
committerwhitequark <whitequark@whitequark.org>
Sat, 22 Dec 2018 09:04:46 +0000 (09:04 +0000)
Previously, only completely empty switches were removed.

passes/proc/proc_clean.cc

index b9e43d1dba9ceab514230d213d2a2e3d9573b4e3..477d1ac60c1398fdfd18ef7b7f5cfa0730a3497b 100644 (file)
@@ -77,18 +77,14 @@ void proc_clean_switch(RTLIL::SwitchRule *sw, RTLIL::CaseRule *parent, bool &did
        }
        else
        {
-               bool all_cases_are_empty = true;
                for (auto cs : sw->cases) {
-                       if (cs->actions.size() != 0 || cs->switches.size() != 0)
-                               all_cases_are_empty = false;
                        if (max_depth != 0)
                                proc_clean_case(cs, did_something, count, max_depth-1);
                }
-               if (all_cases_are_empty) {
+               while (!sw->cases.empty() && (sw->cases.back()->actions.empty() && sw->cases.back()->switches.empty())) {
                        did_something = true;
-                       for (auto cs : sw->cases)
-                               delete cs;
-                       sw->cases.clear();
+                       delete sw->cases.back();
+                       sw->cases.pop_back();
                }
        }
 }