Skip to content
This repository
Browse code

Trim leading nulls from string forms.

  • Loading branch information...
commit 844fe3b9bc6547b23d6401771f9b8cbb117592f6 1 parent 2718553
steve authored

Showing 2 changed files with 62 additions and 6 deletions. Show diff stats Hide diff stats

  1. +9 2 verinum.cc
  2. +53 4 vvp/vpi_const.cc
11 verinum.cc
@@ -17,7 +17,7 @@
17 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 18 */
19 19 #if !defined(WINNT) && !defined(macintosh)
20   -#ident "$Id: verinum.cc,v 1.32 2002/04/27 04:48:43 steve Exp $"
  20 +#ident "$Id: verinum.cc,v 1.33 2002/04/27 23:26:24 steve Exp $"
21 21 #endif
22 22
23 23 # include "config.h"
@@ -233,7 +233,7 @@ string verinum::as_string() const
233 233
234 234 char*tmp = new char[nbits_/8+1];
235 235 char*cp = tmp;
236   - for (unsigned idx = nbits_ ; idx > 0 ; idx -= 8, cp += 1) {
  236 + for (unsigned idx = nbits_ ; idx > 0 ; idx -= 8) {
237 237 V*bp = bits_+idx;
238 238 *cp = 0;
239 239 if (*(--bp) == V1) *cp |= 0x80;
@@ -244,6 +244,10 @@ string verinum::as_string() const
244 244 if (*(--bp) == V1) *cp |= 0x04;
245 245 if (*(--bp) == V1) *cp |= 0x02;
246 246 if (*(--bp) == V1) *cp |= 0x01;
  247 + if (*cp != 0) {
  248 + cp += 1;
  249 + *cp = 0;
  250 + }
247 251 }
248 252
249 253 tmp[nbits_/8] = 0;
@@ -798,6 +802,9 @@ verinum::V operator & (verinum::V l, verinum::V r)
798 802
799 803 /*
800 804 * $Log: verinum.cc,v $
  805 + * Revision 1.33 2002/04/27 23:26:24 steve
  806 + * Trim leading nulls from string forms.
  807 + *
801 808 * Revision 1.32 2002/04/27 04:48:43 steve
802 809 * Display string verinums as strings.
803 810 *
57 vvp/vpi_const.cc
@@ -17,7 +17,7 @@
17 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 18 */
19 19 #if !defined(WINNT)
20   -#ident "$Id: vpi_const.cc,v 1.14 2002/04/27 22:36:39 steve Exp $"
  20 +#ident "$Id: vpi_const.cc,v 1.15 2002/04/27 23:26:24 steve Exp $"
21 21 #endif
22 22
23 23 # include "vpi_priv.h"
@@ -196,6 +196,51 @@ static int binary_get(int code, vpiHandle ref)
196 196 }
197 197 }
198 198
  199 +static void binary_vpiStringVal(struct __vpiBinaryConst*rfp, p_vpi_value vp)
  200 +{
  201 + unsigned nchar = rfp->nbits / 8;
  202 + unsigned tail = rfp->nbits%8;
  203 +
  204 + char*cp = buf;
  205 +
  206 + if (tail > 0) {
  207 + char char_val = 0;
  208 + for (unsigned idx = rfp->nbits-tail; idx < rfp->nbits; idx += 1) {
  209 + unsigned nibble = idx/4;
  210 + unsigned shift = 2 * (idx%4);
  211 + unsigned val = (rfp->bits[nibble] >> shift) & 3;
  212 + if (val & 1)
  213 + char_val |= 1 << idx;
  214 + }
  215 +
  216 + if (char_val != 0)
  217 + *cp++ = char_val;
  218 + }
  219 +
  220 + for (unsigned idx = 0 ; idx < nchar ; idx += 1) {
  221 + unsigned bit = (nchar - idx - 1) * 8;
  222 + unsigned nibble = bit/4;
  223 + unsigned vall = rfp->bits[nibble+0];
  224 + unsigned valh = rfp->bits[nibble+1];
  225 +
  226 + char char_val = 0;
  227 + if (vall&0x01) char_val |= 0x01;
  228 + if (vall&0x04) char_val |= 0x02;
  229 + if (vall&0x10) char_val |= 0x04;
  230 + if (vall&0x40) char_val |= 0x08;
  231 + if (valh&0x01) char_val |= 0x10;
  232 + if (valh&0x04) char_val |= 0x20;
  233 + if (valh&0x10) char_val |= 0x40;
  234 + if (valh&0x40) char_val |= 0x80;
  235 +
  236 + if (char_val != 0)
  237 + *cp++ = char_val;
  238 + }
  239 +
  240 + *cp = 0;
  241 + vp->format = vpiStringVal;
  242 + vp->value.str = buf;
  243 +}
199 244
200 245 static void binary_value(vpiHandle ref, p_vpi_value vp)
201 246 {
@@ -237,9 +282,6 @@ static void binary_value(vpiHandle ref, p_vpi_value vp)
237 282 case vpiHexStrVal: {
238 283 unsigned nchar = (rfp->nbits+3)/4;
239 284 assert(nchar < sizeof buf);
240   - unsigned cum_val = 0;
241   - unsigned nz = 0;
242   - unsigned nx = 0;
243 285 for (unsigned idx = 0 ; idx < rfp->nbits ; idx += 4) {
244 286 unsigned nibble = idx/4;
245 287 unsigned vals = rfp->bits[nibble];
@@ -283,6 +325,10 @@ static void binary_value(vpiHandle ref, p_vpi_value vp)
283 325 break;
284 326 }
285 327
  328 + case vpiStringVal:
  329 + binary_vpiStringVal(rfp, vp);
  330 + break;
  331 +
286 332 default:
287 333 fprintf(stderr, "vvp error: format %d not supported "
288 334 "by vpiBinaryConst\n", vp->format);
@@ -453,6 +499,9 @@ vpiHandle vpip_make_dec_const(int value)
453 499
454 500 /*
455 501 * $Log: vpi_const.cc,v $
  502 + * Revision 1.15 2002/04/27 23:26:24 steve
  503 + * Trim leading nulls from string forms.
  504 + *
456 505 * Revision 1.14 2002/04/27 22:36:39 steve
457 506 * Support drawing vpiBinaryConst in hex.
458 507 *

0 comments on commit 844fe3b

Please sign in to comment.
Something went wrong with that request. Please try again.