diff --git a/ivl_target.h b/ivl_target.h index c19a5339f..3def93d62 100644 --- a/ivl_target.h +++ b/ivl_target.h @@ -625,10 +625,34 @@ extern const char* ivl_nature_name(ivl_nature_t net); * Enumerations are a collections of symbolic names and vector * values. The enumeration has a base type, and a list of names and * values. + * + * FUNCTION SUMMARY + * + * ivl_enum_names + * This is the number of enumeration names in the enum type. + * + * ivl_enum_name + * Get the string name for an item in the enumeration + * + * ivl_enum_bits + * Get the bits (lsb first) of the enumeration value. The width + * of the enumeration should match the length of this string. Every + * name also has bits that make up the value. + * + * ivl_enum_type + * Get the data-type for the base type that the enum uses. This + * will be either IVL_VT_BOOL or IVL_VT_LOGIC + * + * ivl_enum_width + * Return the bit width of the base type for this enum type. + * + * SEMANTIC NOTES */ extern unsigned ivl_enum_names(ivl_enumtype_t net); extern const char*ivl_enum_name(ivl_enumtype_t net, unsigned idx); extern const char*ivl_enum_bits(ivl_enumtype_t net, unsigned idx); +extern ivl_variable_type_t ivl_enum_type(ivl_enumtype_t net); +extern unsigned ivl_enum_width(ivl_enumtype_t net); /* EVENTS * diff --git a/t-dll-api.cc b/t-dll-api.cc index 4e35ed9a3..9c319115a 100644 --- a/t-dll-api.cc +++ b/t-dll-api.cc @@ -231,6 +231,18 @@ extern "C" const char* ivl_enum_bits(ivl_enumtype_t net, unsigned idx) return net->bits_at(idx); } +extern "C" ivl_variable_type_t ivl_enum_type(ivl_enumtype_t net) +{ + assert(net); + return net->base_type(); +} + +extern "C" unsigned ivl_enum_width(ivl_enumtype_t net) +{ + assert(net); + return net->base_width(); +} + extern "C" const char* ivl_event_name(ivl_event_t net) { static char*name_buffer = 0; diff --git a/tgt-vvp/draw_enum.c b/tgt-vvp/draw_enum.c index 9703ed616..6567e1c86 100644 --- a/tgt-vvp/draw_enum.c +++ b/tgt-vvp/draw_enum.c @@ -20,29 +20,61 @@ # include "vvp_priv.h" # include "ivl_alloc.h" # include +# include # include +static void draw_enum2_value(ivl_enumtype_t enumtype, unsigned idx) +{ + long val = 0; + long mask = 1; + const char*bits = ivl_enum_bits(enumtype, idx); + const char*bit; + for (bit = bits, mask = 1 ; bit[0] != 0 ; bit += 1, mask <<= 1) { + if (*bit == '1') + val |= mask; + } + + fprintf(vvp_out, "%ld", val); +} + +static void draw_enum4_value(ivl_enumtype_t enumtype, unsigned idx) +{ + const char*bits = ivl_enum_bits(enumtype, idx); + const char*bit; + + fprintf(vvp_out, "%u'b", ivl_enum_width(enumtype)); + + for (bit = bits+strlen(bits) ; bit > bits ; bit -= 1) + fputc(bit[-1], vvp_out); + +} + void draw_enumeration_in_scope(ivl_enumtype_t enumtype) { unsigned idx; + unsigned name_count = ivl_enum_names(enumtype); + const char*dtype = ivl_enum_type(enumtype)==IVL_VT_BOOL? "2" : "4"; - fprintf(vvp_out, "enum%p .enum\n", enumtype); + fprintf(vvp_out, "enum%p .enum%s (%u)\n", enumtype, + dtype, ivl_enum_width(enumtype)); - for (idx = 0 ; idx < ivl_enum_names(enumtype) ; idx += 1) { - const char*comma = idx+1 < ivl_enum_names(enumtype)? "," : ""; + for (idx = 0 ; idx < name_count ; idx += 1) { + fprintf(vvp_out, " \"%s\" ", ivl_enum_name(enumtype, idx)); - fprintf(vvp_out, " \"%s\"", ivl_enum_name(enumtype, idx)); - - long val = 0; - long mask = 1; - const char*bits = ivl_enum_bits(enumtype, idx); - const char*bit; - for (bit = bits, mask = 1 ; bit[0] != 0 ; bit += 1, mask <<= 1) { - if (*bit == '1') - val |= mask; + switch (ivl_enum_type(enumtype)) { + case IVL_VT_BOOL: + draw_enum2_value(enumtype, idx); + break; + case IVL_VT_LOGIC: + draw_enum4_value(enumtype, idx); + break; + default: + assert(0); } - fprintf(vvp_out, " %ld%s\n", val, comma); + if ((idx+1) < name_count) + fputc(',', vvp_out); + fputc('\n', vvp_out); } fprintf(vvp_out, " ;\n"); diff --git a/vpi/Makefile.in b/vpi/Makefile.in index d57f6c1ef..93fd42b84 100644 --- a/vpi/Makefile.in +++ b/vpi/Makefile.in @@ -165,7 +165,7 @@ $(vpidir)/v2005_math.vpi: ./v2005_math.vpi $(vpidir)/v2005_math.sft: v2005_math.sft $(INSTALL_DATA) $< "$(DESTDIR)$@" -$(vpidir)/v2009_math.vpi: ./v2009.vpi +$(vpidir)/v2009.vpi: ./v2009.vpi $(INSTALL_PROGRAM) ./v2009.vpi "$(DESTDIR)$(vpidir)/v2009.vpi" $(vpidir)/v2009.sft: v2009.sft diff --git a/vpi/v2009_enum.c b/vpi/v2009_enum.c index bcb8e80df..71dcc52d9 100644 --- a/vpi/v2009_enum.c +++ b/vpi/v2009_enum.c @@ -19,6 +19,7 @@ # include "vpi_config.h" # include "sv_vpi_user.h" +# include # include static void missing_arguments(vpiHandle sys) @@ -73,7 +74,52 @@ static PLI_INT32 ivl_method_next_prev_compiletf(ICARUS_VPI_CONST PLI_BYTE8*data) return 0; } -static PLI_INT32 ivl_method_next2_calltf(PLI_BYTE8*data) +static int compare_value_eequal(s_vpi_value*ref1, s_vpi_value*ref2, long wid) +{ + if (ref1->format == vpiIntVal && ref2->format == vpiIntVal) + return ref1->value.integer == ref2->value.integer; + + if (ref1->format == vpiVectorVal && ref2->format == vpiVectorVal) { + int words = (wid-1)/32 + 1; + int idx; + + for (idx = 0 ; idx < words ; idx += 1) { + if (ref1->value.vector[idx].aval != ref2->value.vector[idx].aval) + return 0; + if (ref1->value.vector[idx].bval != ref2->value.vector[idx].bval) + return 0; + } + return 1; + } + + if (ref1->format == vpiVectorVal && ref2->format == vpiIntVal) { + s_vpi_value*tmp = ref1; + ref1 = ref2; + ref2 = tmp; + } + + if (ref1->format == vpiIntVal && ref2->format == vpiVectorVal) { + int use_aval = ref1->value.integer; + int words = (wid-1)/32 + 1; + int idx; + + for (idx = 0 ; idx < words ; idx += 1) { + if (use_aval != ref2->value.vector[idx].aval) + return 0; + if (0 != ref2->value.vector[idx].bval) + return 0; + + use_aval = 0; + } + return 1; + } + + vpi_printf("XXXX formats are: %d vs %d\n", ref1->format, ref2->format); + assert(0); + return 0; +} + +static PLI_INT32 ivl_method_next_calltf(PLI_BYTE8*data) { vpiHandle sys = vpi_handle(vpiSysTfCall, 0); vpiHandle argv = vpi_iterate(vpiArgument, sys); @@ -83,25 +129,46 @@ static PLI_INT32 ivl_method_next2_calltf(PLI_BYTE8*data) vpiHandle enum_list = 0; vpiHandle memb = 0, first_memb = 0; + long use_width = 0; + long item_width = vpi_get(vpiSize, arg_item); s_vpi_value memb_value, item_value; assert(arg_extra == 0); - item_value.format = vpiIntVal; + item_value.format = vpiObjTypeVal; vpi_get_value(arg_item, &item_value); + /* If this value is a vector value, then make a safe copy of + the vector so that other vpi functions don't trash it. */ + if (item_value.format == vpiVectorVal) { + unsigned idx; + unsigned hwid = (item_width - 1)/32 + 1; + s_vpi_vecval*op = calloc(hwid, sizeof(s_vpi_vecval)); + for (idx = 0 ; idx < hwid ; idx += 1) { + op[idx].aval = item_value.value.vector[idx].aval; + op[idx].bval = item_value.value.vector[idx].bval; + } + item_value.value.vector = op; + } + enum_list = vpi_iterate(vpiMember, arg_enum); assert(enum_list); /* Search for the current value in the member list. */ do { memb = vpi_scan(enum_list); - if (first_memb == 0) first_memb = memb; + if (first_memb == 0) { + first_memb = memb; + use_width = vpi_get(vpiSize, first_memb); + assert(use_width == vpi_get(vpiSize, arg_item)); + } if (memb == 0) break; - memb_value.format = vpiIntVal; + + memb_value.format = vpiObjTypeVal; vpi_get_value(memb, &memb_value); - } while (memb_value.value.integer != item_value.value.integer); + + } while (! compare_value_eequal(&item_value, &memb_value, use_width)); if (memb != 0); memb = vpi_scan(enum_list); @@ -114,13 +181,17 @@ static PLI_INT32 ivl_method_next2_calltf(PLI_BYTE8*data) memb_value.format = vpiIntVal; } + /* Free any stached copy of the vector. */ + if (item_value.format == vpiVectorVal) + free(item_value.value.vector); + vpi_get_value(memb, &memb_value); vpi_put_value(sys, &memb_value, 0, vpiNoDelay); return 0; } -static PLI_INT32 ivl_method_prev2_calltf(PLI_BYTE8*data) +static PLI_INT32 ivl_method_prev_calltf(PLI_BYTE8*data) { vpiHandle sys = vpi_handle(vpiSysTfCall, 0); vpiHandle argv = vpi_iterate(vpiArgument, sys); @@ -130,6 +201,7 @@ static PLI_INT32 ivl_method_prev2_calltf(PLI_BYTE8*data) vpiHandle enum_list = 0; vpiHandle memb = 0, prev = 0, last_memb = 0; + int use_wid = 0; s_vpi_value memb_value, item_value; @@ -146,10 +218,13 @@ static PLI_INT32 ivl_method_prev2_calltf(PLI_BYTE8*data) prev = memb; memb = vpi_scan(enum_list); if (memb == 0) break; + if (use_wid == 0) + use_wid = vpi_get(vpiSize, memb); + last_memb = memb; memb_value.format = vpiIntVal; vpi_get_value(memb, &memb_value); - } while (memb_value.value.integer != item_value.value.integer); + } while (! compare_value_eequal(&memb_value, &item_value, use_wid)); while (memb) { last_memb = memb; @@ -170,7 +245,7 @@ void v2009_enum_register(void) s_vpi_systf_data tf_data; tf_data.type = vpiSysFunc; - tf_data.calltf = ivl_method_next2_calltf; + tf_data.calltf = ivl_method_next_calltf; tf_data.compiletf = ivl_method_next_prev_compiletf; tf_data.sizetf = 0; tf_data.tfname = "$ivl_method$next"; @@ -178,7 +253,7 @@ void v2009_enum_register(void) vpi_register_systf(&tf_data); tf_data.type = vpiSysFunc; - tf_data.calltf = ivl_method_prev2_calltf; + tf_data.calltf = ivl_method_prev_calltf; tf_data.compiletf = 0; tf_data.sizetf = 0; tf_data.tfname = "$ivl_method$prev"; diff --git a/vvp/compile.h b/vvp/compile.h index 43edf40fb..442a696b0 100644 --- a/vvp/compile.h +++ b/vvp/compile.h @@ -202,7 +202,10 @@ extern void compile_dff(char*label, struct symb_s arg_e, struct symb_s arg_a); -extern void compile_enum_type(char*label, std::list*names); +extern void compile_enum2_type(char*label, long width, + std::list*names); +extern void compile_enum4_type(char*label, long width, + std::list*names); class __vpiModPath; extern __vpiModPath* compile_modpath(char*label, diff --git a/vvp/enum_type.cc b/vvp/enum_type.cc index 06aefca48..fb82086ce 100644 --- a/vvp/enum_type.cc +++ b/vvp/enum_type.cc @@ -26,6 +26,7 @@ struct enumconst_s { struct __vpiHandle base; const char*name; vvp_vector2_t val2; + vvp_vector4_t val4; }; static struct enumconst_s* enumconst_from_handle(vpiHandle obj) @@ -49,6 +50,22 @@ static struct __vpiEnumTypespec* vpip_enum_typespec_from_handle(vpiHandle obj) return 0; } +static int enum_type_get(int code, vpiHandle obj) +{ + struct __vpiEnumTypespec*ref = vpip_enum_typespec_from_handle(obj); + assert(ref); + + switch (code) { + case vpiSize: + return ref->names.size(); + default: + fprintf(stderr, "vvp error: get %d not supported " + "by __vpiEnumTypespec\n", code); + assert(0); + return 0; + } +} + static vpiHandle enum_type_iterate(int code, vpiHandle obj) { struct __vpiEnumTypespec*ref = vpip_enum_typespec_from_handle(obj); @@ -57,7 +74,7 @@ static vpiHandle enum_type_iterate(int code, vpiHandle obj) if (code == vpiMember) { vpiHandle*args = (vpiHandle*) calloc(ref->names.size(), sizeof(vpiHandle*)); - for (int idx = 0 ; idx < ref->names.size() ; idx += 1) + for (size_t idx = 0 ; idx < ref->names.size() ; idx += 1) args[idx] = vpi_handle(&ref->names[idx]); return vpip_make_iterator(ref->names.size(), args, true); @@ -68,7 +85,7 @@ static vpiHandle enum_type_iterate(int code, vpiHandle obj) static const struct __vpirt enum_type_rt = { vpiEnumTypespec, - 0, //enum_type_get, + enum_type_get, 0, //enum_type_get_str, 0, //enum_type_get_value, 0, //enum_type_put_value, @@ -80,6 +97,19 @@ static const struct __vpirt enum_type_rt = { 0, //enum_type_put_delays }; +static int enum_name_get(int code, vpiHandle obj) +{ + struct enumconst_s*ref = enumconst_from_handle(obj); + assert(ref); + + switch (code) { + case vpiSize: + return ref->val4.size()? ref->val4.size() : ref->val2.size(); + default: + return 0; + } +} + static char* enum_name_get_str(int code, vpiHandle obj) { struct enumconst_s*ref = enumconst_from_handle(obj); @@ -98,20 +128,15 @@ static void enum_name_get_value(vpiHandle obj, p_vpi_value value) struct enumconst_s*ref = enumconst_from_handle(obj); assert(ref); - switch (value->format) { - case vpiObjTypeVal: - value->format = vpiIntVal; - case vpiIntVal: - vector2_to_value(ref->val2, value->value.integer, true); - break; - default: - break; - } + if (ref->val4.size() > 0) + vpip_vec4_get_value(ref->val4, ref->val4.size(), false, value); + else + vpip_vec2_get_value(ref->val2, ref->val2.size(), true, value); } static const struct __vpirt enum_name_rt = { vpiEnumConst, - 0, //enum_name_get, + enum_name_get, enum_name_get_str, enum_name_get_value, 0, //enum_name_put_value, @@ -123,7 +148,29 @@ static const struct __vpirt enum_name_rt = { 0, //enum_name_put_delays }; -void compile_enum_type(char*label, std::list*names) +void compile_enum2_type(char*label, long width, std::list*names) +{ + struct __vpiEnumTypespec*spec = new struct __vpiEnumTypespec; + spec->base.vpi_type = &enum_type_rt; + spec->names = std::vector (names->size()); + + size_t idx = 0; + for (list::iterator cur = names->begin() + ; cur != names->end() ; ++cur, ++idx) { + assert(cur->val4 == 0); + spec->names[idx].base.vpi_type = &enum_name_rt; + spec->names[idx].name = cur->text; + spec->names[idx].val2 = vvp_vector2_t(cur->val2, width); + } + + assert(idx == spec->names.size()); + compile_vpi_symbol(label, vpi_handle(spec)); + + free(label); + delete names; +} + +void compile_enum4_type(char*label, long width, std::list*names) { struct __vpiEnumTypespec*spec = new struct __vpiEnumTypespec; spec->base.vpi_type = &enum_type_rt; @@ -134,7 +181,10 @@ void compile_enum_type(char*label, std::list*names) ; cur != names->end() ; ++cur, ++idx) { spec->names[idx].base.vpi_type = &enum_name_rt; spec->names[idx].name = cur->text; - spec->names[idx].val2 = vvp_vector2_t(cur->val2, 32); + assert(cur->val4); + spec->names[idx].val4 = vector4_from_text(cur->val4, width); + free(cur->val4); + cur->val4 = 0; } assert(idx == spec->names.size()); diff --git a/vvp/lexor.lex b/vvp/lexor.lex index 2736cb765..eba911ced 100644 --- a/vvp/lexor.lex +++ b/vvp/lexor.lex @@ -142,7 +142,8 @@ static char* strdupnew(char const *str) ".concat" { return K_CONCAT; } ".delay" { return K_DELAY; } ".dff" { return K_DFF; } -".enum" { return K_ENUM; } +".enum2" { return K_ENUM2; } +".enum4" { return K_ENUM4; } ".event" { return K_EVENT; } ".event/or" { return K_EVENT_OR; } ".export" { return K_EXPORT; } diff --git a/vvp/parse.y b/vvp/parse.y index c9936c97d..b4f5123e8 100644 --- a/vvp/parse.y +++ b/vvp/parse.y @@ -80,7 +80,8 @@ static struct __vpiModPath*modpath_dst = 0; %token K_CMP_EEQ K_CMP_EQ K_CMP_EQ_R K_CMP_NEE K_CMP_NE K_CMP_NE_R %token K_CMP_GE K_CMP_GE_R K_CMP_GE_S K_CMP_GT K_CMP_GT_R K_CMP_GT_S %token K_CONCAT K_DEBUG K_DELAY K_DFF -%token K_ENUM K_EVENT K_EVENT_OR K_EXPORT K_EXTEND_S K_FUNCTOR K_IMPORT K_ISLAND +%token K_ENUM2 K_ENUM4 K_EVENT K_EVENT_OR K_EXPORT K_EXTEND_S K_FUNCTOR +%token K_IMPORT K_ISLAND %token K_MODPATH %token K_NET K_NET_S K_NET_R K_NET_2S K_NET_2U K_NET8 K_NET8_S %token K_PARAM_STR K_PARAM_L K_PARAM_REAL K_PART K_PART_PV @@ -799,8 +800,10 @@ statement /* Enumeration types */ enum_type - : T_LABEL K_ENUM enum_type_names ';' - { compile_enum_type($1, $3); } + : T_LABEL K_ENUM2 '(' T_NUMBER ')' enum_type_names ';' + { compile_enum2_type($1, $4, $6); } + | T_LABEL K_ENUM4 '(' T_NUMBER ')' enum_type_names ';' + { compile_enum4_type($1, $4, $6); } ; enum_type_names @@ -818,7 +821,9 @@ enum_type_names enum_type_name : T_STRING T_NUMBER - { $$.text = $1; $$.val2 = $2; } + { $$.text = $1; $$.val2 = $2; $$.val4 = 0; } + | T_STRING T_VECTOR + { $$.text = $1; $$.val2 = 0; $$.val4 = $2.text; } ; local_flag diff --git a/vvp/parse_misc.h b/vvp/parse_misc.h index 81c8d00fe..3ac77505d 100644 --- a/vvp/parse_misc.h +++ b/vvp/parse_misc.h @@ -73,6 +73,7 @@ struct numbv_s { struct enum_name_s { char*text; uint64_t val2; + char*val4; }; extern void numbv_init(struct numbv_s*obj); diff --git a/vvp/vpi_const.cc b/vvp/vpi_const.cc index deef61863..2c0981693 100644 --- a/vvp/vpi_const.cc +++ b/vvp/vpi_const.cc @@ -442,7 +442,6 @@ vpiHandle vpip_make_binary_const(unsigned wid, const char*bits) obj->signed_flag = 0; obj->sized_flag = 0; - obj->bits = vvp_vector4_t(wid); const char*bp = bits; if (*bp == 's') { @@ -450,9 +449,18 @@ vpiHandle vpip_make_binary_const(unsigned wid, const char*bits) obj->signed_flag = 1; } + obj->bits = vector4_from_text(bp, wid); + + return &(obj->base); +} + +vvp_vector4_t vector4_from_text(const char*bits, unsigned wid) +{ + vvp_vector4_t res (wid); + for (unsigned idx = 0 ; idx < wid ; idx += 1) { vvp_bit4_t val = BIT4_0; - switch (bp[wid-idx-1]) { + switch (bits[wid-idx-1]) { case '0': val = BIT4_0; break; @@ -467,10 +475,10 @@ vpiHandle vpip_make_binary_const(unsigned wid, const char*bits) break; } - obj->bits.set_bit(idx, val); + res.set_bit(idx, val); } - return &(obj->base); + return res; } struct __vpiBinaryParam : public __vpiBinaryConst { diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 2d5c65628..9bce98f6d 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -711,6 +711,53 @@ void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width, } } +void vpip_vec2_get_value(const vvp_vector2_t&word_val, unsigned width, + bool signed_flag, s_vpi_value*vp) +{ + char *rbuf = 0; + + switch (vp->format) { + default: + fprintf(stderr, "sorry: Format %d not implemented for " + "getting vector2 values.\n", (int)vp->format); + assert(0); + + case vpiSuppressVal: + break; + + case vpiObjTypeVal: + vp->format = vpiIntVal; + case vpiIntVal: + vector2_to_value(word_val, vp->value.integer, true); + break; + + case vpiVectorVal: { + unsigned hwid = (width - 1)/32 + 1; + + rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL); + s_vpi_vecval *op = (p_vpi_vecval)rbuf; + vp->value.vector = op; + + op->aval = op->bval = 0; + for (unsigned idx = 0 ; idx < width ; idx += 1) { + if (word_val.value(idx)) { + op->aval |= (1 << idx % 32); + op->bval &= ~(1 << idx % 32); + } else { + op->aval &= ~(1 << idx % 32); + op->bval &= ~(1 << idx % 32); + } + if (!((idx+1) % 32) && (idx+1 < width)) { + op++; + op->aval = op->bval = 0; + } + } + break; + } + } + +} + /* * Convert a real value to the appropriate integer. */ diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 8aa9f1d73..510f0e1f2 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -611,6 +611,8 @@ extern double real_from_vpi_value(s_vpi_value*vp); extern void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width, bool signed_flag, s_vpi_value*vp); +extern void vpip_vec2_get_value(const vvp_vector2_t&word_val, unsigned width, + bool signed_flag, s_vpi_value*vp); extern void vpip_real_get_value(double real, s_vpi_value*vp); /* diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 27788c3c4..b874381b8 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -1527,11 +1527,11 @@ ostream& operator<< (ostream&out, const vvp_vector4_t&that) return out; } -bool vector4_to_value(const vvp_vector4_t&vec, long&val, - bool is_signed, bool is_arithmetic) +template bool do_vector4_to_value(const vvp_vector4_t&vec, INT&val, + bool is_signed, bool is_arithmetic) { long res = 0; - long msk = 1; + INT msk = 1; bool rc_flag = true; unsigned size = vec.size(); @@ -1555,13 +1555,25 @@ bool vector4_to_value(const vvp_vector4_t&vec, long&val, if (is_signed && vec.value(vec.size()-1) == BIT4_1) { if (vec.size() < 8*sizeof(val)) - res |= (-1L) << vec.size(); + res |= (INT)(-1L) << vec.size(); } val = res; return rc_flag; } +bool vector4_to_value(const vvp_vector4_t&vec, long&val, + bool is_signed, bool is_arithmetic) +{ + return do_vector4_to_value(vec, val, is_signed, is_arithmetic); +} + +bool vector4_to_value(const vvp_vector4_t&vec, int32_t&val, + bool is_signed, bool is_arithmetic) +{ + return do_vector4_to_value(vec, val, is_signed, is_arithmetic); +} + bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val) { unsigned long res = 0; @@ -1591,36 +1603,7 @@ bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val) bool vector4_to_value(const vvp_vector4_t&vec, int64_t&val, bool is_signed, bool is_arithmetic) { - long res = 0; - long msk = 1; - bool rc_flag = true; - - unsigned size = vec.size(); - if (size > 8*sizeof(val)) size = 8*sizeof(val); - for (unsigned idx = 0 ; idx < size ; idx += 1) { - switch (vec.value(idx)) { - case BIT4_0: - break; - case BIT4_1: - res |= msk; - break; - default: - if (is_arithmetic) - return false; - else - rc_flag = false; - } - - msk <<= 1L; - } - - if (is_signed && vec.value(vec.size()-1) == BIT4_1) { - if (vec.size() < 8*sizeof(val)) - res |= (-1L) << vec.size(); - } - - val = res; - return rc_flag; + return do_vector4_to_value(vec, val, is_signed, is_arithmetic); } bool vector4_to_value(const vvp_vector4_t&vec, vvp_time64_t&val) diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index 1e58d6df5..3a173657f 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -490,6 +490,7 @@ template extern T coerce_to_width(const T&that, unsigned width); */ extern bool vector4_to_value(const vvp_vector4_t&a, long&val, bool is_signed, bool is_arithmetic =true); extern bool vector4_to_value(const vvp_vector4_t&a, unsigned long&val); +extern bool vector4_to_value(const vvp_vector4_t&a, int32_t&val, bool is_signed, bool is_arithmetic =true); #ifndef UL_AND_TIME64_SAME extern bool vector4_to_value(const vvp_vector4_t&a, int64_t&val, bool is_signed, bool is_arithmetic =true); extern bool vector4_to_value(const vvp_vector4_t&a, vvp_time64_t&val); @@ -498,6 +499,8 @@ extern bool vector4_to_value(const vvp_vector4_t&a, double&val, bool is_signed); extern bool vector2_to_value(const vvp_vector2_t&a, int32_t&val, bool is_signed); +extern vvp_vector4_t vector4_from_text(const char*bits, unsigned wid); + /* * The __vpiArray handle uses instances of this to keep an array of * real valued variables.