TODO section 22, coverage_gaps H4 corrected. Class-body and module-item include fragments already parsed - the file-scope item loop is the class-item loop. The three shapes that did not - a bare statement list, an enum-member list (riscv-dv's CUSTOM_1, file, included between enum members), a covergroup-item list - become SourceFile::fragment, detected by a whole-file rule that cannot misfire on a valid file: the first structural item failed (directives, macros and null items do not count; a tolerant Ok that recorded a diagnostic counts as failed - an existing parity test caught if/else reading as a generate-if to one parser and a statement to the other), the file does not open with a design-unit keyword, and a shape consumes the file to EOF, tried narrowest-first. Each shape re-lexes a fresh token stream - Rewind does not restore the tokens' comment buckets and the first draft lost comments on non-fragment files. A fragment formats at indent zero through the existing printers; its declarations bind; its enum variants are not exported (pkg::CUSTOM_1 must not resolve to a name that does not exist). FACTS stays 12. The other .svh was never a fragment problem: a define whose formal argument list spans two lines with no backslash. The lexer continues such a directive until the list closes - incrementally, after QA found the first cut quadratic on an unclosed list (20000 lines: 2.5 s -> 0.56 ms), pinned by a byte-visit counter. Opentitan 12 -> 10 failing files, exactly the two predicted; corpus 813 -> 814 of 820; every remaining comment-gap failure proven to fail identically outside a fragment. docs/features/fragment-mode/README.md. Co-Authored-By: Claude Fable 5 <[email protected]>
186 lines
3.5 KiB
Plaintext
186 lines
3.5 KiB
Plaintext
# Fragment files: a whole file that is the bare middle of some larger
|
|
# construct's body, `include`d at exactly that point. See
|
|
# docs/features/fragment-mode/README.md.
|
|
#
|
|
# Three shapes reach fragment mode — an enum-member list, a covergroup-item
|
|
# list and a statement list — and each is printed at indent 0 through the very
|
|
# printer the body it belongs to uses. A class-body fragment and a module-item
|
|
# fragment are ordinary item lists and never enter fragment mode at all; the
|
|
# last two cases here pin that they still format.
|
|
|
|
# the riscv-dv enum fragment, verbatim: one comment and one member with a
|
|
# trailing comma, included between two members of riscv_instr_pkg's enum
|
|
// TODO: Add custom instruction name enum
|
|
CUSTOM_1,
|
|
----
|
|
// TODO: Add custom instruction name enum
|
|
CUSTOM_1,
|
|
====
|
|
# a run of enum members, one per line, values and name ranges kept
|
|
A ,
|
|
B=2,
|
|
ReqPeriResetIdx[0:1],
|
|
OtbnDmem[16],
|
|
C
|
|
----
|
|
A,
|
|
B = 2,
|
|
ReqPeriResetIdx[0:1],
|
|
OtbnDmem[16],
|
|
C
|
|
====
|
|
# a single member with no trailing comma
|
|
CUSTOM_1
|
|
----
|
|
CUSTOM_1
|
|
====
|
|
# comments in every slot of an enum-member fragment
|
|
// before A
|
|
A, // after A
|
|
/* before B */ B = 2,
|
|
// before C
|
|
C
|
|
// after the last member
|
|
----
|
|
// before A
|
|
A, // after A
|
|
/* before B */
|
|
B = 2,
|
|
// before C
|
|
C
|
|
// after the last member
|
|
====
|
|
# `ifdef arms between enum members stay where they were written
|
|
`ifdef ADD_CUSTOM
|
|
CUSTOM_1,
|
|
CUSTOM_2,
|
|
`endif
|
|
LAST
|
|
----
|
|
`ifdef ADD_CUSTOM
|
|
CUSTOM_1,
|
|
CUSTOM_2,
|
|
`endif
|
|
LAST
|
|
====
|
|
# a statement fragment: the middle of a procedural block
|
|
a = 1;
|
|
b<=2;
|
|
foo( x , y );
|
|
----
|
|
a = 1;
|
|
b <= 2;
|
|
foo(x, y);
|
|
====
|
|
# a statement fragment with a begin/end block and an if/else
|
|
if (a) begin
|
|
x = 1;
|
|
end else begin
|
|
x = 2;
|
|
end
|
|
----
|
|
if (a) begin
|
|
x = 1;
|
|
end else begin
|
|
x = 2;
|
|
end
|
|
====
|
|
# a statement fragment with a loop and a case
|
|
foreach (q[i]) begin
|
|
q[i] = i;
|
|
end
|
|
case (y)
|
|
0: z = 1;
|
|
default: z = 0;
|
|
endcase
|
|
----
|
|
foreach (q[i]) begin
|
|
q[i] = i;
|
|
end
|
|
case (y)
|
|
0: z = 1;
|
|
default: z = 0;
|
|
endcase
|
|
====
|
|
# comments in every slot of a statement fragment
|
|
// leading
|
|
a = 1; // trailing
|
|
/* inline */ b = 2;
|
|
|
|
// after a blank line
|
|
c = 3;
|
|
// dangling at the end
|
|
----
|
|
// leading
|
|
a = 1; // trailing
|
|
/* inline */
|
|
b = 2;
|
|
|
|
// after a blank line
|
|
c = 3;
|
|
// dangling at the end
|
|
====
|
|
# a timing control leads a statement fragment
|
|
@(posedge clk) x <= y;
|
|
#10 z = 1;
|
|
----
|
|
@(posedge clk) x <= y;
|
|
#10 z = 1;
|
|
====
|
|
# a cover-item fragment: labelled coverpoints with bodies
|
|
cp_addr : coverpoint addr {
|
|
bins lo = { [0:9] };
|
|
bins hi = {[10:$]};
|
|
}
|
|
cp_rw: coverpoint rw;
|
|
----
|
|
cp_addr: coverpoint addr {
|
|
bins lo = {[0:9]};
|
|
bins hi = {[10:$]};
|
|
}
|
|
cp_rw: coverpoint rw;
|
|
====
|
|
# a cover-item fragment with a cross and an option
|
|
cp_a: coverpoint a;
|
|
cp_b: coverpoint b;
|
|
x_ab : cross cp_a , cp_b;
|
|
option.per_instance = 1;
|
|
----
|
|
cp_a: coverpoint a;
|
|
cp_b: coverpoint b;
|
|
x_ab: cross cp_a, cp_b;
|
|
option.per_instance = 1;
|
|
====
|
|
# comments in every slot of a cover-item fragment
|
|
// before the coverpoint
|
|
cp_a: coverpoint a; // after it
|
|
|
|
// after a blank line
|
|
x: cross cp_a, cp_b;
|
|
// dangling at the end
|
|
----
|
|
// before the coverpoint
|
|
cp_a: coverpoint a; // after it
|
|
|
|
// after a blank line
|
|
x: cross cp_a, cp_b;
|
|
// dangling at the end
|
|
====
|
|
# a class-body fragment is an ordinary item list and formats as it always did
|
|
rand bit [31:0] addr;
|
|
function void do_it();
|
|
x = 1;
|
|
endfunction
|
|
----
|
|
rand bit [31:0] addr;
|
|
function void do_it();
|
|
x = 1;
|
|
endfunction
|
|
====
|
|
# a module-item fragment is an ordinary item list too
|
|
assign y = a & b;
|
|
always_comb z = y;
|
|
----
|
|
assign y = a & b;
|
|
always_comb z = y;
|