Skip to content

Commit

Permalink
Add a check that an instance of libvvp is used only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
ga committed Feb 7, 2024
1 parent 95810b2 commit 9844212
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion vvp/lib_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9844212

Please sign in to comment.