2002-05-18 04:34:11 +02:00
|
|
|
/*
|
2017-06-15 09:47:29 +02:00
|
|
|
* Copyright (c) 2002-2017 Stephen Williams (steve@icarus.com)
|
2002-05-18 04:34:11 +02:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-05-18 04:34:11 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
# include "compile.h"
|
2002-05-18 04:34:11 +02:00
|
|
|
# include "vpi_priv.h"
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cstdio>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cstring>
|
|
|
|
|
# include <cassert>
|
2010-10-24 00:52:56 +02:00
|
|
|
# include "ivl_alloc.h"
|
2002-05-18 04:34:11 +02:00
|
|
|
|
2012-01-23 05:37:01 +01:00
|
|
|
inline __vpiNamedEvent::__vpiNamedEvent(__vpiScope*sc, const char*nam)
|
|
|
|
|
{
|
|
|
|
|
scope_ = sc;
|
|
|
|
|
name_ = vpip_name_string(nam);
|
|
|
|
|
callbacks_ = 0;
|
|
|
|
|
}
|
2012-01-21 02:16:42 +01:00
|
|
|
|
2012-10-09 03:52:24 +02:00
|
|
|
__vpiNamedEvent::~__vpiNamedEvent()
|
|
|
|
|
{
|
|
|
|
|
while (callbacks_) {
|
|
|
|
|
struct __vpiCallback *tmp = callbacks_->next;
|
|
|
|
|
delete callbacks_;
|
|
|
|
|
callbacks_ = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 02:16:42 +01:00
|
|
|
int __vpiNamedEvent::get_type_code(void) const
|
|
|
|
|
{ return vpiNamedEvent; }
|
2008-10-28 18:52:39 +01:00
|
|
|
|
2012-01-21 02:16:42 +01:00
|
|
|
int __vpiNamedEvent::vpi_get(int code)
|
|
|
|
|
{
|
2008-10-28 18:52:39 +01:00
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiAutomatic:
|
2015-12-21 05:26:57 +01:00
|
|
|
return scope_->is_automatic()? 1 : 0;
|
2008-10-28 18:52:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 02:16:42 +01:00
|
|
|
char* __vpiNamedEvent::vpi_get_str(int code)
|
2002-05-19 07:18:16 +02:00
|
|
|
{
|
2008-01-01 18:45:02 +01:00
|
|
|
if (code == vpiFile) { // Not implemented for now!
|
|
|
|
|
return simple_set_rbuf_str(file_names[0]);
|
|
|
|
|
}
|
2012-01-23 05:37:01 +01:00
|
|
|
return generic_get_str(code, scope_, name_, NULL);
|
2002-05-19 07:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-15 09:47:29 +02:00
|
|
|
vpiHandle __vpiNamedEvent::vpi_put_value(p_vpi_value, int)
|
|
|
|
|
{
|
|
|
|
|
// p_vpi_value may be NULL, and an event doesn't care
|
|
|
|
|
// what the value is
|
|
|
|
|
vvp_vector4_t val;
|
|
|
|
|
vvp_net_ptr_t dest(funct, 0);
|
|
|
|
|
vvp_send_vec4(dest, val, vthread_get_wt_context());
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2002-05-19 07:18:16 +02:00
|
|
|
|
2012-01-21 02:16:42 +01:00
|
|
|
vpiHandle __vpiNamedEvent::vpi_handle(int code)
|
|
|
|
|
{
|
2002-05-19 07:18:16 +02:00
|
|
|
switch (code) {
|
|
|
|
|
case vpiScope:
|
2012-01-23 05:37:01 +01:00
|
|
|
return scope_;
|
2009-01-16 20:09:48 +01:00
|
|
|
|
|
|
|
|
case vpiModule:
|
2012-01-23 05:37:01 +01:00
|
|
|
return vpip_module(scope_);
|
2002-05-19 07:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
vpiHandle vpip_make_named_event(const char*name, vvp_net_t*funct)
|
2002-05-18 04:34:11 +02:00
|
|
|
{
|
2012-02-12 22:21:30 +01:00
|
|
|
__vpiNamedEvent*obj = new __vpiNamedEvent(vpip_peek_current_scope(), name);
|
2002-05-18 04:34:11 +02:00
|
|
|
|
2003-04-23 05:09:25 +02:00
|
|
|
obj->funct = funct;
|
2002-05-18 04:34:11 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2002-05-18 04:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
2003-05-04 22:43:36 +02:00
|
|
|
/*
|
|
|
|
|
* This function runs the callbacks for a named event. All the
|
|
|
|
|
* callbacks are listed in the callback member of the event handle,
|
|
|
|
|
* this function scans that list.
|
|
|
|
|
*
|
|
|
|
|
* This also handles the case where the callback has been removed. The
|
|
|
|
|
* vpi_remove_cb doesn't actually remove any callbacks, it marks them
|
2008-01-01 18:45:02 +01:00
|
|
|
* as canceled by clearing the cb_rtn function. This function reaps
|
2003-05-04 22:43:36 +02:00
|
|
|
* those marked handles when it scans the list.
|
2009-02-04 02:25:18 +01:00
|
|
|
*
|
|
|
|
|
* We can not use vpi_free_object() here since it does not really
|
|
|
|
|
* delete the callback.
|
2003-05-04 22:43:36 +02:00
|
|
|
*/
|
2012-01-23 05:37:01 +01:00
|
|
|
void __vpiNamedEvent::run_vpi_callbacks()
|
2002-05-19 07:18:16 +02:00
|
|
|
{
|
2012-01-23 05:37:01 +01:00
|
|
|
struct __vpiCallback*next = callbacks_;
|
2003-05-04 22:43:36 +02:00
|
|
|
struct __vpiCallback*prev = 0;
|
|
|
|
|
while (next) {
|
|
|
|
|
struct __vpiCallback*cur = next;
|
|
|
|
|
next = cur->next;
|
|
|
|
|
|
|
|
|
|
if (cur->cb_data.cb_rtn != 0) {
|
|
|
|
|
callback_execute(cur);
|
|
|
|
|
prev = cur;
|
|
|
|
|
|
|
|
|
|
} else if (prev == 0) {
|
2012-01-23 05:37:01 +01:00
|
|
|
callbacks_ = next;
|
2003-05-04 22:43:36 +02:00
|
|
|
cur->next = 0;
|
2009-02-04 02:25:18 +01:00
|
|
|
delete cur;
|
2003-05-04 22:43:36 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
assert(prev->next == cur);
|
|
|
|
|
prev->next = next;
|
|
|
|
|
cur->next = 0;
|
2009-02-04 02:25:18 +01:00
|
|
|
delete cur;
|
2003-05-04 22:43:36 +02:00
|
|
|
}
|
2002-05-19 07:18:16 +02:00
|
|
|
}
|
|
|
|
|
}
|