1 // -*- mode: C++; c-file-style: "cc-mode" -*-
2 //*************************************************************************
3 //
4 // Copyright 2009-2011 by Wilson Snyder. This program is free software; you
5 // can redistribute it and/or modify it under the terms of either the GNU
6 // Lesser General Public License Version 3 or the Perl Artistic License
7 // Version 2.0.
8 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9 //
10 //*************************************************************************
11 
12 #include <cstdio>
13 #include "svdpi.h"
14 #include "vpi_user.h"
15 #include "TestVpi.h"
16 
17 //======================================================================
18 
19 #define NEED_EXTERNS
20 
21 #ifdef NEED_EXTERNS
22 extern "C" {
23 extern void dpii_check();
24 }
25 #endif
26 
27 //======================================================================
28 
show(vpiHandle obj)29 void show(vpiHandle obj) {
30     const char* namep;
31     if (obj) {
32         namep = vpi_get_str(vpiName, obj);
33     } else {
34         namep = "global";
35     }
36 
37     s_vpi_time t;
38     t.type = vpiSimTime;
39     vpi_get_time(obj, &t);
40     vpi_printf(const_cast<char*>("%s vpiSimTime = %d,%d"), namep, (int)t.high, (int)t.low);
41 
42     // Should be same value as vpiSimTime, just converted to real
43     t.type = vpiScaledRealTime;
44     vpi_get_time(obj, &t);
45     vpi_printf(const_cast<char*>("  vpiScaledRealTime = %g\n"), t.real);
46 
47     // These will both print the precision, because the 0 asks for global scope
48     int u = vpi_get(vpiTimeUnit, obj);
49     int p = vpi_get(vpiTimePrecision, obj);
50     vpi_printf(const_cast<char*>("%s vpiTimeUnit = %d"), namep, u);
51     vpi_printf(const_cast<char*>("  vpiTimePrecision = %d\n"), p);
52 }
53 
dpii_check()54 void dpii_check() {
55     show(0);
56 
57     TestVpiHandle mod = vpi_handle_by_name((PLI_BYTE8*)"top.t", NULL);
58     if (!mod) {
59         vpi_printf(const_cast<char*>("-- Cannot vpi_find module\n"));
60     } else {
61         show(mod);
62     }
63 }
64