Verilog format

This commit is contained in:
Wilson Snyder 2026-02-22 13:50:01 -05:00
parent 7f0be8a072
commit e238a2ca5e
22 changed files with 211 additions and 178 deletions

View File

@ -5,17 +5,17 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
class Base; class Base;
int value; int value;
endclass endclass
module t; module t;
Base b; Base b;
Base a; Base a;
initial begin initial begin
b = null; b = null;
a = new b; // BAD: null handle dereference (IEEE 8.7) a = new b; // BAD: null handle dereference (IEEE 8.7)
if (a != null) $write("unexpected clone\n"); if (a != null) $write("unexpected clone\n");
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end
endmodule endmodule

View File

@ -24,8 +24,8 @@ end
class Cls; class Cls;
int d; int d;
rand int y; rand int y;
rand bit i; rand bit i;
constraint q { constraint q {
if (i) { if (i) {

View File

@ -17,50 +17,60 @@
module t; module t;
class XorTest; class XorTest;
rand bit [7:0] data []; rand bit [7:0] data[];
rand bit [7:0] result; rand bit [7:0] result;
function new(); data = new[4]; endfunction function new();
constraint c_size { data.size() == 4; } data = new[4];
constraint c_xor { result == data.xor(); } endfunction
constraint c_size {data.size() == 4;}
constraint c_xor {result == data.xor();}
endclass endclass
class SumTest; class SumTest;
rand bit [7:0] data []; rand bit [7:0] data[];
rand bit [7:0] result; rand bit [7:0] result;
function new(); data = new[4]; endfunction function new();
constraint c_size { data.size() == 4; } data = new[4];
constraint c_sum { result == data.sum(); } endfunction
constraint c_size {data.size() == 4;}
constraint c_sum {result == data.sum();}
endclass endclass
class AndTest; class AndTest;
rand bit [7:0] data []; rand bit [7:0] data[];
rand bit [7:0] result; rand bit [7:0] result;
function new(); data = new[4]; endfunction function new();
constraint c_size { data.size() == 4; } data = new[4];
constraint c_and { result == data.and(); } endfunction
constraint c_size {data.size() == 4;}
constraint c_and {result == data.and();}
endclass endclass
class OrTest; class OrTest;
rand bit [7:0] data []; rand bit [7:0] data[];
rand bit [7:0] result; rand bit [7:0] result;
function new(); data = new[4]; endfunction function new();
constraint c_size { data.size() == 4; } data = new[4];
constraint c_or { result == data.or(); } endfunction
constraint c_size {data.size() == 4;}
constraint c_or {result == data.or();}
endclass endclass
class ProductTest; class ProductTest;
rand bit [7:0] data []; rand bit [7:0] data[];
rand bit [7:0] result; rand bit [7:0] result;
function new(); data = new[4]; endfunction function new();
constraint c_size { data.size() == 4; } data = new[4];
constraint c_prod { result == data.product(); } endfunction
constraint c_size {data.size() == 4;}
constraint c_prod {result == data.product();}
endclass endclass
initial begin initial begin
static XorTest t_xor = new(); static XorTest t_xor = new();
static SumTest t_sum = new(); static SumTest t_sum = new();
static AndTest t_and = new(); static AndTest t_and = new();
static OrTest t_or = new(); static OrTest t_or = new();
static ProductTest t_prod = new(); static ProductTest t_prod = new();
repeat (10) begin repeat (10) begin

View File

@ -23,7 +23,7 @@ class FuncConstraintTest;
endfunction endfunction
constraint func_con { constraint func_con {
mask inside {[8'h10:8'hF0]}; mask inside {[8'h10 : 8'hF0]};
value >= get_min_value(mask); value >= get_min_value(mask);
value <= get_max_value(mask); value <= get_max_value(mask);
} }

View File

@ -1,6 +1,6 @@
%Warning-CONSTRAINTIGN: t/t_constraint_func_call_unsup.v:18:23: Unsupported: complex function in constraint, treating as state %Warning-CONSTRAINTIGN: t/t_constraint_func_call_unsup.v:16:22: Unsupported: complex function in constraint, treating as state
18 | constraint c { x <= complex_func(y); } 16 | constraint c {x <= complex_func(y);}
| ^~~~~~~~~~~~ | ^~~~~~~~~~~~
... For warning description see https://verilator.org/warn/CONSTRAINTIGN?v=latest ... For warning description see https://verilator.org/warn/CONSTRAINTIGN?v=latest
... Use "/* verilator lint_off CONSTRAINTIGN */" and lint_on around source to disable this message. ... Use "/* verilator lint_off CONSTRAINTIGN */" and lint_on around source to disable this message.
%Error: Exiting due to %Error: Exiting due to

View File

@ -9,13 +9,11 @@ class Cls;
rand bit [7:0] y; rand bit [7:0] y;
function bit [7:0] complex_func(bit [7:0] m); function bit [7:0] complex_func(bit [7:0] m);
if (m > 128) if (m > 128) return m;
return m; else return m + 1;
else
return m + 1;
endfunction endfunction
constraint c { x <= complex_func(y); } constraint c {x <= complex_func(y);}
endclass endclass
module t; module t;

View File

@ -9,8 +9,8 @@
`include "../include/t_flag_relinc.vh" `include "../include/t_flag_relinc.vh"
module t_flag_relinc_sub (); module t_flag_relinc_sub ();
initial begin initial begin
`all_finished; `all_finished;
$finish; $finish;
end end
endmodule endmodule

View File

@ -5,17 +5,17 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
module t; module t;
Iface ifc(); Iface ifc ();
rvlab_tests uut (.ifc); rvlab_tests uut (.ifc);
always begin always begin
uut.test_idcode(); uut.test_idcode();
end end
initial begin initial begin
#1; #1;
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end
endmodule endmodule
interface Iface; interface Iface;
@ -23,15 +23,16 @@ interface Iface;
logic tdo; logic tdo;
task tsk(output logic [31:0] data_o, input logic [31:0] data_i); task tsk(output logic [31:0] data_o, input logic [31:0] data_i);
@(posedge tck); @(posedge tck);
data_o[$size(data_i)-1] <= tdo; data_o[$size(data_i)-1] <= tdo;
endtask endtask
endinterface endinterface
module rvlab_tests ( module rvlab_tests (
Iface ifc); Iface ifc
task test_idcode(); );
bit [31:0] idcode_read; task test_idcode();
ifc.tsk(idcode_read, '0); bit [31:0] idcode_read;
endtask ifc.tsk(idcode_read, '0);
endtask
endmodule endmodule

View File

@ -1,15 +1,18 @@
// DESCRIPTION: Verilator: Verilog Test module // DESCRIPTION: Verilator: Verilog Test module
// //
// This file ONLY is placed under the Creative Commons Public Domain, for // This file ONLY is placed under the Creative Commons Public Domain.
// any use, without warranty, 2026 by Antmicro Ltd. // SPDX-FileCopyrightText: 2026 Antmicro Ltd
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
module t; module t;
initial fork initial
#0 $write("This should be last\n"); fork
begin #0 $write("This should be last\n");
fork $write("This should be second\n"); join_none begin
$write("This should be first\n"); fork
end $write("This should be second\n");
join_none join_none
$write("This should be first\n");
end
join_none
endmodule endmodule

View File

@ -1,7 +1,7 @@
// DESCRIPTION: Verilator: Verilog Test module // DESCRIPTION: Verilator: Verilog Test module
// //
// This file ONLY is placed under the Creative Commons Public Domain, for // This file ONLY is placed under the Creative Commons Public Domain.
// any use, without warranty, 2026 by Antmicro Ltd. // SPDX-FileCopyrightText: 2026 Antmicro Ltd
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
module test; module test;
@ -10,7 +10,7 @@ module test;
mbox = new(); mbox = new();
fork fork
repeat(2) begin repeat (2) begin
int val; int val;
mbox.get(val); mbox.get(val);
fork fork

View File

@ -1,7 +1,7 @@
// DESCRIPTION: Verilator: Verilog Test module // DESCRIPTION: Verilator: Verilog Test module
// //
// This file ONLY is placed under the Creative Commons Public Domain, for // This file ONLY is placed under the Creative Commons Public Domain.
// any use, without warranty, 2026 by Antmicro Ltd. // SPDX-FileCopyrightText: 2026 Antmicro Ltd
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
class events_holder; class events_holder;

View File

@ -7,5 +7,5 @@
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
module subA (output bit [31:0] out); /*verilator hier_block*/ module subA (output bit [31:0] out); /*verilator hier_block*/
subsub subsub(.out(out)); subsub subsub(.out(out));
endmodule endmodule

View File

@ -8,5 +8,5 @@
// Note: no hier_block pragma here to validate partial hier_block design // Note: no hier_block pragma here to validate partial hier_block design
module subB (output bit [31:0] out); module subB (output bit [31:0] out);
assign out = `VALUE_B; assign out = `VALUE_B;
endmodule endmodule

View File

@ -6,10 +6,10 @@
// SPDX-FileCopyrightText: 2024 Antmicro // SPDX-FileCopyrightText: 2024 Antmicro
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
module subsub module subsub #(
#( `include "t_hier_block_import.vh"
`include "t_hier_block_import.vh" ) (
) output bit [31:0] out
(output bit [31:0] out); /*verilator hier_block*/ ); /*verilator hier_block*/
assign out = pt.PARAM_VALUE; assign out = pt.PARAM_VALUE;
endmodule endmodule

View File

@ -4,45 +4,47 @@
// SPDX-FileCopyrightText: 2024 Wilson Snyder // SPDX-FileCopyrightText: 2024 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
module detail_code( module detail_code (
input clk, input clk,
input reset_l); input reset_l
);
endmodule endmodule
module sub_top( module sub_top (
input clk, input clk,
input reset_l); input reset_l
);
detail_code u0( detail_code u0 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u1( detail_code u1 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u2( detail_code u2 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u3( detail_code u3 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u4( detail_code u4 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u5( detail_code u5 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u6( detail_code u6 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
detail_code u7( detail_code u7 (
.clk(clk), .clk(clk),
.reset_l(reset_l) .reset_l(reset_l)
); );
endmodule endmodule

View File

@ -4,17 +4,21 @@
// SPDX-FileCopyrightText: 2026 Wilson Snyder // SPDX-FileCopyrightText: 2026 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
interface ifc #(parameter int width)(input logic [width-1:0] b); interface ifc #(
parameter int width
) (
input logic [width-1:0] b
);
logic [width-1:0] a; logic [width-1:0] a;
typedef logic[width-1:0] type_t; typedef logic [width-1:0] type_t;
always_comb a = type_t'(b); always_comb a = type_t'(b);
endinterface endinterface
module t; module t;
logic [15:0] x; logic [15:0] x;
ifc #(.width(16)) x_ifc(x); ifc #(.width(16)) x_ifc (x);
logic [7:0] y; logic [7:0] y;
ifc #(.width(8)) y_ifc(y); ifc #(.width(8)) y_ifc (y);
initial begin initial begin
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");

View File

@ -4,28 +4,29 @@ lint_off -rule NONSTD
`begin_keywords "1800-2023" `begin_keywords "1800-2023"
`timescale 1ns/1ps `timescale 1ns/1ps
module top( module top(
input logic clk, input logic clk,
input logic rst, input logic rst,
output logic top_out output logic top_out
); );
submod u_submod ( submod u_submod (
.clk (clk), .clk (clk),
.rst (rst), .rst (rst),
.out_signal(top_out) .out_signal(top_out)
); );
endmodule endmodule
`begin_keywords "1800-2023" `begin_keywords "1800-2023"
`timescale 1ns/1ps `timescale 1ns / 1ps
module submod( module submod (
input logic clk, input logic clk,
input logic rst, input logic rst,
output logic out_signal output logic out_signal
); );
always_ff @(posedge clk or posedge rst) begin always_ff @(posedge clk or posedge rst) begin
if (rst) begin if (rst) begin
out_signal <= 1'b0; out_signal <= 1'b0;
end else begin end
out_signal <= ~out_signal; else begin
end out_signal <= ~out_signal;
end end
end
endmodule endmodule

View File

@ -6,13 +6,13 @@
`timescale 1ns/1ps `timescale 1ns/1ps
module top(/*AUTOARG*/ module top(/*AUTOARG*/
input logic clk, input logic clk,
input logic rst, input logic rst,
output logic top_out output logic top_out
); );
submod u_submod (/*AUTOINST*/ submod u_submod (/*AUTOINST*/
.clk (clk), .clk (clk),
.rst (rst), .rst (rst),
.out_signal(top_out) .out_signal(top_out)
); );
endmodule endmodule

View File

@ -4,17 +4,18 @@
// SPDX-FileCopyrightText: 2025 Antmicro Ltd // SPDX-FileCopyrightText: 2025 Antmicro Ltd
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
`timescale 1ns/1ps `timescale 1ns / 1ps
module submod(/*AUTOARG*/ module submod (
input logic clk, input logic clk,
input logic rst, input logic rst,
output logic out_signal output logic out_signal
); );
always_ff @(posedge clk or posedge rst) begin always_ff @(posedge clk or posedge rst) begin
if (rst) begin if (rst) begin
out_signal <= 1'b0; out_signal <= 1'b0;
end else begin end
out_signal <= ~out_signal; else begin
end out_signal <= ~out_signal;
end end
end
endmodule endmodule

View File

@ -20,7 +20,7 @@ module t ( /*AUTOARG*/
int passs; int passs;
} result_t; } result_t;
result_t results [int]; result_t results[int];
result_t expected[int]; result_t expected[int];
localparam MAX = 15; localparam MAX = 15;
@ -41,9 +41,9 @@ module t ( /*AUTOARG*/
always @(clk) begin always @(clk) begin
++cyc; ++cyc;
if (cyc == MAX) begin if (cyc == MAX) begin
expected[1] = '{2, 3}; expected[1] = '{2, 3};
// expected[2] shouldn't be initialized // expected[2] shouldn't be initialized
expected[3] = '{6, 0}; expected[3] = '{6, 0};
`checkh(results, expected); `checkh(results, expected);
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;

View File

@ -14,13 +14,13 @@ module t;
// String-key associative array with size constraint // String-key associative array with size constraint
class StringKeyTest; class StringKeyTest;
rand int data[string]; rand int data[string];
constraint c_size { data.size() == 3; } constraint c_size {data.size() == 3;}
endclass endclass
// Int-key associative array with size constraint // Int-key associative array with size constraint
class IntKeyTest; class IntKeyTest;
rand bit [7:0] values[int]; rand bit [7:0] values[int];
constraint c_size { values.size() == 2; } constraint c_size {values.size() == 2;}
endclass endclass
initial begin initial begin

View File

@ -16,7 +16,7 @@
class DataItem; class DataItem;
rand bit [7:0] value; rand bit [7:0] value;
rand bit [7:0] limit; rand bit [7:0] limit;
constraint default_con { limit inside {[8'd50:8'd200]}; } constraint default_con {limit inside {[8'd50 : 8'd200]};}
endclass endclass
// Test 4: 'this' in inline constraint called from another class method. // Test 4: 'this' in inline constraint called from another class method.
@ -24,7 +24,10 @@ endclass
class Caller; class Caller;
rand bit [7:0] own_value; rand bit [7:0] own_value;
function int do_rand(DataItem item); function int do_rand(DataItem item);
return item.randomize() with { this.value > 8'd30; this.value < 8'd40; }; return item.randomize() with {
this.value > 8'd30;
this.value < 8'd40;
};
endfunction endfunction
endclass endclass
@ -35,18 +38,28 @@ module t;
automatic int rand_ok; automatic int rand_ok;
// Test 1: 'this.member' in inline constraint from module-level code // Test 1: 'this.member' in inline constraint from module-level code
rand_ok = item.randomize() with { this.value > 8'd10; this.value < 8'd50; }; rand_ok = item.randomize() with {
this.value > 8'd10;
this.value < 8'd50;
};
`checkd(rand_ok, 1) `checkd(rand_ok, 1)
`check_range(item.value, 11, 49) `check_range(item.value, 11, 49)
`check_range(item.limit, 50, 200) `check_range(item.limit, 50, 200)
// Test 2: multiple 'this.member' references // Test 2: multiple 'this.member' references
rand_ok = item.randomize() with { this.value > 8'd20; this.value < 8'd30; }; rand_ok = item.randomize() with {
this.value > 8'd20;
this.value < 8'd30;
};
`checkd(rand_ok, 1) `checkd(rand_ok, 1)
`check_range(item.value, 21, 29) `check_range(item.value, 21, 29)
// Test 3: mix of 'this.member' and unqualified member // Test 3: mix of 'this.member' and unqualified member
rand_ok = item.randomize() with { this.value > 8'd5; this.value < 8'd100; limit > 8'd150; }; rand_ok = item.randomize() with {
this.value > 8'd5;
this.value < 8'd100;
limit > 8'd150;
};
`checkd(rand_ok, 1) `checkd(rand_ok, 1)
`check_range(item.value, 6, 99) `check_range(item.value, 6, 99)
`check_range(item.limit, 151, 200) `check_range(item.limit, 151, 200)