Bluespec functions are statically elaborated at compile time, so in general it does not make sense to use $display
statements inside them. However, if the function returns an Action
or ActionValue
, the action it returns can contain a $display
statement, which will then be elaborated inside any rules or methods which call it.
The syntax for creating an ActionValue
is:
actionvalue
//Anything that can go in a rule body can go here.
$display(...);
return value;
endactionvalue
The syntax for a plain Action
is similar, but with action
/endaction
and no return
statement.
This can then be used in a function definition like so:
function ActionValue#(Type) funcName(Type arg);
...
return actionvalue
...
endactionvalue;
endfunction
If you only need the return statement, you can also use the alternative syntax:
function ActionValue#(Type1) funcName(Type2 arg) =
actionvalue
...
endactionvalue;
One final point, if you actually want to generate output from functions at compile time, you can use the message
function. However, note that this only takes a simple String
argument, rather than handling formatting like $display
does.