Put number constants into a static table.

This commit is contained in:
steve 1999-11-06 16:00:17 +00:00
parent 282c58040b
commit c688d95cb8
5 changed files with 122 additions and 29 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: t-vvm.cc,v 1.71 1999/11/01 02:07:41 steve Exp $"
#ident "$Id: t-vvm.cc,v 1.72 1999/11/06 16:00:17 steve Exp $"
#endif
# include <iostream>
@ -30,6 +30,13 @@
# include "netlist.h"
# include "target.h"
// Comparison for use in sorting algorithms.
struct less_verinum {
bool operator() (const verinum&left, const verinum&right)
{ return left.is_before(right); }
};
static string make_temp()
{
static unsigned counter = 0;
@ -115,6 +122,9 @@ class target_vvm : public target_t {
// handle name mapped by this.
map<string,unsigned>string_constants;
unsigned string_counter;
map<verinum,unsigned,less_verinum>number_constants;
unsigned number_counter;
};
@ -498,33 +508,40 @@ void vvm_parm_rval::expr_const(const NetEConst*expr)
return;
}
string tname = make_temp();
tgt_->defn << " vvm_bitset_t<" <<
expr->expr_width() << "> " << tname << ";" << endl;
for (unsigned idx = 0 ; idx < expr->expr_width() ; idx += 1) {
tgt_->defn << " " << tname << "[" << idx << "] = ";
switch (expr->value().get(idx)) {
case verinum::V0:
tgt_->defn << "V0";
break;
case verinum::V1:
tgt_->defn << "V1";
break;
case verinum::Vx:
tgt_->defn << "Vx";
break;
case verinum::Vz:
tgt_->defn << "Vz";
break;
unsigned&res = tgt_->number_constants[expr->value()];
if (res == 0) {
res = tgt_->number_counter ++;
unsigned width = expr->expr_width();
tgt_->init_code << " { vpip_bit_t*bits = new vpip_bit_t["
<< width << "];" << endl;
for (unsigned idx = 0 ; idx < width ; idx += 1) {
tgt_->init_code << " bits[" << idx << "] = ";
switch(expr->value().get(idx)) {
case verinum::V0:
tgt_->init_code << "V0;" << endl;
break;
case verinum::V1:
tgt_->init_code << "V1;" << endl;
break;
case verinum::Vx:
tgt_->init_code << "Vx;" << endl;
break;
case verinum::Vz:
tgt_->init_code << "Vz;" << endl;
break;
}
}
tgt_->defn << ";" << endl;
tgt_->init_code << " vpip_make_number_const("
"&number_table[" << res << "], bits, " << width <<
");" << endl;
tgt_->init_code << " }" << endl;
}
result = make_temp();
tgt_->defn << " struct __vpiHandle " << result << ";" << endl;
tgt_->defn << " vvm_make_vpi_parm(&" << result << ", &"
<< tname << ");" << endl;
result = "&" + result;
ostrstream tmp;
tmp << "&number_table[" << res << "].base" << ends;
result = tmp.str();
return;
}
void vvm_parm_rval::expr_ident(const NetEIdent*expr)
@ -573,8 +590,10 @@ void target_vvm::start_design(ostream&os, const Design*mod)
process_counter = 0;
string_counter = 1;
number_counter = 1;
os << "static struct __vpiStringConst string_table[];" << endl;
os << "static struct __vpiNumberConst number_table[];" << endl;
init_code << "static void design_init(vvm_simulation&sim)" << endl;
init_code << "{" << endl;
@ -588,6 +607,8 @@ void target_vvm::end_design(ostream&os, const Design*mod)
{
os << "static struct __vpiStringConst string_table[" <<
string_counter+1 << "];" << endl;
os << "static struct __vpiNumberConst number_table[" <<
number_counter+1 << "];" << endl;
defn.close();
os << "// **** Definition code" << endl;
@ -1818,6 +1839,9 @@ extern const struct target tgt_vvm = {
};
/*
* $Log: t-vvm.cc,v $
* Revision 1.72 1999/11/06 16:00:17 steve
* Put number constants into a static table.
*
* Revision 1.71 1999/11/01 02:07:41 steve
* Add the synth functor to do generic synthesis
* and add the LPM_FF device to handle rows of

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: verinum.cc,v 1.11 1999/10/22 23:57:53 steve Exp $"
#ident "$Id: verinum.cc,v 1.12 1999/11/06 16:00:17 steve Exp $"
#endif
# include "verinum.h"
@ -213,6 +213,18 @@ string verinum::as_string() const
return result;
}
bool verinum::is_before(const verinum&that) const
{
if (that.nbits_ > nbits_) return true;
if (that.nbits_ < nbits_) return false;
for (unsigned idx = nbits_ ; idx > 0 ; idx -= 1) {
if (bits_[idx-1] < that.bits_[idx-1]) return true;
if (bits_[idx-1] > that.bits_[idx-1]) return false;
}
return false;
}
bool verinum::is_defined() const
{
for (unsigned idx = 0 ; idx < nbits_ ; idx += 1) {
@ -455,6 +467,9 @@ verinum operator - (const verinum&left, const verinum&r)
/*
* $Log: verinum.cc,v $
* Revision 1.12 1999/11/06 16:00:17 steve
* Put number constants into a static table.
*
* Revision 1.11 1999/10/22 23:57:53 steve
* do the <= in bits, not numbers.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: verinum.h,v 1.7 1999/10/22 23:57:53 steve Exp $"
#ident "$Id: verinum.h,v 1.8 1999/11/06 16:00:17 steve Exp $"
#endif
# include <string>
@ -63,6 +63,9 @@ class verinum {
// an ascii description instead of a number value.
bool is_string() const { return string_flag_; }
// Comparison for use in sorting algorithms.
bool is_before(const verinum&that) const;
// Individual bits can be accessed with the get and set
// methods.
V get(unsigned idx) const;
@ -97,6 +100,9 @@ extern verinum operator - (const verinum&left, const verinum&right);
/*
* $Log: verinum.h,v $
* Revision 1.8 1999/11/06 16:00:17 steve
* Put number constants into a static table.
*
* Revision 1.7 1999/10/22 23:57:53 steve
* do the <= in bits, not numbers.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_const.c,v 1.1 1999/10/28 00:47:25 steve Exp $"
#ident "$Id: vpi_const.c,v 1.2 1999/11/06 16:00:18 steve Exp $"
#endif
# include "vpi_priv.h"
@ -42,6 +42,19 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
}
}
static void number_value(vpiHandle ref, p_vpi_value vp)
{
struct __vpiStringConst*rfp = (struct __vpiStringConst*)ref;
assert(ref->vpi_type->type_code == vpiConstant);
switch (vp->format) {
default:
vp->format = vpiSuppressVal;
break;
}
}
static const struct __vpirt vpip_string_rt = {
vpiConstant,
0,
@ -51,6 +64,15 @@ static const struct __vpirt vpip_string_rt = {
0
};
static const struct __vpirt vpip_number_rt = {
vpiConstant,
0,
0,
number_value,
0,
0
};
vpiHandle vpip_make_string_const(struct __vpiStringConst*ref, const char*val)
{
ref->base.vpi_type = &vpip_string_rt;
@ -58,8 +80,21 @@ vpiHandle vpip_make_string_const(struct __vpiStringConst*ref, const char*val)
return &(ref->base);
}
vpiHandle vpip_make_number_const(struct __vpiNumberConst*ref,
const enum vpip_bit_t*bits,
unsigned nbits)
{
ref->base.vpi_type = &vpip_number_rt;
ref->bits = bits;
ref->nbits = nbits;
return &(ref->base);
}
/*
* $Log: vpi_const.c,v $
* Revision 1.2 1999/11/06 16:00:18 steve
* Put number constants into a static table.
*
* Revision 1.1 1999/10/28 00:47:25 steve
* Rewrite vvm VPI support to make objects more
* persistent, rewrite the simulation scheduler

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.3 1999/10/29 03:37:22 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.4 1999/11/06 16:00:18 steve Exp $"
#endif
/*
@ -150,6 +150,13 @@ struct __vpiStringConst {
const char*value;
};
struct __vpiNumberConst {
struct __vpiHandle base;
enum vpip_bit_t*bits;
unsigned nbits;
};
/*
* These are methods to initialize specific handle types. Except for
* vpip_make_iterator, all the vpi_make_* functions expect the caller
@ -160,6 +167,9 @@ extern vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args);
extern vpiHandle vpip_make_net(struct __vpiSignal*ref, const char*name);
extern vpiHandle vpip_make_string_const(struct __vpiStringConst*ref,
const char*val);
extern vpiHandle vpip_make_number_const(struct __vpiNumberConst*ref,
const enum vpip_bit_t*bits,
unsigned nbits);
extern vpiHandle vpip_make_reg(struct __vpiSignal*ref, const char*name);
extern vpiHandle vpip_make_time_var(struct __vpiTimeVar*ref,
const char*val);
@ -226,6 +236,9 @@ extern int vpip_finished();
/*
* $Log: vpi_priv.h,v $
* Revision 1.4 1999/11/06 16:00:18 steve
* Put number constants into a static table.
*
* Revision 1.3 1999/10/29 03:37:22 steve
* Support vpiValueChance callbacks.
*