Fix handling of range selects on loop variables, fixes #1372
authorClifford Wolf <clifford@clifford.at>
Mon, 16 Sep 2019 09:25:16 +0000 (11:25 +0200)
committerClifford Wolf <clifford@clifford.at>
Mon, 16 Sep 2019 09:25:37 +0000 (11:25 +0200)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
frontends/ast/simplify.cc

index 52fcf3ee779c65423f1e563cfcd60624f2236899..b1ee22f4215884d987c71afddc2d43dbf72b1f4e 100644 (file)
@@ -2895,8 +2895,15 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m
 void AstNode::expand_genblock(std::string index_var, std::string prefix, std::map<std::string, std::string> &name_map)
 {
        if (!index_var.empty() && type == AST_IDENTIFIER && str == index_var) {
-               current_scope[index_var]->children[0]->cloneInto(this);
-               return;
+               if (children.empty()) {
+                       current_scope[index_var]->children[0]->cloneInto(this);
+               } else {
+                       AstNode *p = new AstNode(AST_LOCALPARAM, current_scope[index_var]->children[0]->clone());
+                       p->str = stringf("$genval$%d", autoidx++);
+                       current_ast_mod->children.push_back(p);
+                       str = p->str;
+                       id2ast = p;
+               }
        }
 
        if ((type == AST_IDENTIFIER || type == AST_FCALL || type == AST_TCALL) && name_map.count(str) > 0)