Skip to content
Browse files

Generalize the evaluation of floating point delays, and

 get it working with delay assignment statements.

 Allow parameters to be referenced by hierarchical name.
  • Loading branch information...
1 parent b712c3f commit 219df169a37cebe73f110377cebee686c32fbdaa steve committed Jan 14, 2001
Showing with 249 additions and 55 deletions.
  1. +2 −2 Makefile.in
  2. +42 −17 PDelays.cc
  3. +12 −1 PExpr.cc
  4. +21 −1 PExpr.h
  5. +13 −1 elab_expr.cc
  6. +24 −3 elab_pexpr.cc
  7. +15 −5 elaborate.cc
  8. +9 −1 eval.cc
  9. +46 −0 eval_rconst.cc
  10. +14 −1 eval_tree.cc
  11. +7 −15 net_design.cc
  12. +5 −4 parse.y
  13. +9 −2 pform.cc
  14. +21 −1 util.cc
  15. +9 −1 util.h
View
4 Makefile.in
@@ -16,7 +16,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
-#ident "$Id: Makefile.in,v 1.89 2001/01/09 03:11:27 steve Exp $"
+#ident "$Id: Makefile.in,v 1.90 2001/01/14 23:04:55 steve Exp $"
#
#
SHELL = /bin/sh
@@ -96,7 +96,7 @@ FF = nodangle.o synth.o syn-rules.o xnfio.o
O = main.o cprop.o design_dump.o dup_expr.o elaborate.o elab_expr.o \
elab_lval.o elab_net.o elab_anet.o elab_pexpr.o elab_scope.o \
-elab_sig.o emit.o eval.o \
+elab_sig.o emit.o eval.o eval_rconst.o \
eval_tree.o expr_synth.o functor.o lexor.o lexor_keyword.o link_const.o \
mangle.o netlist.o net_assign.o \
net_design.o net_event.o net_force.o net_link.o net_modulo.o net_proc.o \
View
59 PDelays.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: PDelays.cc,v 1.2 2000/02/23 02:56:53 steve Exp $"
+#ident "$Id: PDelays.cc,v 1.3 2001/01/14 23:04:55 steve Exp $"
#endif
# include "PDelays.h"
@@ -52,30 +52,49 @@ void PDelays::set_delays(const svector<PExpr*>*del)
delay_[idx] = (*del)[idx];
}
-void PDelays::eval_delays(Design*des, const string&path,
- unsigned long&rise_time,
- unsigned long&fall_time,
- unsigned long&decay_time) const
+static unsigned long calculate_val(Design*des, const NetScope*scope,
+ const PExpr*expr)
{
- verinum*dv;
+ assert(expr);
+ unsigned long val;
- if (delay_[0]) {
- dv = delay_[0]->eval_const(des, path);
+ int shift = scope->time_unit() - des->get_precision();
+
+ if (verireal*dr = expr->eval_rconst(des, scope)) {
+ val = dr->as_long(shift);
+ delete dr;
+
+ } else {
+ verinum*dv = expr->eval_const(des, scope->name());
assert(dv);
- rise_time = dv->as_ulong();
+ val = dv->as_ulong();
+ val = des->scale_to_precision(val, scope);
delete dv;
+ }
+
+ return val;
+}
+
+void PDelays::eval_delays(Design*des, const string&path,
+ unsigned long&rise_time,
+ unsigned long&fall_time,
+ unsigned long&decay_time) const
+{
+ NetScope*scope = des->find_scope(path);
+ assert(scope);
+
+ int shift = scope->time_unit() - des->get_precision();
+
+
+ if (delay_[0]) {
+ rise_time = calculate_val(des, scope, delay_[0]);
if (delay_[1]) {
- dv = delay_[1]->eval_const(des, path);
- assert(dv);
- fall_time = dv->as_ulong();
- delete dv;
+ fall_time = calculate_val(des, scope, delay_[1]);
if (delay_[2]) {
- dv = delay_[2]->eval_const(des, path);
- assert(dv);
- decay_time = dv->as_ulong();
- delete dv;
+ decay_time = calculate_val(des, scope, delay_[2]);
+
} else {
if (rise_time < fall_time)
decay_time = rise_time;
@@ -96,6 +115,12 @@ void PDelays::eval_delays(Design*des, const string&path,
/*
* $Log: PDelays.cc,v $
+ * Revision 1.3 2001/01/14 23:04:55 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.2 2000/02/23 02:56:53 steve
* Macintosh compilers do not support ident.
*
View
13 PExpr.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: PExpr.cc,v 1.22 2001/01/12 04:31:27 steve Exp $"
+#ident "$Id: PExpr.cc,v 1.23 2001/01/14 23:04:55 steve Exp $"
#endif
# include "PExpr.h"
@@ -133,6 +133,11 @@ const verireal& PEFNumber::value() const
return *value_;
}
+bool PEFNumber::is_constant(Module*) const
+{
+ return true;
+}
+
PEIdent::PEIdent(const string&s)
: text_(s), msb_(0), lsb_(0), idx_(0)
{
@@ -246,6 +251,12 @@ bool PEUnary::is_constant(Module*m) const
/*
* $Log: PExpr.cc,v $
+ * Revision 1.23 2001/01/14 23:04:55 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.22 2001/01/12 04:31:27 steve
* Handle error idents in constants not in any scope (PR#97)
*
View
22 PExpr.h
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: PExpr.h,v 1.47 2000/12/16 19:03:30 steve Exp $"
+#ident "$Id: PExpr.h,v 1.48 2001/01/14 23:04:55 steve Exp $"
#endif
# include <string>
@@ -88,6 +88,11 @@ class PExpr : public LineInfo {
// evaluated, return 0.
virtual verinum* eval_const(const Design*des, const string&path) const;
+ // This attempts to evaluate a constant expression as a
+ // decimal floating point. This is used when calculating delay
+ // constants.
+ virtual verireal* eval_rconst(const Design*, const NetScope*) const;
+
// This method returns true if that expression is the same as
// this expression. This method is used for comparing
// expressions that must be structurally "identical".
@@ -179,6 +184,15 @@ class PEFNumber : public PExpr {
any rounding that is needed to get the value. */
virtual verinum* eval_const(const Design*des, const string&path) const;
+ /* This method returns the full floating point value. */
+ virtual verireal* eval_rconst(const Design*, const NetScope*) const;
+
+ /* A PEFNumber is a constant, so this returns true. */
+ virtual bool is_constant(Module*) const;
+
+ virtual NetExpr*elaborate_expr(Design*des, NetScope*) const;
+ virtual NetExpr*elaborate_pexpr(Design*des, NetScope*sc) const;
+
virtual void dump(ostream&) const;
private:
@@ -432,6 +446,12 @@ class PECallFunction : public PExpr {
/*
* $Log: PExpr.h,v $
+ * Revision 1.48 2001/01/14 23:04:55 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.47 2000/12/16 19:03:30 steve
* Evaluate <= and ?: in parameter expressions (PR#81)
*
View
14 elab_expr.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: elab_expr.cc,v 1.33 2001/01/13 22:20:08 steve Exp $"
+#ident "$Id: elab_expr.cc,v 1.34 2001/01/14 23:04:55 steve Exp $"
#endif
@@ -269,6 +269,12 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope) const
return tmp;
}
+NetExpr* PEFNumber::elaborate_expr(Design*des, NetScope*scope) const
+{
+ long val = value_->as_long();
+ return new NetEConst(verinum(val));
+}
+
NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope) const
{
assert(text_[0] != '$');
@@ -539,6 +545,12 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope) const
/*
* $Log: elab_expr.cc,v $
+ * Revision 1.34 2001/01/14 23:04:55 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.33 2001/01/13 22:20:08 steve
* Parse parameters within nested scopes.
*
View
27 elab_pexpr.cc
@@ -17,10 +17,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: elab_pexpr.cc,v 1.7 2001/01/02 04:21:13 steve Exp $"
+#ident "$Id: elab_pexpr.cc,v 1.8 2001/01/14 23:04:56 steve Exp $"
#endif
# include "PExpr.h"
+# include "util.h"
NetExpr*PExpr::elaborate_pexpr(Design*des, NetScope*sc) const
{
@@ -103,6 +104,11 @@ NetEConcat* PEConcat::elaborate_pexpr(Design*des, NetScope*scope) const
return tmp;
}
+NetExpr*PEFNumber::elaborate_pexpr(Design*des, NetScope*scope) const
+{
+ return elaborate_expr(des, scope);
+}
+
/*
* Parameter expressions may reference other parameters, but only in
* the current scope. Preserve the parameter reference in the
@@ -111,15 +117,24 @@ NetEConcat* PEConcat::elaborate_pexpr(Design*des, NetScope*scope) const
*/
NetExpr*PEIdent::elaborate_pexpr(Design*des, NetScope*scope) const
{
- const NetExpr*ex = scope->get_parameter(text_);
+ string path = text_;
+ string name = parse_last_name(path);
+
+ NetScope*pscope = scope;
+ if (path != "")
+ pscope = des->find_scope(scope, path);
+
+ assert(pscope);
+
+ const NetExpr*ex = pscope->get_parameter(name);
if (ex == 0) {
cerr << get_line() << ": error: identifier ``" << text_ <<
"'' is not a parameter in " << scope->name() << "." << endl;
des->errors += 1;
return 0;
}
- NetExpr*res = new NetEParam(des, scope, text_);
+ NetExpr*res = new NetEParam(des, pscope, name);
assert(res);
return res;
}
@@ -184,6 +199,12 @@ NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const
/*
* $Log: elab_pexpr.cc,v $
+ * Revision 1.8 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.7 2001/01/02 04:21:13 steve
* Support a bunch of unary operators in parameter expressions.
*
View
20 elaborate.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: elaborate.cc,v 1.204 2001/01/10 03:13:23 steve Exp $"
+#ident "$Id: elaborate.cc,v 1.205 2001/01/14 23:04:56 steve Exp $"
#endif
/*
@@ -1538,20 +1538,23 @@ NetProc* PDelayStatement::elaborate(Design*des, const string&path) const
floating point number. In this case, we need to scale the
delay to the units of the design. */
- if (const PEFNumber*fn = dynamic_cast<const PEFNumber*>(delay_)) {
+ if (verireal*fn = delay_? delay_->eval_rconst(des, scope) : 0) {
int shift = scope->time_unit() - des->get_precision();
- long delay = fn->value().as_long(shift);
+ long delay = fn->as_long(shift);
if (delay < 0)
delay = 0;
+ delete fn;
+
if (statement_)
- return new NetPDelay(delay, statement_->elaborate(des, path));
+ return new NetPDelay(delay, statement_->elaborate(des, path));
else
- return new NetPDelay(delay, 0);
+ return new NetPDelay(delay, 0);
}
+
verinum*num = delay_->eval_const(des, path);
if (num == 0) {
/* Ah, the delay is not constant. OK, elaborate the
@@ -1567,6 +1570,7 @@ NetProc* PDelayStatement::elaborate(Design*des, const string&path) const
/* Convert the delay in the units of the scope to the
precision of the design as a whole. */
unsigned long val = des->scale_to_precision(num->as_ulong(), scope);
+ delete num;
/* If there is a statement, then elaborate it and create a
NetPDelay statement to contain it. Note that we create a
@@ -2351,6 +2355,12 @@ Design* elaborate(const map<string,Module*>&modules,
/*
* $Log: elaborate.cc,v $
+ * Revision 1.205 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.204 2001/01/10 03:13:23 steve
* Build task outputs as lval instead of nets. (PR#98)
*
View
10 eval.cc
@@ -17,11 +17,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: eval.cc,v 1.17 2001/01/04 04:47:51 steve Exp $"
+#ident "$Id: eval.cc,v 1.18 2001/01/14 23:04:56 steve Exp $"
#endif
# include "PExpr.h"
# include "netlist.h"
+# include "compiler.h"
verinum* PExpr::eval_const(const Design*, const string&) const
{
@@ -104,6 +105,7 @@ verinum* PEBinary::eval_const(const Design*des, const string&path) const
return res;
}
+
/*
* Evaluate an identifier as a constant expression. This is only
* possible if the identifier is that of a parameter.
@@ -183,6 +185,12 @@ verinum* PEUnary::eval_const(const Design*des, const string&path) const
/*
* $Log: eval.cc,v $
+ * Revision 1.18 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.17 2001/01/04 04:47:51 steve
* Add support for << is signal indices.
*
View
46 eval_rconst.cc
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2001 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) && !defined(macintosh)
+#ident "$Id: eval_rconst.cc,v 1.1 2001/01/14 23:04:56 steve Exp $"
+#endif
+
+# include "PExpr.h"
+
+verireal* PExpr::eval_rconst(const Design*, const NetScope*) const
+{
+ return 0;
+}
+
+verireal* PEFNumber::eval_rconst(const Design*, const NetScope*) const
+{
+ verireal*res = new verireal;
+ *res = *value_;
+ return res;
+}
+
+/*
+ * $Log: eval_rconst.cc,v $
+ * Revision 1.1 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
+ */
+
View
15 eval_tree.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: eval_tree.cc,v 1.20 2001/01/04 16:49:50 steve Exp $"
+#ident "$Id: eval_tree.cc,v 1.21 2001/01/14 23:04:56 steve Exp $"
#endif
# include "netlist.h"
@@ -574,6 +574,13 @@ NetExpr* NetEParam::eval_tree()
assert(scope_);
const NetExpr*expr = scope_->get_parameter(name_);
+ if (expr == 0) {
+ cerr << get_line() << ": internal error: Unable to match "
+ << "parameter " << name_ << " in scope "
+ << scope_->name() << endl;
+ return 0;
+ }
+
assert(expr);
NetExpr*nexpr = expr->dup_expr();
@@ -815,6 +822,12 @@ NetEConst* NetEUReduce::eval_tree()
/*
* $Log: eval_tree.cc,v $
+ * Revision 1.21 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.20 2001/01/04 16:49:50 steve
* Evaluate constant === and !== expressions.
*
View
22 net_design.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: net_design.cc,v 1.17 2000/12/16 01:45:48 steve Exp $"
+#ident "$Id: net_design.cc,v 1.18 2001/01/14 23:04:56 steve Exp $"
#endif
/*
@@ -29,20 +29,6 @@
# include "util.h"
# include <strstream>
-static string parse_last_name(string&path)
-{
- unsigned pos = path.rfind('.');
- if (pos > path.length()) {
- string res = path;
- path = "";
- return res;
- }
-
- string res = path.substr(pos+1, path.length());
- path = path.substr(0, pos);
- return res;
-}
-
Design:: Design()
: errors(0), root_scope_(0), nodes_(0), procs_(0), lcounter_(0)
{
@@ -487,6 +473,12 @@ void Design::delete_process(NetProcTop*top)
/*
* $Log: net_design.cc,v $
+ * Revision 1.18 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.17 2000/12/16 01:45:48 steve
* Detect recursive instantiations (PR#2)
*
View
9 parse.y
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: parse.y,v 1.117 2001/01/13 22:20:08 steve Exp $"
+#ident "$Id: parse.y,v 1.118 2001/01/14 23:04:56 steve Exp $"
#endif
# include "parse_misc.h"
@@ -793,9 +793,10 @@ expr_primary
$$ = tmp;
}
| REALTIME
- { yyerror(@1, "sorry: real constants not supported.");
- delete $1;
- $$ = 0;
+ { PEFNumber*tmp = new PEFNumber($1);
+ tmp->set_file(@1.text);
+ tmp->set_lineno(@1.first_line);
+ $$ = tmp;
}
| STRING
{ PEString*tmp = new PEString($1);
View
11 pform.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: pform.cc,v 1.71 2001/01/10 05:32:44 steve Exp $"
+#ident "$Id: pform.cc,v 1.72 2001/01/14 23:04:56 steve Exp $"
#endif
# include "compiler.h"
@@ -525,14 +525,15 @@ void pform_make_modgates(const string&type,
struct parmvalue_t*overrides,
svector<lgate>*gates)
{
+#if 0
if (overrides && overrides->by_order)
for (unsigned idx = 0 ; idx < overrides->by_order->count() ; idx += 1)
if (! pform_expression_is_constant((*overrides->by_order)[idx])) {
VLerror("error: Parameter override expression"
" must be constant.");
return;
}
-
+#endif
for (unsigned idx = 0 ; idx < gates->count() ; idx += 1) {
lgate cur = (*gates)[idx];
@@ -1010,6 +1011,12 @@ int pform_parse(const char*path, map<string,Module*>&modules,
/*
* $Log: pform.cc,v $
+ * Revision 1.72 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.71 2001/01/10 05:32:44 steve
* Match memories within task scopes. (PR#101)
*
View
22 util.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: util.cc,v 1.1 2000/04/28 16:50:53 steve Exp $"
+#ident "$Id: util.cc,v 1.2 2001/01/14 23:04:56 steve Exp $"
#endif
# include "util.h"
@@ -36,8 +36,28 @@ string parse_first_name(string&path)
return res;
}
+string parse_last_name(string&path)
+{
+ unsigned pos = path.rfind('.');
+ if (pos > path.length()) {
+ string res = path;
+ path = "";
+ return res;
+ }
+
+ string res = path.substr(pos+1, path.length());
+ path = path.substr(0, pos);
+ return res;
+}
+
/*
* $Log: util.cc,v $
+ * Revision 1.2 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.1 2000/04/28 16:50:53 steve
* Catch memory word parameters to tasks.
*
View
10 util.h
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: util.h,v 1.1 2000/04/29 04:53:44 steve Exp $"
+#ident "$Id: util.h,v 1.2 2001/01/14 23:04:56 steve Exp $"
#endif
# include <string>
@@ -31,8 +31,16 @@
*/
extern string parse_first_name(string&path);
+extern string parse_last_name(string&path);
+
/*
* $Log: util.h,v $
+ * Revision 1.2 2001/01/14 23:04:56 steve
+ * Generalize the evaluation of floating point delays, and
+ * get it working with delay assignment statements.
+ *
+ * Allow parameters to be referenced by hierarchical name.
+ *
* Revision 1.1 2000/04/29 04:53:44 steve
* missing header file.
*

0 comments on commit 219df16

Please sign in to comment.
Something went wrong with that request. Please try again.