Get the vvp code to compile with the valgrind hooks again.

This patch updates the vvp code so it will compile with the valgrind hooks
again. There are still new constructs that need to be cleaned up correctly
and some old constructs were changed enough that the old code no longer
works, but the rest of this can be done as an incremental improvement.
This commit is contained in:
Cary R 2012-10-08 18:52:24 -07:00
parent e0f82981e7
commit f957deeca7
13 changed files with 110 additions and 73 deletions

View File

@ -92,10 +92,10 @@ struct __vpiArray : public __vpiHandle {
struct __vpiScope*scope;
const char*name; /* Permanently allocated string */
unsigned array_count;
struct __vpiDecConst first_addr;
struct __vpiDecConst last_addr;
struct __vpiDecConst msb;
struct __vpiDecConst lsb;
__vpiDecConst first_addr;
__vpiDecConst last_addr;
__vpiDecConst msb;
__vpiDecConst lsb;
unsigned vals_width;
// If this is a net array, nets lists the handles.
vpiHandle*nets;
@ -127,7 +127,7 @@ struct __vpiArrayIndex : public __vpiHandle {
vpiHandle vpi_index(int idx);
free_object_fun_t free_object_fun(void);
struct __vpiDecConst *index;
__vpiDecConst *index;
unsigned done;
};
@ -716,7 +716,7 @@ static void vpi_array_var_index_get_value(vpiHandle ref, p_vpi_value vp)
vpiHandle array_index_iterate(int code, vpiHandle ref)
{
struct __vpiDecConst*obj = dynamic_cast<__vpiDecConst*>(ref);
__vpiDecConst *obj = dynamic_cast<__vpiDecConst*>(ref);
assert(obj);
if (code == vpiIndex) {
@ -1884,7 +1884,7 @@ void compile_array_cleanup(void)
#ifdef CHECK_WITH_VALGRIND
void memory_delete(vpiHandle item)
{
struct __vpiArray*arr = ARRAY_HANDLE(item);
struct __vpiArray*arr = (struct __vpiArray*) item;
if (arr->vals_words) delete [] (arr->vals_words-1);
// if (arr->vals4) {}
@ -1905,13 +1905,13 @@ void memory_delete(vpiHandle item)
constant_delete(sig->id.index);
/* These should only be the real words. */
} else {
assert(arr->nets[idx]->vpi_type->type_code ==
assert(arr->nets[idx]->get_type_code() ==
vpiRealVar);
struct __vpiRealVar *sigr = (struct __vpiRealVar *)
arr->nets[idx];
constant_delete(sigr->id.index);
// Why are only the real words still here?
free(arr->nets[idx]);
delete arr->nets[idx];
}
}
free(arr->nets);
@ -1919,18 +1919,18 @@ void memory_delete(vpiHandle item)
while (arr->vpi_callbacks) {
struct __vpiCallback*tmp = arr->vpi_callbacks->next;
delete_vpi_callback(arr->vpi_callbacks);
delete arr->vpi_callbacks;
arr->vpi_callbacks = tmp;
}
free(arr);
delete arr;
}
void A_delete(vpiHandle item)
{
struct __vpiArrayVthrA*obj = (struct __vpiArrayVthrA*) item;
if (obj->address_handle) {
switch (obj->address_handle->vpi_type->type_code) {
switch (obj->address_handle->get_type_code()) {
case vpiMemoryWord:
if (vpi_get(_vpiFromThr, obj->address_handle) == _vpi_at_A) {
A_delete(obj->address_handle);
@ -1944,6 +1944,6 @@ void A_delete(vpiHandle item)
}
}
free(obj);
delete obj;
}
#endif

View File

@ -1054,7 +1054,7 @@ struct __vpiModPath* vpip_make_modpath(vvp_net_t *net)
void modpath_delete()
{
for (unsigned idx = 0; idx < mp_count; idx += 1) {
free(mp_list[idx]);
delete mp_list[idx];
}
free(mp_list);
mp_list = 0;

View File

@ -23,9 +23,6 @@
# include "schedule.h"
# include "vpi_priv.h"
# include "config.h"
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
# include <cstring>
# include <cassert>
# include <cstdlib>
@ -855,14 +852,6 @@ void compile_named_event(char*label, char*name)
#ifdef CHECK_WITH_VALGRIND
void named_event_delete(__vpiHandle*handle)
{
__vpiNamedEvent *obj = (__vpiNamedEvent *) handle;
while (obj->callbacks) {
struct __vpiCallback*tmp = obj->callbacks->next;
delete_vpi_callback(obj->callbacks);
obj->callbacks = tmp;
}
free(obj);
delete dynamic_cast<__vpiNamedEvent *>(handle);
}
#endif

View File

@ -639,8 +639,9 @@ void vvp_vpi_callback::add_vpi_callback(value_callback*cb)
void vvp_vpi_callback::clear_all_callbacks()
{
while (vpi_callbacks_) {
struct __vpiCallback*tmp = vpi_callbacks_->next;
delete_vpi_callback(vpi_callbacks_);
value_callback *tmp = dynamic_cast<value_callback*>
(vpi_callbacks_->next);
delete vpi_callbacks_;
vpi_callbacks_ = tmp;
}
}

View File

@ -83,7 +83,7 @@ void __vpiStringConst::process_string_(void)
__vpiStringConst::~__vpiStringConst()
{
delete[]value_;
delete[] value_;
}
int __vpiStringConst::get_type_code(void) const
@ -650,7 +650,7 @@ int __vpiRealConst::vpi_get(int code)
default:
fprintf(stderr, "vvp error: get %d not supported "
"by vpiDecConst\n", code);
"by vpiRealConst\n", code);
assert(0);
return 0;
}
@ -754,25 +754,20 @@ vpiHandle vpip_make_real_param(char*name, double value,
#ifdef CHECK_WITH_VALGRIND
void constant_delete(vpiHandle item)
{
assert(item->vpi_type->type_code == vpiConstant);
assert(item->get_type_code() == vpiConstant);
switch(vpi_get(vpiConstType, item)) {
case vpiStringConst: {
struct __vpiStringConst*rfp = dynamic_cast<__vpiStringConst*>(item);
delete [] rfp->value;
free(rfp);
break; }
case vpiDecConst: {
struct __vpiDecConst*rfp = dynamic_cast<__vpiDecConst*>(item);
free(rfp);
break; }
case vpiBinaryConst: {
struct __vpiBinaryConst*rfp = dynamic_cast<__vpiBinaryConst*>(item);
delete rfp;
break; }
case vpiRealConst: {
struct __vpiRealConst*rfp = dynamic_cast<__vpiRealConst*>(item);
free(rfp);
break; }
case vpiStringConst:
delete dynamic_cast<__vpiStringConst*>(item);
break;
case vpiDecConst:
delete dynamic_cast<__vpiDecConst*>(item);
break;
case vpiBinaryConst:
delete dynamic_cast<__vpiBinaryConst*>(item);
break;
case vpiRealConst:
delete dynamic_cast<__vpiRealConst*>(item);
break;
default:
assert(0);
}

View File

@ -32,6 +32,15 @@ inline __vpiNamedEvent::__vpiNamedEvent(__vpiScope*sc, const char*nam)
callbacks_ = 0;
}
__vpiNamedEvent::~__vpiNamedEvent()
{
while (callbacks_) {
struct __vpiCallback *tmp = callbacks_->next;
delete callbacks_;
callbacks_ = tmp;
}
}
int __vpiNamedEvent::get_type_code(void) const
{ return vpiNamedEvent; }

View File

@ -273,9 +273,6 @@ struct __vpiSignal : public __vpiHandle {
vpiHandle vpi_handle(int code);
vpiHandle vpi_iterate(int code);
#ifdef CHECK_WITH_VALGRIND
struct __vpiSignal *pool;
#endif
union { // The scope or parent array that contains me.
vpiHandle parent;
struct __vpiScope* scope;
@ -414,6 +411,7 @@ class __vpiNamedEvent : public __vpiHandle {
public:
__vpiNamedEvent(__vpiScope*scope, const char*name);
~__vpiNamedEvent();
int get_type_code(void) const;
int vpi_get(int code);
char* vpi_get_str(int code);
@ -599,7 +597,8 @@ vpiHandle vpip_make_binary_param(char*name, const vvp_vector4_t&bits,
bool signed_flag, bool local_flag,
long file_idx, long lineno);
struct __vpiDecConst : public __vpiHandle {
class __vpiDecConst : public __vpiHandle {
public:
__vpiDecConst(int val =0);
int get_type_code(void) const;
int vpi_get(int code);
@ -614,7 +613,7 @@ class __vpiRealConst : public __vpiHandle {
int get_type_code(void) const;
int vpi_get(int code);
void vpi_get_value(p_vpi_value val);
public:
double value;
};

View File

@ -49,11 +49,13 @@ void vpip_make_root_iterator(__vpiHandle**&table, unsigned&ntable)
}
#ifdef CHECK_WITH_VALGRIND
void port_delete(__vpiHandle*handle);
static void delete_sub_scopes(struct __vpiScope *scope)
{
for (unsigned idx = 0; idx < scope->nintern; idx += 1) {
struct __vpiScope*lscope = (__vpiScope*)(scope->intern)[idx];
switch(scope->intern[idx]->vpi_type->type_code) {
switch(scope->intern[idx]->get_type_code()) {
case vpiFunction:
case vpiTask:
contexts_delete(lscope);
@ -70,7 +72,7 @@ static void delete_sub_scopes(struct __vpiScope *scope)
break;
case vpiModPath:
/* The destination ModPath is cleaned up later. */
free((scope->intern)[idx]);
delete (scope->intern)[idx];
break;
case vpiNamedEvent:
named_event_delete((scope->intern)[idx]);
@ -94,9 +96,15 @@ static void delete_sub_scopes(struct __vpiScope *scope)
case vpiEnumTypespec:
enum_delete((scope->intern)[idx]);
break;
case vpiPort:
port_delete((scope->intern)[idx]);
break;
case vpiStringVar:
case vpiRegArray:
break;
default:
fprintf(stderr, "Need support for type: %d\n",
scope->intern[idx]->vpi_type->type_code);
scope->intern[idx]->get_type_code());
assert(0);
break;
}
@ -528,13 +536,14 @@ unsigned vpip_add_item_to_context(automatic_hooks_s*item,
}
struct vpiPortInfo : public __vpiHandle {
class vpiPortInfo : public __vpiHandle {
public:
vpiPortInfo( __vpiScope *parent,
unsigned index,
int vpi_direction,
unsigned width,
const char *name );
~vpiPortInfo();
int get_type_code(void) const { return vpiPort; }
@ -542,7 +551,7 @@ struct vpiPortInfo : public __vpiHandle {
char* vpi_get_str(int code);
vpiHandle vpi_handle(int code);
protected:
private:
__vpiScope *parent_;
unsigned index_;
int direction_;
@ -563,6 +572,18 @@ vpiPortInfo::vpiPortInfo( __vpiScope *parent,
{
}
vpiPortInfo::~vpiPortInfo()
{
delete[] name_;
}
#ifdef CHECK_WITH_VALGRIND
void port_delete(__vpiHandle *handle)
{
delete dynamic_cast<vpiPortInfo *>(handle);
}
#endif
int vpiPortInfo::vpi_get(int code)
{
switch( code ) {

View File

@ -980,7 +980,7 @@ vpiHandle vpip_make_var4(const char*name, int msb, int lsb,
}
#ifdef CHECK_WITH_VALGRIND
static struct __vpiSignal **signal_pool = 0;
static struct vpiSignal_plug **signal_pool = 0;
static unsigned signal_pool_count = 0;
static unsigned long signal_count = 0;
static unsigned long signal_dels = 0;
@ -988,11 +988,18 @@ static unsigned long signal_dels = 0;
struct vpiSignal_plug {
unsigned char space[sizeof (struct __vpiSignal)];
#ifdef CHECK_WITH_VALGRIND
struct vpiSignal_plug *pool;
#endif
};
void* __vpiSignal::operator new(size_t siz)
{
assert(siz == sizeof(struct vpiSignal_plug));
assert(siz == sizeof(struct vpiSignal_plug)
#ifdef CHECK_WITH_VALGRIND
- sizeof(struct vpiSignal_plug *)
#endif
);
static struct vpiSignal_plug*alloc_array = 0;
static unsigned alloc_index = 0;
const unsigned alloc_count = 512;
@ -1035,7 +1042,7 @@ void signal_delete(vpiHandle item)
obj->node->fil->clear_all_callbacks();
vvp_net_delete(obj->node);
signal_dels += 1;
VALGRIND_MEMPOOL_FREE(obj->pool, obj);
VALGRIND_MEMPOOL_FREE(reinterpret_cast<vpiSignal_plug *>(obj)->pool, obj);
}
void signal_pool_delete()
@ -1426,7 +1433,7 @@ void PV_delete(vpiHandle item)
{
struct __vpiPV *obj = dynamic_cast<__vpiPV*>(item);
if (obj->sbase) {
switch (obj->sbase->vpi_type->type_code) {
switch (obj->sbase->get_type_code()) {
case vpiMemoryWord:
if (vpi_get(_vpiFromThr, obj->sbase) == _vpi_at_A) {
A_delete(obj->sbase);

View File

@ -711,12 +711,14 @@ void print_vpi_call_errors()
#ifdef CHECK_WITH_VALGRIND
static void cleanup_vpi_call_args(unsigned argc, vpiHandle*argv)
{
#if 0
if (argc) {
struct __vpiSysTaskCall*obj = new struct __vpiSysTaskCall;
obj->nargs = argc;
obj->args = argv;
vpi_call_delete(&obj->base);
}
#endif
}
#endif
@ -837,7 +839,7 @@ void vpi_call_delete(vpiHandle item)
/* The object can be NULL if there was an error. */
if (!obj) return;
for (unsigned arg = 0; arg < obj->nargs; arg += 1) {
switch (obj->args[arg]->vpi_type->type_code) {
switch (obj->args[arg]->get_type_code()) {
case vpiConstant:
switch (vpi_get(_vpiFromThr, obj->args[arg])) {
case _vpiNoThr:

View File

@ -150,7 +150,7 @@ void vvp_net_pool_delete()
}
for (unsigned idx = 0; idx < vvp_net_pool_count; idx += 1) {
VALGRIND_DESTROY_MEMPOOL(vvp_net_pool[idx])
VALGRIND_DESTROY_MEMPOOL(vvp_net_pool[idx]);
::delete [] vvp_net_pool[idx];
}
free(vvp_net_pool);

View File

@ -593,6 +593,13 @@ vvp_fun_signal_string_sa::vvp_fun_signal_string_sa()
{
}
#ifdef CHECK_WITH_VALGRIND
void vvp_fun_signal_string_aa::free_instance(vvp_context_t context)
{
// Never knew how to do this!
}
#endif
void vvp_fun_signal_string_sa::recv_string(vvp_net_ptr_t ptr, const std::string&bit,
vvp_context_t)
{
@ -671,6 +678,13 @@ vvp_fun_signal_object_sa::vvp_fun_signal_object_sa()
{
}
#ifdef CHECK_WITH_VALGRIND
void vvp_fun_signal_object_aa::free_instance(vvp_context_t context)
{
// Never knew how to do this!
}
#endif
void vvp_fun_signal_object_sa::recv_object(vvp_net_ptr_t ptr, vvp_object_t bit,
vvp_context_t)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2011 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2012 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -105,7 +105,7 @@ static void __compile_var_string(char*label, char*name,
assert(!name);
array_attach_word(array, array_addr, obj);
}
delete[]label;
free(label);
delete[] name;
}
@ -141,7 +141,7 @@ static void __compile_var_darray(char*label, char*name,
assert(!name);
array_attach_word(array, array_addr, obj);
}
delete[]label;
free(label);
delete[] name;
}