Rewrite multirange arrays sizes [n] as [n-1:0]
authorLukasz Dalek <ldalek@antmicro.com>
Fri, 17 Jul 2020 11:41:09 +0000 (13:41 +0200)
committerLukasz Dalek <ldalek@antmicro.com>
Mon, 3 Aug 2020 12:48:27 +0000 (14:48 +0200)
Signed-off-by: Lukasz Dalek <ldalek@antmicro.com>
frontends/verilog/verilog_parser.y

index 63f0341d9bd645caac337d1b6b3d79f362182254..8e5236639e8cc81a0c0e6369fec2ba211d99c9f2 100644 (file)
@@ -210,14 +210,23 @@ static AstNode *checkRange(AstNode *type_node, AstNode *range_node)
        return range_node;
 }
 
-static void rewriteAsMemoryNode(AstNode *node, AstNode *rangeNode)
+static void rewriteRange(AstNode *rangeNode)
 {
-       node->type = AST_MEMORY;
        if (rangeNode->type == AST_RANGE && rangeNode->children.size() == 1) {
                // SV array size [n], rewrite as [n-1:0]
                rangeNode->children[0] = new AstNode(AST_SUB, rangeNode->children[0], AstNode::mkconst_int(1, true));
                rangeNode->children.push_back(AstNode::mkconst_int(0, false));
        }
+}
+
+static void rewriteAsMemoryNode(AstNode *node, AstNode *rangeNode)
+{
+       node->type = AST_MEMORY;
+       if (rangeNode->type == AST_MULTIRANGE) {
+               for (auto *itr : rangeNode->children)
+                       rewriteRange(itr);
+       } else
+               rewriteRange(rangeNode);
        node->children.push_back(rangeNode);
 }