Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Interview Questions Set 4: Is it possible to override existing constraints?

SystemVerilog Interview Questions

Runnable example from the SystemVerilog Interview Questions Set 4 tutorial (Is it possible to override existing constraints?)

Open in IDE
testbench.sv
class ABC;
	rand bit [3:0] data;

	constraint c_data { data inside {[5:10]}; }
endclass

module tb;
	initial begin
		ABC abc = new;

		// Use inline constraint to override with new value
		// Note that this should not contradict the hard constraints in ABC
		abc.randomize() with { data == 8; };
	end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.