From 19307ba9dca003f3edcb8ab655dfe362ad9736a8 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 9 Oct 2011 22:20:40 -0700 Subject: [PATCH] Add an enum type to the appropriate scope and add valgrind cleanup code. Add the enum type to the scope when it is created. Also delete the type when checking with valgrind. --- vvp/enum_type.cc | 19 +++++++++++++++++++ vvp/vpi_scope.cc | 3 +++ vvp/vvp_cleanup.h | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/vvp/enum_type.cc b/vvp/enum_type.cc index 4e11191de..561d063b0 100644 --- a/vvp/enum_type.cc +++ b/vvp/enum_type.cc @@ -19,6 +19,9 @@ # include "compile.h" # include "enum_type.h" +#ifdef CHECK_WITH_VALGRIND +# include "vvp_cleanup.h" +#endif # include # include @@ -172,6 +175,7 @@ void compile_enum2_type(char*label, long width, bool signed_flag, assert(idx == spec->names.size()); compile_vpi_symbol(label, vpi_handle(spec)); + vpip_attach_to_current_scope(vpi_handle(spec)); free(label); delete names; @@ -198,7 +202,22 @@ void compile_enum4_type(char*label, long width, bool signed_flag, assert(idx == spec->names.size()); compile_vpi_symbol(label, vpi_handle(spec)); + vpip_attach_to_current_scope(vpi_handle(spec)); free(label); delete names; } + +#ifdef CHECK_WITH_VALGRIND +void enum_delete(vpiHandle item) +{ + struct __vpiEnumTypespec*obj = (struct __vpiEnumTypespec*) item; + + for (vector::iterator iter = obj->names.begin(); + iter != obj->names.end(); ++ iter ) { + delete [] iter->name; + } + + delete obj; +} +#endif diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index 084cd064f..5d9d95b9e 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -90,6 +90,9 @@ static void delete_sub_scopes(struct __vpiScope *scope) case vpiRealVar: real_delete((scope->intern)[idx]); break; + case vpiEnumTypespec: + enum_delete((scope->intern)[idx]); + break; default: fprintf(stderr, "Need support for type: %d\n", scope->intern[idx]->vpi_type->type_code); diff --git a/vvp/vvp_cleanup.h b/vvp/vvp_cleanup.h index c6e895dd3..c223f46dc 100644 --- a/vvp/vvp_cleanup.h +++ b/vvp/vvp_cleanup.h @@ -1,7 +1,7 @@ #ifndef __vvp_cleanup_H #define __vvp_cleanup_H /* - * Copyright (c) 2009 Cary R. (cygcary@yahoo.com) + * Copyright (c) 2009-2011 Cary R. (cygcary@yahoo.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 @@ -43,6 +43,7 @@ extern void A_delete(struct __vpiHandle *item); extern void PV_delete(struct __vpiHandle *item); extern void constant_delete(struct __vpiHandle *item); extern void contexts_delete(struct __vpiScope *scope); +extern void enum_delete(struct __vpiHandle *item); extern void memory_delete(struct __vpiHandle *item); extern void named_event_delete(struct __vpiHandle *item); extern void parameter_delete(struct __vpiHandle *item);