diff --git a/vvp/array.cc b/vvp/array.cc index a28332ef3..a13d85dfe 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -1516,13 +1516,13 @@ void array_word_change(vvp_array_t array, unsigned long addr) array->vpi_callbacks = next; cur->next = 0; - delete_vpi_callback(cur); + delete cur; } else { assert(prev->next == cur); prev->next = next; cur->next = 0; - delete_vpi_callback(cur); + delete cur; } } } diff --git a/vvp/compile.cc b/vvp/compile.cc index 5fc1ba667..89fe73717 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -296,17 +296,17 @@ vvp_net_t* vvp_net_lookup(const char*label) case vpiIntVar: case vpiLongIntVar: case vpiIntegerVar: { - __vpiSignal*sig = (__vpiSignal*)vpi; + __vpiSignal*sig = dynamic_cast<__vpiSignal*>(vpi); return sig->node; } case vpiRealVar: { - __vpiRealVar*sig = (__vpiRealVar*)vpi; + __vpiRealVar*sig = dynamic_cast<__vpiRealVar*>(vpi); return sig->net; } case vpiNamedEvent: { - __vpiNamedEvent*tmp = (__vpiNamedEvent*)vpi; + __vpiNamedEvent*tmp = dynamic_cast<__vpiNamedEvent*>(vpi); return tmp->funct; } diff --git a/vvp/event.cc b/vvp/event.cc index 30ffa6f7c..81fc84bf7 100644 --- a/vvp/event.cc +++ b/vvp/event.cc @@ -688,7 +688,9 @@ void vvp_named_event_sa::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit, vvp_net_t*net = port.ptr(); net->send_vec4(bit, 0); - vpip_run_named_event_callbacks(handle_); + __vpiNamedEvent*obj = dynamic_cast<__vpiNamedEvent*>(handle_); + assert(obj); + obj->run_vpi_callbacks(); } vvp_named_event_aa::vvp_named_event_aa(class __vpiHandle*h) diff --git a/vvp/vpi_callback.cc b/vvp/vpi_callback.cc index 089f0a5f8..5c6a617bb 100644 --- a/vvp/vpi_callback.cc +++ b/vvp/vpi_callback.cc @@ -34,15 +34,6 @@ # include # include # include - - -inline __vpiCallback::__vpiCallback() -{ } - -int __vpiCallback::get_type_code(void) const -{ return vpiCallback; } - - /* * Callback handles are created when the VPI function registers a * callback. The handle is stored by the run time, and it triggered @@ -67,24 +58,20 @@ struct sync_cb : public vvp_gen_event_s { virtual void run_run(); }; -struct __vpiCallback* new_vpi_callback() +inline __vpiCallback::__vpiCallback() { - struct __vpiCallback* obj; - - obj = new __vpiCallback; - - obj->cb_sync = 0; - obj->next = 0; - return obj; + cb_sync = 0; + next = 0; } -void delete_vpi_callback(struct __vpiCallback* ref) +__vpiCallback::~__vpiCallback() { - assert(ref); - delete ref->cb_sync; - delete ref; + delete cb_sync; } +int __vpiCallback::get_type_code(void) const +{ return vpiCallback; } + /* * A value change callback is tripped when a bit of a signal @@ -103,7 +90,7 @@ static struct __vpiCallback* make_value_change(p_cb_data data) return 0; } - struct __vpiCallback*obj = new_vpi_callback(); + struct __vpiCallback*obj = new __vpiCallback; obj->cb_data = *data; if (data->time) { obj->cb_time = *(data->time); @@ -150,8 +137,7 @@ static struct __vpiCallback* make_value_change(p_cb_data data) case vpiNamedEvent: struct __vpiNamedEvent*nev; nev = dynamic_cast<__vpiNamedEvent*>(data->obj); - obj->next = nev->callbacks; - nev->callbacks = obj; + nev->add_vpi_callback(obj); break; case vpiMemoryWord: @@ -203,19 +189,17 @@ void sync_cb::run_run() vpi_mode_flag = VPI_MODE_NONE; } - delete_vpi_callback(cur); + delete cur; } static struct __vpiCallback* make_sync(p_cb_data data, bool readonly_flag) { - struct __vpiCallback*obj = new_vpi_callback(); + struct __vpiCallback*obj = new __vpiCallback; obj->cb_data = *data; assert(data->time); obj->cb_time = *(data->time); obj->cb_data.time = &obj->cb_time; - obj->next = 0; - struct sync_cb*cb = new sync_cb; cb->sync_flag = readonly_flag? true : false; cb->handle = obj; @@ -248,14 +232,11 @@ static struct __vpiCallback* make_sync(p_cb_data data, bool readonly_flag) static struct __vpiCallback* make_afterdelay(p_cb_data data, bool simtime_flag) { - struct __vpiCallback*obj = new_vpi_callback(); + struct __vpiCallback*obj = new __vpiCallback; obj->cb_data = *data; assert(data->time); obj->cb_time = *(data->time); obj->cb_data.time = &obj->cb_time; - - obj->next = 0; - struct sync_cb*cb = new sync_cb; cb->sync_flag = false; cb->handle = obj; @@ -317,7 +298,7 @@ void vpiEndOfCompile(void) { cur = EndOfCompile; EndOfCompile = cur->next; (cur->cb_data.cb_rtn)(&cur->cb_data); - delete_vpi_callback(cur); + delete cur; } vpi_mode_flag = VPI_MODE_NONE; @@ -337,7 +318,7 @@ void vpiStartOfSim(void) { cur = StartOfSimulation; StartOfSimulation = cur->next; (cur->cb_data.cb_rtn)(&cur->cb_data); - delete_vpi_callback(cur); + delete cur; } vpi_mode_flag = VPI_MODE_NONE; @@ -359,7 +340,7 @@ void vpiPostsim(void) { if (cur->cb_data.time) vpip_time_to_timestruct(cur->cb_data.time, schedule_simtime()); (cur->cb_data.cb_rtn)(&cur->cb_data); - delete_vpi_callback(cur); + delete cur; } vpi_mode_flag = VPI_MODE_NONE; @@ -377,14 +358,14 @@ void vpiNextSimTime(void) cur = NextSimTime; NextSimTime = cur->next; (cur->cb_data.cb_rtn)(&cur->cb_data); - delete_vpi_callback(cur); + delete cur; } } static struct __vpiCallback* make_prepost(p_cb_data data) { - struct __vpiCallback*obj = new_vpi_callback(); + struct __vpiCallback*obj = new __vpiCallback; obj->cb_data = *data; /* Insert at head of list */ @@ -562,13 +543,13 @@ void vvp_vpi_callback::run_vpi_callbacks() vpi_callbacks_ = next; cur->next = 0; - delete_vpi_callback(cur); + delete cur; } else { assert(prev->next == cur); prev->next = next; cur->next = 0; - delete_vpi_callback(cur); + delete cur; } } } diff --git a/vvp/vpi_event.cc b/vvp/vpi_event.cc index 9c13b7246..1bd3032fc 100644 --- a/vvp/vpi_event.cc +++ b/vvp/vpi_event.cc @@ -25,8 +25,12 @@ # include # include "ivl_alloc.h" -inline __vpiNamedEvent::__vpiNamedEvent() -{ } +inline __vpiNamedEvent::__vpiNamedEvent(__vpiScope*sc, const char*nam) +{ + scope_ = sc; + name_ = vpip_name_string(nam); + callbacks_ = 0; +} int __vpiNamedEvent::get_type_code(void) const { return vpiNamedEvent; } @@ -36,7 +40,7 @@ int __vpiNamedEvent::vpi_get(int code) switch (code) { case vpiAutomatic: - return (int) scope->is_automatic; + return (int) scope_->is_automatic; } return 0; @@ -47,7 +51,7 @@ char* __vpiNamedEvent::vpi_get_str(int code) if (code == vpiFile) { // Not implemented for now! return simple_set_rbuf_str(file_names[0]); } - return generic_get_str(code, scope, name, NULL); + return generic_get_str(code, scope_, name_, NULL); } @@ -55,10 +59,10 @@ vpiHandle __vpiNamedEvent::vpi_handle(int code) { switch (code) { case vpiScope: - return scope; + return scope_; case vpiModule: - return vpip_module(scope); + return vpip_module(scope_); } return 0; @@ -67,12 +71,9 @@ vpiHandle __vpiNamedEvent::vpi_handle(int code) vpiHandle vpip_make_named_event(const char*name, vvp_net_t*funct) { - struct __vpiNamedEvent*obj = new __vpiNamedEvent; + struct __vpiNamedEvent*obj = new __vpiNamedEvent(vpip_peek_current_scope(), name); - obj->name = vpip_name_string(name); - obj->scope = vpip_peek_current_scope(); obj->funct = funct; - obj->callbacks = 0; return obj; } @@ -90,11 +91,9 @@ vpiHandle vpip_make_named_event(const char*name, vvp_net_t*funct) * We can not use vpi_free_object() here since it does not really * delete the callback. */ -void vpip_run_named_event_callbacks(vpiHandle ref) +void __vpiNamedEvent::run_vpi_callbacks() { - struct __vpiNamedEvent*obj = dynamic_cast<__vpiNamedEvent*>(ref); - - struct __vpiCallback*next = obj->callbacks; + struct __vpiCallback*next = callbacks_; struct __vpiCallback*prev = 0; while (next) { struct __vpiCallback*cur = next; @@ -105,7 +104,7 @@ void vpip_run_named_event_callbacks(vpiHandle ref) prev = cur; } else if (prev == 0) { - obj->callbacks = next; + callbacks_ = next; cur->next = 0; delete cur; diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 51854651e..8981bcbaa 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -147,6 +147,7 @@ extern vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args, */ struct __vpiCallback : public __vpiHandle { __vpiCallback(); + ~__vpiCallback(); int get_type_code(void) const; // user supplied callback data @@ -164,8 +165,6 @@ struct __vpiCallback : public __vpiHandle { struct __vpiCallback*next; }; -extern struct __vpiCallback* new_vpi_callback(); -extern void delete_vpi_callback(struct __vpiCallback* ref); extern void callback_execute(struct __vpiCallback*cur); struct __vpiSystemTime : public __vpiHandle { @@ -405,25 +404,34 @@ extern struct __vpiModPath* vpip_make_modpath(vvp_net_t *net) ; * passed in will be saved, so the caller must allocate it (or not * free it) after it is handed to this function. */ -struct __vpiNamedEvent : public __vpiHandle { - __vpiNamedEvent(); +class __vpiNamedEvent : public __vpiHandle { + public: + __vpiNamedEvent(__vpiScope*scope, const char*name); int get_type_code(void) const; int vpi_get(int code); char* vpi_get_str(int code); vpiHandle vpi_handle(int code); - /* base name of the event object */ - const char*name; - /* Parent scope of this object. */ - struct __vpiScope*scope; + inline void add_vpi_callback(__vpiCallback*cb) + { cb->next = callbacks_; + callbacks_ = cb; + } + + void run_vpi_callbacks(void); + /* The functor, used for %set operations. */ vvp_net_t*funct; + + private: + /* base name of the event object */ + const char*name_; + /* Parent scope of this object. */ + struct __vpiScope*scope_; /* List of callbacks interested in this event. */ - struct __vpiCallback*callbacks; + struct __vpiCallback*callbacks_; }; extern vpiHandle vpip_make_named_event(const char*name, vvp_net_t*f); -extern void vpip_run_named_event_callbacks(vpiHandle ref); extern void vpip_real_value_change(struct __vpiCallback*cbh, vpiHandle ref);