Detect constant lessthen-equal expressions.
This commit is contained in:
parent
251eb4f38f
commit
dab04c221d
25
elaborate.cc
25
elaborate.cc
|
|
@ -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.89 1999/09/17 02:06:25 steve Exp $"
|
||||
#ident "$Id: elaborate.cc,v 1.90 1999/09/18 01:53:08 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -1441,6 +1441,8 @@ NetExpr* PEIdent::elaborate_expr(Design*des, const string&path) const
|
|||
assert(msb_);
|
||||
verinum*lsn = lsb_->eval_const(des, path);
|
||||
verinum*msn = msb_->eval_const(des, path);
|
||||
assert(lsn);
|
||||
assert(msn);
|
||||
unsigned long lsv = lsn->as_ulong();
|
||||
unsigned long msv = msn->as_ulong();
|
||||
unsigned long wid = 1 + ((msv>lsv)? (msv-lsv) : (lsv-msv));
|
||||
|
|
@ -2333,7 +2335,23 @@ NetProc* PForStatement::elaborate(Design*des, const string&path) const
|
|||
|
||||
body->append(step);
|
||||
|
||||
NetWhile*loop = new NetWhile(cond_->elaborate_expr(des, path), body);
|
||||
|
||||
/* Elaborate the condition expression. Try to evaluate it too,
|
||||
in case it is a constant. This is an interesting case
|
||||
worthy of a warning. */
|
||||
NetExpr*ce = cond_->elaborate_expr(des, path);
|
||||
if (NetExpr*tmp = ce->eval_tree()) {
|
||||
if (dynamic_cast<NetEConst*>(tmp))
|
||||
cerr << get_line() << ": warning: condition expression "
|
||||
"is constant." << endl;
|
||||
|
||||
ce = tmp;
|
||||
}
|
||||
|
||||
|
||||
/* All done, build up the loop. */
|
||||
|
||||
NetWhile*loop = new NetWhile(ce, body);
|
||||
top->append(loop);
|
||||
return top;
|
||||
}
|
||||
|
|
@ -2600,6 +2618,9 @@ Design* elaborate(const map<string,Module*>&modules,
|
|||
|
||||
/*
|
||||
* $Log: elaborate.cc,v $
|
||||
* Revision 1.90 1999/09/18 01:53:08 steve
|
||||
* Detect constant lessthen-equal expressions.
|
||||
*
|
||||
* Revision 1.89 1999/09/17 02:06:25 steve
|
||||
* Handle unconnected module ports.
|
||||
*
|
||||
|
|
|
|||
63
netlist.cc
63
netlist.cc
|
|
@ -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.64 1999/09/16 04:18:15 steve Exp $"
|
||||
#ident "$Id: netlist.cc,v 1.65 1999/09/18 01:53:08 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <cassert>
|
||||
|
|
@ -920,7 +920,27 @@ NetEBinary* NetEBinary::dup_expr() const
|
|||
assert(0);
|
||||
}
|
||||
|
||||
NetExpr* NetEBinary::eval_eqeq()
|
||||
/*
|
||||
* Some of the derived classes can be evaluated by the compiler, this
|
||||
* method provides the common aid of evaluating the parameter
|
||||
* expressions.
|
||||
*/
|
||||
void NetEBinary::eval_sub_tree_()
|
||||
{
|
||||
NetExpr*tmp = left_->eval_tree();
|
||||
if (tmp) {
|
||||
delete left_;
|
||||
left_ = tmp;
|
||||
}
|
||||
tmp = right_->eval_tree();
|
||||
if (tmp){
|
||||
delete right_;
|
||||
right_ = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NetExpr* NetEBComp::eval_eqeq_()
|
||||
{
|
||||
NetEConst*l = dynamic_cast<NetEConst*>(left_);
|
||||
if (l == 0) return 0;
|
||||
|
|
@ -942,22 +962,36 @@ NetExpr* NetEBinary::eval_eqeq()
|
|||
return new NetEConst(result);
|
||||
}
|
||||
|
||||
NetExpr* NetEBinary::eval_tree()
|
||||
NetExpr* NetEBComp::eval_leeq_()
|
||||
{
|
||||
NetExpr*tmp = left_->eval_tree();
|
||||
if (tmp) {
|
||||
delete left_;
|
||||
left_ = tmp;
|
||||
}
|
||||
tmp = right_->eval_tree();
|
||||
if (tmp){
|
||||
delete right_;
|
||||
right_ = tmp;
|
||||
NetEConst*r = dynamic_cast<NetEConst*>(right_);
|
||||
if (r == 0) return 0;
|
||||
|
||||
verinum rv = r->value();
|
||||
|
||||
/* Detect the case where the right side is greater that or
|
||||
equal to the largest value the left side can possibly
|
||||
have. */
|
||||
unsigned long lv = (1 << left_->expr_width()) - 1;
|
||||
if (lv <= rv.as_ulong()) {
|
||||
verinum result(verinum::V1, 1);
|
||||
return new NetEConst(result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
NetExpr* NetEBComp::eval_tree()
|
||||
{
|
||||
eval_sub_tree_();
|
||||
|
||||
switch (op_) {
|
||||
case 'e':
|
||||
return eval_eqeq();
|
||||
return eval_eqeq_();
|
||||
|
||||
case 'L':
|
||||
return eval_leeq_();
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -1836,6 +1870,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
|
|||
|
||||
/*
|
||||
* $Log: netlist.cc,v $
|
||||
* Revision 1.65 1999/09/18 01:53:08 steve
|
||||
* Detect constant lessthen-equal expressions.
|
||||
*
|
||||
* Revision 1.64 1999/09/16 04:18:15 steve
|
||||
* elaborate concatenation repeats.
|
||||
*
|
||||
|
|
|
|||
20
netlist.h
20
netlist.h
|
|
@ -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.65 1999/09/16 04:18:15 steve Exp $"
|
||||
#ident "$Id: netlist.h,v 1.66 1999/09/18 01:53:08 steve Exp $"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -1146,22 +1146,17 @@ class NetEBinary : public NetExpr {
|
|||
|
||||
virtual bool set_width(unsigned w);
|
||||
|
||||
// If both of my subexpressions are constants, then I can
|
||||
// probably evaluate this part of the expression at compile
|
||||
// time.
|
||||
virtual NetExpr* eval_tree();
|
||||
|
||||
virtual NetEBinary* dup_expr() const;
|
||||
|
||||
virtual void expr_scan(struct expr_scan_t*) const;
|
||||
virtual void dump(ostream&) const;
|
||||
|
||||
NetExpr*eval_eqeq();
|
||||
|
||||
protected:
|
||||
char op_;
|
||||
NetExpr* left_;
|
||||
NetExpr* right_;
|
||||
|
||||
virtual void eval_sub_tree_();
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -1222,6 +1217,12 @@ class NetEBComp : public NetEBinary {
|
|||
~NetEBComp();
|
||||
|
||||
virtual bool set_width(unsigned w);
|
||||
virtual NetExpr* eval_tree();
|
||||
|
||||
private:
|
||||
NetExpr*eval_eqeq_();
|
||||
NetExpr*eval_leeq_();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -1584,6 +1585,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
|
|||
|
||||
/*
|
||||
* $Log: netlist.h,v $
|
||||
* Revision 1.66 1999/09/18 01:53:08 steve
|
||||
* Detect constant lessthen-equal expressions.
|
||||
*
|
||||
* Revision 1.65 1999/09/16 04:18:15 steve
|
||||
* elaborate concatenation repeats.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue