From 98442126491a7d176da28bccb43d85badd047e86 Mon Sep 17 00:00:00 2001 From: ga Date: Wed, 7 Feb 2024 19:17:32 +0000 Subject: [PATCH] Add a check that an instance of libvvp is used only once. --- vvp/lib_main.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vvp/lib_main.cc b/vvp/lib_main.cc index 0696a61b9..62256d0ad 100644 --- a/vvp/lib_main.cc +++ b/vvp/lib_main.cc @@ -57,6 +57,7 @@ extern "C" const char*optarg; bool verbose_flag = false; static int vvp_return_value = 0; +static int vvp_used = 0; void vvp_set_stop_is_finish(bool flag) { @@ -265,12 +266,23 @@ static void final_cleanup() extern void vpip_mcd_init(FILE *log); extern void vvp_vpi_init(void); +static void report_used(void) +{ + fprintf(stderr, + "This VVP simulation has already run and can not be reused\n"); +} + void vvp_init(const char *logfile_name, int argc, char*argv[]) { struct rusage cycle; FILE *logfile = 0x0; extern void vpi_set_vlog_info(int, char**); + if (vvp_used++) { + report_used(); + return; + } + if( ::getenv("VVP_WAIT_FOR_DEBUGGER") != 0 ) { fprintf( stderr, "Waiting for debugger...\n"); bool debugger_release = false; @@ -327,8 +339,18 @@ void vvp_init(const char *logfile_name, int argc, char*argv[]) int vvp_run(const char *design_path) { struct rusage cycles[3]; - int ret_cd = compile_design(design_path); + int ret_cd; + if (vvp_used++ != 1) { + if (vvp_used == 1) + fprintf(stderr, "vvp_init() has not been called\n"); + else + report_used(); + return 1; + } + ++vvp_used; + + ret_cd = compile_design(design_path); destroy_lexor(); print_vpi_call_errors(); if (ret_cd) return ret_cd;