Skip to content

Write a class, a compound constraint, and a factory function from scratch

write-from-scratch

A handle declared but never assigned with new() is null, and using it fails at runtime, not at compile time. A factory function’s one job is to construct the object before returning it.

Fix the class and function below.

Requirements

  1. addr’s low 2 bits are always 0 (addr[1:0] == 2’b00).
  2. size stays between 1 and 8, inclusive.
  3. make_item() returns a valid (non-null) handle.

Source on GitHub

sv_mechanics_chain.sv