File: TestVpi.h

package info (click to toggle)
verilator 5.006-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 52,732 kB
  • sloc: cpp: 113,602; perl: 18,047; ansic: 8,633; python: 4,688; yacc: 4,382; sh: 2,094; lex: 1,815; makefile: 1,119
file content (53 lines) | stat: -rw-r--r-- 1,619 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// -*- mode: C++; c-file-style: "cc-mode" -*-
//*************************************************************************
//
// Copyright 2013-2023 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// Lesser General Public License Version 3 or the Perl Artistic License
// Version 2.0.
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
//
//*************************************************************************

#include "vpi_user.h"

// Avoid C++11 in this file as not all simulators allow it

//======================================================================

class TestVpiHandle {
    /// For testing, etc, wrap vpiHandle in an auto-releasing class
    vpiHandle m_handle;  // No = as no C++11
    bool m_freeit;  // No = as no C++11

public:
    TestVpiHandle()
        : m_handle(NULL)
        , m_freeit(true) {}
    TestVpiHandle(vpiHandle h)
        : m_handle(h)
        , m_freeit(true) {}
    ~TestVpiHandle() { release(); }
    operator vpiHandle() const { return m_handle; }
    TestVpiHandle& operator=(vpiHandle h) {
        release();
        m_handle = h;
        return *this;
    }
    void release() {
        if (m_handle && m_freeit) {
            // Below not VL_DO_DANGLING so is portable
#ifdef IVERILOG
            vpi_free_object(m_handle);
#else
            vpi_release_handle(m_handle);
#endif
            m_handle = NULL;
        }
    }
    // Freed by another action e.g. vpi_scan; so empty and don't free again
    void freed() {
        m_handle = NULL;
        m_freeit = false;
    }
};