From c18cbca8136d52bb96160d0cd1e4d0db1ca8d640 Mon Sep 17 00:00:00 2001 From: James Hanlon Date: Thu, 17 Dec 2020 16:26:53 +0000 Subject: [PATCH] Add support for package imports preceeding parameters in interfaces (#2714) Co-authored-by: James Hanlon --- src/verilog.y | 2 +- test_regress/t/t_interface_import_param.pl | 21 ++++++++++ test_regress/t/t_interface_import_param.v | 47 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 test_regress/t/t_interface_import_param.pl create mode 100644 test_regress/t/t_interface_import_param.v diff --git a/src/verilog.y b/src/verilog.y index ea9b10d96..2dfacd20d 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1403,7 +1403,7 @@ portSig: interface_declaration: // IEEE: interface_declaration + interface_nonansi_header + interface_ansi_header: // // timeunits_delcarationE is instead in interface_item - intFront parameter_port_listE portsStarE ';' + intFront importsAndParametersE portsStarE ';' interface_itemListE yENDINTERFACE endLabelE { if ($2) $1->addStmtp($2); if ($3) $1->addStmtp($3); diff --git a/test_regress/t/t_interface_import_param.pl b/test_regress/t/t_interface_import_param.pl new file mode 100755 index 000000000..b46d46042 --- /dev/null +++ b/test_regress/t/t_interface_import_param.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + ); + +execute( + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_interface_import_param.v b/test_regress/t/t_interface_import_param.v new file mode 100644 index 000000000..82969649d --- /dev/null +++ b/test_regress/t/t_interface_import_param.v @@ -0,0 +1,47 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// A test that a package import declaration can preceed a parameter port list +// in an interface declaration. See 25.3 of the 1800-2017 LRM. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2013 by Jeremy Bennett. +// SPDX-License-Identifier: CC0-1.0 + +package bus_pkg; + parameter WIDTH = 8; +endpackage + +interface simple_bus + import bus_pkg::*; // Import preceding parameters. + #(p_width = WIDTH) + (input logic clk); + + logic req, gnt; + logic [p_width-1:0] addr; + logic [p_width-1:0] data; + + modport slave(input req, addr, clk, + output gnt, + input data); + + modport master(input gnt, clk, + output req, addr, + output data); + +endinterface + +module mem(simple_bus a); + logic avail; + always @(posedge a.clk) + a.gnt <= a.req & avail; + initial begin + if ($bits(a.data) != 8) $stop; + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule + +module t (input clk); + simple_bus sb(clk); + mem mem(sb.slave); +endmodule