Add the :module header statement.

This commit is contained in:
steve 2001-03-23 02:40:22 +00:00
parent 034cdae445
commit 2858c2f09b
8 changed files with 96 additions and 32 deletions

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* $Id: README.txt,v 1.6 2001/03/21 05:12:15 steve Exp $
* $Id: README.txt,v 1.7 2001/03/23 02:40:22 steve Exp $
*/
VVP SIMULATION ENGINE
@ -32,6 +32,20 @@ Statements may span multiple lines, as long as there is no text (other
then the first character of a label) in the first column of hte
continuation line.
HEADER SYNTAX
Before any other non-commentary code starts, the source may contain
some header statements. These are used for passing parameters or
global details from the compiler to the vvp run-time. In all cases,
the header statement starts with a left-justified keyword, and ends
with a string.
* :module "name" ;
This header statement names a vpi module that vvp should load before
the rest of the program is compiled. The compiler looks in the
standard VPI_MODULE_PATH for files named "name.vpi", and tries to
dynamic load them.
LABELS AND SYMBOLS

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.11 2001/03/22 22:38:13 steve Exp $"
#ident "$Id: compile.cc,v 1.12 2001/03/23 02:40:22 steve Exp $"
#endif
# include "compile.h"
@ -152,6 +152,12 @@ void compile_init(void)
opcode_count += 1;
}
void compile_load_vpi_module(char*name)
{
vpip_load_module(name, module_path);
free(name);
}
/*
* The parser calls this function to create a functor. I allocate a
* functor, and map the name to the vvp_ipoint_t address for the
@ -518,6 +524,9 @@ void compile_dump(FILE*fd)
/*
* $Log: compile.cc,v $
* Revision 1.12 2001/03/23 02:40:22 steve
* Add the :module header statement.
*
* Revision 1.11 2001/03/22 22:38:13 steve
* Detect undefined system tasks at compile time.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: compile.h,v 1.8 2001/03/22 22:38:14 steve Exp $"
#ident "$Id: compile.h,v 1.9 2001/03/23 02:40:22 steve Exp $"
#endif
# include <stdio.h>
@ -45,6 +45,9 @@ extern void compile_cleanup(void);
*/
extern unsigned compile_errors;
extern const char* module_path;
extern void compile_load_vpi_module(char*name);
/*
* This function is called by the parser to compile a functor
* statement. The strings passed in are allocated by the lexor, but
@ -117,6 +120,9 @@ extern void compile_dump(FILE*fd);
/*
* $Log: compile.h,v $
* Revision 1.9 2001/03/23 02:40:22 steve
* Add the :module header statement.
*
* Revision 1.8 2001/03/22 22:38:14 steve
* Detect undefined system tasks at compile time.
*

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.5 2001/03/20 02:48:40 steve Exp $"
#ident "$Id: lexor.lex,v 1.6 2001/03/23 02:40:22 steve Exp $"
#endif
# include "parse_misc.h"
@ -30,6 +30,10 @@
%%
/* These are some special header keywords. */
^":vpi_module" { return K_vpi_module; }
/* A label is any non-blank text that appears left justified. */
^[.$_a-zA-Z][.$_a-zA-Z0-9]* {
yylval.text = strdup(yytext);
@ -99,6 +103,9 @@ int yywrap()
/*
* $Log: lexor.lex,v $
* Revision 1.6 2001/03/23 02:40:22 steve
* Add the :module header statement.
*
* Revision 1.5 2001/03/20 02:48:40 steve
* Copyright notices.
*

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.6 2001/03/22 22:38:14 steve Exp $"
#ident "$Id: main.cc,v 1.7 2001/03/23 02:40:22 steve Exp $"
#endif
# include "config.h"
@ -73,7 +73,10 @@ int main(int argc, char*argv[])
vpi_mcd_init();
compile_init();
vpip_load_modules(module_cnt, module_tab, module_path);
#if 0
for (unsigned idx = 0 ; idx < module_cnt ; idx += 1)
vpip_load_module(module_tab[idx], module_path);
#endif
compile_design(design_path);
compile_cleanup();
@ -96,6 +99,9 @@ int main(int argc, char*argv[])
/*
* $Log: main.cc,v $
* Revision 1.7 2001/03/23 02:40:22 steve
* Add the :module header statement.
*
* Revision 1.6 2001/03/22 22:38:14 steve
* Detect undefined system tasks at compile time.
*

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.10 2001/03/21 05:13:03 steve Exp $"
#ident "$Id: parse.y,v 1.11 2001/03/23 02:40:22 steve Exp $"
#endif
# include "parse_misc.h"
@ -50,6 +50,7 @@ extern FILE*yyin;
%token K_FUNCTOR K_SCOPE K_THREAD K_VAR K_vpi_call
%token K_vpi_module
%token <text> T_INSTR
%token <text> T_LABEL
@ -67,6 +68,20 @@ extern FILE*yyin;
%%
source_file : header_lines_opt program ;
header_lines_opt : header_lines | ;
header_lines
: header_line
| header_lines header_line
;
header_line
: K_vpi_module T_STRING ';'
{ compile_load_vpi_module($2); }
;
/* A program is simply a list of statements. No other structure. */
program
: statement
@ -274,6 +289,9 @@ int compile_design(const char*path)
/*
* $Log: parse.y,v $
* Revision 1.11 2001/03/23 02:40:22 steve
* Add the :module header statement.
*
* Revision 1.10 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_modules.cc,v 1.2 2001/03/22 05:39:34 steve Exp $"
#ident "$Id: vpi_modules.cc,v 1.3 2001/03/23 02:40:22 steve Exp $"
#endif
# include "config.h"
@ -27,35 +27,36 @@
typedef void (*vlog_startup_routines_t)(void);
void vpip_load_modules(unsigned cnt, const char*mod[], const char*path)
void vpip_load_module(const char*name, const char*path)
{
for (unsigned idx = 0 ; idx < cnt ; idx += 1) {
char buf[4096];
sprintf(buf, "%s/%s.vpi", path, mod[idx]);
//printf("Load %s...\n", buf);
ivl_dll_t dll = ivl_dlopen(buf);
if (dll == 0) {
fprintf(stderr, "%s: %s\n", mod[idx], dlerror());
continue;
}
void*table = ivl_dlsym(dll, LU "vlog_startup_routines" TU);
if (table == 0) {
fprintf(stderr, "%s: no vlog_startup_routines\n", mod[idx]);
ivl_dlclose(dll);
continue;
}
vlog_startup_routines_t*routines = (vlog_startup_routines_t*)table;
for (unsigned tmp = 0 ; routines[tmp] ; tmp += 1)
(routines[tmp])();
char buf[4096];
sprintf(buf, "%s/%s.vpi", path, name);
//printf("Load %s...\n", buf);
ivl_dll_t dll = ivl_dlopen(buf);
if (dll == 0) {
fprintf(stderr, "%s: %s\n", name, dlerror());
return;
}
void*table = ivl_dlsym(dll, LU "vlog_startup_routines" TU);
if (table == 0) {
fprintf(stderr, "%s: no vlog_startup_routines\n", name);
ivl_dlclose(dll);
return;
}
vlog_startup_routines_t*routines = (vlog_startup_routines_t*)table;
for (unsigned tmp = 0 ; routines[tmp] ; tmp += 1)
(routines[tmp])();
}
/*
* $Log: vpi_modules.cc,v $
* Revision 1.3 2001/03/23 02:40:22 steve
* Add the :module header statement.
*
* Revision 1.2 2001/03/22 05:39:34 steve
* Test print that interferes with output.
*

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.5 2001/03/21 05:13:03 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.6 2001/03/23 02:40:23 steve Exp $"
#endif
# include "vpi_user.h"
@ -150,7 +150,7 @@ vpiHandle vpip_make_string_const(char*text);
* contained functions before compilation commences. It is called only
* once.
*/
extern void vpip_load_modules(unsigned cnt, const char*tab[], const char*path);
extern void vpip_load_module(const char*name, const char*path);
/*
* The vpip_build_vpi_call function creates a __vpiSysTaskCall object
@ -180,6 +180,9 @@ extern void vpip_execute_vpi_call(vpiHandle obj);
/*
* $Log: vpi_priv.h,v $
* Revision 1.6 2001/03/23 02:40:23 steve
* Add the :module header statement.
*
* Revision 1.5 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*