Add vvp "quiet" flag (issue #1193)

This adds a "-q" option on the vvp command line and a vvp_set_quiet_flag()
function in the VVP library API. Setting this flag will cause all output
to standard output via MCD bit 0 to be suppressed. It will not prevent the
output being sent to a log file if the vvp "-l" option has been used, and
it will not affect output to the STDOUT file descriptor.
This commit is contained in:
Martin Whitaker 2024-12-31 13:05:36 +00:00
parent 03835c9d50
commit adb6a2f454
5 changed files with 43 additions and 11 deletions

View File

@ -68,6 +68,11 @@ void vvp_set_stop_is_finish(bool flag, int exit_code)
stop_is_finish_exit_code = exit_code; stop_is_finish_exit_code = exit_code;
} }
void vvp_set_quiet_flag(bool flag)
{
vpip_mcd0_disable = flag;
}
void vvp_set_verbose_flag(bool flag) void vvp_set_verbose_flag(bool flag)
{ {
verbose_flag = flag; verbose_flag = flag;

View File

@ -21,6 +21,13 @@ extern "C" {
extern void vvp_set_stop_is_finish(bool flag, int exit_code); extern void vvp_set_stop_is_finish(bool flag, int exit_code);
/* vvp_set_quiet_flag(true) is equivalent to vvp's "-q" option.
*
* This function may be called at any time.
*/
extern void vvp_set_quiet_flag(bool flag);
/* vvp_set_verbose(true) is equivalent to vvp's "-v" option. /* vvp_set_verbose(true) is equivalent to vvp's "-v" option.
* *
* This function may be called at any time. * This function may be called at any time.

View File

@ -53,7 +53,7 @@ int main(int argc, char*argv[])
unsigned flag_errors = 0; unsigned flag_errors = 0;
const char *logfile_name = 0x0; const char *logfile_name = 0x0;
while ((opt = getopt(argc, argv, "+hil:M:m:nNsvV")) != EOF) switch (opt) { while ((opt = getopt(argc, argv, "+hil:M:m:nNqsvV")) != EOF) switch (opt) {
case 'h': case 'h':
fprintf(stderr, fprintf(stderr,
"Usage: vvp [options] input-file [+plusargs...]\n" "Usage: vvp [options] input-file [+plusargs...]\n"
@ -66,6 +66,7 @@ int main(int argc, char*argv[])
" -m module Load vpi module.\n" " -m module Load vpi module.\n"
" -n Non-interactive ($stop = $finish).\n" " -n Non-interactive ($stop = $finish).\n"
" -N Same as -n, but exit code is 1 instead of 0\n" " -N Same as -n, but exit code is 1 instead of 0\n"
" -q Quiet mode (suppress output on MCD bit 0).\n"
" -s $stop right away.\n" " -s $stop right away.\n"
" -v Verbose progress messages.\n" " -v Verbose progress messages.\n"
" -V Print the version information.\n" ); " -V Print the version information.\n" );
@ -92,6 +93,9 @@ int main(int argc, char*argv[])
case 'N': case 'N':
vvp_set_stop_is_finish(true, 1); vvp_set_stop_is_finish(true, 1);
break; break;
case 'q':
vvp_set_quiet_flag(true);
break;
case 's': case 's':
schedule_stop(0); schedule_stop(0);
break; break;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000-2020 Stephen G. Tell <steve@telltronics.org> * Copyright (c) 2000-2024 Stephen G. Tell <steve@telltronics.org>
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU * and/or modify it in source code form under the terms of the GNU
@ -34,8 +34,8 @@ extern FILE* vpi_trace;
/* /*
* This table keeps track of the MCD files. Note that there may be * This table keeps track of the MCD files. Note that there may be
* only 31 such files, and mcd bit0 (32'h00_00_00_01) is the special * only 31 such files, and mcd bit0 (32'h00_00_00_01) is the special
* standard output file, which may be replicated to a logfile * standard output file, which may be replicated to a logfile and/or
* depending on flags to the command line. * suppressed depending on flags to the command line.
*/ */
/* /*
@ -55,6 +55,8 @@ static unsigned fd_table_len = 0;
static FILE* logfile; static FILE* logfile;
bool vpip_mcd0_disable = false;
/* Initialize mcd portion of vpi. Must be called before /* Initialize mcd portion of vpi. Must be called before
* any vpi_mcd routines can be used. * any vpi_mcd routines can be used.
*/ */
@ -217,9 +219,12 @@ vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap)
for(int i = 0; i < 31; i++) { for(int i = 0; i < 31; i++) {
if((mcd>>i) & 1) { if((mcd>>i) & 1) {
if(mcd_table[i].fp) { if(mcd_table[i].fp) {
// echo to logfile if (i == 0) {
if (i == 0 && logfile) if (logfile)
fputs(buf_ptr, logfile); fputs(buf_ptr, logfile);
if (vpip_mcd0_disable)
continue;
}
fputs(buf_ptr, mcd_table[i].fp); fputs(buf_ptr, mcd_table[i].fp);
} else { } else {
rc = EOF; rc = EOF;
@ -251,10 +256,13 @@ extern "C" void vpip_mcd_rawwrite(PLI_UINT32 mcd, const char*buf, size_t cnt)
if (mcd_table[idx].fp == 0) if (mcd_table[idx].fp == 0)
continue; continue;
if (idx == 0) {
if (logfile)
fwrite(buf, 1, cnt, logfile);
if (vpip_mcd0_disable)
continue;
}
fwrite(buf, 1, cnt, mcd_table[idx].fp); fwrite(buf, 1, cnt, mcd_table[idx].fp);
if (idx == 0 && logfile)
fwrite(buf, 1, cnt, logfile);
} }
} }
@ -265,7 +273,12 @@ extern "C" PLI_INT32 vpi_mcd_flush(PLI_UINT32 mcd)
if (IS_MCD(mcd)) { if (IS_MCD(mcd)) {
for(int i = 0; i < 31; i++) { for(int i = 0; i < 31; i++) {
if((mcd>>i) & 1) { if((mcd>>i) & 1) {
if (i == 0 && logfile) fflush(logfile); if (i == 0) {
if (logfile)
fflush(logfile);
if (vpip_mcd0_disable)
continue;
}
if (fflush(mcd_table[i].fp)) rc |= 1<<i; if (fflush(mcd_table[i].fp)) rc |= 1<<i;
} }
} }

View File

@ -1154,4 +1154,7 @@ extern vpiHandle vpip_module(__vpiScope*scope);
extern int vpip_delay_selection; extern int vpip_delay_selection;
/* A flag to disable output to MCD bit 0. */
extern bool vpip_mcd0_disable;
#endif /* IVL_vpi_priv_H */ #endif /* IVL_vpi_priv_H */