3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-12 17:06:15 +00:00

Add Selection::clear() method

Use method in `select.cc` to reduce code duplication.
This commit is contained in:
Krystine Sherwin 2025-04-05 10:56:01 +13:00
parent dab67f84da
commit d8a9ad6860
No known key found for this signature in database
3 changed files with 17 additions and 20 deletions

View file

@ -891,6 +891,14 @@ void RTLIL::Selection::optimize(RTLIL::Design *design)
} }
} }
void RTLIL::Selection::clear()
{
full_selection = false;
complete_selection = false;
selected_modules.clear();
selected_members.clear();
}
RTLIL::Design::Design() RTLIL::Design::Design()
: verilog_defines (new define_map_t) : verilog_defines (new define_map_t)
{ {

View file

@ -1241,6 +1241,9 @@ struct RTLIL::Selection
return !selects_all() && selected_modules.empty() && selected_members.empty(); return !selects_all() && selected_modules.empty() && selected_members.empty();
} }
// clear this selection, leaving it empty
void clear();
// create a new selection which is empty // create a new selection which is empty
static Selection EmptySelection(RTLIL::Design *design = nullptr) { return Selection(false, false, design); }; static Selection EmptySelection(RTLIL::Design *design = nullptr) { return Selection(false, false, design); };

View file

@ -159,10 +159,7 @@ static void select_all(RTLIL::Design *design, RTLIL::Selection &lhs)
static void select_op_neg(RTLIL::Design *design, RTLIL::Selection &lhs) static void select_op_neg(RTLIL::Design *design, RTLIL::Selection &lhs)
{ {
if (lhs.selects_all()) { if (lhs.selects_all()) {
lhs.full_selection = false; lhs.clear();
lhs.complete_selection = false;
lhs.selected_modules.clear();
lhs.selected_members.clear();
return; return;
} }
@ -341,9 +338,8 @@ static void select_op_union(RTLIL::Design* design, RTLIL::Selection &lhs, const
for (auto mod : new_rhs.selected_modules) for (auto mod : new_rhs.selected_modules)
lhs.selected_modules.insert(mod); lhs.selected_modules.insert(mod);
} else { } else {
lhs.clear();
lhs.full_selection = true; lhs.full_selection = true;
lhs.selected_modules.clear();
lhs.selected_members.clear();
} }
return; return;
} }
@ -361,10 +357,7 @@ static void select_op_union(RTLIL::Design* design, RTLIL::Selection &lhs, const
static void select_op_diff(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs) static void select_op_diff(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
{ {
if (rhs.complete_selection) { if (rhs.complete_selection) {
lhs.full_selection = false; lhs.clear();
lhs.complete_selection = false;
lhs.selected_modules.clear();
lhs.selected_members.clear();
return; return;
} }
@ -378,9 +371,7 @@ static void select_op_diff(RTLIL::Design *design, RTLIL::Selection &lhs, const R
lhs.selected_members.erase(mod); lhs.selected_members.erase(mod);
} }
} else { } else {
lhs.full_selection = false; lhs.clear();
lhs.selected_modules.clear();
lhs.selected_members.clear();
} }
return; return;
} }
@ -435,10 +426,7 @@ static void select_op_intersect(RTLIL::Design *design, RTLIL::Selection &lhs, co
return; return;
if (rhs.empty()) { if (rhs.empty()) {
lhs.full_selection = false; lhs.clear();
lhs.complete_selection = false;
lhs.selected_modules.clear();
lhs.selected_members.clear();
return; return;
} }
@ -680,9 +668,7 @@ static void select_filter_active_mod(RTLIL::Design *design, RTLIL::Selection &se
return; return;
if (sel.full_selection) { if (sel.full_selection) {
sel.full_selection = false; sel.clear();
sel.selected_modules.clear();
sel.selected_members.clear();
sel.selected_modules.insert(design->selected_active_module); sel.selected_modules.insert(design->selected_active_module);
return; return;
} }