TODO section 26; closes docs/topo.md 2.9-15 and 2.9-19; coverage_gaps
M4/M5/M6 corrected against a fresh opentitan census.
A bind directive's target is a path of segments with optional indices
(bind top.gen[0].u_core chk u_chk (...)); a lone target binds as a
module reference, an instance path records nothing rather than a guess.
Each connection's port half resolves against the module being bound in
and its expression half in the target module's scope first, the
workspace's member path when the target lives elsewhere, the writing
scope last (Target::BindScope, resolve::in_bind_target - the
inline-constraint shape). FACTS_FORMAT 14 -> 15: binds now post
references and an instantiation edge.
Expression-position spaced macro calls (assign x = `WIDTH (a + b);)
keep the author's gap, read from the source as glued_null_item reads
its gap; verify.rs untouched, both pins stand. A conditional directive
inside a connection value becomes ExprKind::Verbatim, byte-exact
through raw_inline as Doc::Inline, with the closing paren's line and
the list's break read from the source - so the instantiation keeps its
edge, lens and port references instead of collapsing to opaque bytes
(opentitan: the two padring sites in chip_earlgrey_{asic,cw340}.sv,
+2 edges, everything else byte-identical to 0.31.0).
lucisv.instantiate [uri, position, module] renders the inline ghost's
plan as plain text through workspace/applyEdit for clients without
inline completion; the Neovim README documents it.
QA: 3186 tests / 47 binaries, corpus 814/820, independent binary diff
over corpus and 2 645 opentitan files: only the two named files differ.
docs/features/bind-semantics/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
502 lines
9.6 KiB
Plaintext
502 lines
9.6 KiB
Plaintext
# bare macro invocation as a module item, no semicolon
|
|
module m;
|
|
`ASSERT_INIT
|
|
wire w;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_INIT
|
|
wire w;
|
|
endmodule
|
|
====
|
|
# macro item with arguments and no trailing semicolon
|
|
module m;
|
|
`ASSERT_INIT(CheckNGreaterZero_A, N > 0)
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_INIT(CheckNGreaterZero_A, N > 0)
|
|
endmodule
|
|
====
|
|
# macro item with arguments keeps a trailing semicolon
|
|
module m;
|
|
`FFARNC(q, d, en, '0, clk_i, rst_ni);
|
|
endmodule
|
|
----
|
|
module m;
|
|
`FFARNC(q, d, en, '0, clk_i, rst_ni);
|
|
endmodule
|
|
====
|
|
# bare macro item keeps its semicolon
|
|
module m;
|
|
`MY_MACRO;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`MY_MACRO;
|
|
endmodule
|
|
====
|
|
# macro item argument list spanning several lines is re-indented, not reflowed
|
|
module m;
|
|
`ASSERT(LongNameCheck_A,
|
|
a_i == b_i,
|
|
clk_i, !rst_ni)
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT(LongNameCheck_A,
|
|
a_i == b_i,
|
|
clk_i, !rst_ni)
|
|
endmodule
|
|
====
|
|
# nested parens, brackets and braces inside macro arguments
|
|
module m;
|
|
`ASSERT_INIT(Nested_A, f(g(h(1))) == {a, b[3:0], '{c: 1}})
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_INIT(Nested_A, f(g(h(1))) == {a, b[3:0], '{c: 1}})
|
|
endmodule
|
|
====
|
|
# a string argument may contain an unbalanced parenthesis
|
|
module m;
|
|
`ASSERT_INIT(Msg_A, W > 0, "width must be > 0 (really)")
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_INIT(Msg_A, W > 0, "width must be > 0 (really)")
|
|
endmodule
|
|
====
|
|
# macro items between ordinary items, comments and blank lines preserved
|
|
module m;
|
|
// leading comment
|
|
`ASSERT_KNOWN(AKnown_A, a_i) // trailing comment
|
|
|
|
wire w;
|
|
// before the second macro
|
|
`ASSERT_KNOWN(BKnown_A, b_i)
|
|
assign w = a_i;
|
|
endmodule
|
|
----
|
|
module m;
|
|
// leading comment
|
|
`ASSERT_KNOWN(AKnown_A, a_i) // trailing comment
|
|
|
|
wire w;
|
|
// before the second macro
|
|
`ASSERT_KNOWN(BKnown_A, b_i)
|
|
assign w = a_i;
|
|
endmodule
|
|
====
|
|
# macro item inside a generate for block
|
|
module m;
|
|
generate
|
|
for (genvar i = 0; i < N; i++) begin : g_bit
|
|
`FF(q[i], d[i], '0, clk_i, rst_ni)
|
|
end
|
|
endgenerate
|
|
endmodule
|
|
----
|
|
module m;
|
|
generate
|
|
for (genvar i = 0; i < N; i++) begin : g_bit
|
|
`FF(q[i], d[i], '0, clk_i, rst_ni)
|
|
end
|
|
endgenerate
|
|
endmodule
|
|
====
|
|
# macro item inside a generate if / else block
|
|
module m;
|
|
if (Secure) begin : g_secure
|
|
`ASSERT_INIT(SecureWidth_A, W > 1)
|
|
end else begin : g_plain
|
|
`ASSERT_INIT(PlainWidth_A, W > 0)
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
if (Secure) begin : g_secure
|
|
`ASSERT_INIT(SecureWidth_A, W > 1)
|
|
end else begin : g_plain
|
|
`ASSERT_INIT(PlainWidth_A, W > 0)
|
|
end
|
|
endmodule
|
|
====
|
|
# macro at statement position inside an always block
|
|
module m;
|
|
always_ff @(posedge clk_i) begin
|
|
`DV_CHECK(a_i)
|
|
q <= d;
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
always_ff @(posedge clk_i) begin
|
|
`DV_CHECK(a_i)
|
|
q <= d;
|
|
end
|
|
endmodule
|
|
====
|
|
# macro statement with a trailing semicolon inside a begin/end block
|
|
module m;
|
|
initial begin
|
|
`uvm_info("id", "hello", UVM_LOW);
|
|
x = 1;
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
initial begin
|
|
`uvm_info("id", "hello", UVM_LOW);
|
|
x = 1;
|
|
end
|
|
endmodule
|
|
====
|
|
# macro statement in a function body and in a task body
|
|
module m;
|
|
function automatic int f(input int a);
|
|
`TRACE_ENTER(f)
|
|
return a;
|
|
endfunction
|
|
task automatic t();
|
|
`TRACE_ENTER(t)
|
|
endtask
|
|
endmodule
|
|
----
|
|
module m;
|
|
function automatic int f(input int a);
|
|
`TRACE_ENTER(f)
|
|
return a;
|
|
endfunction
|
|
task automatic t();
|
|
`TRACE_ENTER(t)
|
|
endtask
|
|
endmodule
|
|
====
|
|
# macro item in a package body
|
|
package p;
|
|
`DEFINE_REGS(foo)
|
|
localparam int W = 8;
|
|
endpackage
|
|
----
|
|
package p;
|
|
`DEFINE_REGS(foo)
|
|
localparam int W = 8;
|
|
endpackage
|
|
====
|
|
# macro-defined type name still starts a declaration, not a macro item
|
|
module m;
|
|
`MY_TYPE_T sig;
|
|
`MY_TYPE_T [3:0] vec;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`MY_TYPE_T sig;
|
|
`MY_TYPE_T [3:0] vec;
|
|
endmodule
|
|
====
|
|
# macro usage in expression position is unchanged
|
|
module m;
|
|
localparam int W = `WIDTH;
|
|
wire [`WIDTH-1:0] bus;
|
|
assign bus = `PACK(a_i, b_i);
|
|
endmodule
|
|
----
|
|
module m;
|
|
localparam int W = `WIDTH;
|
|
wire [`WIDTH-1:0] bus;
|
|
assign bus = `PACK(a_i, b_i);
|
|
endmodule
|
|
====
|
|
# a macro item may sit between two instantiations
|
|
module m;
|
|
`ASSERT_INIT(One_A, N > 0)
|
|
prim_flop u_a (.d(d_i), .q(q_o));
|
|
`ASSERT_KNOWN(Known_A, q_o)
|
|
prim_flop u_b (.d(q_o), .q(r_o));
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_INIT(One_A, N > 0)
|
|
prim_flop u_a (.d(d_i), .q(q_o));
|
|
`ASSERT_KNOWN(Known_A, q_o)
|
|
prim_flop u_b (.d(q_o), .q(r_o));
|
|
endmodule
|
|
====
|
|
# macro item at file scope, outside any module
|
|
`SOME_GLOBAL_MACRO(a, b)
|
|
module m;
|
|
wire w;
|
|
endmodule
|
|
----
|
|
`SOME_GLOBAL_MACRO(a, b)
|
|
module m;
|
|
wire w;
|
|
endmodule
|
|
====
|
|
# a string argument spanning lines keeps its own bytes: no line inside it is re-indented
|
|
module m;
|
|
if (X) begin : g
|
|
`uvm_info("id", "line one
|
|
line two", UVM_LOW);
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
if (X) begin : g
|
|
`uvm_info("id", "line one
|
|
line two", UVM_LOW);
|
|
end
|
|
endmodule
|
|
====
|
|
# a `define whose body continues a string is passed through untouched
|
|
module m;
|
|
if (X) begin : g
|
|
`define MSG "line one \
|
|
line two"
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
if (X) begin : g
|
|
`define MSG "line one \
|
|
line two"
|
|
end
|
|
endmodule
|
|
====
|
|
# a space before the argument list is an invocation, not a broken declaration
|
|
class ibex_ifetch_pmp_seq_item extends uvm_sequence_item;
|
|
bit [31:0] fetch_addr;
|
|
`uvm_object_utils_begin(ibex_ifetch_pmp_seq_item)
|
|
`uvm_field_int (fetch_addr, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
endclass
|
|
----
|
|
class ibex_ifetch_pmp_seq_item extends uvm_sequence_item;
|
|
bit [31:0] fetch_addr;
|
|
`uvm_object_utils_begin(ibex_ifetch_pmp_seq_item)
|
|
`uvm_field_int (fetch_addr, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
endclass
|
|
====
|
|
# a spaced macro call is a statement too, semicolon and all
|
|
module m;
|
|
initial begin
|
|
`uvm_info ("id", "msg", UVM_LOW);
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
initial begin
|
|
`uvm_info ("id", "msg", UVM_LOW);
|
|
end
|
|
endmodule
|
|
====
|
|
# a spaced macro call is reproduced verbatim: the space and the inner spacing stay
|
|
module m;
|
|
`ASSERT_INIT ( CheckN_A , N > 0 )
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_INIT ( CheckN_A , N > 0 )
|
|
endmodule
|
|
====
|
|
# a multi-line spaced macro call is re-indented, not reflowed
|
|
module m;
|
|
`ASSERT_NEVER (NoOverflow_A,
|
|
a && b,
|
|
clk_i, rst_ni)
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ASSERT_NEVER (NoOverflow_A,
|
|
a && b,
|
|
clk_i, rst_ni)
|
|
endmodule
|
|
====
|
|
# a bare macro that ends its line is complete: the next line declares on its own
|
|
class c extends b;
|
|
`uvm_component_new
|
|
|
|
uvm_report_server rs;
|
|
endclass
|
|
----
|
|
class c extends b;
|
|
`uvm_component_new
|
|
|
|
uvm_report_server rs;
|
|
endclass
|
|
====
|
|
# a comment between a bare macro item and the declaration under it changes nothing
|
|
class c extends b;
|
|
`uvm_object_new
|
|
|
|
// Non-null if this is a later item.
|
|
ibex_icache_core_base_seq prev_sequence = null;
|
|
endclass
|
|
----
|
|
class c extends b;
|
|
`uvm_object_new
|
|
|
|
// Non-null if this is a later item.
|
|
ibex_icache_core_base_seq prev_sequence = null;
|
|
endclass
|
|
====
|
|
# a macro-named type still declares when name and declarator share a line
|
|
module m;
|
|
`MY_TYPE_T sig;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`MY_TYPE_T sig;
|
|
endmodule
|
|
====
|
|
# a spaced macro call inside a format fence comes out byte-exact
|
|
module m;
|
|
// verilog_format: off
|
|
`uvm_field_int (fetch_addr,UVM_DEFAULT)
|
|
// verilog_format: on
|
|
wire a;
|
|
endmodule
|
|
----
|
|
module m;
|
|
// verilog_format: off
|
|
`uvm_field_int (fetch_addr,UVM_DEFAULT)
|
|
// verilog_format: on
|
|
wire a;
|
|
endmodule
|
|
====
|
|
# a macro statement that ends its line is complete: a symbol opens the next statement
|
|
class c extends b;
|
|
task t;
|
|
`uvm_info(`gfn, "waiting for rst_n assertion...", UVM_MEDIUM)
|
|
@(negedge cfg.clk_rst_vif.rst_n);
|
|
`DV_WAIT
|
|
#10ns;
|
|
`SEND
|
|
-> ev;
|
|
`PRE
|
|
{a, b} = c;
|
|
endtask
|
|
endclass
|
|
----
|
|
class c extends b;
|
|
task t;
|
|
`uvm_info(`gfn, "waiting for rst_n assertion...", UVM_MEDIUM)
|
|
@(negedge cfg.clk_rst_vif.rst_n);
|
|
`DV_WAIT
|
|
#10ns;
|
|
`SEND
|
|
-> ev;
|
|
`PRE
|
|
{a, b} = c;
|
|
endtask
|
|
endclass
|
|
====
|
|
# a `(` on the next line opens a new statement; a `;` on it still ends the macro
|
|
module m;
|
|
initial begin
|
|
`M
|
|
(x) = y;
|
|
`AFTER
|
|
;
|
|
end
|
|
endmodule
|
|
----
|
|
module m;
|
|
initial begin
|
|
`M
|
|
(x) = y;
|
|
`AFTER;
|
|
end
|
|
endmodule
|
|
====
|
|
# a symbol on the macro's own line still continues it
|
|
module m;
|
|
`MY_TYPE_T [3:0] vec;
|
|
`MY_MODULE #(.W(8)) u_param (.a(sig));
|
|
initial `LVALUE(x) = 1;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`MY_TYPE_T [3:0] vec;
|
|
`MY_MODULE #(.W(8)) u_param (.a(sig));
|
|
initial `LVALUE(x) = 1;
|
|
endmodule
|
|
====
|
|
# a macro whose arguments span lines ends on its last line, not on its first
|
|
module m;
|
|
`PACKED(a,
|
|
b) [3:0] vec;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`PACKED(a,
|
|
b) [3:0] vec;
|
|
endmodule
|
|
====
|
|
# a macro item followed by a comment line and then a statement symbol
|
|
class c extends b;
|
|
task t;
|
|
`uvm_info(`gfn, "done", UVM_HIGH)
|
|
// wait for the next edge
|
|
@(posedge clk);
|
|
endtask
|
|
endclass
|
|
----
|
|
class c extends b;
|
|
task t;
|
|
`uvm_info(`gfn, "done", UVM_HIGH)
|
|
// wait for the next edge
|
|
@(posedge clk);
|
|
endtask
|
|
endclass
|
|
====
|
|
# a spaced macro call in expression position keeps its gap (M4 residue)
|
|
module m;
|
|
localparam int W = `WIDTH (8);
|
|
assign x = `WIDTH (a + b);
|
|
endmodule
|
|
----
|
|
module m;
|
|
localparam int W = `WIDTH (8);
|
|
assign x = `WIDTH (a + b);
|
|
endmodule
|
|
====
|
|
# the same macro glued to its `(` stays glued: the two spellings are one token each
|
|
module m;
|
|
assign x = `WIDTH(a + b);
|
|
endmodule
|
|
----
|
|
module m;
|
|
assign x = `WIDTH(a + b);
|
|
endmodule
|
|
====
|
|
# a spaced macro call in a parameter override and in both connection kinds
|
|
module m;
|
|
sub #(.P(`MACRO (1))) u_sub (.a(`FOO (1)), `BAR (2));
|
|
endmodule
|
|
----
|
|
module m;
|
|
sub #(.P(`MACRO (1))) u_sub (.a(`FOO (1)), `BAR (2));
|
|
endmodule
|
|
====
|
|
# a comment in the gap owns the space; the macro is still not glued to its `(`
|
|
module m;
|
|
assign x = `W /*c*/ (a);
|
|
endmodule
|
|
----
|
|
module m;
|
|
assign x = `W /*c*/ (a);
|
|
endmodule
|
|
====
|
|
# a `(` opening the next line becomes one space, which is still two tokens
|
|
module m;
|
|
assign z = `W
|
|
(a);
|
|
endmodule
|
|
----
|
|
module m;
|
|
assign z = `W (a);
|
|
endmodule
|