From 25bbc6effc54cb783110179c3c92defb9745aa61 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:27:35 +1300 Subject: [PATCH] rtlil: Add selection helpers New methods on Design to push/pop selection instead of accessing the selection stack directly. Includes methods for pushing a full/complete/empty selection. Also helper methods on modules to check `is_selected` and `is_selected_whole`. --- kernel/rtlil.cc | 39 +++++++++++++++++++++++++++++++++++++++ kernel/rtlil.h | 9 +++++++++ 2 files changed, 48 insertions(+) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 9ecf7c90b..3cf760de0 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -1146,6 +1146,35 @@ bool RTLIL::Design::selected_whole_module(RTLIL::Module *mod) const return selected_whole_module(mod->name); } +void RTLIL::Design::push_selection(RTLIL::Selection sel) +{ + sel.current_design = this; + selection_stack.push_back(sel); +} + +void RTLIL::Design::push_empty_selection() +{ + RTLIL::Selection sel(false, false, this); + push_selection(sel); +} + +void RTLIL::Design::push_full_selection() +{ + RTLIL::Selection sel(true, false, this); + push_selection(sel); +} + +void RTLIL::Design::push_complete_selection() +{ + RTLIL::Selection sel(true, true, this); + sel.optimize(this); + push_selection(sel); +} + +void RTLIL::Design::pop_selection() +{ + selection_stack.pop_back(); +} std::vector RTLIL::Design::selected_modules(RTLIL::SelectPartials partials, RTLIL::SelectBoxes boxes) const { @@ -2407,6 +2436,16 @@ bool RTLIL::Module::has_processes_warn() const return !processes.empty(); } +bool RTLIL::Module::is_selected() const +{ + return design->selected_module(this->name); +} + +bool RTLIL::Module::is_selected_whole() const +{ + return design->selected_whole_module(this->name); +} + std::vector RTLIL::Module::selected_wires() const { std::vector result; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 92167b19d..b89f46988 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -1239,6 +1239,12 @@ struct RTLIL::Design bool selected_module(RTLIL::Module *mod) const; bool selected_whole_module(RTLIL::Module *mod) const; + void push_selection(RTLIL::Selection sel); + void push_empty_selection(); + void push_full_selection(); + void push_complete_selection(); + void pop_selection(); + RTLIL::Selection &selection() { return selection_stack.back(); } @@ -1356,6 +1362,9 @@ public: bool has_memories_warn() const; bool has_processes_warn() const; + bool is_selected() const; + bool is_selected_whole() const; + std::vector selected_wires() const; std::vector selected_cells() const; std::vector selected_memories() const;