aboutsummaryrefslogtreecommitdiffstats
path: root/frontends/ast
diff options
context:
space:
mode:
authorZachary Snow <zach@zachjs.com>2021-03-04 14:07:56 -0500
committerZachary Snow <zachary.j.snow@gmail.com>2021-03-16 11:01:30 -0400
commit4f187d53c5a0580275857ec308b41f57808ec727 (patch)
tree296bfc0f1f7fdffbb9c2fedd3a91d92a1677cbfd /frontends/ast
parent3d9698153fc7f01cef0dec99cc834ffecec766a5 (diff)
downloadyosys-4f187d53c5a0580275857ec308b41f57808ec727.tar.gz
yosys-4f187d53c5a0580275857ec308b41f57808ec727.tar.bz2
yosys-4f187d53c5a0580275857ec308b41f57808ec727.zip
verilog: support module scope identifiers in parametric modules
Diffstat (limited to 'frontends/ast')
-rw-r--r--frontends/ast/simplify.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index d68b13b2a..d9eae3a06 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -1691,11 +1691,15 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
if (type == AST_IDENTIFIER) {
if (current_scope.count(str) == 0) {
AstNode *current_scope_ast = (current_ast_mod == nullptr) ? current_ast : current_ast_mod;
- const std::string& mod_scope = current_scope_ast->str;
- if (str[0] == '\\' && str.substr(0, mod_scope.size()) == mod_scope) {
- std::string new_str = "\\" + str.substr(mod_scope.size() + 1);
+ size_t pos = str.find('.', 1);
+ if (str[0] == '\\' && pos != std::string::npos) {
+ std::string new_str = "\\" + str.substr(pos + 1);
if (current_scope.count(new_str)) {
- str = new_str;
+ std::string prefix = str.substr(0, pos);
+ auto it = current_scope_ast->attributes.find(ID::hdlname);
+ if ((it != current_scope_ast->attributes.end() && it->second->str == prefix)
+ || prefix == current_scope_ast->str)
+ str = new_str;
}
}
for (auto node : current_scope_ast->children) {