From 8b8af10f5e612eb1a39320e20b2d1d6f1e7d45df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20W=C3=B6lfel?= Date: Wed, 19 Jun 2019 12:47:48 +0200 Subject: Unpacked array declaration using size Allows fixed-sized array dimension specified by a single number. This commit is based on the work from PeterCrozier https://github.com/YosysHQ/yosys/pull/560. But is split out of the original work. --- frontends/verilog/verilog_parser.y | 8 +++++++- tests/various/unpacked_arrays.sv | 4 ++++ tests/various/unpacked_arrays.ys | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/various/unpacked_arrays.sv create mode 100644 tests/various/unpacked_arrays.ys diff --git a/frontends/verilog/verilog_parser.y b/frontends/verilog/verilog_parser.y index a034f9601..f77321f09 100644 --- a/frontends/verilog/verilog_parser.y +++ b/frontends/verilog/verilog_parser.y @@ -1385,7 +1385,13 @@ wire_name: node->children.push_back(rng); } node->type = AST_MEMORY; - node->children.push_back($2); + auto *rangeNode = $2; + 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)); + } + node->children.push_back(rangeNode); } if (current_function_or_task == NULL) { if (do_not_require_port_stubs && (node->is_input || node->is_output) && port_stubs.count(*$1) == 0) { diff --git a/tests/various/unpacked_arrays.sv b/tests/various/unpacked_arrays.sv new file mode 100644 index 000000000..2f4ed0d3f --- /dev/null +++ b/tests/various/unpacked_arrays.sv @@ -0,0 +1,4 @@ +module unpacked_arrays; + reg array_range [0:7]; + reg array_size [8]; +endmodule diff --git a/tests/various/unpacked_arrays.ys b/tests/various/unpacked_arrays.ys new file mode 100644 index 000000000..419152d9c --- /dev/null +++ b/tests/various/unpacked_arrays.ys @@ -0,0 +1,2 @@ +read_verilog -sv unpacked_arrays.sv +stat -- cgit v1.2.3 From 6a6dd5e0575950174e3abde7a13a3e3be73e5299 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 20 Jun 2019 12:06:07 +0200 Subject: Add proper test for SV-style arrays Signed-off-by: Clifford Wolf --- tests/simple/arrays02.sv | 16 ++++++++++++++++ tests/various/unpacked_arrays.sv | 4 ---- tests/various/unpacked_arrays.ys | 2 -- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 tests/simple/arrays02.sv delete mode 100644 tests/various/unpacked_arrays.sv delete mode 100644 tests/various/unpacked_arrays.ys diff --git a/tests/simple/arrays02.sv b/tests/simple/arrays02.sv new file mode 100644 index 000000000..76c2a7388 --- /dev/null +++ b/tests/simple/arrays02.sv @@ -0,0 +1,16 @@ +module uut_arrays02(clock, we, addr, wr_data, rd_data); + +input clock, we; +input [3:0] addr, wr_data; +output [3:0] rd_data; +reg [3:0] rd_data; + +reg [3:0] memory [16]; + +always @(posedge clock) begin + if (we) + memory[addr] <= wr_data; + rd_data <= memory[addr]; +end + +endmodule diff --git a/tests/various/unpacked_arrays.sv b/tests/various/unpacked_arrays.sv deleted file mode 100644 index 2f4ed0d3f..000000000 --- a/tests/various/unpacked_arrays.sv +++ /dev/null @@ -1,4 +0,0 @@ -module unpacked_arrays; - reg array_range [0:7]; - reg array_size [8]; -endmodule diff --git a/tests/various/unpacked_arrays.ys b/tests/various/unpacked_arrays.ys deleted file mode 100644 index 419152d9c..000000000 --- a/tests/various/unpacked_arrays.ys +++ /dev/null @@ -1,2 +0,0 @@ -read_verilog -sv unpacked_arrays.sv -stat -- cgit v1.2.3