Raw text carrying a string literal across a line break, and the #( ... ) of a parameterized type, were emitted as a single Doc::Text with embedded newlines -- violating that variant's contract and leaving the printer's column tracker stale, so every later fits() on the line broke conservatively. Both now emit Doc::Inline, whose printer arm resumes measuring from the text's own last line. Output bytes are identical except where the stale column forced a spurious break: one corpus file (id_queue_tb.sv) improves, pass set unchanged at 813/820, verify.rs untouched. Found by QA in the directive-split round; pinned by a printer test and a classes.cases entry. Co-Authored-By: Claude Fable 5 <[email protected]>
576 lines
12 KiB
Plaintext
576 lines
12 KiB
Plaintext
# empty class
|
|
class c;
|
|
endclass
|
|
----
|
|
class c;
|
|
endclass
|
|
====
|
|
# class body is indented one level and endclass keeps its label
|
|
class c;
|
|
localparam int W = 8;
|
|
endclass : c
|
|
----
|
|
class c;
|
|
localparam int W = 8;
|
|
endclass : c
|
|
====
|
|
# virtual class
|
|
virtual class base;
|
|
endclass
|
|
----
|
|
virtual class base;
|
|
endclass
|
|
====
|
|
# extends a plain base class
|
|
class c extends base;
|
|
endclass
|
|
----
|
|
class c extends base;
|
|
endclass
|
|
====
|
|
# extends a package-scoped base class
|
|
class c extends pkg::base;
|
|
endclass
|
|
----
|
|
class c extends pkg::base;
|
|
endclass
|
|
====
|
|
# extends with named parameter overrides, joined onto the header line
|
|
class ibex_icache_core_driver
|
|
extends dv_base_driver #(.ITEM_T (req_item),
|
|
.CFG_T (agent_cfg));
|
|
endclass
|
|
----
|
|
class ibex_icache_core_driver extends dv_base_driver #(.ITEM_T(req_item), .CFG_T(agent_cfg));
|
|
endclass
|
|
====
|
|
# extends overrides break one per line when the header does not fit
|
|
class ibex_icache_core_agent extends dv_base_agent #(.CFG_T(ibex_icache_core_agent_cfg), .DRIVER_T(ibex_icache_core_driver), .MONITOR_T(ibex_icache_core_monitor));
|
|
endclass
|
|
----
|
|
class ibex_icache_core_agent extends dv_base_agent #(
|
|
.CFG_T(ibex_icache_core_agent_cfg),
|
|
.DRIVER_T(ibex_icache_core_driver),
|
|
.MONITOR_T(ibex_icache_core_monitor)
|
|
);
|
|
endclass
|
|
====
|
|
# extends with ordered (positional) overrides
|
|
class cov extends dv_base_agent_cov #(agent_cfg);
|
|
endclass
|
|
----
|
|
class cov extends dv_base_agent_cov #(agent_cfg);
|
|
endclass
|
|
====
|
|
# class parameter port list, and an extends clause using those parameters
|
|
class push_pull_driver #(
|
|
parameter int HostDataWidth = 32,
|
|
parameter int DeviceDataWidth = HostDataWidth
|
|
) extends dv_base_driver #(.CFG_T(cfg_t));
|
|
endclass
|
|
----
|
|
class push_pull_driver #(
|
|
parameter int HostDataWidth = 32,
|
|
parameter int DeviceDataWidth = HostDataWidth
|
|
) extends dv_base_driver #(.CFG_T(cfg_t));
|
|
endclass
|
|
====
|
|
# implements clause
|
|
class c implements a, b;
|
|
endclass
|
|
----
|
|
class c implements a, b;
|
|
endclass
|
|
====
|
|
# rand and randc properties
|
|
class item extends uvm_sequence_item;
|
|
rand bit [31:0] branch_addr;
|
|
randc int num_insns;
|
|
endclass
|
|
----
|
|
class item extends uvm_sequence_item;
|
|
rand bit [31:0] branch_addr;
|
|
randc int num_insns;
|
|
endclass
|
|
====
|
|
# local, protected, static and const properties
|
|
class c;
|
|
local int a;
|
|
protected bit b;
|
|
static int count;
|
|
const int limit = 4;
|
|
endclass
|
|
----
|
|
class c;
|
|
local int a;
|
|
protected bit b;
|
|
static int count;
|
|
const int limit = 4;
|
|
endclass
|
|
====
|
|
# a virtual-interface property
|
|
class cfg extends dv_base_agent_cfg;
|
|
virtual ibex_icache_core_if vif;
|
|
virtual interface other_if oif;
|
|
endclass
|
|
----
|
|
class cfg extends dv_base_agent_cfg;
|
|
virtual ibex_icache_core_if vif;
|
|
virtual interface other_if oif;
|
|
endclass
|
|
====
|
|
# a property whose type is parameterized
|
|
class c;
|
|
uvm_analysis_port #(bit [31:0]) analysis_port;
|
|
push_pull_agent_cfg #(HostDataWidth, DeviceDataWidth) cfg;
|
|
endclass
|
|
----
|
|
class c;
|
|
uvm_analysis_port #(bit [31:0]) analysis_port;
|
|
push_pull_agent_cfg #(HostDataWidth, DeviceDataWidth) cfg;
|
|
endclass
|
|
====
|
|
# methods: new, void function, task, and the qualifiers before them
|
|
class c;
|
|
function new(string name, uvm_component parent);
|
|
super.new(name, parent);
|
|
endfunction : new
|
|
virtual function void build_phase(uvm_phase phase);
|
|
super.build_phase(phase);
|
|
endfunction
|
|
virtual task automatic reset_signals();
|
|
cfg.vif.reset();
|
|
endtask
|
|
local function int helper();
|
|
return 1;
|
|
endfunction
|
|
endclass
|
|
----
|
|
class c;
|
|
function new(string name, uvm_component parent);
|
|
super.new(name, parent);
|
|
endfunction : new
|
|
virtual function void build_phase(uvm_phase phase);
|
|
super.build_phase(phase);
|
|
endfunction
|
|
virtual task automatic reset_signals();
|
|
cfg.vif.reset();
|
|
endtask
|
|
local function int helper();
|
|
return 1;
|
|
endfunction
|
|
endclass
|
|
====
|
|
# pure virtual prototypes have no body and no endfunction/endtask
|
|
virtual class sub_driver;
|
|
pure virtual function void reset_signals();
|
|
pure virtual task wait_cb(int num = 1);
|
|
endclass
|
|
----
|
|
virtual class sub_driver;
|
|
pure virtual function void reset_signals();
|
|
pure virtual task wait_cb(int num = 1);
|
|
endclass
|
|
====
|
|
# extern prototypes, and the out-of-body definition that goes with one
|
|
class dv_base_mem;
|
|
extern function void set_enable(bit enable);
|
|
endclass
|
|
|
|
function void dv_base_mem::set_enable(bit enable);
|
|
this.enable = enable;
|
|
endfunction
|
|
----
|
|
class dv_base_mem;
|
|
extern function void set_enable(bit enable);
|
|
endclass
|
|
|
|
function void dv_base_mem::set_enable(bit enable);
|
|
this.enable = enable;
|
|
endfunction
|
|
====
|
|
# a constraint block is reproduced byte for byte, only re-indented
|
|
class item;
|
|
constraint c_branch_addr_alignment {
|
|
// The branch address is always required to be half-word aligned.
|
|
!branch_addr[0];
|
|
(trans_type != Branch) -> branch_addr == 0;
|
|
solve trans_type before branch_addr;
|
|
}
|
|
endclass
|
|
----
|
|
class item;
|
|
constraint c_branch_addr_alignment {
|
|
// The branch address is always required to be half-word aligned.
|
|
!branch_addr[0];
|
|
(trans_type != Branch) -> branch_addr == 0;
|
|
solve trans_type before branch_addr;
|
|
}
|
|
endclass
|
|
====
|
|
# a constraint written at column 1 is re-indented into the class body
|
|
class item;
|
|
constraint c_dist {
|
|
num_insns dist { 0 :/ 5, [1:20] :/ 20, [21:100] :/ 1 };
|
|
}
|
|
endclass
|
|
----
|
|
class item;
|
|
constraint c_dist {
|
|
num_insns dist { 0 :/ 5, [1:20] :/ 20, [21:100] :/ 1 };
|
|
}
|
|
endclass
|
|
====
|
|
# a covergroup is reproduced byte for byte too, endgroup label included
|
|
class cov;
|
|
covergroup branch_dest_cg with function sample (bit [31:0] addr);
|
|
coverpoint addr {
|
|
bins zero = { 0 };
|
|
bins mid = default;
|
|
}
|
|
endgroup : branch_dest_cg
|
|
endclass
|
|
----
|
|
class cov;
|
|
covergroup branch_dest_cg with function sample (bit [31:0] addr);
|
|
coverpoint addr {
|
|
bins zero = { 0 };
|
|
bins mid = default;
|
|
}
|
|
endgroup : branch_dest_cg
|
|
endclass
|
|
====
|
|
# macro items inside a class body
|
|
class c extends base;
|
|
`uvm_component_utils(c)
|
|
`uvm_component_new
|
|
endclass
|
|
----
|
|
class c extends base;
|
|
`uvm_component_utils(c)
|
|
`uvm_component_new
|
|
endclass
|
|
====
|
|
# a bare macro item followed by a parameterized-type declaration
|
|
class c;
|
|
`uvm_component_new
|
|
uvm_analysis_port #(bit [31:0]) analysis_port;
|
|
endclass
|
|
----
|
|
class c;
|
|
`uvm_component_new
|
|
uvm_analysis_port #(bit [31:0]) analysis_port;
|
|
endclass
|
|
====
|
|
# compiler directives between class members
|
|
class c;
|
|
`ifdef VERILATOR
|
|
int a;
|
|
`else
|
|
int b;
|
|
`endif
|
|
`define CB cfg.vif.host_push_cb
|
|
endclass
|
|
----
|
|
class c;
|
|
`ifdef VERILATOR
|
|
int a;
|
|
`else
|
|
int b;
|
|
`endif
|
|
`define CB cfg.vif.host_push_cb
|
|
endclass
|
|
====
|
|
# a class inside a package
|
|
package p;
|
|
class c extends base;
|
|
int x;
|
|
endclass : c
|
|
endpackage
|
|
----
|
|
package p;
|
|
class c extends base;
|
|
int x;
|
|
endclass : c
|
|
endpackage
|
|
====
|
|
# a class nested inside a class
|
|
class outer;
|
|
class inner;
|
|
int x;
|
|
endclass
|
|
int y;
|
|
endclass
|
|
----
|
|
class outer;
|
|
class inner;
|
|
int x;
|
|
endclass
|
|
int y;
|
|
endclass
|
|
====
|
|
# typedef forward-declaring a class
|
|
typedef class push_pull_sub_driver;
|
|
typedef class push_host_driver;
|
|
----
|
|
typedef class push_pull_sub_driver;
|
|
typedef class push_host_driver;
|
|
====
|
|
# comments on class members, and a blank line between them
|
|
class c;
|
|
// what this holds
|
|
int a; // trailing
|
|
|
|
// and this
|
|
int b;
|
|
endclass
|
|
----
|
|
class c;
|
|
// what this holds
|
|
int a; // trailing
|
|
|
|
// and this
|
|
int b;
|
|
endclass
|
|
====
|
|
# a comment written just before endclass stays inside the class
|
|
class c;
|
|
int a;
|
|
// last word
|
|
endclass
|
|
----
|
|
class c;
|
|
int a;
|
|
// last word
|
|
endclass
|
|
====
|
|
# a comment after a constraint's closing brace is not swallowed by it
|
|
class c;
|
|
constraint x {
|
|
a == 0;
|
|
} // why
|
|
int b;
|
|
endclass
|
|
----
|
|
class c;
|
|
constraint x {
|
|
a == 0;
|
|
} // why
|
|
int b;
|
|
endclass
|
|
====
|
|
# statements a class body needs: new, super, scoped create, disable fork
|
|
class c;
|
|
function void build_phase(uvm_phase phase);
|
|
super.build_phase(phase);
|
|
analysis_port = new("analysis_port", this);
|
|
rsp = rsp_item::type_id::create("rsp");
|
|
endfunction
|
|
task t();
|
|
fork
|
|
a();
|
|
join_any
|
|
disable fork;
|
|
endtask
|
|
endclass
|
|
----
|
|
class c;
|
|
function void build_phase(uvm_phase phase);
|
|
super.build_phase(phase);
|
|
analysis_port = new("analysis_port", this);
|
|
rsp = rsp_item::type_id::create("rsp");
|
|
endfunction
|
|
task t();
|
|
fork
|
|
a();
|
|
join_any
|
|
disable fork;
|
|
endtask
|
|
endclass
|
|
====
|
|
# a parameterized class reference in expression position stays tight
|
|
class c;
|
|
function void build_phase(uvm_phase phase);
|
|
if (!uvm_config_db#(virtual core_if)::get(this, "", "vif", cfg.vif)) begin
|
|
`uvm_fatal(`gfn, "no vif")
|
|
end
|
|
sub = push_host_driver#(HostDataWidth, DeviceDataWidth)::type_id::create("sub");
|
|
endfunction
|
|
endclass
|
|
----
|
|
class c;
|
|
function void build_phase(uvm_phase phase);
|
|
if (!uvm_config_db#(virtual core_if)::get(this, "", "vif", cfg.vif)) begin
|
|
`uvm_fatal(`gfn, "no vif")
|
|
end
|
|
sub = push_host_driver#(HostDataWidth, DeviceDataWidth)::type_id::create("sub");
|
|
endfunction
|
|
endclass
|
|
====
|
|
# a local variable of virtual-interface type inside a method
|
|
class c;
|
|
virtual task body();
|
|
virtual core_ibex_dut_probe_if ibex_dut_vif;
|
|
x = 1;
|
|
endtask
|
|
endclass
|
|
----
|
|
class c;
|
|
virtual task body();
|
|
virtual core_ibex_dut_probe_if ibex_dut_vif;
|
|
x = 1;
|
|
endtask
|
|
endclass
|
|
====
|
|
# a declaration of a parameterized type inside a method body
|
|
class c;
|
|
task t();
|
|
item #(A, B) req;
|
|
req = null;
|
|
endtask
|
|
endclass
|
|
----
|
|
class c;
|
|
task t();
|
|
item #(A, B) req;
|
|
req = null;
|
|
endtask
|
|
endclass
|
|
====
|
|
# an instantiation still wins over a parameterized-type declaration
|
|
module m;
|
|
sub #(.W(8)) u (.a(a));
|
|
port_t #(int) p;
|
|
endmodule
|
|
----
|
|
module m;
|
|
sub #(.W(8)) u (.a(a));
|
|
port_t #(int) p;
|
|
endmodule
|
|
====
|
|
# a typedef and an import inside a class body
|
|
class c;
|
|
typedef enum logic [1:0] {A, B} state_e;
|
|
import pkg::thing;
|
|
endclass
|
|
----
|
|
class c;
|
|
typedef enum logic [1:0] {A, B} state_e;
|
|
import pkg::thing;
|
|
endclass
|
|
====
|
|
# a class with a static lifetime keyword
|
|
class static c;
|
|
int x;
|
|
endclass
|
|
----
|
|
class static c;
|
|
int x;
|
|
endclass
|
|
====
|
|
# a constraint standing alone with no braces (prototype form)
|
|
class c;
|
|
constraint x;
|
|
endclass
|
|
----
|
|
class c;
|
|
constraint x;
|
|
endclass
|
|
====
|
|
# a string inside a constraint keeps its bytes when the block is re-indented
|
|
class c;
|
|
constraint x {
|
|
name == "a
|
|
b";
|
|
}
|
|
endclass
|
|
----
|
|
class c;
|
|
constraint x {
|
|
name == "a
|
|
b";
|
|
}
|
|
endclass
|
|
====
|
|
# a shallow copy: `new <expression>` (IEEE 1800 8.12)
|
|
class c;
|
|
function riscv_instr get_rand_instr();
|
|
riscv_instr instr_h;
|
|
// Shallow copy for all relevant fields, avoid using create()
|
|
instr_h = new instr_template[name];
|
|
h2 = new pkg::templates[idx].handle;
|
|
return instr_h;
|
|
endfunction
|
|
endclass
|
|
----
|
|
class c;
|
|
function riscv_instr get_rand_instr();
|
|
riscv_instr instr_h;
|
|
// Shallow copy for all relevant fields, avoid using create()
|
|
instr_h = new instr_template[name];
|
|
h2 = new pkg::templates[idx].handle;
|
|
return instr_h;
|
|
endfunction
|
|
endclass
|
|
====
|
|
# the constructor, the bare handle and the dynamic-array resize keep their old parse
|
|
class c;
|
|
function void f();
|
|
a = new;
|
|
b = new(x, y);
|
|
data_valid = new[num_ways];
|
|
q = new[n](old_q);
|
|
endfunction
|
|
endclass
|
|
----
|
|
class c;
|
|
function void f();
|
|
a = new;
|
|
b = new(x, y);
|
|
data_valid = new[num_ways];
|
|
q = new[n](old_q);
|
|
endfunction
|
|
endclass
|
|
====
|
|
# a shallow copy at the line-length boundary is not broken apart
|
|
class c;
|
|
function void f();
|
|
this.a_fairly_long_destination_handle_name = new a_fairly_long_source_handle[i];
|
|
endfunction
|
|
endclass
|
|
----
|
|
class c;
|
|
function void f();
|
|
this.a_fairly_long_destination_handle_name = new a_fairly_long_source_handle[i];
|
|
endfunction
|
|
endclass
|
|
====
|
|
# a bare `new` whose `;` opens the next line is still a bare handle
|
|
class c;
|
|
function void f();
|
|
h =
|
|
new;
|
|
g = 1;
|
|
endfunction
|
|
endclass
|
|
----
|
|
class c;
|
|
function void f();
|
|
h = new;
|
|
g = 1;
|
|
endfunction
|
|
endclass
|
|
====
|
|
# the printer's column stays honest after a multi-line #( ... ): the
|
|
# initializer is measured from the raw text's last line, not from an
|
|
# accumulated count, so a call that fits the real line stays on it
|
|
class c;
|
|
uvm_analysis_port #(bit [31:0],
|
|
foo_t) p = new("a_fairly_long_component_name", some_parent_handle, extra_argument);
|
|
endclass
|
|
----
|
|
class c;
|
|
uvm_analysis_port #(bit [31:0],
|
|
foo_t) p = new("a_fairly_long_component_name", some_parent_handle, extra_argument);
|
|
endclass
|