Function Call
Function can be call by function_name(argument).
System function of SystemVerilog like $clog2 can be used too.
package PackageA {
function FunctionA (
a: input logic,
b: input logic,
) {}
}
module ModuleA {
let _a: logic = PackageA::FunctionA(1, 1);
let _b: logic = $clog2(1);
}
System Function
The following system tasks and functions of SystemVerilog (IEEE Std 1800-2023 Clause 20 and 21) can be used, and they are emitted to SystemVerilog as is.
Note that the native simulator supports only a part of them.
In addition, $assert and $assert_continue are available for native test.
| Category | Functions |
|---|---|
| Simulation control system tasks | $stop, $finish, $exit |
| Simulation time system functions | $time, $stime, $realtime |
| Timescale system tasks and system functions | $timeunit, $timeprecision, $printtimescale, $timeformat |
| Conversion functions | $rtoi, $itor, $realtobits, $bitstoreal, $shortrealtobits, $bitstoshortreal, $signed, $unsigned, $cast |
| Data query functions | $typename, $bits, $isunbounded |
| Array query functions | $dimensions, $unpacked_dimensions, $left, $right, $low, $high, $increment, $size |
| Math functions | $clog2, $ln, $log10, $exp, $sqrt, $pow, $floor, $ceil, $sin, $cos, $tan, $asin, $acos, $atan, $atan2, $hypot, $sinh, $cosh, $tanh, $asinh, $acosh, $atanh |
| Bit vector system functions | $countbits, $countones, $onehot, $onehot0, $isunknown |
| Severity system tasks | $fatal, $error, $warning, $info |
| Assertion control system tasks | $asserton, $assertoff, $assertkill, $assertpasson, $assertpassoff, $assertfailon, $assertfailoff, $assertnonvacuouson, $assertvacuousoff, $assertcontrol |
| Sampled value system functions | $sampled, $rose, $fell, $stable, $changed, $past, $past_gclk, $rose_gclk, $fell_gclk, $stable_gclk, $changed_gclk, $future_gclk, $rising_gclk, $falling_gclk, $steady_gclk, $changing_gclk |
| Built-in coverage access system functions | $coverage_control, $coverage_get_max, $coverage_get, $coverage_merge, $coverage_save |
| Predefined coverage system tasks and system functions | $set_coverage_db_name, $load_coverage_db, $get_coverage |
| Probabilistic distribution functions | $random, $urandom, $urandom_range, $dist_uniform, $dist_normal, $dist_exponential, $dist_poisson, $dist_chi_square, $dist_t, $dist_erlang |
| Stochastic analysis tasks and functions | $q_initialize, $q_add, $q_remove, $q_full, $q_exam |
| Programmable logic array modeling system tasks | $async$and$array, $sync$and$array, $async$and$plane, $sync$and$plane, $async$nand$array, $sync$nand$array, $async$nand$plane, $sync$nand$plane, $async$or$array, $sync$or$array, $async$or$plane, $sync$or$plane, $async$nor$array, $sync$nor$array, $async$nor$plane, $sync$nor$plane |
| Miscellaneous tasks and functions | $system |
| Input/output system tasks and system functions | $display, $displayb, $displayo, $displayh, $write, $writeb, $writeo, $writeh, $strobe, $strobeb, $strobeo, $strobeh, $monitor, $monitorb, $monitoro, $monitorh, $monitoron, $monitoroff, $fopen, $fclose, $fdisplay, $fdisplayb, $fdisplayo, $fdisplayh, $fwrite, $fwriteb, $fwriteo, $fwriteh, $fstrobe, $fstrobeb, $fstrobeo, $fstrobeh, $fmonitor, $fmonitorb, $fmonitoro, $fmonitorh, $swrite, $swriteb, $swriteo, $swriteh, $sformat, $sformatf, $fgetc, $ungetc, $fgets, $fscanf, $sscanf, $fread, $ftell, $fseek, $rewind, $fflush, $ferror, $feof |
| Loading memory array data from a file | $readmemb, $readmemh |
| Writing memory array data to a file | $writememb, $writememh |
| Command line input | $test$plusargs, $value$plusargs |
| Value change dump (VCD) files | $dumpfile, $dumpvars, $dumpoff, $dumpon, $dumpall, $dumplimit, $dumpflush, $dumpports, $dumpportsoff, $dumpportson, $dumpportsall, $dumpportslimit, $dumpportsflush |
Named Argument
If a function has many arguments, function call with named arguments is useful. Named arguments can’t be used with positional arguments at the same time.
module ModuleA {
function FunctionA (
a: input logic,
b: input logic,
c: input logic,
d: input logic,
) {}
let _a: logic = FunctionA(
a: 1,
b: 1,
c: 1,
d: 1,
);
// Mixing positional and named arguments is Error
//let _a: logic = FunctionA(
// 1,
// 2,
// a: 1,
// b: 1,
//);
}