summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-01-05 12:27:59 +0100
committerClifford Wolf <clifford@clifford.at>2013-01-05 12:27:59 +0100
commitbc630ba0fa249c09d4f3fb5ef48eb6d573a21879 (patch)
treeabff2016a0b4db4797d86114162a54c243402438
parente9fffd68e318e8060b3bed2a0c13333cd547cd49 (diff)
Added a:*=* syntax to select framework
-rw-r--r--kernel/select.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/kernel/select.cc b/kernel/select.cc
index 8a91f1b1..c0e0c74a 100644
--- a/kernel/select.cc
+++ b/kernel/select.cc
@@ -33,6 +33,31 @@ static bool match_ids(RTLIL::IdString id, std::string pattern)
return false;
}
+static bool match_attr_val(const RTLIL::Const &value, std::string pattern)
+{
+ if (!fnmatch(pattern.c_str(), value.str.c_str(), FNM_NOESCAPE))
+ return true;
+ return false;
+}
+
+static bool match_attr(const std::map<RTLIL::IdString, RTLIL::Const> &attributes, std::string name_pat, std::string value_pat, bool use_value_pat)
+{
+ if (name_pat.find('*') != std::string::npos || name_pat.find('?') != std::string::npos || name_pat.find('[') != std::string::npos) {
+ for (auto &it : attributes) {
+ if (!fnmatch(name_pat.c_str(), it.first.c_str(), FNM_NOESCAPE) && (!use_value_pat || match_attr_val(it.second, value_pat)))
+ return true;
+ if (it.first.size() > 0 && it.first[0] == '\\' && !fnmatch(name_pat.c_str(), it.first.substr(1).c_str(), FNM_NOESCAPE) && (!use_value_pat || match_attr_val(it.second, value_pat)))
+ return true;
+ }
+ } else {
+ if (name_pat.size() > 0 && (name_pat[0] == '\\' || name_pat[0] == '$') && attributes.count(name_pat) && (!use_value_pat || match_attr_val(attributes.at(name_pat), value_pat)))
+ return true;
+ if (attributes.count("\\" + name_pat) && (!use_value_pat || match_attr_val(attributes.at("\\" + name_pat), value_pat)))
+ return true;
+ }
+ return false;
+}
+
static void select_op_neg(RTLIL::Design *design, RTLIL::Selection &lhs)
{
if (lhs.full_selection) {
@@ -316,6 +341,28 @@ static void select_stmt(RTLIL::Design *design, std::string arg)
for (auto &it : mod->processes)
if (match_ids(it.first, arg_memb.substr(2)))
sel.selected_members[mod->name].insert(it.first);
+ } else
+ if (arg_memb.substr(0, 2) == "a:") {
+ bool use_value_pat = false;
+ std::string name_pat = arg_memb.substr(2);
+ std::string value_pat;
+ if (name_pat.find('=') != std::string::npos) {
+ value_pat = name_pat.substr(name_pat.find('=')+1);
+ name_pat = name_pat.substr(0, name_pat.find('='));
+ use_value_pat = true;
+ }
+ for (auto &it : mod->wires)
+ if (match_attr(it.second->attributes, name_pat, value_pat, use_value_pat))
+ sel.selected_members[mod->name].insert(it.first);
+ for (auto &it : mod->memories)
+ if (match_attr(it.second->attributes, name_pat, value_pat, use_value_pat))
+ sel.selected_members[mod->name].insert(it.first);
+ for (auto &it : mod->cells)
+ if (match_attr(it.second->attributes, name_pat, value_pat, use_value_pat))
+ sel.selected_members[mod->name].insert(it.first);
+ for (auto &it : mod->processes)
+ if (match_attr(it.second->attributes, name_pat, value_pat, use_value_pat))
+ sel.selected_members[mod->name].insert(it.first);
} else {
if (arg_memb.substr(0, 2) == "n:")
arg_memb = arg_memb.substr(2);