Allow var objects as vpiHandle arguments to %vpi_call.

This commit is contained in:
steve 2001-03-21 05:13:03 +00:00
parent e24facfaf6
commit 2b8d9abd3e
8 changed files with 148 additions and 34 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: compile.cc,v 1.7 2001/03/20 06:16:24 steve Exp $" #ident "$Id: compile.cc,v 1.8 2001/03/21 05:13:03 steve Exp $"
#endif #endif
# include "compile.h" # include "compile.h"
@ -92,6 +92,14 @@ static symbol_table_t sym_codespace = 0;
*/ */
static symbol_table_t sym_functors = 0; static symbol_table_t sym_functors = 0;
/*
* VPI objects are indexed during compile time so that they can be
* linked together as they are created. This symbol table matches
* labels to vpiHandles.
*/
static symbol_table_t sym_vpi = 0;
/* /*
* If a functor parameter makes a forward reference to a functor, then * If a functor parameter makes a forward reference to a functor, then
* I need to save that reference and resolve it after the functors are * I need to save that reference and resolve it after the functors are
@ -115,7 +123,7 @@ static struct resolv_list_s*resolv_list = 0;
*/ */
void compile_init(void) void compile_init(void)
{ {
scope_init(); sym_vpi = new_symbol_table();
sym_functors = new_symbol_table(); sym_functors = new_symbol_table();
functor_init(); functor_init();
sym_codespace = new_symbol_table(); sym_codespace = new_symbol_table();
@ -359,6 +367,21 @@ void compile_thread(char*start_sym)
free(start_sym); free(start_sym);
} }
void compile_vpi_symbol(const char*label, vpiHandle obj)
{
symbol_value_t val;
val.ptr = obj;
sym_set_value(sym_vpi, label, val);
}
vpiHandle compile_vpi_lookup(const char*label)
{
symbol_value_t val;
val = sym_get_value(sym_vpi, label);
return (vpiHandle) val.ptr;
}
/* /*
* A variable is a special functor, so we allocate that functor and * A variable is a special functor, so we allocate that functor and
* write the label into the symbol table. * write the label into the symbol table.
@ -377,10 +400,12 @@ void compile_variable(char*label, char*name, int msb, int lsb)
obj->ival = 0x22; obj->ival = 0x22;
obj->oval = 0x02; obj->oval = 0x02;
} }
free(label);
/* Make the vpiHandle for the reg. */ /* Make the vpiHandle for the reg. */
vpip_make_reg(name, msb, lsb, fdx); vpiHandle obj = vpip_make_reg(name, msb, lsb, fdx);
compile_vpi_symbol(label, obj);
free(label);
} }
/* /*
@ -425,7 +450,6 @@ void compile_cleanup(void)
} }
} }
scope_cleanup();
} }
void compile_dump(FILE*fd) void compile_dump(FILE*fd)
@ -447,6 +471,9 @@ void compile_dump(FILE*fd)
/* /*
* $Log: compile.cc,v $ * $Log: compile.cc,v $
* Revision 1.8 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*
* Revision 1.7 2001/03/20 06:16:24 steve * Revision 1.7 2001/03/20 06:16:24 steve
* Add support for variable vectors. * Add support for variable vectors.
* *

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: compile.h,v 1.6 2001/03/20 06:16:24 steve Exp $" #ident "$Id: compile.h,v 1.7 2001/03/21 05:13:03 steve Exp $"
#endif #endif
# include <stdio.h> # include <stdio.h>
@ -53,6 +53,9 @@ extern void compile_functor(char*label, char*type, unsigned init,
unsigned argc, struct symb_s*argv); unsigned argc, struct symb_s*argv);
extern void compile_vpi_symbol(const char*label, vpiHandle obj);
extern vpiHandle compile_vpi_lookup(const char*label);
/* /*
* A code statement is a label, an opcode and up to 3 operands. There * A code statement is a label, an opcode and up to 3 operands. There
* are a few lexical types that the parser recognizes of the operands, * are a few lexical types that the parser recognizes of the operands,
@ -108,6 +111,9 @@ extern void compile_dump(FILE*fd);
/* /*
* $Log: compile.h,v $ * $Log: compile.h,v $
* Revision 1.7 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*
* Revision 1.6 2001/03/20 06:16:24 steve * Revision 1.6 2001/03/20 06:16:24 steve
* Add support for variable vectors. * Add support for variable vectors.
* *

50
vvp/examples/hello2.vvp Normal file
View File

@ -0,0 +1,50 @@
; 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
; This example slightly extends the hello.vvp example by ading the
; set and display of a reg variable. The Verilog source that would
; make this might be:
;
; module main;
; reg [3:0] value1;
; initial begin
; value1 = 1;
; $display("value = %b", value1);
; end
; endmodule
;
; Notice that the var "value1" is placed into the "main" scope simply
; by having main current when the .var statement is compiled. And also
; notice that the Vmain.value1 label is automatically converted to a
; vpiHandle by the compiler when the %vpi_call statement is compiled.
Smain .scope "main";
Vmain.value1 .var "value1", 3, 0;
T00 %set Vmain.value1[0], 1;
%set Vmain.value1[1], 0;
%set Vmain.value1[2], 0;
%set Vmain.value1[3], 0;
%vpi_call "$display", "value = %b", Vmain.value1;
%end;
.thread T00;

View File

@ -42,8 +42,9 @@ register that contains the bit value to assign.
* %vpi_call <name> [, ...] * %vpi_call <name> [, ...]
This instruction makes a call to a system task or function that was This instruction makes a call to a system task or function that was
declared using VPI. The name is given in the source as a string. It is declared using VPI. The operands are compiled down to a vpiHandle for
not yet defined how arguments are to be passed. the call. The instruction contains only the vpiHandle for the
call. See the vpi.txt file for more on system task/function calls.
* %waitfor <functor-label> * %waitfor <functor-label>

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: parse.y,v 1.9 2001/03/20 06:16:24 steve Exp $" #ident "$Id: parse.y,v 1.10 2001/03/21 05:13:03 steve Exp $"
#endif #endif
# include "parse_misc.h" # include "parse_misc.h"
@ -188,7 +188,12 @@ operand
/* The argument_list is a list of vpiHandle objects that can be /* The argument_list is a list of vpiHandle objects that can be
passed to a %vpi_call statement (and hence built into a passed to a %vpi_call statement (and hence built into a
vpiCallSysTask handle). We build up an arbitrary sized list with vpiCallSysTask handle). We build up an arbitrary sized list with
the struct argv_s type. */ the struct argv_s type.
Each argument of the call is represented as a vpiHandle
object. If the argument is a symbol, it is located in the sym_vpi
symbol table. if it is someother supported object, the necessary
vpiHandle object is created to support it. */
argument_opt argument_opt
: ',' argument_list : ',' argument_list
@ -217,6 +222,10 @@ argument_list
argument argument
: T_STRING : T_STRING
{ $$ = vpip_make_string_const($1); } { $$ = vpip_make_string_const($1); }
| T_SYMBOL
{ $$ = compile_vpi_lookup($1);
free($1);
}
; ;
@ -265,6 +274,9 @@ int compile_design(const char*path)
/* /*
* $Log: parse.y,v $ * $Log: parse.y,v $
* Revision 1.10 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*
* Revision 1.9 2001/03/20 06:16:24 steve * Revision 1.9 2001/03/20 06:16:24 steve
* Add support for variable vectors. * Add support for variable vectors.
* *

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: vpi_priv.h,v 1.4 2001/03/20 06:16:24 steve Exp $" #ident "$Id: vpi_priv.h,v 1.5 2001/03/21 05:13:03 steve Exp $"
#endif #endif
# include "vpi_user.h" # include "vpi_user.h"
@ -177,11 +177,12 @@ extern void vpip_execute_vpi_call(vpiHandle obj);
* These are functions used by the compiler to prepare for compilation * These are functions used by the compiler to prepare for compilation
* and to finish compilation in preparation for execution. * and to finish compilation in preparation for execution.
*/ */
extern void scope_init(void);
extern void scope_cleanup(void);
/* /*
* $Log: vpi_priv.h,v $ * $Log: vpi_priv.h,v $
* Revision 1.5 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*
* Revision 1.4 2001/03/20 06:16:24 steve * Revision 1.4 2001/03/20 06:16:24 steve
* Add support for variable vectors. * Add support for variable vectors.
* *

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: vpi_scope.cc,v 1.1 2001/03/18 00:37:55 steve Exp $" #ident "$Id: vpi_scope.cc,v 1.2 2001/03/21 05:13:03 steve Exp $"
#endif #endif
# include "compile.h" # include "compile.h"
@ -26,7 +26,6 @@
# include <malloc.h> # include <malloc.h>
# include <assert.h> # include <assert.h>
static symbol_table_t scope_table = 0;
static struct __vpiScope*current_scope = 0; static struct __vpiScope*current_scope = 0;
static void attach_to_scope_(struct __vpiScope*scope, vpiHandle obj) static void attach_to_scope_(struct __vpiScope*scope, vpiHandle obj)
@ -60,14 +59,12 @@ void compile_scope_decl(char*label, char*name, char*parent)
current_scope = scope; current_scope = scope;
symbol_value_t val; compile_vpi_symbol(label, &scope->base);
val.ptr = scope;
sym_set_value(scope_table, label, val);
free(label); free(label);
if (parent) { if (parent) {
val = sym_get_value(scope_table, parent); vpiHandle obj = compile_vpi_lookup(parent);
struct __vpiScope*sp = (struct __vpiScope*) val.ptr; struct __vpiScope*sp = (struct __vpiScope*) obj;
attach_to_scope_(sp, &scope->base); attach_to_scope_(sp, &scope->base);
free(parent); free(parent);
} }
@ -75,8 +72,8 @@ void compile_scope_decl(char*label, char*name, char*parent)
void compile_scope_recall(char*symbol) void compile_scope_recall(char*symbol)
{ {
symbol_value_t val = sym_get_value(scope_table, symbol); vpiHandle obj = compile_vpi_lookup(symbol);
current_scope = (struct __vpiScope*)val.ptr; current_scope = (struct __vpiScope*)obj;
free(symbol); free(symbol);
} }
@ -90,18 +87,12 @@ void vpip_attach_to_current_scope(vpiHandle obj)
attach_to_scope_(current_scope, obj); attach_to_scope_(current_scope, obj);
} }
void scope_init(void)
{
scope_table = new_symbol_table();
}
void scope_cleanup(void)
{
}
/* /*
* $Log: vpi_scope.cc,v $ * $Log: vpi_scope.cc,v $
* Revision 1.2 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*
* Revision 1.1 2001/03/18 00:37:55 steve * Revision 1.1 2001/03/18 00:37:55 steve
* Add support for vpi scopes. * Add support for vpi scopes.
* *

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: vpi_signal.cc,v 1.1 2001/03/20 06:16:24 steve Exp $" #ident "$Id: vpi_signal.cc,v 1.2 2001/03/21 05:13:03 steve Exp $"
#endif #endif
/* /*
@ -26,6 +26,7 @@
*/ */
# include "vpi_priv.h" # include "vpi_priv.h"
# include "functor.h"
# include <malloc.h> # include <malloc.h>
# include <assert.h> # include <assert.h>
@ -71,6 +72,8 @@ static char* signal_get_str(int code, vpiHandle ref)
return 0; return 0;
} }
static char buf[4096];
/* /*
* The get_value method reads the values of the functors and returns * The get_value method reads the values of the functors and returns
* the vector to the caller. This causes no side-effect, and reads the * the vector to the caller. This causes no side-effect, and reads the
@ -78,13 +81,33 @@ static char* signal_get_str(int code, vpiHandle ref)
*/ */
static void signal_get_value(vpiHandle ref, s_vpi_value*vp) static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
{ {
static const char bit_char[4] = { '0', '1', 'x', 'z' };
assert((ref->vpi_type->type_code==vpiNet) assert((ref->vpi_type->type_code==vpiNet)
|| (ref->vpi_type->type_code==vpiReg)); || (ref->vpi_type->type_code==vpiReg));
struct __vpiSignal*rfp = (struct __vpiSignal*)ref; struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
/* XXXX Not implemented yet. */ unsigned wid = (rfp->msb >= rfp->lsb)
assert(0); ? (rfp->msb - rfp->lsb + 1)
: (rfp->lsb - rfp->msb + 1);
switch (vp->format) {
case vpiBinStrVal:
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx);
functor_t fp = functor_index(fptr);
buf[wid-idx-1] = bit_char[fp->oval&3];
}
buf[wid] = 0;
vp->value.str = buf;
break;
default:
/* XXXX Not implemented yet. */
assert(0);
}
} }
/* /*
@ -140,6 +163,9 @@ vpiHandle vpip_make_reg(char*name, int msb, int lsb, vvp_ipoint_t base)
/* /*
* $Log: vpi_signal.cc,v $ * $Log: vpi_signal.cc,v $
* Revision 1.2 2001/03/21 05:13:03 steve
* Allow var objects as vpiHandle arguments to %vpi_call.
*
* Revision 1.1 2001/03/20 06:16:24 steve * Revision 1.1 2001/03/20 06:16:24 steve
* Add support for variable vectors. * Add support for variable vectors.
* *