From 9fb317a4e1772c26700ea6d5a9fbd6657ea68681 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 5 Sep 2011 16:10:08 -0700 Subject: [PATCH] A vpiBitVar can have a non-zero LSB and can be unsigned. The general bit variable can be either signed or unsigned and can have a non-zero LSB. --- vvp/parse.y | 4 ++-- vvp/vpi_priv.h | 2 +- vvp/vpi_signal.cc | 52 +++++++++++++++++++++++++++-------------------- vvp/words.cc | 4 ++-- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/vvp/parse.y b/vvp/parse.y index 23bab0337..5b7a310f1 100644 --- a/vvp/parse.y +++ b/vvp/parse.y @@ -682,10 +682,10 @@ statement | T_LABEL K_VAR_I local_flag T_STRING ',' T_NUMBER T_NUMBER ';' { compile_variable($1, $4, $6, $7, vpiIntegerVar, true, $3); } - | T_LABEL K_VAR_2S local_flag T_STRING ',' T_NUMBER T_NUMBER ';' + | T_LABEL K_VAR_2S local_flag T_STRING ',' signed_t_number signed_t_number ';' { compile_variable($1, $4, $6, $7, vpiIntVar, true, $3); } - | T_LABEL K_VAR_2U local_flag T_STRING ',' T_NUMBER T_NUMBER ';' + | T_LABEL K_VAR_2U local_flag T_STRING ',' signed_t_number signed_t_number ';' { compile_variable($1, $4, $6, $7, vpiIntVar, false, $3); } | T_LABEL K_VAR_R T_STRING ',' signed_t_number signed_t_number ';' diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 71c859fbc..68272c41c 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -263,7 +263,7 @@ extern unsigned vpip_size(__vpiSignal *sig); extern struct __vpiScope* vpip_scope(__vpiSignal*sig); extern vpiHandle vpip_make_int2(const char*name, int msb, int lsb, - vvp_net_t*vec); + bool signed_flag, vvp_net_t*vec); extern vpiHandle vpip_make_int4(const char*name, int msb, int lsb, vvp_net_t*vec); extern vpiHandle vpip_make_var4(const char*name, int msb, int lsb, diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index f51ccee52..08df4e1ce 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-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 @@ -996,31 +996,39 @@ vpiHandle vpip_make_int4(const char*name, int msb, int lsb, vvp_net_t*vec) } /* - * Construct a vpi + * Construct the two-state SystemVerilog variables. */ -vpiHandle vpip_make_int2(const char*name, int msb, int lsb, vvp_net_t*vec) +vpiHandle vpip_make_int2(const char*name, int msb, int lsb, bool signed_flag, + vvp_net_t*vec) { - vpiHandle obj = vpip_make_net4(name, msb,lsb, true, vec); + vpiHandle obj = vpip_make_net4(name, msb, lsb, signed_flag, vec); - assert(lsb == 0); - switch (msb) { - case 7: - obj->vpi_type = &vpip_byte_rt; - break; - case 15: - obj->vpi_type = &vpip_shortint_rt; - break; - case 31: - obj->vpi_type = &vpip_int_rt; - break; - case 63: - obj->vpi_type = &vpip_longint_rt; - break; - default: - // Every other type of bit vector is a vpiBitVar with - // array dimensions. + // All unsigned 2-state variables are a vpiBitVar. All 2-state + // variables with a non-zero lsb are also a vpiBitVar. + if ((! signed_flag) || (lsb != 0) ) { obj->vpi_type = &vpip_bitvar_rt; - break; + } else { + // These could also be bit declarations with matching + // information, but for now they get the apparent type. + switch (msb) { + case 7: + obj->vpi_type = &vpip_byte_rt; + break; + case 15: + obj->vpi_type = &vpip_shortint_rt; + break; + case 31: + obj->vpi_type = &vpip_int_rt; + break; + case 63: + obj->vpi_type = &vpip_longint_rt; + break; + default: + // Every other type of bit vector is a vpiBitVar with + // array dimensions. + obj->vpi_type = &vpip_bitvar_rt; + break; + } } return obj; diff --git a/vvp/words.cc b/vvp/words.cc index 9485cc257..a1168223f 100644 --- a/vvp/words.cc +++ b/vvp/words.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-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 @@ -117,7 +117,7 @@ void compile_variable(char*label, char*name, obj = vpip_make_int4(name, msb, lsb, net); break; case vpiIntVar: // This handles all the atom2 int types - obj = vpip_make_int2(name, msb, lsb, net); + obj = vpip_make_int2(name, msb, lsb, signed_flag, net); break; default: fprintf(stderr, "internal error: %s: vpi_type_code=%d\n", name, vpi_type_code);