From 4692756eb9faf2650d14bef0093fb46c860da63e Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 11 Oct 2011 18:27:45 -0700 Subject: [PATCH] Add primitive vpiBaseTypespec support for enumerations. We don't currently have the information needed to correctly provide the base typespec, but in the next() and prev() methods I need to know if the enumeration is two or four state. This patch sets the base typespec for four state enumerations to vpiReg and to vpiBitVar for two state enumerations. This provide enough information to get next() and prev() working correctly. --- sv_vpi_user.h | 5 ++++- vvp/enum_type.cc | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sv_vpi_user.h b/sv_vpi_user.h index e6e20b527..606f7f73f 100644 --- a/sv_vpi_user.h +++ b/sv_vpi_user.h @@ -1,7 +1,7 @@ #ifndef __sv_vpi_user_H #define __sv_vpi_user_H /* - * Copyright (c) 2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2010-2011 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 @@ -54,6 +54,9 @@ EXTERN_C_START #define vpiEnumTypespec 633 #define vpiEnumConst 634 +/********* One-to-One ***********/ +#define vpiBaseTypespec 703 + /********* Many-to-One ***********/ #define vpiMember 742 diff --git a/vvp/enum_type.cc b/vvp/enum_type.cc index 561d063b0..b59b74641 100644 --- a/vvp/enum_type.cc +++ b/vvp/enum_type.cc @@ -43,6 +43,7 @@ static struct enumconst_s* enumconst_from_handle(vpiHandle obj) struct __vpiEnumTypespec { struct __vpiHandle base; std::vector names; + int base_type_code; bool is_signed; }; @@ -63,6 +64,13 @@ static int enum_type_get(int code, vpiHandle obj) case vpiSize: return ref->names.size(); + /* This is not currently set correctly. We always use vpiReg for + * four state variables and vpiBitVar for two state variables. + * This minimal functionality is needed to get the next() and + * prev() methods to work correctly with invalid values. */ + case vpiBaseTypespec: + return ref->base_type_code; + case vpiSigned: return ref->is_signed; @@ -163,6 +171,7 @@ void compile_enum2_type(char*label, long width, bool signed_flag, spec->base.vpi_type = &enum_type_rt; spec->names = std::vector (names->size()); spec->is_signed = signed_flag; + spec->base_type_code = vpiBitVar; size_t idx = 0; for (list::iterator cur = names->begin() @@ -188,6 +197,7 @@ void compile_enum4_type(char*label, long width, bool signed_flag, spec->base.vpi_type = &enum_type_rt; spec->names = std::vector (names->size()); spec->is_signed = signed_flag; + spec->base_type_code = vpiReg; size_t idx = 0; for (list::iterator cur = names->begin()