netlist support for ternary operator.

This commit is contained in:
steve 1999-07-17 19:50:59 +00:00
parent cfb27a1fc4
commit a5921ceae8
11 changed files with 174 additions and 21 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: PExpr.cc,v 1.5 1999/06/16 03:13:29 steve Exp $"
#ident "$Id: PExpr.cc,v 1.6 1999/07/17 19:50:59 steve Exp $"
#endif
# include "PExpr.h"
@ -77,12 +77,25 @@ bool PEString::is_constant(Module*) const
return true;
}
PETernary::PETernary(PExpr*e, PExpr*t, PExpr*f)
: expr_(e), tru_(t), fal_(f)
{
}
PETernary::~PETernary()
{
}
bool PETernary::is_constant(Module*) const
{
return false;
}
/*
* $Log: PExpr.cc,v $
* Revision 1.6 1999/07/17 19:50:59 steve
* netlist support for ternary operator.
*
* Revision 1.5 1999/06/16 03:13:29 steve
* More syntax parse with sorry stubs.
*

15
PExpr.h
View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: PExpr.h,v 1.13 1999/06/16 03:13:29 steve Exp $"
#ident "$Id: PExpr.h,v 1.14 1999/07/17 19:50:59 steve Exp $"
#endif
# include <string>
@ -208,10 +208,16 @@ class PEBinary : public PExpr {
class PETernary : public PExpr {
public:
explicit PETernary(PExpr*e, PExpr*t, PExpr*f)
: expr_(e), tru_(t), fal_(f) { }
explicit PETernary(PExpr*e, PExpr*t, PExpr*f);
~PETernary();
virtual bool is_constant(Module*) const;
virtual void dump(ostream&out) const;
virtual NetNet* elaborate_net(Design*des, const string&path) const;
virtual NetExpr*elaborate_expr(Design*des, const string&path) const;
virtual verinum* eval_const(const Design*des, const string&path) const;
private:
PExpr*expr_;
PExpr*tru_;
@ -220,6 +226,9 @@ class PETernary : public PExpr {
/*
* $Log: PExpr.h,v $
* Revision 1.14 1999/07/17 19:50:59 steve
* netlist support for ternary operator.
*
* Revision 1.13 1999/06/16 03:13:29 steve
* More syntax parse with sorry stubs.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: design_dump.cc,v 1.31 1999/07/03 02:12:51 steve Exp $"
#ident "$Id: design_dump.cc,v 1.32 1999/07/17 19:50:59 steve Exp $"
#endif
/*
@ -609,6 +609,12 @@ void NetESignal::dump_node(ostream&o, unsigned ind) const
dump_node_pins(o, ind+4);
}
void NetETernary::dump(ostream&o) const
{
o << "(" << *cond_ << ")? (" << *true_val_ << ") : (" <<
false_val_ << ")";
}
void NetEUnary::dump(ostream&o) const
{
o << op_ << "(";
@ -678,6 +684,9 @@ void Design::dump(ostream&o) const
/*
* $Log: design_dump.cc,v $
* Revision 1.32 1999/07/17 19:50:59 steve
* netlist support for ternary operator.
*
* Revision 1.31 1999/07/03 02:12:51 steve
* Elaborate user defined tasks.
*

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.56 1999/07/17 18:06:02 steve Exp $"
#ident "$Id: elaborate.cc,v 1.57 1999/07/17 19:50:59 steve Exp $"
#endif
/*
@ -820,6 +820,24 @@ NetNet* PENumber::elaborate_net(Design*des, const string&path) const
return net;
}
NetNet* PETernary::elaborate_net(Design*des, const string&) const
{
cerr << get_line() << ": Sorry, I cannot elaborate ?: as a net."
<< endl;
des->errors += 1;
return 0;
}
NetExpr*PETernary::elaborate_expr(Design*des, const string&path) const
{
NetExpr*con = expr_->elaborate_expr(des, path);
NetExpr*tru = tru_->elaborate_expr(des, path);
NetExpr*fal = fal_->elaborate_expr(des, path);
NetETernary*res = new NetETernary(con, tru, fal);
return res;
}
NetNet* PEUnary::elaborate_net(Design*des, const string&path) const
{
NetNet* sub_sig = expr_->elaborate_net(des, path);
@ -1844,6 +1862,9 @@ Design* elaborate(const map<string,Module*>&modules,
/*
* $Log: elaborate.cc,v $
* Revision 1.57 1999/07/17 19:50:59 steve
* netlist support for ternary operator.
*
* Revision 1.56 1999/07/17 18:06:02 steve
* Better handling of bit width of + operators.
*

10
emit.cc
View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: emit.cc,v 1.17 1999/07/17 03:39:11 steve Exp $"
#ident "$Id: emit.cc,v 1.18 1999/07/17 19:50:59 steve Exp $"
#endif
/*
@ -284,6 +284,11 @@ void NetESubSignal::expr_scan(struct expr_scan_t*tgt) const
tgt->expr_subsignal(this);
}
void NetETernary::expr_scan(struct expr_scan_t*tgt) const
{
tgt->expr_ternary(this);
}
void NetEUnary::expr_scan(struct expr_scan_t*tgt) const
{
tgt->expr_unary(this);
@ -303,6 +308,9 @@ void emit(ostream&o, const Design*des, const char*type)
/*
* $Log: emit.cc,v $
* Revision 1.18 1999/07/17 19:50:59 steve
* netlist support for ternary operator.
*
* Revision 1.17 1999/07/17 03:39:11 steve
* simplified process scan for targets.
*

11
eval.cc
View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: eval.cc,v 1.3 1999/05/30 01:11:46 steve Exp $"
#ident "$Id: eval.cc,v 1.4 1999/07/17 19:51:00 steve Exp $"
#endif
# include "PExpr.h"
@ -71,8 +71,17 @@ verinum* PENumber::eval_const(const Design*, const string&) const
return new verinum(value());
}
verinum* PETernary::eval_const(const Design*, const string&) const
{
assert(0);
}
/*
* $Log: eval.cc,v $
* Revision 1.4 1999/07/17 19:51:00 steve
* netlist support for ternary operator.
*
* Revision 1.3 1999/05/30 01:11:46 steve
* Exressions are trees that can duplicate, and not DAGS.
*

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.44 1999/07/17 18:06:02 steve Exp $"
#ident "$Id: netlist.cc,v 1.45 1999/07/17 19:51:00 steve Exp $"
#endif
# include <cassert>
@ -488,14 +488,20 @@ NetEBinary::NetEBinary(char op, NetExpr*l, NetExpr*r)
case '|':
case '%':
case '/':
if (l->expr_width() >= r->expr_width()) {
expr_width(l->expr_width());
r->set_width(expr_width());
} else {
expr_width(r->expr_width());
l->set_width(expr_width());
}
if (l->expr_width() > r->expr_width())
r->set_width(l->expr_width());
if (r->expr_width() > l->expr_width())
l->set_width(r->expr_width());
if (l->expr_width() < r->expr_width())
r->set_width(l->expr_width());
if (r->expr_width() < l->expr_width())
l->set_width(r->expr_width());
assert(l->expr_width() == r->expr_width());
expr_width(l->expr_width());
break;
}
}
@ -784,6 +790,33 @@ bool NetESubSignal::set_width(unsigned w)
return true;
}
NetETernary::NetETernary(NetExpr*c, NetExpr*t, NetExpr*f)
: cond_(c), true_val_(t), false_val_(f)
{
expr_width(true_val_->expr_width());
}
NetETernary::~NetETernary()
{
delete cond_;
delete true_val_;
delete false_val_;
}
NetETernary* NetETernary::dup_expr() const
{
assert(0);
}
bool NetETernary::set_width(unsigned w)
{
bool flag = true;
flag = flag && true_val_->set_width(w);
flag = flag && false_val_->set_width(w);
expr_width(true_val_->expr_width());
return flag;
}
NetEUnary::~NetEUnary()
{
delete expr_;
@ -1356,6 +1389,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))
/*
* $Log: netlist.cc,v $
* Revision 1.45 1999/07/17 19:51:00 steve
* netlist support for ternary operator.
*
* Revision 1.44 1999/07/17 18:06:02 steve
* Better handling of bit width of + operators.
*

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.46 1999/07/17 03:08:32 steve Exp $"
#ident "$Id: netlist.h,v 1.47 1999/07/17 19:51:00 steve Exp $"
#endif
/*
@ -1066,7 +1066,31 @@ class NetEConst : public NetExpr {
};
/*
* This class represents a unaru operator, with the single operand
* This class represents the ternary (?:) operator. It has 3
* expressions, one of which is a condition used to select which of
* the other two expressions is the result.
*/
class NetETernary : public NetExpr {
public:
NetETernary(NetExpr*c, NetExpr*t, NetExpr*f);
~NetETernary();
virtual bool set_width(unsigned w);
virtual NetETernary* dup_expr() const;
virtual void expr_scan(struct expr_scan_t*) const;
virtual void dump(ostream&) const;
private:
NetExpr*cond_;
NetExpr*true_val_;
NetExpr*false_val_;
};
/*
* This class represents a unary operator, with the single operand
* and a single character for the operator. The operator values are:
*
* ~ -- Bit-wise negation
@ -1342,6 +1366,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
/*
* $Log: netlist.h,v $
* Revision 1.47 1999/07/17 19:51:00 steve
* netlist support for ternary operator.
*
* Revision 1.46 1999/07/17 03:08:32 steve
* part select in expressions.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: pform_dump.cc,v 1.27 1999/07/12 00:59:36 steve Exp $"
#ident "$Id: pform_dump.cc,v 1.28 1999/07/17 19:51:00 steve Exp $"
#endif
/*
@ -101,6 +101,11 @@ void PEString::dump(ostream&out) const
out << "\"" << text_ << "\"";
}
void PETernary::dump(ostream&out) const
{
out << "(" << *expr_ << ")?(" << *tru_ << "):(" << *fal_ << ")";
}
void PEUnary::dump(ostream&out) const
{
out << op_ << "(" << *expr_ << ")";
@ -525,6 +530,9 @@ void PUdp::dump(ostream&out) const
/*
* $Log: pform_dump.cc,v $
* Revision 1.28 1999/07/17 19:51:00 steve
* netlist support for ternary operator.
*
* Revision 1.27 1999/07/12 00:59:36 steve
* procedural blocking assignment delays.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: target.cc,v 1.14 1999/07/17 03:39:11 steve Exp $"
#ident "$Id: target.cc,v 1.15 1999/07/17 19:51:00 steve Exp $"
#endif
# include "target.h"
@ -221,6 +221,12 @@ void expr_scan_t::expr_subsignal(const NetESubSignal*)
"unhandled expr_subsignal." << endl;
}
void expr_scan_t::expr_ternary(const NetETernary*)
{
cerr << "expr_scan_t (" << typeid(*this).name() << "): "
"unhandled expr_ternary." << endl;
}
void expr_scan_t::expr_unary(const NetEUnary*)
{
cerr << "expr_scan_t (" << typeid(*this).name() << "): "
@ -235,6 +241,9 @@ void expr_scan_t::expr_binary(const NetEBinary*ex)
/*
* $Log: target.cc,v $
* Revision 1.15 1999/07/17 19:51:00 steve
* netlist support for ternary operator.
*
* Revision 1.14 1999/07/17 03:39:11 steve
* simplified process scan for targets.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: target.h,v 1.14 1999/07/17 03:39:11 steve Exp $"
#ident "$Id: target.h,v 1.15 1999/07/17 19:51:00 steve Exp $"
#endif
# include "netlist.h"
@ -108,6 +108,7 @@ struct expr_scan_t {
virtual void expr_memory(const NetEMemory*);
virtual void expr_signal(const NetESignal*);
virtual void expr_subsignal(const NetESubSignal*);
virtual void expr_ternary(const NetETernary*);
virtual void expr_unary(const NetEUnary*);
virtual void expr_binary(const NetEBinary*);
};
@ -129,6 +130,9 @@ extern const struct target *target_table[];
/*
* $Log: target.h,v $
* Revision 1.15 1999/07/17 19:51:00 steve
* netlist support for ternary operator.
*
* Revision 1.14 1999/07/17 03:39:11 steve
* simplified process scan for targets.
*