IEEE 1800 §23.2.2.2 allows an ANSI header's first port to carry no
direction — the normal spelling for interface ports — but
parse_port_list classified any leading identifier as a non-ANSI list
and errored on what followed. One clause fixes it: a leading Ident is
ANSI when the parser's existing type-then-name lookahead
(at_typed_declarator, which already walks pkg:: chains, #() overrides
and packed dims) or the new 4-token modport lookahead (ident.ident
ident) says so; the complement is exactly the old non-ANSI list, and
macro-led lists never enter the clause. bus_if.mp was a second,
independent gap (it parsed in no position before) and is glued into
DataType::name the way pkg::t already was. No AST change — the new
ports are AnsiPort { dir: None }, the shape later ports always had.
Two match-widenings ride along: bind_data_type and type_def's
type_span read the pre-dot half as the type, and the modport half is
bindable by nothing — pinned for rename by QA.
The safety case, established twice (dev, then QA independently via a
worktree build): corpus 813/820 both sides, TSVs byte-identical, and
all 820 formatted outputs SHA-256-identical across the change; zero
snapshot churn; verify.rs untouched. QA's boundary AST-diff harness
(~20 shapes at the classification edge) and a 50-file
direction-stripping fuzz sweep found no misfire. The
previously-blocked fixtures flipped to first-port order; instantiate
now plans interface-typed port lists instead of refusing. The two
remaining unsupported shapes (generic interface ports, virtual
modport declarations) are pinned by a lead-added test so a future
round changes them on purpose.
24 tests added (dev 21 + QA 2 + lead 1).
docs/features/ansi-first-port/README.md
Co-Authored-By: Claude Fable 5 <[email protected]>
246 lines
5.4 KiB
Plaintext
246 lines
5.4 KiB
Plaintext
# empty module, no port list
|
|
module m;endmodule
|
|
----
|
|
module m;
|
|
endmodule
|
|
====
|
|
# empty parenthesized port list
|
|
module m ( ) ;
|
|
endmodule
|
|
----
|
|
module m ();
|
|
endmodule
|
|
====
|
|
# ANSI ports fit on one line
|
|
module m(input a,output b);endmodule
|
|
----
|
|
module m (input a, output b);
|
|
endmodule
|
|
====
|
|
# ANSI ports with directions and types
|
|
module m(input wire clk,input wire rst_n,output logic [7:0] q);endmodule
|
|
----
|
|
module m (input wire clk, input wire rst_n, output logic [7:0] q);
|
|
endmodule
|
|
====
|
|
# non-ANSI header: names in the port list, declarations in the body
|
|
module m(a,b,c);
|
|
input a;
|
|
input [3:0] b;
|
|
output reg c;
|
|
endmodule
|
|
----
|
|
module m (a, b, c);
|
|
input a;
|
|
input [3:0] b;
|
|
output reg c;
|
|
endmodule
|
|
====
|
|
# port list too wide for 100 columns breaks one per line
|
|
module wide_module_name(input wire clock_signal_in,input wire reset_signal_in,input wire [31:0] data_word_in,output wire [31:0] data_word_out);endmodule
|
|
----
|
|
module wide_module_name (
|
|
input wire clock_signal_in,
|
|
input wire reset_signal_in,
|
|
input wire [31:0] data_word_in,
|
|
output wire [31:0] data_word_out
|
|
);
|
|
endmodule
|
|
====
|
|
# parameter port list, single parameter
|
|
module m#(parameter WIDTH=8)(input [WIDTH-1:0] d);endmodule
|
|
----
|
|
module m #(parameter WIDTH = 8) (input [WIDTH-1:0] d);
|
|
endmodule
|
|
====
|
|
# parameter port list with types
|
|
module m #(parameter int WIDTH = 8, parameter type T = logic) (input T d);endmodule
|
|
----
|
|
module m #(parameter int WIDTH = 8, parameter type T = logic) (input T d);
|
|
endmodule
|
|
====
|
|
# parameter port list too wide breaks
|
|
module m #(parameter int DATA_WIDTH_IN_BITS = 32, parameter int ADDRESS_WIDTH_IN_BITS = 24, parameter int NUMBER_OF_BANKS = 4) ();endmodule
|
|
----
|
|
module m #(
|
|
parameter int DATA_WIDTH_IN_BITS = 32,
|
|
parameter int ADDRESS_WIDTH_IN_BITS = 24,
|
|
parameter int NUMBER_OF_BANKS = 4
|
|
) ();
|
|
endmodule
|
|
====
|
|
# localparam-style parameter without the keyword repeated
|
|
module m #(WIDTH = 8, DEPTH = 16) ();endmodule
|
|
----
|
|
module m #(WIDTH = 8, DEPTH = 16) ();
|
|
endmodule
|
|
====
|
|
# inout and multi-name ports
|
|
module m(input a,b,inout wire io,output c);endmodule
|
|
----
|
|
module m (input a, b, inout wire io, output c);
|
|
endmodule
|
|
====
|
|
# unpacked and packed dimensions on ports
|
|
module m(input logic [7:0] mem [0:3], output logic [3:0][7:0] q);endmodule
|
|
----
|
|
module m (input logic [7:0] mem [0:3], output logic [3:0][7:0] q);
|
|
endmodule
|
|
====
|
|
# module with default port values in the parameter list
|
|
module m #(parameter WIDTH = 8) (input [WIDTH-1:0] a, output [WIDTH-1:0] y);
|
|
assign y=a;
|
|
endmodule
|
|
----
|
|
module m #(parameter WIDTH = 8) (input [WIDTH-1:0] a, output [WIDTH-1:0] y);
|
|
assign y = a;
|
|
endmodule
|
|
====
|
|
# two modules separated by blank lines, collapsed to one
|
|
module a;endmodule
|
|
|
|
|
|
|
|
module b;endmodule
|
|
----
|
|
module a;
|
|
endmodule
|
|
|
|
module b;
|
|
endmodule
|
|
====
|
|
# package with a parameter and a typedef
|
|
package pkg;
|
|
parameter int N=4;
|
|
typedef logic [7:0] byte_t;
|
|
endpackage
|
|
----
|
|
package pkg;
|
|
parameter int N = 4;
|
|
typedef logic [7:0] byte_t;
|
|
endpackage
|
|
====
|
|
# import and timeunit inside a module
|
|
module m;
|
|
import pkg::*;
|
|
timeunit 1ns/1ps;
|
|
endmodule
|
|
----
|
|
module m;
|
|
import pkg::*;
|
|
timeunit 1ns / 1ps;
|
|
endmodule
|
|
====
|
|
# module with a lifetime-free body and trailing endmodule label
|
|
module m;
|
|
endmodule : m
|
|
----
|
|
module m;
|
|
endmodule : m
|
|
====
|
|
# closing label on endpackage
|
|
package p;
|
|
localparam int W = 8;
|
|
endpackage : p
|
|
----
|
|
package p;
|
|
localparam int W = 8;
|
|
endpackage : p
|
|
====
|
|
# two header imports stay two statements (never merged into one)
|
|
module prim_alert_rxtx_tb
|
|
import prim_alert_pkg::*;
|
|
import prim_mubi_pkg::mubi4_t;
|
|
(
|
|
input clk_i,
|
|
output logic done_o
|
|
);
|
|
endmodule
|
|
----
|
|
module prim_alert_rxtx_tb
|
|
import prim_alert_pkg::*;
|
|
import prim_mubi_pkg::mubi4_t;
|
|
(input clk_i, output logic done_o);
|
|
endmodule
|
|
====
|
|
# a single header import with several paths keeps its one statement
|
|
module m
|
|
import a::*, b::t;
|
|
(
|
|
input clk_i
|
|
);
|
|
endmodule
|
|
----
|
|
module m
|
|
import a::*, b::t;
|
|
(input clk_i);
|
|
endmodule
|
|
====
|
|
# three header imports before a parameter list
|
|
module m
|
|
import a::*;
|
|
import b::t;
|
|
import c::u;
|
|
#(
|
|
parameter int W = 8
|
|
) (
|
|
input clk_i
|
|
);
|
|
endmodule
|
|
----
|
|
module m
|
|
import a::*;
|
|
import b::t;
|
|
import c::u;
|
|
#(parameter int W = 8) (input clk_i);
|
|
endmodule
|
|
====
|
|
# a direction-less first ANSI port: the normal spelling of an interface port
|
|
module m(bus_if bus,input logic clk);endmodule
|
|
----
|
|
module m (bus_if bus, input logic clk);
|
|
endmodule
|
|
====
|
|
# the same port with a modport, and alone in the list
|
|
module m( bus_if.mp bus );endmodule
|
|
----
|
|
module m (bus_if.mp bus);
|
|
endmodule
|
|
====
|
|
# a package-scoped type as the first port
|
|
module m(my_pkg::state_t s,output logic q);endmodule
|
|
----
|
|
module m (my_pkg::state_t s, output logic q);
|
|
endmodule
|
|
====
|
|
# an interface header takes the same list
|
|
interface i(bus_if.mp bus,input logic clk);endinterface
|
|
----
|
|
interface i (bus_if.mp bus, input logic clk);
|
|
endinterface
|
|
====
|
|
# a typed first port with packed dimensions and a parameterized one
|
|
module m(word_t [3:0] d,item #(A, B) req,input a);endmodule
|
|
----
|
|
module m (word_t [3:0] d, item #(A, B) req, input a);
|
|
endmodule
|
|
====
|
|
# a direction-less first port in a list too wide for one line
|
|
module wide_module_name_here(bus_if.mp bus_interface_port,my_pkg::state_t current_state_in,input logic clock_signal,output logic [31:0] result_word_out);endmodule
|
|
----
|
|
module wide_module_name_here (
|
|
bus_if.mp bus_interface_port,
|
|
my_pkg::state_t current_state_in,
|
|
input logic clock_signal,
|
|
output logic [31:0] result_word_out
|
|
);
|
|
endmodule
|
|
====
|
|
# a name-only non-ANSI list is untouched by the disambiguation
|
|
module m(a,b);input a;output b;endmodule
|
|
----
|
|
module m (a, b);
|
|
input a;
|
|
output b;
|
|
endmodule
|