From eeeb9ff09982ba47aca03aaeb9627125e6e05be3 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 30 Oct 2019 12:23:24 -0700 Subject: [PATCH] Create files with default suffix when $dumpfile doesn't include a suffix. --- vpi/sys_fst.c | 2 +- vpi/sys_lxt.c | 2 +- vpi/sys_lxt2.c | 2 +- vpi/sys_priv.c | 20 ++++++++++++++++++++ vpi/sys_priv.h | 2 ++ vpi/sys_vcd.c | 2 +- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/vpi/sys_fst.c b/vpi/sys_fst.c index 5286c1443..0bb185744 100644 --- a/vpi/sys_fst.c +++ b/vpi/sys_fst.c @@ -435,7 +435,7 @@ static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) return 0; } - path = get_filename(callh, name, vpi_scan(argv)); + path = get_filename_with_suffix(callh, name, vpi_scan(argv), "fst"); vpi_free_object(argv); if (! path) return 0; diff --git a/vpi/sys_lxt.c b/vpi/sys_lxt.c index d0de6765d..100a5fa31 100644 --- a/vpi/sys_lxt.c +++ b/vpi/sys_lxt.c @@ -490,7 +490,7 @@ static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) return 0; } - path = get_filename(callh, name, vpi_scan(argv)); + path = get_filename_with_suffix(callh, name, vpi_scan(argv), "lxt"); vpi_free_object(argv); if (! path) return 0; diff --git a/vpi/sys_lxt2.c b/vpi/sys_lxt2.c index 3327264d1..4d10c1c10 100644 --- a/vpi/sys_lxt2.c +++ b/vpi/sys_lxt2.c @@ -543,7 +543,7 @@ static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) return 0; } - path = get_filename(callh, name, vpi_scan(argv)); + path = get_filename_with_suffix(callh, name, vpi_scan(argv), "lx2"); vpi_free_object(argv); if (! path) return 0; diff --git a/vpi/sys_priv.c b/vpi/sys_priv.c index dd9714325..5636bad8e 100644 --- a/vpi/sys_priv.c +++ b/vpi/sys_priv.c @@ -103,6 +103,26 @@ char *get_filename(vpiHandle callh, const char *name, vpiHandle file) return strdup(val.value.str); } +char* get_filename_with_suffix(vpiHandle callh, const char *name, vpiHandle file, const char*suff) +{ + char*path = get_filename(callh, name, file); + if (path == 0) return 0; + + /* If the name already has a suffix, then don't replace it or + add another suffix. Just return this path. */ + char*tailp = strrchr(path, '.'); + if (tailp != 0) return path; + + /* The name doesn't have a suffix, so append the passed in + suffix to the file name. */ + char*new_path = malloc(strlen(path) + strlen(suff) + 2); + strcpy(new_path, path); + strcat(new_path, "."); + strcat(new_path, suff); + free(path); + return new_path; +} + void check_for_extra_args(vpiHandle argv, vpiHandle callh, const char *name, const char *arg_str, unsigned opt) { diff --git a/vpi/sys_priv.h b/vpi/sys_priv.h index d9052d51d..13e620b5d 100644 --- a/vpi/sys_priv.h +++ b/vpi/sys_priv.h @@ -37,6 +37,8 @@ extern PLI_UINT64 timerec_to_time64(const struct t_vpi_time*timerec); extern char *as_escaped(char *arg); extern char *get_filename(vpiHandle callh, const char *name, vpiHandle file); +extern char *get_filename_with_suffix(vpiHandle callh, const char*name, + vpiHandle file, const char*suff); extern void check_for_extra_args(vpiHandle argv, vpiHandle callh, const char *name, const char *arg_str, unsigned opt); diff --git a/vpi/sys_vcd.c b/vpi/sys_vcd.c index fb97a2fad..b6362c900 100644 --- a/vpi/sys_vcd.c +++ b/vpi/sys_vcd.c @@ -467,7 +467,7 @@ static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) return 0; } - path = get_filename(callh, name, vpi_scan(argv)); + path = get_filename_with_suffix(callh, name, vpi_scan(argv), "vcd"); vpi_free_object(argv); if (! path) return 0;