2 * Copyright (c) 1999-2008 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
32 for (unsigned idx
= 0 ; idx
< 3 ; idx
+= 1)
39 for (unsigned idx
= 0 ; idx
< 3 ; idx
+= 1)
44 void PDelays::set_delay(PExpr
*del
)
47 assert(delay_
[0] == 0);
53 void PDelays::set_delays(const svector
<PExpr
*>*del
, bool df
)
56 assert(del
->count() <= 3);
57 for (unsigned idx
= 0 ; idx
< del
->count() ; idx
+= 1)
58 delay_
[idx
] = (*del
)[idx
];
63 static NetExpr
*calculate_val(Design
*des
, NetScope
*scope
, const PExpr
*expr
)
66 NetExpr
*dex
= expr
->elaborate_expr(des
, scope
, -1, false);
69 /* If the delay expression is a real constant or vector
70 constant, then evaluate it, scale it to the local time
71 units, and return an adjusted value. */
73 if (NetECReal
*tmp
= dynamic_cast<NetECReal
*>(dex
)) {
74 verireal fn
= tmp
->value();
76 int shift
= scope
->time_unit() - des
->get_precision();
77 long delay
= fn
.as_long(shift
);
82 NetEConst
*tmp2
= new NetEConst(verinum(delay
));
83 tmp2
->set_line(*expr
);
88 if (NetEConst
*tmp
= dynamic_cast<NetEConst
*>(dex
)) {
89 verinum fn
= tmp
->value();
92 des
->scale_to_precision(fn
.as_ulong(), scope
);
95 NetEConst
*tmp2
= new NetEConst(verinum(delay
));
96 tmp2
->set_line(*expr
);
100 /* Oops, cannot evaluate down to a constant. */
104 static NetExpr
* make_delay_nets(Design
*des
, NetExpr
*expr
)
106 if (dynamic_cast<NetESignal
*> (expr
))
109 if (dynamic_cast<NetEConst
*> (expr
))
112 NetNet
*sig
= expr
->synthesize(des
);
114 cerr
<< expr
->get_fileline() << ": error: Expression " << *expr
115 << " is not suitable for delay expression." << endl
;
119 expr
= new NetESignal(sig
);
123 void PDelays::eval_delays(Design
*des
, NetScope
*scope
,
127 bool as_nets_flag
) const
133 rise_time
= calculate_val(des
, scope
, delay_
[0]);
135 rise_time
= make_delay_nets(des
, rise_time
);
138 fall_time
= calculate_val(des
, scope
, delay_
[1]);
140 fall_time
= make_delay_nets(des
, fall_time
);
143 decay_time
= calculate_val(des
, scope
, delay_
[2]);
145 decay_time
= make_delay_nets(des
, decay_time
);
148 if (rise_time
< fall_time
)
149 decay_time
= rise_time
;
151 decay_time
= fall_time
;
154 assert(delay_
[2] == 0);
155 fall_time
= rise_time
;
156 decay_time
= rise_time
;