3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-24 01:25:33 +00:00

Add Selection::complete_selection

Used to select all modules including boxes, set when both `full` and `boxes` are true in the constructor, pulling down `full_selection`.
Add `Selection::selects_all()` method as short hand for `full_selection || complete_selection`.
Update selection operations to account for complete selections.
Add static methods to `Selection` for creating a new empty/full/complete selection to make it clearer to users when doing so.
Use said static methods to replace most instances of the `Selection` constructor.
Update `Selection::optimize` to use
This commit is contained in:
Krystine Sherwin 2025-03-14 14:08:15 +13:00
parent 9a9cd05f6c
commit a30bacfcb1
No known key found for this signature in database
6 changed files with 86 additions and 53 deletions

View file

@ -779,6 +779,8 @@ bool RTLIL::Selection::boxed_module(const RTLIL::IdString &mod_name) const
bool RTLIL::Selection::selected_module(const RTLIL::IdString &mod_name) const
{
if (complete_selection)
return true;
if (!selects_boxes && boxed_module(mod_name))
return false;
if (full_selection)
@ -792,6 +794,8 @@ bool RTLIL::Selection::selected_module(const RTLIL::IdString &mod_name) const
bool RTLIL::Selection::selected_whole_module(const RTLIL::IdString &mod_name) const
{
if (complete_selection)
return true;
if (!selects_boxes && boxed_module(mod_name))
return false;
if (full_selection)
@ -803,6 +807,8 @@ bool RTLIL::Selection::selected_whole_module(const RTLIL::IdString &mod_name) co
bool RTLIL::Selection::selected_member(const RTLIL::IdString &mod_name, const RTLIL::IdString &memb_name) const
{
if (complete_selection)
return true;
if (!selects_boxes && boxed_module(mod_name))
return false;
if (full_selection)
@ -821,16 +827,13 @@ void RTLIL::Selection::optimize(RTLIL::Design *design)
current_design = design;
}
if (selects_boxes && full_selection) {
selected_modules.clear();
selected_members.clear();
if (selects_boxes && full_selection)
complete_selection = true;
if (complete_selection) {
full_selection = false;
for (auto mod : current_design->modules()) {
selected_modules.insert(mod->name);
}
return;
selects_boxes = true;
}
if (full_selection) {
if (selects_all()) {
selected_modules.clear();
selected_members.clear();
return;
@ -878,10 +881,13 @@ void RTLIL::Selection::optimize(RTLIL::Design *design)
selected_modules.insert(mod_name);
}
if (!selects_boxes && selected_modules.size() == current_design->modules_.size()) {
full_selection = true;
if (selected_modules.size() == current_design->modules_.size()) {
selected_modules.clear();
selected_members.clear();
if (selects_boxes)
complete_selection = true;
else
full_selection = true;
}
}
@ -1160,21 +1166,17 @@ void RTLIL::Design::push_selection(RTLIL::Selection sel)
void RTLIL::Design::push_empty_selection()
{
RTLIL::Selection sel(false, false, this);
push_selection(sel);
push_selection(RTLIL::Selection::EmptySelection(this));
}
void RTLIL::Design::push_full_selection()
{
RTLIL::Selection sel(true, false, this);
push_selection(sel);
push_selection(RTLIL::Selection::FullSelection(this));
}
void RTLIL::Design::push_complete_selection()
{
RTLIL::Selection sel(true, true, this);
sel.optimize(this);
push_selection(sel);
push_selection(RTLIL::Selection::CompleteSelection(this));
}
void RTLIL::Design::pop_selection()

View file

@ -1166,11 +1166,13 @@ struct RTLIL::Selection
{
bool full_selection;
bool selects_boxes;
bool complete_selection;
pool<RTLIL::IdString> selected_modules;
dict<RTLIL::IdString, pool<RTLIL::IdString>> selected_members;
RTLIL::Design *current_design;
Selection(bool full = true, bool boxes = false, RTLIL::Design *design = nullptr) : full_selection(full), selects_boxes(boxes), current_design(design) { }
Selection(bool full = true, bool boxes = false, RTLIL::Design *design = nullptr) :
full_selection(full && !boxes), selects_boxes(boxes), complete_selection(full && boxes), current_design(design) { }
bool boxed_module(const RTLIL::IdString &mod_name) const;
bool selected_module(const RTLIL::IdString &mod_name) const;
@ -1178,21 +1180,29 @@ struct RTLIL::Selection
bool selected_member(const RTLIL::IdString &mod_name, const RTLIL::IdString &memb_name) const;
void optimize(RTLIL::Design *design);
bool selects_all() const {
return full_selection || complete_selection;
}
template<typename T1> void select(T1 *module) {
if (!full_selection && selected_modules.count(module->name) == 0) {
if (!selects_all() && selected_modules.count(module->name) == 0) {
selected_modules.insert(module->name);
selected_members.erase(module->name);
}
}
template<typename T1, typename T2> void select(T1 *module, T2 *member) {
if (!full_selection && selected_modules.count(module->name) == 0)
if (!selects_all() && selected_modules.count(module->name) == 0)
selected_members[module->name].insert(member->name);
}
bool empty() const {
return !full_selection && selected_modules.empty() && selected_members.empty();
return !selects_all() && selected_modules.empty() && selected_members.empty();
}
static Selection EmptySelection(RTLIL::Design *design = nullptr) { return Selection(false, false, design); };
static Selection FullSelection(RTLIL::Design *design = nullptr) { return Selection(true, false, design); };
static Selection CompleteSelection(RTLIL::Design *design = nullptr) { return Selection(true, true, design); };
};
struct RTLIL::Monitor
@ -1282,8 +1292,8 @@ struct RTLIL::Design
void push_selection(RTLIL::Selection sel);
void push_empty_selection();
void push_full_selection();
void push_complete_selection();
void push_full_selection(); // all modules excluding boxes
void push_complete_selection(); // all modules including boxes
void pop_selection();
RTLIL::Selection &selection() {