Create the vpiMemory handle type.

This commit is contained in:
steve 1999-11-10 02:52:24 +00:00
parent 02f8099aa7
commit 82f3f0f741
8 changed files with 195 additions and 36 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: elab_expr.cc,v 1.7 1999/10/18 00:02:21 steve Exp $" #ident "$Id: elab_expr.cc,v 1.8 1999/11/10 02:52:24 steve Exp $"
#endif #endif
@ -271,7 +271,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, const string&path) const
assert(lsb_ == 0); assert(lsb_ == 0);
assert(idx_ == 0); assert(idx_ == 0);
NetExpr*i = msb_->elaborate_expr(des, path); NetExpr*i = msb_->elaborate_expr(des, path);
if (i == 0) { if (msb_ && i == 0) {
cerr << get_line() << ": error: Unable to exaborate " cerr << get_line() << ": error: Unable to exaborate "
"index expression `" << *msb_ << "'" << endl; "index expression `" << *msb_ << "'" << endl;
des->errors += 1; des->errors += 1;
@ -324,6 +324,9 @@ NetExpr*PETernary::elaborate_expr(Design*des, const string&path) const
/* /*
* $Log: elab_expr.cc,v $ * $Log: elab_expr.cc,v $
* Revision 1.8 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
* Revision 1.7 1999/10/18 00:02:21 steve * Revision 1.7 1999/10/18 00:02:21 steve
* Catch unindexed memory reference. * Catch unindexed memory reference.
* *

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: elaborate.cc,v 1.122 1999/11/05 21:45:19 steve Exp $" #ident "$Id: elaborate.cc,v 1.123 1999/11/10 02:52:24 steve Exp $"
#endif #endif
/* /*
@ -1671,6 +1671,11 @@ NetProc* PCallTask::elaborate(Design*des, const string&path) const
/* /*
* A call to a system task involves elaborating all the parameters, * A call to a system task involves elaborating all the parameters,
* then passing the list to the NetSTask object. * then passing the list to the NetSTask object.
*XXXX
* There is a single special in the call to a system task. Normally,
* an expression cannot take an unindexed memory. However, it is
* possible to take a system task parameter a memory if the expression
* is trivial.
*/ */
NetProc* PCallTask::elaborate_sys(Design*des, const string&path) const NetProc* PCallTask::elaborate_sys(Design*des, const string&path) const
{ {
@ -1678,6 +1683,7 @@ NetProc* PCallTask::elaborate_sys(Design*des, const string&path) const
for (unsigned idx = 0 ; idx < nparms() ; idx += 1) { for (unsigned idx = 0 ; idx < nparms() ; idx += 1) {
PExpr*ex = parm(idx); PExpr*ex = parm(idx);
eparms[idx] = ex? ex->elaborate_expr(des, path) : 0; eparms[idx] = ex? ex->elaborate_expr(des, path) : 0;
} }
@ -2329,6 +2335,9 @@ Design* elaborate(const map<string,Module*>&modules,
/* /*
* $Log: elaborate.cc,v $ * $Log: elaborate.cc,v $
* Revision 1.123 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
* Revision 1.122 1999/11/05 21:45:19 steve * Revision 1.122 1999/11/05 21:45:19 steve
* Fix NetConst being set to zero width, and clean * Fix NetConst being set to zero width, and clean
* up elaborate_set_cmp_ for NetEBinary. * up elaborate_set_cmp_ for NetEBinary.

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: t-vvm.cc,v 1.72 1999/11/06 16:00:17 steve Exp $" #ident "$Id: t-vvm.cc,v 1.73 1999/11/10 02:52:24 steve Exp $"
#endif #endif
# include <iostream> # include <iostream>
@ -154,15 +154,7 @@ class vvm_proc_rval : public expr_scan_t {
virtual void expr_const(const NetEConst*); virtual void expr_const(const NetEConst*);
virtual void expr_concat(const NetEConcat*); virtual void expr_concat(const NetEConcat*);
virtual void expr_ident(const NetEIdent*); virtual void expr_ident(const NetEIdent*);
virtual void expr_memory(const NetEMemory*mem) virtual void expr_memory(const NetEMemory*mem);
{
mem->index()->expr_scan(this);
string idx = make_temp();
os_ << setw(indent_) << "" << "const unsigned " <<
idx << " = " << result << ".as_unsigned();" <<
endl;
result = mangle(mem->name()) + "[" + idx + "]";
}
virtual void expr_signal(const NetESignal*); virtual void expr_signal(const NetESignal*);
virtual void expr_subsignal(const NetESubSignal*sig); virtual void expr_subsignal(const NetESubSignal*sig);
virtual void expr_ternary(const NetETernary*); virtual void expr_ternary(const NetETernary*);
@ -243,6 +235,13 @@ void vvm_proc_rval::expr_ident(const NetEIdent*expr)
result = mangle(expr->name()); result = mangle(expr->name());
} }
void vvm_proc_rval::expr_memory(const NetEMemory*mem)
{
const string mname = mangle(mem->name());
mem->index()->expr_scan(this);
result = mname + ".get_word(" + result + ".as_unsigned())";
}
void vvm_proc_rval::expr_signal(const NetESignal*expr) void vvm_proc_rval::expr_signal(const NetESignal*expr)
{ {
result = mangle(expr->name()) + "_bits"; result = mangle(expr->name()) + "_bits";
@ -482,6 +481,7 @@ class vvm_parm_rval : public expr_scan_t {
private: private:
virtual void expr_const(const NetEConst*expr); virtual void expr_const(const NetEConst*expr);
virtual void expr_ident(const NetEIdent*); virtual void expr_ident(const NetEIdent*);
virtual void expr_memory(const NetEMemory*mem);
virtual void expr_signal(const NetESignal*); virtual void expr_signal(const NetESignal*);
private: private:
@ -553,6 +553,12 @@ void vvm_parm_rval::expr_ident(const NetEIdent*expr)
} }
} }
void vvm_parm_rval::expr_memory(const NetEMemory*mem)
{
assert(mem->index() == 0);
result = string("&") + mangle(mem->name()) + ".base";
}
void vvm_parm_rval::expr_signal(const NetESignal*expr) void vvm_parm_rval::expr_signal(const NetESignal*expr)
{ {
string res = string("&") + mangle(expr->name()) + ".base"; string res = string("&") + mangle(expr->name()) + ".base";
@ -717,9 +723,13 @@ void target_vvm::signal(ostream&os, const NetNet*sig)
void target_vvm::memory(ostream&os, const NetMemory*mem) void target_vvm::memory(ostream&os, const NetMemory*mem)
{ {
os << "static vvm_bitset_t<" << mem->width() << "> " << const string mname = mangle(mem->name());
mangle(mem->name()) << "[" << mem->count() << "]; " << os << "static vvm_memory_t<" << mem->width() << ", " <<
mem->count() << "> " << mname << ";"
" /* " << mem->name() << " */" << endl; " /* " << mem->name() << " */" << endl;
init_code << " vpip_make_memory(&" << mname << ", \"" <<
mem->name() << "\", " << mem->width() << ", " <<
mem->count() << ");" << endl;
} }
void target_vvm::task_def(ostream&os, const NetTaskDef*def) void target_vvm::task_def(ostream&os, const NetTaskDef*def)
@ -1352,9 +1362,8 @@ void target_vvm::proc_assign_mem(ostream&os, const NetAssignMem*amem)
defn << " /* " << amem->get_line() << " */" << endl; defn << " /* " << amem->get_line() << " */" << endl;
if (mem->width() == amem->rval()->expr_width()) { if (mem->width() == amem->rval()->expr_width()) {
defn << " " << mangle(mem->name()) defn << " " << mangle(mem->name()) << ".set_word(" <<
<< "[" << index << ".as_unsigned()] = " << rval << index << ".as_unsigned(), " << rval << ");" << endl;
";" << endl;
} else { } else {
assert(mem->width() <= amem->rval()->expr_width()); assert(mem->width() <= amem->rval()->expr_width());
@ -1365,9 +1374,8 @@ void target_vvm::proc_assign_mem(ostream&os, const NetAssignMem*amem)
defn << " " << tmp << "[" << idx << "] = " << defn << " " << tmp << "[" << idx << "] = " <<
rval << "[" << idx << "];" << endl; rval << "[" << idx << "];" << endl;
defn << " " << mangle(mem->name()) defn << " " << mangle(mem->name()) << ".set_word(" <<
<< "[" << index << ".as_unsigned()] = " << tmp << ";" index << ".as_unsigned(), " << tmp << ");" << endl;
<< endl;
} }
} }
@ -1839,6 +1847,9 @@ extern const struct target tgt_vvm = {
}; };
/* /*
* $Log: t-vvm.cc,v $ * $Log: t-vvm.cc,v $
* Revision 1.73 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
* Revision 1.72 1999/11/06 16:00:17 steve * Revision 1.72 1999/11/06 16:00:17 steve
* Put number constants into a static table. * Put number constants into a static table.
* *

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_user.h,v 1.6 1999/11/07 20:33:30 steve Exp $" #ident "$Id: vpi_user.h,v 1.7 1999/11/10 02:52:24 steve Exp $"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@ -96,6 +96,8 @@ typedef struct t_vpi_value {
/* OBJECT CODES */ /* OBJECT CODES */
#define vpiConstant 7 #define vpiConstant 7
#define vpiIterator 27 #define vpiIterator 27
#define vpiMemory 29
#define vpiMemoryWord 30
#define vpiNet 36 #define vpiNet 36
#define vpiReg 48 #define vpiReg 48
#define vpiSysTaskCall 57 #define vpiSysTaskCall 57
@ -205,6 +207,9 @@ extern void (*vlog_startup_routines[])();
/* /*
* $Log: vpi_user.h,v $ * $Log: vpi_user.h,v $
* Revision 1.7 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
* Revision 1.6 1999/11/07 20:33:30 steve * Revision 1.6 1999/11/07 20:33:30 steve
* Add VCD output and related system tasks. * Add VCD output and related system tasks.
* *

View File

@ -18,7 +18,7 @@
# 59 Temple Place - Suite 330 # 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA # Boston, MA 02111-1307, USA
# #
#ident "$Id: Makefile.in,v 1.10 1999/10/28 21:36:00 steve Exp $" #ident "$Id: Makefile.in,v 1.11 1999/11/10 02:52:24 steve Exp $"
# #
# #
SHELL = /bin/sh SHELL = /bin/sh
@ -62,7 +62,7 @@ O = vvm_bit.o vvm_calltf.o vvm_event.o vvm_pevent.o \
vvm_simulation.o vvm_thread.o vpip.o vvm_simulation.o vvm_thread.o vpip.o
P = vpi_callback.o \ P = vpi_callback.o \
vpi_const.o vpi_iter.o vpi_null.o \ vpi_const.o vpi_iter.o vpi_memory.o vpi_null.o \
vpi_priv.o vpi_signal.o vpi_simulation.o vpi_systask.o vpi_time.o vpi_priv.o vpi_signal.o vpi_simulation.o vpi_systask.o vpi_time.o
libvvm.a: $O libvvm.a: $O

91
vvm/vpi_memory.c Normal file
View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 1999 Picture Elements, Inc.
* Stephen Williams (steve@picturel.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. In order to redistribute the software in
* binary form, you will need a Picture Elements Binary Software
* License.
*
* 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
* ---
* You should also have recieved a copy of the Picture Elements
* Binary Software License offer along with the source. This offer
* allows you to obtain the right to redistribute the software in
* binary (compiled) form. If you have not received it, contact
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
*/
#if !defined(WINNT)
#ident "$Id: vpi_memory.c,v 1.1 1999/11/10 02:52:24 steve Exp $"
#endif
# include "vpi_priv.h"
# include <stdlib.h>
# include <assert.h>
static int memory_get(int code, vpiHandle ref)
{
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
assert(ref->vpi_type->type_code==vpiMemory);
switch (code) {
case vpiSize:
return rfp->size;
default:
return 0;
}
}
static char* memory_get_str(int code, vpiHandle ref)
{
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
assert(ref->vpi_type->type_code==vpiMemory);
switch (code) {
case vpiFullName:
return (char*)rfp->name;
}
return 0;
}
static const struct __vpirt vpip_memory_rt = {
vpiMemory,
memory_get,
memory_get_str,
0,
0,
0
};
vpiHandle vpip_make_memory(struct __vpiMemory*ref, const char*name,
unsigned wid, unsigned siz)
{
ref->base.vpi_type = &vpip_memory_rt;
ref->name = name;
ref->bits = calloc(wid*siz, sizeof(enum vpip_bit_t));
ref->width = wid;
ref->size = siz;
return &(ref->base);
}
/*
* $Log: vpi_memory.c,v $
* Revision 1.1 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
*/

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.5 1999/11/06 16:52:16 steve Exp $" #ident "$Id: vpi_priv.h,v 1.6 1999/11/10 02:52:24 steve Exp $"
#endif #endif
/* /*
@ -79,15 +79,6 @@ struct __vpiCallback {
struct __vpiCallback*next; struct __vpiCallback*next;
}; };
/*
* This type is occasionally useful. Really! And while we're at it,
* create a single instance of the null object. (This is all we need.)
*/
struct __vpiNull {
struct __vpiHandle base;
};
extern struct __vpiNull vpip_null;
/* /*
* The vpiHandle for an iterator has this structure. The definition of * The vpiHandle for an iterator has this structure. The definition of
* the methods lives in vpi_iter.c * the methods lives in vpi_iter.c
@ -100,6 +91,28 @@ struct __vpiIterator {
unsigned next; unsigned next;
}; };
/*
* Memory is an array of bits that is accessible in N-bit chunks, with
* N being the width of a word.
*/
struct __vpiMemory {
struct __vpiHandle base;
/* The signal has a name (this points to static memory.) */
const char*name;
enum vpip_bit_t*bits;
unsigned width;
unsigned size;
};
/*
* This type is occasionally useful. Really! And while we're at it,
* create a single instance of the null object. (This is all we need.)
*/
struct __vpiNull {
struct __vpiHandle base;
};
extern struct __vpiNull vpip_null;
/* /*
* This structure represents nets and registers. You can tell which by * This structure represents nets and registers. You can tell which by
* the type_code in the base. The bits member points to the actual * the type_code in the base. The bits member points to the actual
@ -173,6 +186,8 @@ extern vpiHandle vpip_make_string_const(struct __vpiStringConst*ref,
extern vpiHandle vpip_make_number_const(struct __vpiNumberConst*ref, extern vpiHandle vpip_make_number_const(struct __vpiNumberConst*ref,
const enum vpip_bit_t*bits, const enum vpip_bit_t*bits,
unsigned nbits); unsigned nbits);
extern vpiHandle vpip_make_memory(struct __vpiMemory*ref, const char*name,
unsigned width, unsigned size);
extern vpiHandle vpip_make_reg(struct __vpiSignal*ref, const char*name); extern vpiHandle vpip_make_reg(struct __vpiSignal*ref, const char*name);
extern vpiHandle vpip_make_time_var(struct __vpiTimeVar*ref, extern vpiHandle vpip_make_time_var(struct __vpiTimeVar*ref,
const char*val); const char*val);
@ -239,6 +254,9 @@ extern int vpip_finished();
/* /*
* $Log: vpi_priv.h,v $ * $Log: vpi_priv.h,v $
* Revision 1.6 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
* Revision 1.5 1999/11/06 16:52:16 steve * Revision 1.5 1999/11/06 16:52:16 steve
* complete value retrieval for number constants. * complete value retrieval for number constants.
* *

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: vvm.h,v 1.20 1999/11/01 02:07:41 steve Exp $" #ident "$Id: vvm.h,v 1.21 1999/11/10 02:52:24 steve Exp $"
#endif #endif
# include <vector> # include <vector>
@ -254,8 +254,30 @@ template <unsigned WIDTH> class vvm_signal_t : public __vpiSignal {
} }
}; };
template <unsigned WIDTH, unsigned SIZE>
class vvm_memory_t : public __vpiMemory {
public:
void set_word(unsigned addr, const vvm_bitset_t<WIDTH>&val)
{ unsigned base = WIDTH * addr;
for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
bits[base+idx] = val[idx];
}
vvm_bitset_t<WIDTH> get_word(unsigned addr) const
{ vvm_bitset_t<WIDTH> val;
unsigned base = WIDTH * addr;
for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
val[idx] = bits[base+idx];
return val;
}
};
/* /*
* $Log: vvm.h,v $ * $Log: vvm.h,v $
* Revision 1.21 1999/11/10 02:52:24 steve
* Create the vpiMemory handle type.
*
* Revision 1.20 1999/11/01 02:07:41 steve * Revision 1.20 1999/11/01 02:07:41 steve
* Add the synth functor to do generic synthesis * Add the synth functor to do generic synthesis
* and add the LPM_FF device to handle rows of * and add the LPM_FF device to handle rows of