# TODO §54.2 — `randsequence` (IEEE 1800 §18.17) as real nodes: a production # list with weighted alternatives, not an opaque leaf. Zero occurrences in the # corpus and in opentitan, so the LRM's own examples are the cases. # docs/features/coverage-gaps-l/README.md # # §18.17's opening example: a start production and three plain ones. module m; initial begin randsequence (main) main : first second done; first : add | dec; second : pop | push; done : {$display("done");}; add : {$display("add");}; dec : {$display("dec");}; pop : {$display("pop");}; push : {$display("push");}; endsequence end endmodule ---- module m; initial begin randsequence (main) main : first second done; first : add | dec; second : pop | push; done : { $display("done"); }; add : { $display("add"); }; dec : { $display("dec"); }; pop : { $display("pop"); }; push : { $display("push"); }; endsequence end endmodule ==== # Weighted alternatives (§18.17.2): `:= weight`, with and without the code # block that runs when the alternative is chosen. Alternatives that fit stay # on the production's line; the case after this one is the same list too wide # for one, broken one per line with each `|` under the `:`. module m; initial begin randsequence (top) top : a := 3 | b := 2 | c := 1; a : add; b : dec := 5 {$display("chosen");}; c : add; add : {x = x + 1;}; dec : {x = x - 1;}; endsequence end endmodule ---- module m; initial begin randsequence (top) top : a := 3 | b := 2 | c := 1; a : add; b : dec := 5 { $display("chosen"); }; c : add; add : { x = x + 1; }; dec : { x = x - 1; }; endsequence end endmodule ==== # The three control shapes an alternative's items may take (§18.17.3–4) and # the interleaving `rand join` (§18.17.6). module m; initial begin randsequence (main) main : gen loop sel mix; gen : if (cond) add else dec; loop : repeat (3) add; sel : case (mode) 0, 1 : add; 2 : dec; default : add; endcase; mix : rand join add dec; bias : rand join (0.5) add dec; add : {x++;}; dec : {x--;}; endsequence end endmodule ---- module m; initial begin randsequence (main) main : gen loop sel mix; gen : if (cond) add else dec; loop : repeat (3) add; sel : case (mode) 0, 1: add; 2: dec; default: add; endcase; mix : rand join add dec; bias : rand join (0.5) add dec; add : { x++; }; dec : { x--; }; endsequence end endmodule ==== # A production with a return type and formal arguments (§18.17.5), and a # reference that passes arguments to one. module m; initial begin randsequence (main) main : bump(3) use_it; void bump(int step) : { total = total + step; }; int use_it : { return total; }; endsequence end endmodule ---- module m; initial begin randsequence (main) main : bump(3) use_it; void bump(int step) : { total = total + step; }; int use_it : { return total; }; endsequence end endmodule ==== # `break` and `return` inside a production's code block are the ordinary # statements they are, and `randsequence ()` may name no start production. module m; initial begin randsequence () main : { if (done) break; return; }; endsequence end endmodule ---- module m; initial begin randsequence () main : { if (done) break; return; }; endsequence end endmodule ==== # Every gap of the grammar takes a comment and prints it back where it was # written: around the `(main)`, around the `:`, the `|` and the `:=`, and # inside a code block and a case arm. module m; initial begin randsequence /*a*/ ( /*b*/ main /*c*/ ) // above the production main /*d*/ : /*e*/ first /*f*/ | /*g*/ second /*h*/ := /*i*/ 3 /*j*/ ; // after it first : { /*k*/ x = 1; /*l*/ }; second : if /*m*/ (c) first /*n*/ else /*o*/ first; third : case /*p*/ (x) 1 /*q*/: /*r*/ first /*s*/ ; default first; endcase; fourth : rand /*t*/ join (2) first second; // before endsequence endsequence end endmodule ---- module m; initial begin randsequence /*a*/ ( /*b*/ main /*c*/ ) // above the production main /*d*/ : /*e*/ first /*f*/ | /*g*/ second /*h*/ := /*i*/ 3 /*j*/ ; // after it first : { /*k*/ x = 1; /*l*/ }; second : if /*m*/ (c) first /*n*/ else /*o*/ first; third : case /*p*/ (x) 1 /*q*/: /*r*/ first /*s*/ ; default first; endcase; fourth : rand /*t*/ join (2) first second; // before endsequence endsequence end endmodule ==== # The same production with alternatives too wide for one line: one per line, # each `|` starting its own, indented under the production's head. module m; initial begin randsequence (top) top : first_alternative_name := 3 | second_alternative_name := 2 | third_alternative_name := 1; first_alternative_name : { x = 1; }; second_alternative_name : { x = 2; }; third_alternative_name : { x = 3; }; endsequence end endmodule ---- module m; initial begin randsequence (top) top : first_alternative_name := 3 | second_alternative_name := 2 | third_alternative_name := 1; first_alternative_name : { x = 1; }; second_alternative_name : { x = 2; }; third_alternative_name : { x = 3; }; endsequence end endmodule