Add support for string constants to VPI.

This commit is contained in:
steve 2001-03-18 04:35:18 +00:00
parent 66f7ef97da
commit 6779f01f3a
11 changed files with 254 additions and 33 deletions

View File

@ -16,7 +16,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
#ident "$Id: Makefile.in,v 1.5 2001/03/18 00:37:55 steve Exp $"
#ident "$Id: Makefile.in,v 1.6 2001/03/18 04:35:18 steve Exp $"
#
#
SHELL = /bin/sh
@ -54,7 +54,8 @@ clean:
distclean: clean
rm -f config.h Makefile config.cache config.log config.status
V = vpi_modules.o vpi_iter.o vpi_mcd.o vpi_priv.o vpi_scope.o vpi_tasks.o
V = vpi_modules.o vpi_const.o vpi_iter.o vpi_mcd.o vpi_priv.o \
vpi_scope.o vpi_tasks.o
O = main.o parse.o parse_misc.o lexor.o compile.o functor.o symbols.o \
codes.o vthread.o schedule.o tables.o $V

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: compile.cc,v 1.5 2001/03/18 00:37:55 steve Exp $"
#ident "$Id: compile.cc,v 1.6 2001/03/18 04:35:18 steve Exp $"
#endif
# include "compile.h"
@ -308,7 +308,7 @@ void compile_code(char*label, char*mnem, comp_operands_t opa)
free(mnem);
}
void compile_vpi_call(char*label, char*name)
void compile_vpi_call(char*label, char*name, unsigned argc, vpiHandle*argv)
{
vvp_cpoint_t ptr = codespace_allocate();
@ -328,7 +328,7 @@ void compile_vpi_call(char*label, char*name)
/* Create a vpiHandle that bundles the call information, and
store that handle in the instruction. */
code->handle = vpip_build_vpi_call(name);
code->handle = vpip_build_vpi_call(name, argc, argv);
/* Done with the lexor-allocated name string. */
free(name);
@ -434,6 +434,9 @@ void compile_dump(FILE*fd)
/*
* $Log: compile.cc,v $
* Revision 1.6 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.5 2001/03/18 00:37:55 steve
* Add support for vpi scopes.
*

View File

@ -19,10 +19,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: compile.h,v 1.4 2001/03/18 00:37:55 steve Exp $"
#ident "$Id: compile.h,v 1.5 2001/03/18 04:35:18 steve Exp $"
#endif
# include <stdio.h>
# include "vpi_user.h"
/*
* The functions described here are the compile time support
@ -77,7 +78,8 @@ struct comp_operands_s {
typedef struct comp_operands_s*comp_operands_t;
extern void compile_code(char*label, char*mnem, comp_operands_t opa);
extern void compile_vpi_call(char*label, char*name);
extern void compile_vpi_call(char*label, char*name,
unsigned argc, vpiHandle*argv);
/*
* The parser uses these functions to compile .scope statements.
@ -105,6 +107,9 @@ extern void compile_dump(FILE*fd);
/*
* $Log: compile.h,v $
* Revision 1.5 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.4 2001/03/18 00:37:55 steve
* Add support for vpi scopes.
*

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.2 2001/03/16 01:44:34 steve Exp $"
#ident "$Id: main.cc,v 1.3 2001/03/18 04:35:18 steve Exp $"
#endif
# include "config.h"
@ -33,6 +33,8 @@ const char*module_path = ".";
unsigned module_cnt = 0;
const char*module_tab[64];
extern void vpi_mcd_init(void);
int main(int argc, char*argv[])
{
int opt;
@ -64,6 +66,12 @@ int main(int argc, char*argv[])
design_path = argv[optind];
/* This is needed to get the MCD I/O routines ready for
anything. It is done early because it is plausible that the
compile might affect it, and it is cheap to do. */
vpi_mcd_init();
compile_init();
vpip_load_modules(module_cnt, module_tab, module_path);
compile_design(design_path);
@ -81,6 +89,9 @@ int main(int argc, char*argv[])
/*
* $Log: main.cc,v $
* Revision 1.3 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.2 2001/03/16 01:44:34 steve
* Add structures for VPI support, and all the %vpi_call
* instruction. Get linking of VPI modules to work.

View File

@ -18,6 +18,9 @@ extern FILE*yyin;
unsigned long numb;
struct textv_s textv;
comp_operands_t opa;
struct argv_s argv;
vpiHandle vpi;
};
@ -30,7 +33,11 @@ extern FILE*yyin;
%token <text> T_SYMBOL
%type <textv> symbols
%type <opa> operand operands operands_opt
%type <text> label_opt
%type <opa> operand operands operands_opt
%type <argv> argument_opt argument_list
%type <vpi> argument
%%
@ -62,22 +69,17 @@ statement
operands. The meaning of and restrictions on the operands depends
on the specific instruction. */
| T_LABEL T_INSTR operands_opt ';'
| label_opt T_INSTR operands_opt ';'
{ compile_code($1, $2, $3);
}
| T_INSTR operands_opt ';'
{ compile_code(0, $1, $2);
}
/* %vpi_call statements are instructions that have unusual operand
requirements so are handled by their own rules. */
| T_LABEL K_vpi_call T_STRING ';'
{ compile_vpi_call($1, $3); }
| label_opt K_vpi_call T_STRING argument_opt ';'
{ compile_vpi_call($1, $3, $4.argc, $4.argv); }
| K_vpi_call T_STRING ';'
{ compile_vpi_call(0, $2); }
/* Scope statements come in two forms. There are the scope
declaration and the scope recall. */
@ -106,6 +108,14 @@ statement
;
/* There are a few places where the label is optional. This rule
returns the label value if present, or 0 if not. */
label_opt
: T_LABEL { $$ = $1; }
| { $$ = 0; }
;
operands_opt
: operands { $$ = $1; }
| { $$ = 0; }
@ -144,6 +154,42 @@ operand
}
;
/* The argument_list is a list of vpiHandle objects that can be
passed to a %vpi_call statement (and hence built into a
vpiCallSysTask handle). We build up an arbitrary sized list with
the struct argv_s type. */
argument_opt
: ',' argument_list
{ $$ = $2; }
|
{ struct argv_s tmp;
argv_init(&tmp);
$$ = tmp;
}
;
argument_list
: argument
{ struct argv_s tmp;
argv_init(&tmp);
argv_add(&tmp, $1);
$$ = tmp;
}
| argument_list ',' argument
{ struct argv_s tmp = $1;
argv_add(&tmp, $3);
$$ = tmp;
}
;
argument
: T_STRING
{ $$ = vpip_make_string_const($1); }
;
/* functor operands can only be a list of symbols. */
symbols
: T_SYMBOL

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001 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
@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: parse_misc.cc,v 1.1 2001/03/11 00:29:39 steve Exp $"
#ident "$Id: parse_misc.cc,v 1.2 2001/03/18 04:35:18 steve Exp $"
#endif
# include "parse_misc.h"
@ -40,13 +40,30 @@ void textv_init(struct textv_s*obj)
void textv_add(struct textv_s*obj, char*item)
{
obj->text = realloc(obj->text, (obj->cnt+1) * sizeof(char*));
obj->text = (char**)realloc(obj->text, (obj->cnt+1) * sizeof(char*));
obj->text[obj->cnt] = item;
obj->cnt += 1;
}
void argv_init(struct argv_s*obj)
{
obj->argc = 0;
obj->argv = 0;
}
void argv_add(struct argv_s*obj, vpiHandle item)
{
obj->argv = (vpiHandle*)
realloc(obj->argv, (obj->argc+1)*sizeof(vpiHandle));
obj->argv[obj->argc] = item;
obj->argc += 1;
}
/*
* $Log: parse_misc.cc,v $
* Revision 1.2 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.1 2001/03/11 00:29:39 steve
* Add the vvp engine to cvs.
*

View File

@ -19,9 +19,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: parse_misc.h,v 1.1 2001/03/11 00:29:39 steve Exp $"
#ident "$Id: parse_misc.h,v 1.2 2001/03/18 04:35:18 steve Exp $"
#endif
# include "vpi_priv.h"
/*
* This method is called to compile the design file. The input is read
* and a list of statements is created.
@ -48,8 +51,21 @@ struct textv_s {
extern void textv_init(struct textv_s*obj);
extern void textv_add(struct textv_s*obj, char*item);
struct argv_s {
unsigned argc;
vpiHandle*argv;
};
extern void argv_init(struct argv_s*obj);
extern void argv_add(struct argv_s*obj, vpiHandle);
/*
* $Log: parse_misc.h,v $
* Revision 1.2 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.1 2001/03/11 00:29:39 steve
* Add the vvp engine to cvs.
*

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* $Id: vpi.txt,v 1.3 2001/03/18 00:37:55 steve Exp $
* $Id: vpi.txt,v 1.4 2001/03/18 04:35:18 steve Exp $
*/
@ -84,6 +84,13 @@ creates and that the %vpi_call instruction ultimately refers to. All
the arguments must be some sort of object that can be represented by a
vpiHandle at compile time.
Arguments are handled at compile time by the parser, which uses the
argument_list rule to build a list of vpiHandle objects. Each argument
in the argument_list invokes whatever function is appropriate for the
token in order to make a vpiHandle object for the argument_list. When
all this is done, an array of vpiHandles is passed to code to create a
vpiSysTfCall object that has all that is needed to make the call.
SCOPES

91
vvp/vpi_const.cc Normal file
View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2001 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
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_const.cc,v 1.1 2001/03/18 04:35:18 steve Exp $"
#endif
# include "vpi_priv.h"
# include <malloc.h>
# include <assert.h>
static int string_get(int code, vpiHandle ref)
{
struct __vpiStringConst*rfp = (struct __vpiStringConst*)ref;
assert(ref->vpi_type->type_code == vpiConstant);
switch (code) {
case vpiConstType:
return vpiStringConst;
default:
assert(0);
return 0;
}
}
static void string_value(vpiHandle ref, p_vpi_value vp)
{
struct __vpiStringConst*rfp = (struct __vpiStringConst*)ref;
assert(ref->vpi_type->type_code == vpiConstant);
switch (vp->format) {
case vpiObjTypeVal:
case vpiStringVal:
vp->value.str = (char*)rfp->value;
vp->format = vpiStringVal;
break;
default:
vp->format = vpiSuppressVal;
break;
}
}
static const struct __vpirt vpip_string_rt = {
vpiConstant,
string_get,
0,
string_value,
0,
0,
0
};
vpiHandle vpip_make_string_const(char*text)
{
struct __vpiStringConst*obj;
obj = (struct __vpiStringConst*)
malloc(sizeof (struct __vpiStringConst));
obj->base.vpi_type = &vpip_string_rt;
obj->value = text;
return &obj->base;
}
/*
* $Log: vpi_const.cc,v $
* Revision 1.1 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
*/

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.2 2001/03/18 00:37:55 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.3 2001/03/18 04:35:18 steve Exp $"
#endif
# include "vpi_user.h"
@ -72,6 +72,8 @@ struct __vpiIterator {
unsigned next;
};
extern vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args);
/*
* Scopes are created by .scope statements in the source.
*/
@ -111,6 +113,18 @@ struct __vpiSysTaskCall {
extern struct __vpiSysTaskCall*vpip_cur_task;
/*
* These are implemented in vpi_const.cc. These are vpiHandles for
* constants.
*/
struct __vpiStringConst {
struct __vpiHandle base;
const char*value;
};
vpiHandle vpip_make_string_const(char*text);
/*
* This function is called before any compilation to load VPI
* modules. This gives the modules a chance to announce their
@ -127,9 +141,15 @@ extern void vpip_load_modules(unsigned cnt, const char*tab[], const char*path);
* The %vpi_call instruction has as its only parameter the handle that
* is returned by the vpip_build_vpi_call. This includes all the
* information needed by vpip_execute_vpi_call to actually execute the
* call.
* call. However, the vpiSysTaskCall that is the returned handle,
* holds a parameter argument list that is passed in here.
*
* Note that the argv array is saved in the handle, should should not
* be released by the caller.
*/
extern vpiHandle vpip_build_vpi_call(const char*name);
extern vpiHandle vpip_build_vpi_call(const char*name,
unsigned argc,
vpiHandle*argv);
extern void vpip_execute_vpi_call(vpiHandle obj);
@ -143,6 +163,9 @@ extern void scope_cleanup(void);
/*
* $Log: vpi_priv.h,v $
* Revision 1.3 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.2 2001/03/18 00:37:55 steve
* Add support for vpi scopes.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_tasks.cc,v 1.2 2001/03/18 00:37:55 steve Exp $"
#ident "$Id: vpi_tasks.cc,v 1.3 2001/03/18 04:35:18 steve Exp $"
#endif
/*
@ -58,11 +58,7 @@ static vpiHandle systask_iter(int type, vpiHandle ref)
if (rfp->nargs == 0)
return 0;
#if 0
return vpip_make_iterator(rfp->nargs, rfp->args);
#else
return 0;
#endif
}
static const struct __vpirt vpip_systask_rt = {
@ -143,7 +139,9 @@ static struct __vpiUserSystf* vpip_find_systf(const char*name)
* describes the call, and return it. The %vpi_call instruction will
* store this handle for when it is executed.
*/
vpiHandle vpip_build_vpi_call(const char*name)
vpiHandle vpip_build_vpi_call(const char*name,
unsigned argc,
vpiHandle*argv)
{
struct __vpiSysTaskCall*obj = (struct __vpiSysTaskCall*)
calloc(1, sizeof (struct __vpiSysTaskCall));
@ -151,8 +149,8 @@ vpiHandle vpip_build_vpi_call(const char*name)
obj->base.vpi_type = &vpip_systask_rt;
obj->scope = vpip_peek_current_scope();
obj->defn = vpip_find_systf(name);
obj->nargs = 0;
obj->args = 0;
obj->nargs = argc;
obj->args = argv;
/* If there is a compiletf function, call it here. */
if (obj->defn->info.compiletf)
@ -192,6 +190,9 @@ void vpi_register_systf(const struct t_vpi_systf_data*ss)
/*
* $Log: vpi_tasks.cc,v $
* Revision 1.3 2001/03/18 04:35:18 steve
* Add support for string constants to VPI.
*
* Revision 1.2 2001/03/18 00:37:55 steve
* Add support for vpi scopes.
*