Take vector form as parameters to vpi_call.

This commit is contained in:
steve 2001-04-04 04:33:08 +00:00
parent 1b2a6f8bed
commit 48ff66cbce
6 changed files with 99 additions and 18 deletions

7
vvp/examples/vector.vvp Normal file
View File

@ -0,0 +1,7 @@
:vpi_module "system";
main .scope "main";
T0 %vpi_call "$display", "Display the number: %b", 5'b0zx1;
%end;
.thread T0;

View File

@ -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.9 2001/03/26 04:00:39 steve Exp $"
#ident "$Id: lexor.lex,v 1.10 2001/04/04 04:33:08 steve Exp $"
#endif
# include "parse_misc.h"
@ -46,6 +46,23 @@
yylval.text = strdup(yytext+1);
return T_STRING; }
[1-9][0-9]*"'b"[01xz]+ {
yylval.vect.idx = strtoul(yytext, 0, 10);
yylval.vect.text = (char*)malloc(yylval.vect.idx + 1);
const char*bits = strchr(yytext, 'b');
bits += 1;
unsigned pad = 0;
if (strlen(bits) < yylval.vect.idx)
pad = yylval.vect.idx - strlen(bits);
memset(yylval.vect.text, '0', pad);
for (unsigned idx = pad ; idx < yylval.vect.idx ; idx += 1)
yylval.vect.text[idx] = bits[idx-pad];
yylval.vect.text[yylval.vect.idx] = 0;
return T_VECTOR; }
/* These are some keywords that are recognized. */
".event" { return K_EVENT; }
@ -76,6 +93,7 @@
return T_NUMBER; }
/* Symbols are pretty much what is left. They are used to refer to
labels so the rule must match a string that a label would match. */
[.$_a-zA-Z][.$_a-zA-Z0-9<>]* {
@ -105,6 +123,9 @@ int yywrap()
/*
* $Log: lexor.lex,v $
* Revision 1.10 2001/04/04 04:33:08 steve
* Take vector form as parameters to vpi_call.
*
* Revision 1.9 2001/03/26 04:00:39 steve
* Add the .event statement and the %wait instruction.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: main.cc,v 1.7 2001/03/23 02:40:22 steve Exp $"
#ident "$Id: main.cc,v 1.8 2001/04/04 04:33:08 steve Exp $"
#endif
# include "config.h"
@ -77,7 +77,8 @@ int main(int argc, char*argv[])
for (unsigned idx = 0 ; idx < module_cnt ; idx += 1)
vpip_load_module(module_tab[idx], module_path);
#endif
compile_design(design_path);
if (int rc = compile_design(design_path))
return rc;
compile_cleanup();
if (dump_path) {
@ -99,6 +100,9 @@ int main(int argc, char*argv[])
/*
* $Log: main.cc,v $
* Revision 1.8 2001/04/04 04:33:08 steve
* Take vector form as parameters to vpi_call.
*
* Revision 1.7 2001/03/23 02:40:22 steve
* Add the :module header statement.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: parse.y,v 1.16 2001/04/02 00:24:30 steve Exp $"
#ident "$Id: parse.y,v 1.17 2001/04/04 04:33:08 steve Exp $"
#endif
# include "parse_misc.h"
@ -44,6 +44,8 @@ extern FILE*yyin;
struct symb_s symb;
struct symbv_s symbv;
struct symb_s vect;
struct argv_s argv;
vpiHandle vpi;
};
@ -57,6 +59,7 @@ extern FILE*yyin;
%token <numb> T_NUMBER
%token <text> T_STRING
%token <text> T_SYMBOL
%token <vect> T_VECTOR
%type <symb> symbol
%type <symbv> symbols
@ -256,10 +259,10 @@ argument_list
argument
: T_STRING
{ $$ = vpip_make_string_const($1); }
| T_NUMBER
{ $$ = vpip_make_binary_const($1); }
| T_SYMBOL
{ $$ = compile_vpi_lookup($1); free($1); }
| T_VECTOR
{ $$ = vpip_make_binary_const($1.idx, $1.text); }
;
@ -301,6 +304,11 @@ int compile_design(const char*path)
yypath = path;
yyline = 1;
yyin = fopen(path, "r");
if (yyin == 0) {
fprintf(stderr, "%s: Unable to open input file.\n", path);
return -1;
}
int rc = yyparse();
return rc;
}
@ -308,6 +316,9 @@ int compile_design(const char*path)
/*
* $Log: parse.y,v $
* Revision 1.17 2001/04/04 04:33:08 steve
* Take vector form as parameters to vpi_call.
*
* Revision 1.16 2001/04/02 00:24:30 steve
* Take numbers as system task parameters.
*

View File

@ -17,10 +17,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_const.cc,v 1.2 2001/04/02 00:24:31 steve Exp $"
#ident "$Id: vpi_const.cc,v 1.3 2001/04/04 04:33:08 steve Exp $"
#endif
# include "vpi_priv.h"
# include <stdio.h>
# include <malloc.h>
# include <string.h>
# include <assert.h>
@ -98,14 +99,32 @@ static int binary_get(int code, vpiHandle ref)
}
}
static char buf[4096];
static void binary_value(vpiHandle ref, p_vpi_value vp)
{
struct __vpiStringConst*rfp = (struct __vpiStringConst*)ref;
struct __vpiBinaryConst*rfp = (struct __vpiBinaryConst*)ref;
assert(ref->vpi_type->type_code == vpiConstant);
switch (vp->format) {
case vpiObjTypeVal:
case vpiBinStrVal:
for (unsigned idx = 0 ; idx < rfp->nbits ; idx += 1) {
unsigned nibble = idx/4;
unsigned shift = 2 * (idx%4);
unsigned val = (rfp->bits[nibble] >> shift) & 3;
buf[rfp->nbits-idx-1] = "01xz"[val];
}
buf[rfp->nbits] = 0;
vp->value.str = buf;
vp->format = vpiBinStrVal;
break;
default:
fprintf(stderr, "vvp error: format %d not supported "
"by vpiBinaryConst\n", vp->format);
vp->format = vpiSuppressVal;
break;
}
@ -121,7 +140,7 @@ static const struct __vpirt vpip_binary_rt = {
0
};
vpiHandle vpip_make_binary_const(long val)
vpiHandle vpip_make_binary_const(unsigned wid, char*bits)
{
struct __vpiBinaryConst*obj;
@ -129,25 +148,41 @@ vpiHandle vpip_make_binary_const(long val)
malloc(sizeof (struct __vpiBinaryConst));
obj->base.vpi_type = &vpip_binary_rt;
obj->nbits = 8*sizeof(long);
obj->bits = (unsigned char*)malloc(obj->nbits / 4);
memset(obj->bits, 0, obj->nbits / 4);
obj->nbits = wid;
obj->bits = (unsigned char*)malloc((obj->nbits + 3) / 4);
memset(obj->bits, 0, (obj->nbits + 3) / 4);
for (unsigned idx = 0 ; idx < obj->nbits ; idx += 1) {
unsigned nibble = idx / 4;
unsigned val = 0;
switch (bits[wid-idx-1]) {
case '0':
val = 0;
break;
case '1':
val = 1;
break;
case 'x':
val = 2;
break;
case 'z':
val = 3;
break;
}
if (val & 1)
obj->bits[nibble] |= 1 << 2 * (idx%4);
val >>= 1;
obj->bits[nibble] |= val << (2 * (idx%4));
}
free(bits);
return &(obj->base);
}
/*
* $Log: vpi_const.cc,v $
* Revision 1.3 2001/04/04 04:33:08 steve
* Take vector form as parameters to vpi_call.
*
* Revision 1.2 2001/04/02 00:24:31 steve
* Take numbers as system task parameters.
*

View File

@ -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.9 2001/04/02 00:24:31 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.10 2001/04/04 04:33:09 steve Exp $"
#endif
# include "vpi_user.h"
@ -151,7 +151,7 @@ struct __vpiBinaryConst {
unsigned char*bits;
};
vpiHandle vpip_make_binary_const(long val);
vpiHandle vpip_make_binary_const(unsigned wid, char*bits);
/*
* This function is called before any compilation to load VPI
@ -191,6 +191,9 @@ vpiHandle vpip_sim_time(void);
/*
* $Log: vpi_priv.h,v $
* Revision 1.10 2001/04/04 04:33:09 steve
* Take vector form as parameters to vpi_call.
*
* Revision 1.9 2001/04/02 00:24:31 steve
* Take numbers as system task parameters.
*