2013-10-14 00:05:57 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2023-01-01 15:18:39 +00:00
|
|
|
// Copyright 2013-2023 by Wilson Snyder. This program is free software; you can
|
2013-10-14 00:05:57 +00:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2020-03-21 15:24:24 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
2013-10-14 00:05:57 +00:00
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2013-10-14 00:05:57 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
#include "vpi_user.h"
|
|
|
|
|
2021-02-03 22:39:03 +00:00
|
|
|
// Avoid C++11 in this file as not all simulators allow it
|
2021-02-03 22:36:25 +00:00
|
|
|
|
2013-10-14 00:05:57 +00:00
|
|
|
//======================================================================
|
|
|
|
|
|
|
|
class TestVpiHandle {
|
|
|
|
/// For testing, etc, wrap vpiHandle in an auto-releasing class
|
2021-02-03 22:36:25 +00:00
|
|
|
vpiHandle m_handle; // No = as no C++11
|
|
|
|
bool m_freeit; // No = as no C++11
|
2019-11-10 01:35:12 +00:00
|
|
|
|
2013-10-14 00:05:57 +00:00
|
|
|
public:
|
2021-02-03 22:39:03 +00:00
|
|
|
TestVpiHandle()
|
|
|
|
: m_handle(NULL)
|
|
|
|
, m_freeit(true) {}
|
2019-11-10 01:35:12 +00:00
|
|
|
TestVpiHandle(vpiHandle h)
|
2021-02-04 00:43:29 +00:00
|
|
|
: m_handle(h)
|
|
|
|
, m_freeit(true) {}
|
2020-12-19 02:16:57 +00:00
|
|
|
~TestVpiHandle() { release(); }
|
2018-08-25 13:52:45 +00:00
|
|
|
operator vpiHandle() const { return m_handle; }
|
2022-09-16 12:17:38 +00:00
|
|
|
TestVpiHandle& operator=(vpiHandle h) {
|
2020-12-19 02:16:57 +00:00
|
|
|
release();
|
2019-11-10 01:35:12 +00:00
|
|
|
m_handle = h;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-12-19 02:16:57 +00:00
|
|
|
void release() {
|
|
|
|
if (m_handle && m_freeit) {
|
|
|
|
// Below not VL_DO_DANGLING so is portable
|
2021-02-04 00:29:24 +00:00
|
|
|
#ifdef IVERILOG
|
|
|
|
vpi_free_object(m_handle);
|
|
|
|
#else
|
2020-12-19 02:16:57 +00:00
|
|
|
vpi_release_handle(m_handle);
|
2021-02-04 00:29:24 +00:00
|
|
|
#endif
|
2020-12-19 02:16:57 +00:00
|
|
|
m_handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 01:36:04 +00:00
|
|
|
// Freed by another action e.g. vpi_scan; so empty and don't free again
|
|
|
|
void freed() {
|
|
|
|
m_handle = NULL;
|
2020-12-19 02:16:57 +00:00
|
|
|
m_freeit = false;
|
2013-10-14 00:05:57 +00:00
|
|
|
}
|
|
|
|
};
|