diff --git a/Makefile.in b/Makefile.in index 19931db35..e7ba3965b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -18,7 +18,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.18 1999/09/23 00:21:54 steve Exp $" +#ident "$Id: Makefile.in,v 1.19 1999/09/29 00:42:50 steve Exp $" # # SHELL = /bin/sh @@ -62,7 +62,8 @@ FF = nobufz.o propinit.o sigfold.o xnfio.o xnfsyn.o O = main.o cprop.o design_dump.o elaborate.o elab_expr.o emit.o eval.o \ eval_tree.o functor.o \ -lexor.o mangle.o netlist.o parse.o parse_misc.o pform.o pform_dump.o \ +lexor.o mangle.o netlist.o pad_to_width.o \ +parse.o parse_misc.o pform.o pform_dump.o \ set_width.o \ verinum.o verireal.o target.o targets.o Module.o PDelays.o PExpr.o PGate.o \ PTask.o PFunction.o PWire.o Statement.o \ diff --git a/elaborate.cc b/elaborate.cc index f8df8a568..d8cd5bed7 100644 --- a/elaborate.cc +++ b/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.100 1999/09/25 02:57:30 steve Exp $" +#ident "$Id: elaborate.cc,v 1.101 1999/09/29 00:42:50 steve Exp $" #endif /* @@ -31,6 +31,7 @@ # include # include "pform.h" # include "netlist.h" +# include "netmisc.h" string Design::local_symbol(const string&path) { @@ -1525,26 +1526,6 @@ NetNet* PAssign_::elaborate_lval(Design*des, const string&path, return reg; } -/* - * This funciton transforms an expression by padding the high bits - * with V0 until the expression has the desired width. This may mean - * not transforming the expression at all, if it is already wide - * enough. - */ -static NetExpr*pad_to_width(NetExpr*expr, unsigned wid) -{ - if (wid > expr->expr_width()) { - verinum pad(verinum::V0, wid - expr->expr_width()); - NetEConst*co = new NetEConst(pad); - NetEConcat*cc = new NetEConcat(2); - cc->set(0, co); - cc->set(1, expr); - cc->set_width(wid); - expr = cc; - } - return expr; -} - NetProc* PAssign::elaborate(Design*des, const string&path) const { /* Catch the case where the lvalue is a reference to a memory @@ -2591,6 +2572,9 @@ Design* elaborate(const map&modules, /* * $Log: elaborate.cc,v $ + * Revision 1.101 1999/09/29 00:42:50 steve + * Allow expanding of additive operators. + * * Revision 1.100 1999/09/25 02:57:30 steve * Parse system function calls. * diff --git a/netmisc.h b/netmisc.h new file mode 100644 index 000000000..89eb272b6 --- /dev/null +++ b/netmisc.h @@ -0,0 +1,42 @@ +#ifndef __netmisc_H +#define __netmisc_H +/* + * Copyright (c) 1999 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) +#ident "$Id: netmisc.h,v 1.1 1999/09/29 00:42:51 steve Exp $" +#endif + +# include "netlist.h" + +/* + * This funciton transforms an expression by padding the high bits + * with V0 until the expression has the desired width. This may mean + * not transforming the expression at all, if it is already wide + * enough. + */ +extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid); + + +/* + * $Log: netmisc.h,v $ + * Revision 1.1 1999/09/29 00:42:51 steve + * Allow expanding of additive operators. + * + */ +#endif diff --git a/pad_to_width.cc b/pad_to_width.cc new file mode 100644 index 000000000..04e4dad8f --- /dev/null +++ b/pad_to_width.cc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1999 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#if !defined(WINNT) +#ident "$Id: pad_to_width.cc,v 1.1 1999/09/29 00:42:51 steve Exp $" +#endif + +# include "netlist.h" +# include "netmisc.h" + +/* + * This funciton transforms an expression by padding the high bits + * with V0 until the expression has the desired width. This may mean + * not transforming the expression at all, if it is already wide + * enough. + */ +NetExpr*pad_to_width(NetExpr*expr, unsigned wid) +{ + if (wid > expr->expr_width()) { + verinum pad(verinum::V0, wid - expr->expr_width()); + NetEConst*co = new NetEConst(pad); + NetEConcat*cc = new NetEConcat(2); + cc->set(0, co); + cc->set(1, expr); + cc->set_width(wid); + expr = cc; + } + return expr; +} + + +/* + * $Log: pad_to_width.cc,v $ + * Revision 1.1 1999/09/29 00:42:51 steve + * Allow expanding of additive operators. + * + */ + diff --git a/set_width.cc b/set_width.cc index 5f05e6792..949db62b7 100644 --- a/set_width.cc +++ b/set_width.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: set_width.cc,v 1.3 1999/09/23 03:56:57 steve Exp $" +#ident "$Id: set_width.cc,v 1.4 1999/09/29 00:42:51 steve Exp $" #endif /* @@ -28,6 +28,7 @@ * whatever is needed to deal with the size mismatch. */ # include "netlist.h" +# include "netmisc.h" # include @@ -76,21 +77,30 @@ bool NetEBinary::set_width(unsigned w) */ 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()); + unsigned wid = w; + if (left_->expr_width() > wid) + wid = left_->expr_width(); + if (right_->expr_width() > wid) + wid = right_->expr_width(); - if (left_->expr_width() == w) - expr_width(w); - else if (left_->expr_width() == (w-1)) - expr_width(w); - else - flag = false; + left_->set_width(wid); + right_->set_width(wid); - return flag; + if (left_->expr_width() < wid) { + NetExpr*tmp = pad_to_width(left_, wid); + assert(tmp); + left_ = tmp; + } + + if (right_->expr_width() < wid) { + NetExpr*tmp = pad_to_width(right_, wid); + assert(tmp); + right_ = tmp; + } + + expr_width(wid); + return wid == w; } /* @@ -251,6 +261,9 @@ bool NetEUnary::set_width(unsigned w) /* * $Log: set_width.cc,v $ + * Revision 1.4 1999/09/29 00:42:51 steve + * Allow expanding of additive operators. + * * Revision 1.3 1999/09/23 03:56:57 steve * Support shift operators. *