Reformulate number-to-real on vvp code generator
[iverilog.git] / PGate.cc
blob058cf299861040fb1350733a9ec9b88fba87227e
1 /*
2 * Copyright (c) 1999-2004 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)
8 * any later version.
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
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: PGate.cc,v 1.18 2006/01/03 05:22:14 steve Exp $"
21 #endif
23 # include "config.h"
25 # include "PGate.h"
26 # include "PExpr.h"
27 # include "verinum.h"
28 # include <assert.h>
30 PGate::PGate(perm_string name,
31 svector<PExpr*>*pins,
32 const svector<PExpr*>*del)
33 : name_(name), pins_(pins)
35 if (del) delay_.set_delays(del);
36 str0_ = STRONG;
37 str1_ = STRONG;
40 PGate::PGate(perm_string name,
41 svector<PExpr*>*pins,
42 PExpr*del)
43 : name_(name), pins_(pins)
45 if (del) delay_.set_delay(del);
46 str0_ = STRONG;
47 str1_ = STRONG;
50 PGate::PGate(perm_string name, svector<PExpr*>*pins)
51 : name_(name), pins_(pins)
53 str0_ = STRONG;
54 str1_ = STRONG;
57 PGate::~PGate()
61 PGate::strength_t PGate::strength0() const
63 return str0_;
66 void PGate::strength0(PGate::strength_t s)
68 str0_ = s;
71 PGate::strength_t PGate::strength1() const
73 return str1_;
76 void PGate::strength1(PGate::strength_t s)
78 str1_ = s;
81 void PGate::elaborate_scope(Design*, NetScope*) const
86 * This method is used during elaboration to calculate the
87 * rise/fall/decay times for the gate. These values were set in pform
88 * by the constructor, so here I evaluate the expression in the given
89 * design context and save the calculated delays into the output
90 * parameters. This method understands how to handle the different
91 * numbers of expressions.
94 void PGate::eval_delays(Design*des, NetScope*scope,
95 NetExpr*&rise_expr,
96 NetExpr*&fall_expr,
97 NetExpr*&decay_expr,
98 bool as_net_flag) const
100 delay_.eval_delays(des, scope,
101 rise_expr, fall_expr, decay_expr,
102 as_net_flag);
105 void PGate::eval_delays(Design*des, NetScope*scope,
106 unsigned long&rise_time,
107 unsigned long&fall_time,
108 unsigned long&decay_time) const
110 NetExpr*rise_expr, *fall_expr, *decay_expr;
111 delay_.eval_delays(des, scope, rise_expr, fall_expr, decay_expr);
113 if (rise_expr == 0) {
114 rise_time = 0;
115 fall_time = 0;
116 decay_time = 0;
119 if (NetEConst*tmp = dynamic_cast<NetEConst*> (rise_expr)) {
120 rise_time = tmp->value().as_ulong();
122 } else {
123 cerr << get_line() << ": error: Delay expressions must be "
124 << "constant here." << endl;
125 cerr << get_line() << ": : Cannot calculate "
126 << *rise_expr << endl;
127 des->errors += 1;
128 rise_time = 0;
131 if (NetEConst*tmp = dynamic_cast<NetEConst*> (fall_expr)) {
132 fall_time = tmp->value().as_ulong();
134 } else {
135 if (fall_expr != rise_expr) {
136 cerr << get_line() << ": error: Delay expressions must be "
137 << "constant here." << endl;
138 cerr << get_line() << ": : Cannot calculate "
139 << *rise_expr << endl;
141 des->errors += 1;
142 fall_time = 0;
145 if (NetEConst*tmp = dynamic_cast<NetEConst*> (decay_expr)) {
146 decay_time = tmp->value().as_ulong();
148 } else {
149 cerr << get_line() << ": error: Delay expressions must be "
150 << "constant here." << endl;
151 cerr << get_line() << ": : Cannot calculate "
152 << *rise_expr << endl;
153 des->errors += 1;
154 decay_time = 0;
158 PGAssign::PGAssign(svector<PExpr*>*pins)
159 : PGate(perm_string(), pins)
161 assert(pins->count() == 2);
164 PGAssign::PGAssign(svector<PExpr*>*pins, svector<PExpr*>*dels)
165 : PGate(perm_string(), pins, dels)
167 assert(pins->count() == 2);
170 PGAssign::~PGAssign()
174 PGBuiltin::PGBuiltin(Type t, perm_string name,
175 svector<PExpr*>*pins,
176 svector<PExpr*>*del)
177 : PGate(name, pins, del), type_(t), msb_(0), lsb_(0)
181 PGBuiltin::PGBuiltin(Type t, perm_string name,
182 svector<PExpr*>*pins,
183 PExpr*del)
184 : PGate(name, pins, del), type_(t), msb_(0), lsb_(0)
189 PGBuiltin::~PGBuiltin()
193 void PGBuiltin::set_range(PExpr*msb, PExpr*lsb)
195 assert(msb_ == 0);
196 assert(lsb_ == 0);
198 msb_ = msb;
199 lsb_ = lsb;
202 PGModule::PGModule(perm_string type, perm_string name, svector<PExpr*>*pins)
203 : PGate(name, pins), overrides_(0), pins_(0),
204 npins_(0), parms_(0), nparms_(0), msb_(0), lsb_(0)
206 type_ = type;
209 PGModule::PGModule(perm_string type, perm_string name,
210 named<PExpr*>*pins, unsigned npins)
211 : PGate(name, 0), overrides_(0), pins_(pins),
212 npins_(npins), parms_(0), nparms_(0), msb_(0), lsb_(0)
214 type_ = type;
217 PGModule::~PGModule()
221 void PGModule::set_parameters(svector<PExpr*>*o)
223 assert(overrides_ == 0);
224 overrides_ = o;
227 void PGModule::set_parameters(named<PExpr*>*pa, unsigned npa)
229 assert(parms_ == 0);
230 assert(overrides_ == 0);
231 parms_ = pa;
232 nparms_ = npa;
235 void PGModule::set_range(PExpr*msb, PExpr*lsb)
237 assert(msb_ == 0);
238 assert(lsb_ == 0);
240 msb_ = msb;
241 lsb_ = lsb;
244 perm_string PGModule::get_type()
246 return type_;
250 * $Log: PGate.cc,v $
251 * Revision 1.18 2006/01/03 05:22:14 steve
252 * Handle complex net node delays.
254 * Revision 1.17 2006/01/02 05:33:19 steve
255 * Node delays can be more general expressions in structural contexts.
257 * Revision 1.16 2004/02/18 17:11:54 steve
258 * Use perm_strings for named langiage items.
260 * Revision 1.15 2003/03/06 04:37:12 steve
261 * lex_strings.add module names earlier.
263 * Revision 1.14 2002/08/12 01:34:58 steve
264 * conditional ident string using autoconfig.
266 * Revision 1.13 2001/11/22 06:20:59 steve
267 * Use NetScope instead of string for scope path.
269 * Revision 1.12 2001/10/21 00:42:47 steve
270 * Module types in pform are char* instead of string.
272 * Revision 1.11 2001/10/19 01:55:32 steve
273 * Method to get the type_ member
275 * Revision 1.10 2001/07/25 03:10:48 steve
276 * Create a config.h.in file to hold all the config
277 * junk, and support gcc 3.0. (Stephan Boettcher)
279 * Revision 1.9 2000/05/06 15:41:56 steve
280 * Carry assignment strength to pform.
282 * Revision 1.8 2000/03/08 04:36:53 steve
283 * Redesign the implementation of scopes and parameters.
284 * I now generate the scopes and notice the parameters
285 * in a separate pass over the pform. Once the scopes
286 * are generated, I can process overrides and evalutate
287 * paremeters before elaboration begins.
289 * Revision 1.7 2000/02/23 02:56:53 steve
290 * Macintosh compilers do not support ident.
292 * Revision 1.6 2000/02/18 05:15:02 steve
293 * Catch module instantiation arrays.
295 * Revision 1.5 1999/09/14 01:50:35 steve
296 * Handle gates without delays.
298 * Revision 1.4 1999/09/04 19:11:46 steve
299 * Add support for delayed non-blocking assignments.
301 * Revision 1.3 1999/08/01 21:18:55 steve
302 * elaborate rise/fall/decay for continuous assign.
304 * Revision 1.2 1999/08/01 16:34:50 steve
305 * Parse and elaborate rise/fall/decay times
306 * for gates, and handle the rules for partial
307 * lists of times.
309 * Revision 1.1 1999/02/15 02:06:15 steve
310 * Elaborate gate ranges.