move binary operators to derived classes.

This commit is contained in:
steve 1999-07-31 03:16:54 +00:00
parent bfff287386
commit d2f77defe6
3 changed files with 187 additions and 50 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: elaborate.cc,v 1.61 1999/07/28 03:46:57 steve Exp $"
#ident "$Id: elaborate.cc,v 1.62 1999/07/31 03:16:54 steve Exp $"
#endif
/*
@ -899,13 +899,36 @@ NetExpr* PEBinary::elaborate_expr(Design*des, const string&path) const
return 0;
}
NetEBinary*tmp = new NetEBinary(op_, lp, rp);
tmp->set_line(*this);
NetEBinary*tmp;
switch (op_) {
case 'e':
case 'n':
default:
tmp = new NetEBinary(op_, lp, rp);
tmp->set_line(*this);
break;
case '^':
case '&':
case '|':
tmp = new NetEBBits(op_, lp, rp);
tmp->set_line(*this);
break;
case '+':
case '-':
tmp = new NetEBAdd(op_, lp, rp);
tmp->set_line(*this);
break;
case 'e': /* == */
case 'E': /* === */
case 'n': /* != */
case 'N': /* !== */
case 'L': /* <= */
case 'G': /* >= */
case '<':
case '>':
tmp = new NetEBComp(op_, lp, rp);
tmp->set_line(*this);
flag = tmp->set_width(1);
if (flag == false) {
cerr << get_line() << ": expression bit width"
@ -913,9 +936,8 @@ NetExpr* PEBinary::elaborate_expr(Design*des, const string&path) const
des->errors += 1;
}
break;
default:
;
}
return tmp;
}
@ -1969,6 +1991,9 @@ Design* elaborate(const map<string,Module*>&modules,
/*
* $Log: elaborate.cc,v $
* Revision 1.62 1999/07/31 03:16:54 steve
* move binary operators to derived classes.
*
* Revision 1.61 1999/07/28 03:46:57 steve
* Handle no ports at all for tasks.
*

View File

@ -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.48 1999/07/24 02:11:20 steve Exp $"
#ident "$Id: netlist.cc,v 1.49 1999/07/31 03:16:54 steve Exp $"
#endif
# include <cassert>
@ -561,6 +561,89 @@ NetExpr* NetExpr::eval_tree()
return 0;
}
NetEBAdd::NetEBAdd(char op, NetExpr*l, NetExpr*r)
: NetEBinary(op, l, r)
{
}
NetEBAdd::~NetEBAdd()
{
}
/*
* The bitwise logical operators have operands the same size as the
* result. Anything else is a mess.
*/
bool NetEBAdd::set_width(unsigned w)
{
bool flag = true;
if (left_->expr_width() > right_->expr_width())
right_->set_width(left_->expr_width());
else
left_->set_width(right_->expr_width());
if (left_->expr_width() == w)
expr_width(w);
else if (left_->expr_width() == (w-1))
expr_width(w);
else
flag = false;
return flag;
}
NetEBBits::NetEBBits(char op, NetExpr*l, NetExpr*r)
: NetEBinary(op, l, r)
{
}
NetEBBits::~NetEBBits()
{
}
/*
* The bitwise logical operators have operands the same size as the
* result. Anything else is a mess.
*/
bool NetEBBits::set_width(unsigned w)
{
bool flag = true;
flag = left_->set_width(w) && flag;
flag = right_->set_width(w) && flag;
expr_width(w);
return flag;
}
NetEBComp::NetEBComp(char op, NetExpr*l, NetExpr*r)
: NetEBinary(op, l, r)
{
}
NetEBComp::~NetEBComp()
{
}
/*
* Comparison operators allow the subexpressions to have
* their own natural width. However, I do need to make
* sure that the subexpressions have the same width.
*/
bool NetEBComp::set_width(unsigned w)
{
bool flag = true;
assert(w == 1);
expr_width(w);
flag = left_->set_width(right_->expr_width());
if (!flag)
flag = right_->set_width(left_->expr_width());
return flag;
}
NetEBinary::NetEBinary(char op, NetExpr*l, NetExpr*r)
: op_(op), left_(l), right_(r)
{
@ -601,37 +684,17 @@ bool NetEBinary::set_width(unsigned w)
bool flag = true;
switch (op_) {
case 'a': // logical and (&&)
case 'o': // logical or (||)
assert(w == 1);
expr_width(w);
break;
/* Comparison operators allow the subexpressions to have
their own natural width. However, I do need to make
sure that the subexpressions have the same width. */
case 'E': /* === */
case 'e': /* == */
case 'N': /* !== */
case 'n': /* != */
case '<': /* < */
case '>': /* > */
assert(w == 1);
expr_width(w);
flag = left_->set_width(right_->expr_width());
if (!flag)
flag = right_->set_width(left_->expr_width());
break;
case 'l': // left shift (<<)
case 'r': // right shift (>>)
flag = left_->set_width(w);
expr_width(w);
break;
case 'o': // logical or (||)
assert(w == 1);
expr_width(w);
break;
/* The default rule is that the operands of the binary
operator might as well use the same width as the
output from the binary operation. */
@ -642,25 +705,6 @@ bool NetEBinary::set_width(unsigned w)
op_ << "." << endl;
flag = false;
case '+':
case '-':
flag = true;
if (left_->expr_width() > right_->expr_width())
right_->set_width(left_->expr_width());
else
left_->set_width(right_->expr_width());
if (left_->expr_width() == w)
expr_width(w);
else if (left_->expr_width() == (w-1))
expr_width(w);
else
flag = false;
break;
case '^':
case '&':
case '|':
case '%':
case '/':
flag = left_->set_width(w) && flag;
@ -1483,6 +1527,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
/*
* $Log: netlist.cc,v $
* Revision 1.49 1999/07/31 03:16:54 steve
* move binary operators to derived classes.
*
* Revision 1.48 1999/07/24 02:11:20 steve
* Elaborate task input ports.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: netlist.h,v 1.51 1999/07/24 02:11:20 steve Exp $"
#ident "$Id: netlist.h,v 1.52 1999/07/31 03:16:54 steve Exp $"
#endif
/*
@ -987,6 +987,8 @@ class NetProcTop : public LineInfo {
* % -- Arithmetic modulus
* & -- Bit-wise AND
* | -- Bit-wise OR
* < -- Less then
* > -- Greater then
* e -- Logical equality (==)
* E -- Case equality (===)
* L -- Less or equal
@ -1023,12 +1025,72 @@ class NetEBinary : public NetExpr {
NetExpr*eval_eqeq();
private:
protected:
char op_;
NetExpr* left_;
NetExpr* right_;
};
/*
* The addition operators have slightly more complex width
* calculations because there is the optional carry bit that can be
* used. The operators covered by this class are:
* + -- Arithmetic add
* - -- Arithmetic minus
*/
class NetEBAdd : public NetEBinary {
public:
NetEBAdd(char op, NetExpr*l, NetExpr*r);
~NetEBAdd();
virtual bool set_width(unsigned w);
};
/*
* The bitwise binary operators are represented by this class. This is
* a specialization of the binary operator, so is derived from
* NetEBinary. The particular constraints on these operators are that
* operand and result widths match exactly, and each bit slice of the
* operation can be represented by a simple gate. The operators
* covered by this class are:
*
* ^ -- Bit-wise exclusive OR
* & -- Bit-wise AND
* | -- Bit-wise OR
*/
class NetEBBits : public NetEBinary {
public:
NetEBBits(char op, NetExpr*l, NetExpr*r);
~NetEBBits();
virtual bool set_width(unsigned w);
};
/*
* The binary comparison operators are handled by this class. This
* this case the bit width of the expression is 1 bit, and the
* operands take their natural widths. The supported operators are:
*
* < -- Less then
* > -- Greater then
* e -- Logical equality (==)
* E -- Case equality (===)
* L -- Less or equal (<=)
* G -- Greater or equal (>=)
* n -- Logical inequality (!=)
* N -- Case inequality (!==)
*/
class NetEBComp : public NetEBinary {
public:
NetEBComp(char op, NetExpr*l, NetExpr*r);
~NetEBComp();
virtual bool set_width(unsigned w);
};
/*
* This expression node supports the concat expression. This is an
* operator that just glues the results of many expressions into a
@ -1375,6 +1437,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
/*
* $Log: netlist.h,v $
* Revision 1.52 1999/07/31 03:16:54 steve
* move binary operators to derived classes.
*
* Revision 1.51 1999/07/24 02:11:20 steve
* Elaborate task input ports.
*