From e633fcc1996f0fccf8ec35e1dcdaf2fb3a58c548 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 28 Dec 2020 09:55:54 -0800 Subject: [PATCH] Initial fix for GH449 --- vhdlpp/sequential_emit.cc | 4 +-- vpi/sys_finish.c | 64 ++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/vhdlpp/sequential_emit.cc b/vhdlpp/sequential_emit.cc index 25dc6f60d..359366cd1 100644 --- a/vhdlpp/sequential_emit.cc +++ b/vhdlpp/sequential_emit.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2020 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) * Copyright CERN 2015 * @author Maciej Suminski (maciej.suminski@cern.ch) @@ -556,7 +556,7 @@ int ReportStmt::emit(ostream&out, Entity*ent, ScopeBase*scope) out << "\" (" << get_fileline() << ")\");"; if(severity_ == FAILURE) - out << "$finish();"; + out << "$finish(0);"; out << std::endl; diff --git a/vpi/sys_finish.c b/vpi/sys_finish.c index 3be3d0810..211873a3d 100644 --- a/vpi/sys_finish.c +++ b/vpi/sys_finish.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2020 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -19,22 +19,72 @@ #include "sys_priv.h" #include +#include static PLI_INT32 sys_finish_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name) { vpiHandle callh, argv; s_vpi_value val; - long diag_msg = 1; + int diag_msg = 1; + int had_arg = 0; /* Get the argument list and look for the diagnostic message level. */ callh = vpi_handle(vpiSysTfCall, 0); argv = vpi_iterate(vpiArgument, callh); if (argv) { - vpiHandle arg = vpi_scan(argv); - vpi_free_object(argv); - val.format = vpiIntVal; - vpi_get_value(arg, &val); - diag_msg = val.value.integer; + vpiHandle arg = vpi_scan(argv); + vpi_free_object(argv); + val.format = vpiIntVal; + vpi_get_value(arg, &val); + diag_msg = val.value.integer; + if ((diag_msg < 0) || (diag_msg > 2)) { + vpi_printf("WARNING: %s:%d: ", vpi_get_str(vpiFile, callh), + (int)vpi_get(vpiLineNo, callh)); + vpi_printf("%s(%d) argument must be 0, 1, or 2.\n", + (const char*)name, (int)diag_msg); + } + had_arg = 1; + } + + if (diag_msg != 0) { + s_vpi_time now; + int units; + uint64_t raw_time; + vpi_printf("%s:%d: %s", + vpi_get_str(vpiFile, callh), + (int)vpi_get(vpiLineNo, callh), + (const char*)name); + if (had_arg) vpi_printf("(%d)", diag_msg); + now.type = vpiSimTime; + vpi_get_time(0, &now); + raw_time = now.high; + raw_time <<= 32; + raw_time |= now.low; + vpi_printf(" called at %" PRIu64, raw_time); + units = vpi_get(vpiTimePrecision, 0); + switch (units) { + case 2: vpi_printf(" (100s)\n"); break; + case 1: vpi_printf(" (10s)\n"); break; + case 0: vpi_printf(" (1s)\n"); break; + case -1: vpi_printf(" (100ms)\n"); break; + case -2: vpi_printf(" (10ms)\n"); break; + case -3: vpi_printf(" (1ms)\n"); break; + case -4: vpi_printf(" (100us)\n"); break; + case -5: vpi_printf(" (10us)\n"); break; + case -6: vpi_printf(" (1us)\n"); break; + case -7: vpi_printf(" (100ns)\n"); break; + case -8: vpi_printf(" (10ns)\n"); break; + case -9: vpi_printf(" (1ns)\n"); break; + case -10: vpi_printf(" (100ps)\n"); break; + case -11: vpi_printf(" (10ps)\n"); break; + case -12: vpi_printf(" (1ps)\n"); break; + case -13: vpi_printf(" (100fs)\n"); break; + case -14: vpi_printf(" (10fs)\n"); break; + case -15: vpi_printf(" (1fs)\n"); break; + default: + vpi_printf("unknown time unit '%d'", units); + assert(0); + } } if (strcmp((const char*)name, "$stop") == 0) {