Allow signed constant vectors for call_vpi parameters.
This commit is contained in:
parent
3275d1f252
commit
a18662ed13
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: lexor.lex,v 1.32 2002/03/18 00:19:34 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.33 2002/04/14 03:53:20 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -50,22 +50,35 @@
|
|||
assert(yylval.text);
|
||||
return T_STRING; }
|
||||
|
||||
[1-9][0-9]*"'b"[01xz]+ {
|
||||
/* Binary vector tokens are pared here. The result of this is a
|
||||
string of binary 4-values in the yylval.vect.text string. This is
|
||||
preceeded by an 's' if the vector is signed. */
|
||||
[1-9][0-9]*("'b"|"'sb")[01xz]+ {
|
||||
yylval.vect.idx = strtoul(yytext, 0, 10);
|
||||
yylval.vect.text = (char*)malloc(yylval.vect.idx + 1);
|
||||
yylval.vect.text = (char*)malloc(yylval.vect.idx + 2);
|
||||
assert(yylval.vect.text);
|
||||
char*dest = yylval.vect.text;
|
||||
|
||||
const char*bits = strchr(yytext, 'b');
|
||||
const char*bits = strchr(yytext, '\'');
|
||||
assert(bits);
|
||||
bits += 1;
|
||||
|
||||
if (*bits == 's') {
|
||||
*dest++ = 's';
|
||||
bits += 1;
|
||||
}
|
||||
|
||||
assert(*bits == 'b');
|
||||
bits += 1;
|
||||
unsigned pad = 0;
|
||||
if (strlen(bits) < yylval.vect.idx)
|
||||
pad = yylval.vect.idx - strlen(bits);
|
||||
|
||||
memset(yylval.vect.text, '0', pad);
|
||||
memset(dest, '0', pad);
|
||||
for (unsigned idx = pad ; idx < yylval.vect.idx ; idx += 1)
|
||||
yylval.vect.text[idx] = bits[idx-pad];
|
||||
dest[idx] = bits[idx-pad];
|
||||
|
||||
yylval.vect.text[yylval.vect.idx] = 0;
|
||||
dest[yylval.vect.idx] = 0;
|
||||
return T_VECTOR; }
|
||||
|
||||
|
||||
|
|
@ -159,6 +172,9 @@ int yywrap()
|
|||
|
||||
/*
|
||||
* $Log: lexor.lex,v $
|
||||
* Revision 1.33 2002/04/14 03:53:20 steve
|
||||
* Allow signed constant vectors for call_vpi parameters.
|
||||
*
|
||||
* Revision 1.32 2002/03/18 00:19:34 steve
|
||||
* Add the .ufunc statement.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: vpi_const.cc,v 1.12 2002/03/18 05:33:24 steve Exp $"
|
||||
#ident "$Id: vpi_const.cc,v 1.13 2002/04/14 03:53:20 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "vpi_priv.h"
|
||||
|
|
@ -182,8 +182,8 @@ static int binary_get(int code, vpiHandle ref)
|
|||
case vpiConstType:
|
||||
return vpiBinaryConst;
|
||||
|
||||
case vpiSigned: // FIXME: Need to get signed flag right.
|
||||
return 0;
|
||||
case vpiSigned:
|
||||
return rfp->signed_flag? 1 : 0;
|
||||
|
||||
case vpiSize:
|
||||
return rfp->nbits;
|
||||
|
|
@ -225,7 +225,8 @@ static void binary_value(vpiHandle ref, p_vpi_value vp)
|
|||
for (unsigned idx = 0 ; idx < wid ; idx += 1)
|
||||
tmp[idx] = (rfp->bits[idx/4] >> 2*(idx%4)) & 3;
|
||||
|
||||
vpip_bits_to_dec_str(tmp, wid, buf, sizeof buf, 0);
|
||||
vpip_bits_to_dec_str(tmp, wid, buf, sizeof buf,
|
||||
rfp->signed_flag);
|
||||
|
||||
delete[]tmp;
|
||||
vp->value.str = buf;
|
||||
|
|
@ -269,6 +270,11 @@ static const struct __vpirt vpip_binary_rt = {
|
|||
0
|
||||
};
|
||||
|
||||
/*
|
||||
* Make a VPI constant from a vector string. The string is normally a
|
||||
* ASCII string, with each letter a 4-value bit. The first character
|
||||
* may be an 's' if the vector is signed.
|
||||
*/
|
||||
vpiHandle vpip_make_binary_const(unsigned wid, char*bits)
|
||||
{
|
||||
struct __vpiBinaryConst*obj;
|
||||
|
|
@ -277,14 +283,21 @@ vpiHandle vpip_make_binary_const(unsigned wid, char*bits)
|
|||
malloc(sizeof (struct __vpiBinaryConst));
|
||||
obj->base.vpi_type = &vpip_binary_rt;
|
||||
|
||||
obj->signed_flag = 0;
|
||||
obj->nbits = wid;
|
||||
obj->bits = (unsigned char*)malloc((obj->nbits + 3) / 4);
|
||||
memset(obj->bits, 0, (obj->nbits + 3) / 4);
|
||||
|
||||
const char*bp = bits;
|
||||
if (*bp == 's') {
|
||||
bp += 1;
|
||||
obj->signed_flag = 1;
|
||||
}
|
||||
|
||||
for (unsigned idx = 0 ; idx < obj->nbits ; idx += 1) {
|
||||
unsigned nibble = idx / 4;
|
||||
unsigned val = 0;
|
||||
switch (bits[wid-idx-1]) {
|
||||
switch (bp[wid-idx-1]) {
|
||||
case '0':
|
||||
val = 0;
|
||||
break;
|
||||
|
|
@ -409,6 +422,9 @@ vpiHandle vpip_make_dec_const(int value)
|
|||
|
||||
/*
|
||||
* $Log: vpi_const.cc,v $
|
||||
* Revision 1.13 2002/04/14 03:53:20 steve
|
||||
* Allow signed constant vectors for call_vpi parameters.
|
||||
*
|
||||
* Revision 1.12 2002/03/18 05:33:24 steve
|
||||
* vpip_bits_to_dec_str takes a bit array in a specific format.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: vpi_priv.h,v 1.29 2002/04/14 02:56:19 steve Exp $"
|
||||
#ident "$Id: vpi_priv.h,v 1.30 2002/04/14 03:53:20 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "vpi_user.h"
|
||||
|
|
@ -179,6 +179,7 @@ struct __vpiBinaryConst {
|
|||
struct __vpiHandle base;
|
||||
unsigned nbits;
|
||||
unsigned char*bits;
|
||||
unsigned signed_flag :1;
|
||||
};
|
||||
|
||||
vpiHandle vpip_make_binary_const(unsigned wid, char*bits);
|
||||
|
|
@ -268,6 +269,9 @@ extern unsigned vpip_bits_to_dec_str(const unsigned char *bits,
|
|||
|
||||
/*
|
||||
* $Log: vpi_priv.h,v $
|
||||
* Revision 1.30 2002/04/14 03:53:20 steve
|
||||
* Allow signed constant vectors for call_vpi parameters.
|
||||
*
|
||||
* Revision 1.29 2002/04/14 02:56:19 steve
|
||||
* Support signed expressions through to VPI.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue