More precise handling of verinum bit lengths.
This commit is contained in:
parent
295306aad5
commit
c677afd8e3
16
lexor.lex
16
lexor.lex
|
|
@ -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.13 1999/05/08 20:19:20 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.14 1999/05/13 04:02:09 steve Exp $"
|
||||
#endif
|
||||
|
||||
//# define YYSTYPE lexval
|
||||
|
|
@ -158,7 +158,7 @@ static verinum*make_unsized_hex(const char*txt);
|
|||
bits[idx] = (value&1) ? verinum::V1 : verinum::V0;
|
||||
}
|
||||
|
||||
yylval.number = new verinum(bits, nbits);
|
||||
yylval.number = new verinum(bits, nbits, false);
|
||||
delete[]bits;
|
||||
return NUMBER; }
|
||||
|
||||
|
|
@ -312,7 +312,7 @@ static int check_identifier(const char*name)
|
|||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
static verinum*make_binary_with_size(unsigned size, const char*ptr)
|
||||
static verinum*make_binary_with_size(unsigned size, bool fixed, const char*ptr)
|
||||
{
|
||||
assert(tolower(*ptr) == 'b');
|
||||
verinum::V*bits = new verinum::V[size];
|
||||
|
|
@ -364,7 +364,7 @@ static verinum*make_binary_with_size(unsigned size, const char*ptr)
|
|||
}
|
||||
}
|
||||
|
||||
return new verinum(bits, size);
|
||||
return new verinum(bits, size, fixed);
|
||||
}
|
||||
|
||||
static verinum*make_sized_binary(const char*txt)
|
||||
|
|
@ -375,14 +375,14 @@ static verinum*make_sized_binary(const char*txt)
|
|||
ptr += 1;
|
||||
assert(tolower(*ptr) == 'b');
|
||||
|
||||
return make_binary_with_size(size, ptr);
|
||||
return make_binary_with_size(size, true, ptr);
|
||||
}
|
||||
|
||||
static verinum*make_unsized_binary(const char*txt)
|
||||
{
|
||||
assert(*txt == '\'');
|
||||
txt += 1;
|
||||
return make_binary_with_size(64, txt);
|
||||
return make_binary_with_size(64, false, txt);
|
||||
}
|
||||
|
||||
static verinum*make_sized_octal(const char*txt)
|
||||
|
|
@ -433,7 +433,7 @@ static verinum*make_sized_octal(const char*txt)
|
|||
bits[idx++] = verinum::V0;
|
||||
}
|
||||
|
||||
return new verinum(bits, size);
|
||||
return new verinum(bits, size, true);
|
||||
}
|
||||
|
||||
static verinum*make_unsized_octal(const char*txt)
|
||||
|
|
@ -507,7 +507,7 @@ static verinum*make_sized_hex(const char*txt)
|
|||
bits[idx++] = verinum::V0;
|
||||
}
|
||||
|
||||
return new verinum(bits, size);
|
||||
return new verinum(bits, size, true);
|
||||
}
|
||||
|
||||
static verinum*make_unsized_hex(const char*txt)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: netlist.cc,v 1.24 1999/05/12 04:03:19 steve Exp $"
|
||||
#ident "$Id: netlist.cc,v 1.25 1999/05/13 04:02:09 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <cassert>
|
||||
|
|
@ -375,6 +375,8 @@ void NetCase::set_case(unsigned idx, NetExpr*e, NetProc*p)
|
|||
assert(idx < nitems_);
|
||||
items_[idx].guard = e;
|
||||
items_[idx].statement = p;
|
||||
if (items_[idx].guard.ref())
|
||||
items_[idx].guard.ref()->set_width(expr_.ref()->expr_width());
|
||||
}
|
||||
|
||||
NetTask::~NetTask()
|
||||
|
|
@ -506,6 +508,7 @@ NetEConst::~NetEConst()
|
|||
void NetEConst::set_width(unsigned w)
|
||||
{
|
||||
assert(w <= value_.len());
|
||||
value_ = verinum(value_, w);
|
||||
expr_width(w);
|
||||
}
|
||||
|
||||
|
|
@ -1051,6 +1054,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
|
|||
|
||||
/*
|
||||
* $Log: netlist.cc,v $
|
||||
* Revision 1.25 1999/05/13 04:02:09 steve
|
||||
* More precise handling of verinum bit lengths.
|
||||
*
|
||||
* Revision 1.24 1999/05/12 04:03:19 steve
|
||||
* emit NetAssignMem objects in vvm target.
|
||||
*
|
||||
|
|
|
|||
83
verinum.cc
83
verinum.cc
|
|
@ -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.7 1999/05/09 01:38:33 steve Exp $"
|
||||
#ident "$Id: verinum.cc,v 1.8 1999/05/13 04:02:09 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "verinum.h"
|
||||
|
|
@ -25,12 +25,12 @@
|
|||
# include <cassert>
|
||||
|
||||
verinum::verinum()
|
||||
: bits_(0), nbits_(0), string_flag_(false)
|
||||
: bits_(0), nbits_(0), has_len_(false), string_flag_(false)
|
||||
{
|
||||
}
|
||||
|
||||
verinum::verinum(const V*bits, unsigned nbits)
|
||||
: string_flag_(false)
|
||||
verinum::verinum(const V*bits, unsigned nbits, bool has_len)
|
||||
: has_len_(has_len), string_flag_(false)
|
||||
{
|
||||
nbits_ = nbits;
|
||||
bits_ = new V [nbits];
|
||||
|
|
@ -40,7 +40,7 @@ verinum::verinum(const V*bits, unsigned nbits)
|
|||
}
|
||||
|
||||
verinum::verinum(const string&str)
|
||||
: string_flag_(true)
|
||||
: has_len_(true), string_flag_(true)
|
||||
{
|
||||
nbits_ = str.length() * 8;
|
||||
bits_ = new V [nbits_];
|
||||
|
|
@ -61,7 +61,7 @@ verinum::verinum(const string&str)
|
|||
}
|
||||
|
||||
verinum::verinum(verinum::V val, unsigned n)
|
||||
: string_flag_(false)
|
||||
: has_len_(true), string_flag_(false)
|
||||
{
|
||||
nbits_ = n;
|
||||
bits_ = new V[nbits_];
|
||||
|
|
@ -70,7 +70,7 @@ verinum::verinum(verinum::V val, unsigned n)
|
|||
}
|
||||
|
||||
verinum::verinum(unsigned long val, unsigned n)
|
||||
: string_flag_(false)
|
||||
: has_len_(true), string_flag_(false)
|
||||
{
|
||||
nbits_ = n;
|
||||
bits_ = new V[nbits_];
|
||||
|
|
@ -85,6 +85,18 @@ verinum::verinum(const verinum&that)
|
|||
string_flag_ = that.string_flag_;
|
||||
nbits_ = that.nbits_;
|
||||
bits_ = new V[nbits_];
|
||||
has_len_ = that.has_len_;
|
||||
for (unsigned idx = 0 ; idx < nbits_ ; idx += 1)
|
||||
bits_[idx] = that.bits_[idx];
|
||||
}
|
||||
|
||||
verinum::verinum(const verinum&that, unsigned nbits)
|
||||
{
|
||||
assert(nbits <= that.nbits_);
|
||||
string_flag_ = false;
|
||||
nbits_ = nbits;
|
||||
bits_ = new V[nbits_];
|
||||
has_len_ = true;
|
||||
for (unsigned idx = 0 ; idx < nbits_ ; idx += 1)
|
||||
bits_[idx] = that.bits_[idx];
|
||||
}
|
||||
|
|
@ -94,6 +106,20 @@ verinum::~verinum()
|
|||
delete[]bits_;
|
||||
}
|
||||
|
||||
verinum& verinum::operator= (const verinum&that)
|
||||
{
|
||||
if (this == &that) return *this;
|
||||
delete[]bits_;
|
||||
nbits_ = that.nbits_;
|
||||
bits_ = new V[that.nbits_];
|
||||
for (unsigned idx = 0 ; idx < nbits_ ; idx += 1)
|
||||
bits_[idx] = that.bits_[idx];
|
||||
|
||||
has_len_ = that.has_len_;
|
||||
string_flag_ = that.string_flag_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
verinum::V verinum::get(unsigned idx) const
|
||||
{
|
||||
return bits_[idx];
|
||||
|
|
@ -182,6 +208,15 @@ string verinum::as_string() const
|
|||
return result;
|
||||
}
|
||||
|
||||
bool verinum::is_defined() const
|
||||
{
|
||||
for (unsigned idx = 0 ; idx < nbits_ ; idx += 1) {
|
||||
if (bits_[idx] == Vx) return false;
|
||||
if (bits_[idx] == Vz) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ostream& operator<< (ostream&o, verinum::V v)
|
||||
{
|
||||
switch (v) {
|
||||
|
|
@ -201,9 +236,38 @@ ostream& operator<< (ostream&o, verinum::V v)
|
|||
return o;
|
||||
}
|
||||
|
||||
/*
|
||||
* This operator is used by various dumpers to write the verilog
|
||||
* number in a Verilog format.
|
||||
*/
|
||||
ostream& operator<< (ostream&o, const verinum&v)
|
||||
{
|
||||
o << v.len() << "'b";
|
||||
/* If the verinum number has a fixed length, dump all the bits
|
||||
literally. This is how we express the fixed length in the
|
||||
output. */
|
||||
if (v.has_len()) {
|
||||
o << v.len() << "'b";
|
||||
if (v.len() == 0) {
|
||||
o << "0";
|
||||
return o;
|
||||
}
|
||||
|
||||
for (unsigned idx = v.len() ; idx > 0 ; idx -= 1)
|
||||
o << v[idx-1];
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/* If the number is fully defined (no x or z) then print it
|
||||
out as a decimal number. */
|
||||
if (v.is_defined()) {
|
||||
o << "'d" << v.as_ulong();
|
||||
return o;
|
||||
}
|
||||
|
||||
/* Oh, well. Print the minimum to get the value properly
|
||||
displayed. */
|
||||
o << "'b";
|
||||
|
||||
if (v.len() == 0) {
|
||||
o << "0";
|
||||
|
|
@ -241,6 +305,9 @@ bool operator == (const verinum&left, const verinum&right)
|
|||
|
||||
/*
|
||||
* $Log: verinum.cc,v $
|
||||
* Revision 1.8 1999/05/13 04:02:09 steve
|
||||
* More precise handling of verinum bit lengths.
|
||||
*
|
||||
* Revision 1.7 1999/05/09 01:38:33 steve
|
||||
* Add implementation of integer to verunum constructor.
|
||||
*
|
||||
|
|
|
|||
30
verinum.h
30
verinum.h
|
|
@ -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.4 1998/12/20 02:05:41 steve Exp $"
|
||||
#ident "$Id: verinum.h,v 1.5 1999/05/13 04:02:09 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <string>
|
||||
|
|
@ -37,15 +37,32 @@ class verinum {
|
|||
|
||||
verinum();
|
||||
verinum(const string&str);
|
||||
verinum(const V*v, unsigned nbits);
|
||||
verinum(const V*v, unsigned nbits, bool has_len =true);
|
||||
verinum(V, unsigned nbits =1);
|
||||
verinum(unsigned long val, unsigned bits);
|
||||
verinum(const verinum&);
|
||||
|
||||
// Copy only the specified number of bits from the
|
||||
// source. Also mark this number as has_len.
|
||||
verinum(const verinum&, unsigned bits);
|
||||
|
||||
~verinum();
|
||||
verinum& operator= (const verinum&);
|
||||
|
||||
// Number of significant bits in this number.
|
||||
unsigned len() const { return nbits_; }
|
||||
|
||||
// A number "has a length" if the length was specified fixed
|
||||
// in some way.
|
||||
bool has_len() const { return has_len_; }
|
||||
|
||||
// A number is "defined" if there are no x or z bits in its value.
|
||||
bool is_defined() const;
|
||||
|
||||
// A number is "a string" if its value came directly from
|
||||
// an ascii description instead of a number value.
|
||||
bool is_string() const { return string_flag_; }
|
||||
|
||||
// Individual bits can be accessed with the get and set
|
||||
// methods.
|
||||
V get(unsigned idx) const;
|
||||
|
|
@ -58,18 +75,14 @@ class verinum {
|
|||
signed long as_long() const;
|
||||
string as_string() const;
|
||||
|
||||
bool is_string() const { return string_flag_; }
|
||||
|
||||
private:
|
||||
V* bits_;
|
||||
unsigned nbits_;
|
||||
bool has_len_;
|
||||
|
||||
// These are some convenience flags that help us do a better
|
||||
// job of pretty-printing values.
|
||||
bool string_flag_;
|
||||
|
||||
private: // not implemented
|
||||
verinum& operator= (const verinum&);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -81,6 +94,9 @@ extern bool operator == (const verinum&left, const verinum&right);
|
|||
|
||||
/*
|
||||
* $Log: verinum.h,v $
|
||||
* Revision 1.5 1999/05/13 04:02:09 steve
|
||||
* More precise handling of verinum bit lengths.
|
||||
*
|
||||
* Revision 1.4 1998/12/20 02:05:41 steve
|
||||
* Function to calculate wire initial value.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue