plusargs in systemverilog

Master the Power of Plusargs in SystemVerilog: Must-Know Tips

Plus args are command-line switches supported by the simulator. Usually, they are application-specific. As per SystemVerilog LRM, arguments beginning with the ‘+’ character will be available using the $test$plusargs and $value$plusargs PLI APIs. Plus args are very useful in controlling many things in your environment, such as controlling your debug mode, setting a value like the debug_level in your environment, or selecting/deselecting a particular field in your simulation.

What is the Syntax of plusargs in SystemVerilog?

  • $test$plusargs (string)
  • $value$plusargs (string, variable)

These are system functions that search the list of plusargs in SystemVerilog. For this built-in system function, if a string is found, the function returns the value 1’b1. If no string is found matching, the function returns the value 1’b0, and the variable provided is not modified.

Let’s take an example of how to use these functions in your environment to gain control.

initial begin
  if ($test$plusargs("USER_TEST")) begin
    $display("Configuring User Test"); 
    //Execute some code for this mode
  end
end

Once you compile and later run the simulator with the command-line argument: +USER_TEST, the output will be:

Configuring User Test

Similarly, if you want to read values from the command line into variables, the second system function, $value$plusargs, will be handy.

For Example

initial begin
  string testname;
  if ($value$plusargs("TEST=%s",testname)) begin 
    $display(" Running TEST= %s.",testname); 
  end 
end

Once you compile and pass an argument to the simulator as +TEST=AXI_TEST, the output would be:

Running TEST=AXI_TEST

Similar Posts