A7.1.2 What the Bound Module Can See

MediumDebugIcarus · browser samples / server checksReview the topic

Five small edits to a bound checker. Say which ones compile and still catch the bug, and which do not compile.

Hardware context: A rule module bound into a FIFO, reading its internal count. Know which names a bound checker and its target can see, and how to reach the others.

A rule module is bound into a FIFO. Its port cnt is connected to the FIFO's internal count. The test pushes five words into four places.

Write answer(q). For each graded edit, return 1 if the program compiles and still reports the overflow. Return 0 otherwise.

Questions 0 to 2 are worked examples on other edits. Questions 3 to 7 are graded only by the full check.

Signals in the Timeline

SignalWidthRole
question4input of each check
Full specification
The program
module fifo #(parameter logic [2:0] CAP = 3'd4) (input logic clk, push, pop, output logic full);
  logic [2:0] count = 0;                       // internal: not a port of fifo
  always @(posedge clk) count <= count + push - pop;
  assign full = (count == CAP);
endmodule
module fifo_rules (input logic clk, input logic [2:0] cnt, input logic full);
  int fails = 0;
  localparam logic [2:0] DEPTH = 3'd4;         // the checker's own name
  cap: assert property (@(posedge clk) cnt <= DEPTH) else fails++;
endmodule
bind fifo fifo_rules rules (.clk(clk), .cnt(count), .full(full));
module tb;
  logic clk = 0, push = 0, pop = 0, full;
  always #5 clk = ~clk;
  fifo u_fifo (.clk, .push, .pop, .full);
  initial begin
    #12 push = 1;                              // five pushes into four places
    #50 push = 0;
    #10 $display("fails=%0d", u_fifo.rules.fails);
    $finish;
  end
endmodule
qEdit (graded)
3the checker reads fifo's parameter CAP by its plain name
4the checker reads fifo's port push by its plain name
5tb also prints u_fifo.count, a downward name
6the checker reads $root.tb.u_fifo.count
7the bind connects count[1:0] to cnt
qEdit (worked example)
0the checker connected with .* (port names match: clk, cnt renamed count)
1two fifo instances, bind to the module type: rule instances
2two fifo instances, two bind statements on fifo (rules and rules2): rule instances

Simulator note: Every key was measured on Verilator 5.052 and agrees with IEEE 1800-2023 23.11 and 23.8. Your answer function is checked by a small bench on Icarus 12.

Examples

Example 1

The Checker Connected with .* (Port Names Match: Clk, Cnt Renamed Count)
Input
answer(0)
Output
answer = 1

The implicit connection pairs ports with the same names in the target.

Example 2

Two Fifo Instances, Bind to the Module Type: Rule Instances
Input
answer(1)
Output
answer = 2

Each instance of the target type gets its own rule instance.

Example 3

Two Fifo Instances, Two Bind Statements on Fifo (Rules and rules2): Rule Instances
Input
answer(2)
Output
answer = 4

Each bind statement adds one instance to every fifo: two times two.

Constraints and Contract

  • Return one value per question from answer(q).
  • Keep the function header.

Hints

Hint 1

The actual expressions of a bind are resolved inside the target, so they may name its internal signals.

Hint 2

Inside the bound module, plain names resolve in the bound module itself, as in any other module.

Hint 3

Hierarchical names work both ways: up by module name, down by instance name.

What the grader checks: Eight constant answers: three worked examples and five graded questions, each a compile-and-run result on Verilator 5.052.

8 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 4 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

The Checker Connected with .* (Port Names Match: Clk, Cnt Renamed Count)

Input
answer(0)
Expected output
answer = 1

The implicit connection pairs ports with the same names in the target.

Run samples executes all 3 public checks. Check all tests runs 8 checks on the server.

Icarus · browser samples / server checks