Files
lucisv/crates/vlog_formatter/tests/cases/interfaces.cases
T
lucioandClaude Fable 5 2a63faf9a2 Add interfaces, modport, clocking blocks and virtual interface types
interface...endinterface shares the module header/body machinery (ItemKind::Module with kw == "interface"); modport and clocking are structural items; virtual <iface>[#(...)] is accepted in every type position. module-filename now applies to interfaces.

Coverage loop round 1, cluster 5: 712 -> 740 / 820 (86.8% -> 90.2%).
Feature README: docs/features/interfaces/README.md

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-21 00:01:53 -07:00

344 lines
8.7 KiB
Plaintext

# an interface is a module with a different closing keyword
# IEEE 1800-2017 25.3
interface simple_if;
logic a;
endinterface
----
interface simple_if;
logic a;
endinterface
====
# ANSI ports with no type at all, and a string parameter
# corpus/ibex/vendor/lowrisc_ip/dv/sv/common_ifs/clk_rst_if.sv:15
interface clk_rst_if #(parameter string IfName = "main") (inout clk, inout rst_n);
bit o_clk;
endinterface
----
interface clk_rst_if #(parameter string IfName = "main") (inout clk, inout rst_n);
bit o_clk;
endinterface
====
# directional ports with no type, and an `endinterface : name` label
# corpus/ibex/vendor/lowrisc_ip/dv/sv/common_ifs/rst_shadowed_if.sv:11
interface rst_shadowed_if(input rst_n, output rst_shadowed_n);
logic rst_shadowed_n_int;
endinterface : rst_shadowed_if
----
interface rst_shadowed_if (input rst_n, output rst_shadowed_n);
logic rst_shadowed_n_int;
endinterface : rst_shadowed_if
====
# a package import between the interface name and its port list
# corpus/ibex/dv/uvm/core_ibex/fcov/core_ibex_fcov_if.sv:8
interface core_ibex_fcov_if import ibex_pkg::*; (
input clk_i,
input rst_ni
);
logic x;
endinterface
----
interface core_ibex_fcov_if
import ibex_pkg::*;
(input clk_i, input rst_ni);
logic x;
endinterface
====
# the same import between the name and a `#(` parameter port list
# corpus/ibex/dv/uvm/core_ibex/fcov/core_ibex_pmp_fcov_if.sv:7
interface core_ibex_pmp_fcov_if import ibex_pkg::*; #(
parameter bit PMPEnable = 1'b0
) (
input clk_i
);
logic y;
endinterface
----
interface core_ibex_pmp_fcov_if
import ibex_pkg::*;
#(parameter bit PMPEnable = 1'b0) (input clk_i);
logic y;
endinterface
====
# an import written on its own line after the name
# corpus/ibex/dv/uvm/icache/dv/env/ibex_icache_ram_if.sv:5
interface ibex_icache_ram_if
import ibex_pkg::*;
#(
parameter int unsigned TagSizeECC = 1
) (
input clk
);
logic z;
endinterface
----
interface ibex_icache_ram_if
import ibex_pkg::*;
#(parameter int unsigned TagSizeECC = 1) (input clk);
logic z;
endinterface
====
# the same header import grammar on a module (IEEE 1800-2017 23.2.1)
module m import pkg_a::*; import pkg_b::t; #(parameter int W = 8) (input logic clk);
endmodule
----
module m
import pkg_a::*;
import pkg_b::t;
#(parameter int W = 8) (input logic clk);
endmodule
====
# two parameters, the second defaulting from the first
# corpus/ibex/vendor/lowrisc_ip/dv/sv/push_pull_agent/push_pull_if.sv:7
interface push_pull_if #(parameter int HostDataWidth = 32,
parameter int DeviceDataWidth = HostDataWidth) (
input clk,
input rst_n
);
logic req;
endinterface
----
interface push_pull_if #(
parameter int HostDataWidth = 32,
parameter int DeviceDataWidth = HostDataWidth
) (input clk, input rst_n);
logic req;
endinterface
====
# a doc comment on each parameter and each port
# corpus/common_cells/src/stream_intf.sv:18
interface STREAM_DV #(
/// Custom payload type.
parameter type payload_t = logic
)(
/// Interface clock.
input logic clk_i
);
payload_t data;
endinterface
----
interface STREAM_DV #(
/// Custom payload type.
parameter type payload_t = logic
) (
/// Interface clock.
input logic clk_i
);
payload_t data;
endinterface
====
# modport port lists collapse when they fit, like every other port list
# corpus/common_cells/src/stream_intf.sv:29
interface STREAM_DV;
logic valid, ready;
modport In (
output ready,
input valid, data
);
modport Out (
output valid, data,
input ready
);
endinterface
----
interface STREAM_DV;
logic valid, ready;
modport In (output ready, input valid, data);
modport Out (output valid, data, input ready);
endinterface
====
# a modport too wide for one line breaks one direction group per line
interface wide_if;
modport producer (output data_valid_signal, data_payload_signal, input backpressure_signal_from_sink);
endinterface
----
interface wide_if;
modport producer (
output data_valid_signal, data_payload_signal,
input backpressure_signal_from_sink
);
endinterface
====
# several modports in one declaration, and the import/export/clocking forms
# IEEE 1800-2017 25.5
interface m_if;
modport master (input a, output b), slave (output a, input b);
modport tb (clocking cb, import drive_task, check_task);
endinterface
----
interface m_if;
modport master (input a, output b), slave (output a, input b);
modport tb (clocking cb, import drive_task, check_task);
endinterface
====
# a clocking block: one item per line, skews as written
# corpus/common_cells/test/stream_register_tb.sv:75
module stream_register_tb;
clocking cb @(posedge clk);
default input #2 output #4;
output clr, inp_data, inp_valid, oup_ready;
input inp_ready, oup_valid, oup_data;
endclocking
endmodule
----
module stream_register_tb;
clocking cb @(posedge clk);
default input #2 output #4;
output clr, inp_data, inp_valid, oup_ready;
input inp_ready, oup_valid, oup_data;
endclocking
endmodule
====
# an edge skew, and a `default output` half with no `input` half
# corpus/ibex/dv/uvm/icache/dv/ibex_icache_core_agent/ibex_icache_core_if.sv:31
interface ibex_icache_core_if (input clk, input rst_n);
clocking driver_cb @(posedge clk);
default output negedge;
output req;
input negedge valid;
endclocking
endinterface
----
interface ibex_icache_core_if (input clk, input rst_n);
clocking driver_cb @(posedge clk);
default output negedge;
output req;
input negedge valid;
endclocking
endinterface
====
# a named `default clocking`, and an `endclocking : label`
# corpus/ibex/dv/uvm/icache/dv/ibex_icache_mem_agent/ibex_icache_mem_if.sv:19
interface ibex_icache_mem_if (input clk);
default clocking driver_cb @(posedge clk);
input req;
endclocking : driver_cb
endinterface
----
interface ibex_icache_mem_if (input clk);
default clocking driver_cb @(posedge clk);
input req;
endclocking : driver_cb
endinterface
====
# an anonymous `default clocking` with an empty body
# corpus/ibex/dv/formal/check/top.sv:143
module top;
default clocking @(posedge clk_i); endclocking
endmodule
----
module top;
default clocking @(posedge clk_i);
endclocking
endmodule
====
# `default clocking cb;` selects an existing block: no event, no body
# IEEE 1800-2017 14.12
module m;
clocking cb @(posedge clk);
input a;
endclocking
default clocking cb;
endmodule
----
module m;
clocking cb @(posedge clk);
input a;
endclocking
default clocking cb;
endmodule
====
# a virtual interface type in a typedef
# corpus/ibex/dv/uvm/icache/dv/env/ibex_icache_env_pkg.sv:28
package p;
typedef virtual push_pull_if#(.DeviceDataWidth(194)) scrambling_key_vif;
typedef virtual pins_if #(NUM_MAX_INTERRUPTS) intr_vif;
typedef virtual interface bus_if plain_vif;
endpackage
----
package p;
typedef virtual push_pull_if #(.DeviceDataWidth(194)) scrambling_key_vif;
typedef virtual pins_if #(NUM_MAX_INTERRUPTS) intr_vif;
typedef virtual interface bus_if plain_vif;
endpackage
====
# a virtual interface type as a function argument
# corpus/common_cells/test/stream_test.sv:31
package p;
class stream_driver;
virtual STREAM_DV stream;
function new (virtual STREAM_DV dv_if, int unsigned n);
this.stream = dv_if;
endfunction
endclass
endpackage
----
package p;
class stream_driver;
virtual STREAM_DV stream;
function new(virtual STREAM_DV dv_if, int unsigned n);
this.stream = dv_if;
endfunction
endclass
endpackage
====
# comments everywhere: before the interface, in the port list, between
# modport entries, and after `endinterface`
// what this interface is for
interface commented_if (
// the clock
input clk,
input rst_n // and the reset
);
// a modport
modport in_mp (
// only the clock
input clk
);
modport out_mp (input rst_n); // and this one
endinterface // done
----
// what this interface is for
interface commented_if (
// the clock
input clk,
input rst_n // and the reset
);
// a modport
modport in_mp (
// only the clock
input clk
);
modport out_mp (input rst_n); // and this one
endinterface // done
====
# a `// verilog_format: off` fence inside an interface body is honoured,
# exactly as it is inside a module body
interface fenced_if;
logic a;
// verilog_format: off
logic b ;
logic c ;
// verilog_format: on
logic d;
endinterface
----
interface fenced_if;
logic a;
// verilog_format: off
logic b ;
logic c ;
// verilog_format: on
logic d;
endinterface
====
# an interface is instantiated and connected like a module
module tb;
clk_rst_if #(.IfName("main")) clk_rst_if_inst (.clk(clk), .rst_n(rst_n));
dut u_dut (.bus(bus_if_inst.master));
endmodule
----
module tb;
clk_rst_if #(.IfName("main")) clk_rst_if_inst (.clk(clk), .rst_n(rst_n));
dut u_dut (.bus(bus_if_inst.master));
endmodule