2 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: PDelays.cc,v 1.15 2006/07/08 21:48:46 steve Exp $"
34 for (unsigned idx
= 0 ; idx
< 3 ; idx
+= 1)
41 for (unsigned idx
= 0 ; idx
< 3 ; idx
+= 1)
46 void PDelays::set_delay(PExpr
*del
)
49 assert(delay_
[0] == 0);
55 void PDelays::set_delays(const svector
<PExpr
*>*del
, bool df
)
58 assert(del
->count() <= 3);
59 for (unsigned idx
= 0 ; idx
< del
->count() ; idx
+= 1)
60 delay_
[idx
] = (*del
)[idx
];
65 static NetExpr
*calculate_val(Design
*des
, NetScope
*scope
, const PExpr
*expr
)
68 NetExpr
*dex
= expr
->elaborate_expr(des
, scope
, -1, false);
69 if (NetExpr
*tmp
= dex
->eval_tree()) {
74 /* If the delay expression is a real constant or vector
75 constant, then evaluate it, scale it to the local time
76 units, and return an adjusted value. */
78 if (NetECReal
*tmp
= dynamic_cast<NetECReal
*>(dex
)) {
79 verireal fn
= tmp
->value();
81 int shift
= scope
->time_unit() - des
->get_precision();
82 long delay
= fn
.as_long(shift
);
87 NetEConst
*tmp2
= new NetEConst(verinum(delay
));
88 tmp2
->set_line(*expr
);
93 if (NetEConst
*tmp
= dynamic_cast<NetEConst
*>(dex
)) {
94 verinum fn
= tmp
->value();
97 des
->scale_to_precision(fn
.as_ulong(), scope
);
100 NetEConst
*tmp2
= new NetEConst(verinum(delay
));
101 tmp2
->set_line(*expr
);
105 /* Oops, cannot evaluate down to a constant. */
109 static NetExpr
* make_delay_nets(Design
*des
, NetExpr
*expr
)
111 if (dynamic_cast<NetESignal
*> (expr
))
114 if (dynamic_cast<NetEConst
*> (expr
))
117 NetNet
*sig
= expr
->synthesize(des
);
119 cerr
<< expr
->get_line() << ": error: Expression " << *expr
120 << " is not suitable for delay expression." << endl
;
124 expr
= new NetESignal(sig
);
128 void PDelays::eval_delays(Design
*des
, NetScope
*scope
,
132 bool as_nets_flag
) const
138 rise_time
= calculate_val(des
, scope
, delay_
[0]);
140 rise_time
= make_delay_nets(des
, rise_time
);
143 fall_time
= calculate_val(des
, scope
, delay_
[1]);
145 fall_time
= make_delay_nets(des
, fall_time
);
148 decay_time
= calculate_val(des
, scope
, delay_
[2]);
150 decay_time
= make_delay_nets(des
, decay_time
);
153 if (rise_time
< fall_time
)
154 decay_time
= rise_time
;
156 decay_time
= fall_time
;
159 assert(delay_
[2] == 0);
160 fall_time
= rise_time
;
161 decay_time
= rise_time
;
171 * $Log: PDelays.cc,v $
172 * Revision 1.15 2006/07/08 21:48:46 steve
173 * Handle real valued literals in net contexts.
175 * Revision 1.14 2006/06/02 04:48:49 steve
176 * Make elaborate_expr methods aware of the width that the context
177 * requires of it. In the process, fix sizing of the width of unary
178 * minus is context determined sizes.
180 * Revision 1.13 2006/01/03 05:22:14 steve
181 * Handle complex net node delays.
183 * Revision 1.12 2006/01/02 05:33:19 steve
184 * Node delays can be more general expressions in structural contexts.
186 * Revision 1.11 2003/06/21 01:21:42 steve
187 * Harmless fixup of warnings.
189 * Revision 1.10 2003/02/08 19:49:21 steve
190 * Calculate delay statement delays using elaborated
191 * expressions instead of pre-elaborated expression
194 * Remove the eval_pexpr methods from PExpr.
196 * Revision 1.9 2002/08/12 01:34:58 steve
197 * conditional ident string using autoconfig.
199 * Revision 1.8 2001/12/29 20:19:31 steve
200 * Do not delete delay expressions of UDP instances.
202 * Revision 1.7 2001/11/22 06:20:59 steve
203 * Use NetScope instead of string for scope path.
205 * Revision 1.6 2001/11/07 04:01:59 steve
206 * eval_const uses scope instead of a string path.
208 * Revision 1.5 2001/07/25 03:10:48 steve
209 * Create a config.h.in file to hold all the config
210 * junk, and support gcc 3.0. (Stephan Boettcher)
212 * Revision 1.4 2001/01/20 02:15:50 steve
213 * apologize for not supporting non-constant delays.
215 * Revision 1.3 2001/01/14 23:04:55 steve
216 * Generalize the evaluation of floating point delays, and
217 * get it working with delay assignment statements.
219 * Allow parameters to be referenced by hierarchical name.
221 * Revision 1.2 2000/02/23 02:56:53 steve
222 * Macintosh compilers do not support ident.
224 * Revision 1.1 1999/09/04 19:11:46 steve
225 * Add support for delayed non-blocking assignments.