From a9e2d86f86291e82e752dab5cec796f7263ad905 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 2 Feb 2014 16:47:17 +0100 Subject: [PATCH] Added suuport for module attribute matching with A:[=] syntax --- passes/cmds/select.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/passes/cmds/select.cc b/passes/cmds/select.cc index 550545384..9c0a39650 100644 --- a/passes/cmds/select.cc +++ b/passes/cmds/select.cc @@ -48,8 +48,11 @@ static bool match_ids(RTLIL::IdString id, std::string pattern) static bool match_attr_val(const RTLIL::Const &value, std::string pattern) { - if ((value.flags & RTLIL::CONST_FLAG_STRING) == 0) - return false; + if ((value.flags & RTLIL::CONST_FLAG_STRING) == 0) { + char *endp = NULL; + long int v = strtol(pattern.c_str(), &endp, 0); + return *endp == 0 && value.as_int() == v; + } if (!fnmatch(pattern.c_str(), value.decode_string().c_str(), FNM_NOESCAPE)) return true; return false; @@ -529,7 +532,7 @@ static void select_stmt(RTLIL::Design *design, std::string arg) } else { size_t pos = arg.find('/'); if (pos == std::string::npos) { - if (arg.find(':') == std::string::npos) + if (arg.find(':') == std::string::npos || arg.substr(0, 1) == "A") arg_mod = arg; else arg_mod = "*", arg_memb = arg; @@ -550,6 +553,17 @@ static void select_stmt(RTLIL::Design *design, std::string arg) sel.full_selection = false; for (auto &mod_it : design->modules) { + if (arg_mod.substr(0, 2) == "A:") { + bool use_value_pat = false; + std::string name_pat = arg_mod.substr(2), 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; + } + if (!match_attr(mod_it.second->attributes, name_pat, value_pat, use_value_pat)) + continue; + } else if (!match_ids(mod_it.first, arg_mod)) continue; @@ -726,8 +740,11 @@ struct SelectPass : public Pass { log(" \n"); log(" select the specified object(s) from the current module\n"); log("\n"); - log("A can be a module name or wildcard expression (*, ?, [..])\n"); - log("matching module names.\n"); + log("A can be a module name, wildcard expression (*, ?, [..])\n"); + log("matching module names, or one of the following:\n"); + log("\n"); + log(" A:, A:=\n"); + log(" all modules with an attribute matching the given pattern\n"); log("\n"); log("An can be an object name, wildcard expression, or one of\n"); log("the following:\n"); -- 2.30.2