I answered a very similar question on my sister's website, Electronics StackExchange, for a β way to conditionally run a compile-time error in verilog . The solution is to conditionally create an instance of modules that do not exist. I recommend that a non-existent module have a very long name and meaningful name explains the error, this also reduces the risk that non-existent modules accidentally have the same name as an existing module.
generate if (PARAM1 == 1 && PARAM2 == 2) begin : use_logicA // instantiate module logic_A end else if (PARAM1 == 2 && PARAM2 == 1) begin : use_logicB // instantiate module logic_B end else begin : illegal illegal_parameter_condition_triggered_will_instantiate_an non_existing_module(); end endgenerate
This works because the verification of the existence of a non-existent module is not performed until the parameter values ββare evaluated at the design stage.
A better solution would be to use the SystemVerilog approach; especially with a simulator that complements the IEEE Std 1800-2009 or later standard. Then you can use $error() and give a more meaningful message to go with the error (for example, print the values ββof the parameters that caused the error condition). You can learn more about this in IEEE Std 1800-2012 20.11 Development System Objectives
generate if (PARAM1 == 1 && PARAM2 == 2) begin : use_logicA // instantiate module logic_A end else if (PARAM1 == 2 && PARAM2 == 1) begin : use_logicB // instantiate module logic_B end else begin : illegal $error("Expected PRAM1/2 to be 1/2 or 2/1, but was %0d/%0d", PARAM1, PARAM2 ); end endgenerate
source share