diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 04cd66799..1821f049f 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -2161,6 +2161,9 @@ static PLI_INT32 sys_severity_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) free(dstr); if (strncmp(name,"$fatal",6) == 0) { + /* Set the exit code from vvp as an error code. */ + vpip_set_return_value(1); + /* Now tell the simulator to finish. */ vpi_control(vpiFinish, finish_number.value.integer); } diff --git a/vpi/sys_finish.c b/vpi/sys_finish.c index cc3a88326..3be3d0810 100644 --- a/vpi/sys_finish.c +++ b/vpi/sys_finish.c @@ -42,6 +42,8 @@ static PLI_INT32 sys_finish_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name) return 0; } + vpip_set_return_value(0); + vpi_control(vpiFinish, diag_msg); return 0; } diff --git a/vpi_user.h b/vpi_user.h index db0a9bd5f..0be7fbfeb 100644 --- a/vpi_user.h +++ b/vpi_user.h @@ -630,7 +630,14 @@ extern DLLEXPORT void (*vlog_startup_routines[])(void); /* Format a scalar a la %v. The str points to a 4byte character buffer. The value must be a vpiStrengthVal. */ extern void vpip_format_strength(char*str, s_vpi_value*value, unsigned bit); + /* Set the return value to return from the vvp run time. This is + usually 0 or 1. This is the exit code that the vvp process + returns, and in distinct from the finish_number that is an + argument to $fatal and other severity tasks. The $fatal and + $finish system tasks bundled with iverilog use this function to + tell vvp to exit SUCCESS or FAILURE. */ extern void vpip_set_return_value(int value); + extern s_vpi_vecval vpip_calc_clog2(vpiHandle arg); extern void vpip_make_systf_system_defined(vpiHandle ref); diff --git a/vvp/stop.cc b/vvp/stop.cc index c82728188..5f20d09a9 100644 --- a/vvp/stop.cc +++ b/vvp/stop.cc @@ -535,7 +535,7 @@ void stop_handler(int rc) /* The user may be running in a non-interactive environment, so * they want $stop and to be the same as $finish. */ if (stop_is_finish) { - vpip_set_return_value(stop_is_finish_exit_code); + vpip_set_return_value(stop_is_finish_exit_code); schedule_finish(0); return; }