Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support decimal constants in behavioral delays.

  • Loading branch information...
commit 084a464cf163150cac35b846249914d75923b90e 1 parent c0f951c
steve authored
View
20 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.19 2000/06/30 15:50:20 steve Exp $"
+#ident "$Id: PExpr.cc,v 1.20 2000/12/10 22:01:35 steve Exp $"
#endif
# include "PExpr.h"
@@ -118,6 +118,21 @@ PExpr* PEEvent::expr() const
return expr_;
}
+PEFNumber::PEFNumber(verireal*v)
+: value_(v)
+{
+}
+
+PEFNumber::~PEFNumber()
+{
+ delete value_;
+}
+
+const verireal& PEFNumber::value() const
+{
+ return *value_;
+}
+
PEIdent::PEIdent(const string&s)
: text_(s), msb_(0), lsb_(0), idx_(0)
{
@@ -228,6 +243,9 @@ bool PEUnary::is_constant(Module*m) const
/*
* $Log: PExpr.cc,v $
+ * Revision 1.20 2000/12/10 22:01:35 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.19 2000/06/30 15:50:20 steve
* Allow unary operators in constant expressions.
*
View
27 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.45 2000/12/06 06:31:09 steve Exp $"
+#ident "$Id: PExpr.h,v 1.46 2000/12/10 22:01:35 steve Exp $"
#endif
# include <string>
@@ -163,6 +163,28 @@ class PEEvent : public PExpr {
PExpr *expr_;
};
+/*
+ * This holds a floating point constant in the source.
+ */
+class PEFNumber : public PExpr {
+
+ public:
+ explicit PEFNumber(verireal*vp);
+ ~PEFNumber();
+
+ const verireal& value() const;
+
+ /* The eval_const method as applied to a floating point number
+ gets the *integer* value of the number. This accounts for
+ any rounding that is needed to get the value. */
+ virtual verinum* eval_const(const Design*des, const string&path) const;
+
+ virtual void dump(ostream&) const;
+
+ private:
+ verireal*value_;
+};
+
class PEIdent : public PExpr {
public:
@@ -409,6 +431,9 @@ class PECallFunction : public PExpr {
/*
* $Log: PExpr.h,v $
+ * Revision 1.46 2000/12/10 22:01:35 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.45 2000/12/06 06:31:09 steve
* Check lvalue of procedural continuous assign (PR#29)
*
View
12 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.30 2000/11/29 05:24:00 steve Exp $"
+#ident "$Id: elab_expr.cc,v 1.31 2000/12/10 22:01:35 steve Exp $"
#endif
@@ -26,8 +26,11 @@
NetExpr* PExpr::elaborate_expr(Design*des, NetScope*) const
{
- cerr << get_line() << ": I do not know how to elaborate expression: "
- << *this << endl;
+ cerr << get_line() << ": internal error: I do not know how to elaborate"
+ << " expression. " << endl;
+ cerr << get_line() << ": : Expression is: " << *this
+ << endl;
+ des->errors += 1;
return 0;
}
@@ -526,6 +529,9 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope) const
/*
* $Log: elab_expr.cc,v $
+ * Revision 1.31 2000/12/10 22:01:35 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.30 2000/11/29 05:24:00 steve
* synthesis for unary reduction ! and N operators.
*
View
23 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.200 2000/12/10 06:41:59 steve Exp $"
+#ident "$Id: elaborate.cc,v 1.201 2000/12/10 22:01:36 steve Exp $"
#endif
/*
@@ -1537,6 +1537,24 @@ NetProc* PDelayStatement::elaborate(Design*des, const string&path) const
NetScope*scope = des->find_scope(path);
assert(scope);
+ /* Catch the special case that the delay is given as a
+ 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_)) {
+ int shift = scope->time_unit() - des->get_precision();
+
+ long delay = fn->value().as_long(shift);
+ if (delay < 0)
+ delay = 0;
+
+ if (statement_)
+ return new NetPDelay(delay, statement_->elaborate(des, path));
+ else
+ return new NetPDelay(delay, 0);
+
+ }
+
verinum*num = delay_->eval_const(des, path);
if (num == 0) {
/* Ah, the delay is not constant. OK, elaborate the
@@ -2336,6 +2354,9 @@ Design* elaborate(const map<string,Module*>&modules,
/*
* $Log: elaborate.cc,v $
+ * Revision 1.201 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.200 2000/12/10 06:41:59 steve
* Support delays on continuous assignment from idents. (PR#40)
*
View
11 eval.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.cc,v 1.15 2000/09/07 22:38:13 steve Exp $"
+#ident "$Id: eval.cc,v 1.16 2000/12/10 22:01:36 steve Exp $"
#endif
# include "PExpr.h"
@@ -116,6 +116,12 @@ verinum* PEIdent::eval_const(const Design*des, const string&path) const
return new verinum(eval->value());
}
+verinum* PEFNumber::eval_const(const Design*, const string&) const
+{
+ long val = value_->as_long();
+ return new verinum(val);
+}
+
verinum* PENumber::eval_const(const Design*, const string&) const
{
return new verinum(value());
@@ -163,6 +169,9 @@ verinum* PEUnary::eval_const(const Design*des, const string&path) const
/*
* $Log: eval.cc,v $
+ * Revision 1.16 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.15 2000/09/07 22:38:13 steve
* Support unary + and - in constants.
*
View
13 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.111 2000/12/06 06:31:09 steve Exp $"
+#ident "$Id: parse.y,v 1.112 2000/12/10 22:01:36 steve Exp $"
#endif
# include "parse_misc.h"
@@ -372,6 +372,17 @@ delay_value_simple
$$->set_lineno(@1.first_line);
}
}
+ | REALTIME
+ { verireal*tmp = $1;
+ if (tmp == 0) {
+ yyerror(@1, "internal error: delay.");
+ $$ = 0;
+ } else {
+ $$ = new PEFNumber(tmp);
+ $$->set_file(@1.text);
+ $$->set_lineno(@1.first_line);
+ }
+ }
| IDENTIFIER
{ PEIdent*tmp = new PEIdent($1);
tmp->set_file(@1.text);
View
10 pform_dump.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_dump.cc,v 1.63 2000/11/11 01:52:09 steve Exp $"
+#ident "$Id: pform_dump.cc,v 1.64 2000/12/10 22:01:36 steve Exp $"
#endif
/*
@@ -128,6 +128,11 @@ void PEEvent::dump(ostream&out) const
}
+void PEFNumber::dump(ostream &out) const
+{
+ out << value();
+}
+
void PENumber::dump(ostream&out) const
{
out << value();
@@ -801,6 +806,9 @@ void PUdp::dump(ostream&out) const
/*
* $Log: pform_dump.cc,v $
+ * Revision 1.64 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.63 2000/11/11 01:52:09 steve
* change set for support of nmos, pmos, rnmos, rpmos, notif0, and notif1
* change set to correct behavior of bufif0 and bufif1
View
24 verinum.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: verinum.cc,v 1.20 2000/09/28 03:55:55 steve Exp $"
+#ident "$Id: verinum.cc,v 1.21 2000/12/10 22:01:36 steve Exp $"
#endif
# include "verinum.h"
@@ -103,6 +103,25 @@ verinum::verinum(const verinum&that, unsigned nbits)
bits_[idx] = that.bits_[idx];
}
+verinum::verinum(long that)
+: has_len_(false), has_sign_(true), string_flag_(false)
+{
+ long tmp;
+
+ tmp = that/2;
+ nbits_ = 1;
+ while ((tmp != 0) && (tmp != -1)) {
+ nbits_ += 1;
+ tmp /= 2;
+ }
+
+ bits_ = new V[nbits_];
+ for (unsigned idx = 0 ; idx < nbits_ ; idx += 1) {
+ bits_[idx] = (that & 1)? V1 : V0;
+ that /= 2;
+ }
+}
+
verinum::~verinum()
{
delete[]bits_;
@@ -531,6 +550,9 @@ verinum operator * (const verinum&left, const verinum&right)
/*
* $Log: verinum.cc,v $
+ * Revision 1.21 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.20 2000/09/28 03:55:55 steve
* handel, by truncation, verinums that are to long for long integers.
*
View
8 verinum.h
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: verinum.h,v 1.12 2000/09/27 18:28:37 steve Exp $"
+#ident "$Id: verinum.h,v 1.13 2000/12/10 22:01:36 steve Exp $"
#endif
# include <string>
@@ -42,6 +42,9 @@ class verinum {
verinum(unsigned long val, unsigned bits);
verinum(const verinum&);
+ // Create a signed number, with an unspecified number of bits.
+ explicit verinum(long val);
+
// Copy only the specified number of bits from the
// source. Also mark this number as has_len.
verinum(const verinum&, unsigned bits);
@@ -108,6 +111,9 @@ extern verinum v_not(const verinum&left);
/*
* $Log: verinum.h,v $
+ * Revision 1.13 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.12 2000/09/27 18:28:37 steve
* multiply in parameter expressions.
*
View
36 verireal.cc
@@ -17,11 +17,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: verireal.cc,v 1.2 2000/02/23 02:56:56 steve Exp $"
+#ident "$Id: verireal.cc,v 1.3 2000/12/10 22:01:36 steve Exp $"
#endif
# include "verireal.h"
# include <ctype.h>
+# include <iostream>
# include <assert.h>
verireal::verireal()
@@ -90,8 +91,41 @@ verireal::~verireal()
{
}
+long verireal::as_long(int shift) const
+{
+ long val = mant_;
+ int ex = exp10_ + shift;
+
+ while (ex < 0) {
+ long mod = val % 10;
+ val /= 10;
+ if (mod >= 5)
+ val += 1;
+
+ ex += 1;
+ }
+
+ while (ex > 0) {
+ val *= 10;
+ ex -= 1;
+ }
+
+ if (sign_)
+ return -val;
+ else
+ return val;
+}
+
+ostream& operator<< (ostream&out, const verireal&v)
+{
+ out << (v.sign_? "-" : "+") << v.mant_ << "e" << v.exp10_;
+}
+
/*
* $Log: verireal.cc,v $
+ * Revision 1.3 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.2 2000/02/23 02:56:56 steve
* Macintosh compilers do not support ident.
*
View
26 verireal.h
@@ -19,24 +19,48 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: verireal.h,v 1.2 2000/02/23 02:56:56 steve Exp $"
+#ident "$Id: verireal.h,v 1.3 2000/12/10 22:01:36 steve Exp $"
#endif
+class ostream;
+
+/*
+ * This class holds a floating point decimal number. The number is
+ * stored as an integer mantissa and a power of 10. The mantissa is an
+ * integer so that decimal numbers in the source (which are decimal)
+ * can be stored exactly.
+ */
+
class verireal {
+ friend ostream& operator<< (ostream&, const verireal&);
+
public:
explicit verireal();
explicit verireal(const char*text);
~verireal();
+ /* Return the value of the floating point number as an
+ integer, rounded as needed. The shift is the power of 10 to
+ multiply the value before calculating the result. So for
+ example if the value is 2.5 and shift == 1, the result
+ is 25. */
+ long as_long(int shift =0) const;
+
+
private:
bool sign_;
unsigned long mant_;
signed int exp10_;
};
+extern ostream& operator<< (ostream&, const verireal&);
+
/*
* $Log: verireal.h,v $
+ * Revision 1.3 2000/12/10 22:01:36 steve
+ * Support decimal constants in behavioral delays.
+ *
* Revision 1.2 2000/02/23 02:56:56 steve
* Macintosh compilers do not support ident.
*
Please sign in to comment.
Something went wrong with that request. Please try again.