Merge branch 'master' into verilog-ams
[sverilog.git] / PGate.cc
blob7cacffe433d97d6baaab7541d43467a939440115
1 /*
2 * Copyright (c) 1999-2007 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
20 # include "config.h"
22 # include "PGate.h"
23 # include "PExpr.h"
24 # include "verinum.h"
25 # include <assert.h>
27 PGate::PGate(perm_string name,
28 svector<PExpr*>*pins,
29 const svector<PExpr*>*del)
30 : name_(name), pins_(pins)
32 if (del) delay_.set_delays(del);
33 str0_ = STRONG;
34 str1_ = STRONG;
37 PGate::PGate(perm_string name,
38 svector<PExpr*>*pins,
39 PExpr*del)
40 : name_(name), pins_(pins)
42 if (del) delay_.set_delay(del);
43 str0_ = STRONG;
44 str1_ = STRONG;
47 PGate::PGate(perm_string name, svector<PExpr*>*pins)
48 : name_(name), pins_(pins)
50 str0_ = STRONG;
51 str1_ = STRONG;
54 PGate::~PGate()
58 PGate::strength_t PGate::strength0() const
60 return str0_;
63 void PGate::strength0(PGate::strength_t s)
65 str0_ = s;
68 PGate::strength_t PGate::strength1() const
70 return str1_;
73 void PGate::strength1(PGate::strength_t s)
75 str1_ = s;
78 void PGate::elaborate_scope(Design*, NetScope*) const
83 * This method is used during elaboration to calculate the
84 * rise/fall/decay times for the gate. These values were set in pform
85 * by the constructor, so here I evaluate the expression in the given
86 * design context and save the calculated delays into the output
87 * parameters. This method understands how to handle the different
88 * numbers of expressions.
91 void PGate::eval_delays(Design*des, NetScope*scope,
92 NetExpr*&rise_expr,
93 NetExpr*&fall_expr,
94 NetExpr*&decay_expr,
95 bool as_net_flag) const
97 delay_.eval_delays(des, scope,
98 rise_expr, fall_expr, decay_expr,
99 as_net_flag);
102 void PGate::eval_delays(Design*des, NetScope*scope,
103 unsigned long&rise_time,
104 unsigned long&fall_time,
105 unsigned long&decay_time) const
107 NetExpr*rise_expr, *fall_expr, *decay_expr;
108 delay_.eval_delays(des, scope, rise_expr, fall_expr, decay_expr);
110 if (rise_expr == 0) {
111 rise_time = 0;
112 fall_time = 0;
113 decay_time = 0;
116 if (NetEConst*tmp = dynamic_cast<NetEConst*> (rise_expr)) {
117 rise_time = tmp->value().as_ulong();
119 } else {
120 cerr << get_fileline() << ": error: Delay expressions must be "
121 << "constant here." << endl;
122 cerr << get_fileline() << ": : Cannot calculate "
123 << *rise_expr << endl;
124 des->errors += 1;
125 rise_time = 0;
128 if (NetEConst*tmp = dynamic_cast<NetEConst*> (fall_expr)) {
129 fall_time = tmp->value().as_ulong();
131 } else {
132 if (fall_expr != rise_expr) {
133 cerr << get_fileline() << ": error: Delay expressions must be "
134 << "constant here." << endl;
135 cerr << get_fileline() << ": : Cannot calculate "
136 << *rise_expr << endl;
138 des->errors += 1;
139 fall_time = 0;
142 if (NetEConst*tmp = dynamic_cast<NetEConst*> (decay_expr)) {
143 decay_time = tmp->value().as_ulong();
145 } else {
146 cerr << get_fileline() << ": error: Delay expressions must be "
147 << "constant here." << endl;
148 cerr << get_fileline() << ": : Cannot calculate "
149 << *rise_expr << endl;
150 des->errors += 1;
151 decay_time = 0;
155 PGAssign::PGAssign(svector<PExpr*>*pins)
156 : PGate(perm_string(), pins)
158 assert(pins->count() == 2);
161 PGAssign::PGAssign(svector<PExpr*>*pins, svector<PExpr*>*dels)
162 : PGate(perm_string(), pins, dels)
164 assert(pins->count() == 2);
167 PGAssign::~PGAssign()
171 PGBuiltin::PGBuiltin(Type t, perm_string name,
172 svector<PExpr*>*pins,
173 svector<PExpr*>*del)
174 : PGate(name, pins, del), type_(t), msb_(0), lsb_(0)
178 PGBuiltin::PGBuiltin(Type t, perm_string name,
179 svector<PExpr*>*pins,
180 PExpr*del)
181 : PGate(name, pins, del), type_(t), msb_(0), lsb_(0)
186 PGBuiltin::~PGBuiltin()
190 void PGBuiltin::set_range(PExpr*msb, PExpr*lsb)
192 assert(msb_ == 0);
193 assert(lsb_ == 0);
195 msb_ = msb;
196 lsb_ = lsb;
199 PGModule::PGModule(perm_string type, perm_string name, svector<PExpr*>*pins)
200 : PGate(name, pins), overrides_(0), pins_(0),
201 npins_(0), parms_(0), nparms_(0), msb_(0), lsb_(0)
203 type_ = type;
206 PGModule::PGModule(perm_string type, perm_string name,
207 named<PExpr*>*pins, unsigned npins)
208 : PGate(name, 0), overrides_(0), pins_(pins),
209 npins_(npins), parms_(0), nparms_(0), msb_(0), lsb_(0)
211 type_ = type;
214 PGModule::~PGModule()
218 void PGModule::set_parameters(svector<PExpr*>*o)
220 assert(overrides_ == 0);
221 overrides_ = o;
224 void PGModule::set_parameters(named<PExpr*>*pa, unsigned npa)
226 assert(parms_ == 0);
227 assert(overrides_ == 0);
228 parms_ = pa;
229 nparms_ = npa;
232 void PGModule::set_range(PExpr*msb, PExpr*lsb)
234 assert(msb_ == 0);
235 assert(lsb_ == 0);
237 msb_ = msb;
238 lsb_ = lsb;
241 perm_string PGModule::get_type()
243 return type_;