1 /*
2 * Copyright (c) 1999-2019 Stephen Williams (steve@icarus.com)
3 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 # include "config.h"
21
22 # include "netlist.h"
23 # include <cassert>
24 # include <cstdlib>
25 # include "ivl_assert.h"
26
dup_expr() const27 NetEAccess* NetEAccess::dup_expr() const
28 {
29 NetEAccess*tmp = new NetEAccess(branch_, nature_);
30 ivl_assert(*this, tmp);
31 tmp->set_line(*this);
32 return tmp;
33 }
34
dup_expr() const35 NetEArrayPattern*NetEArrayPattern::dup_expr() const
36 {
37 vector<NetExpr*>tmp (items_.size());
38 for (size_t idx = 0 ; idx < tmp.size() ; idx += 1)
39 tmp[idx] = items_[idx]->dup_expr();
40
41 NetEArrayPattern*res = new NetEArrayPattern(net_type(), tmp);
42 res->set_line(*this);
43 return res;
44 }
45
dup_expr() const46 NetEBinary* NetEBinary::dup_expr() const
47 {
48 ivl_assert(*this, 0);
49 return 0;
50 }
51
dup_expr() const52 NetEBAdd* NetEBAdd::dup_expr() const
53 {
54 NetEBAdd*tmp = new NetEBAdd(op_, left_->dup_expr(), right_->dup_expr(),
55 expr_width(), has_sign());
56 ivl_assert(*this, tmp);
57 tmp->set_line(*this);
58 return tmp;
59 }
60
dup_expr() const61 NetEBBits* NetEBBits::dup_expr() const
62 {
63 NetEBBits*tmp = new NetEBBits(op_, left_->dup_expr(), right_->dup_expr(),
64 expr_width(), has_sign());
65 ivl_assert(*this, tmp);
66 tmp->set_line(*this);
67 return tmp;
68 }
69
dup_expr() const70 NetEBComp* NetEBComp::dup_expr() const
71 {
72 NetEBComp*tmp = new NetEBComp(op_, left_->dup_expr(), right_->dup_expr());
73 ivl_assert(*this, tmp);
74 tmp->set_line(*this);
75 return tmp;
76 }
77
dup_expr() const78 NetEBDiv* NetEBDiv::dup_expr() const
79 {
80 NetEBDiv*tmp = new NetEBDiv(op_, left_->dup_expr(), right_->dup_expr(),
81 expr_width(), has_sign());
82 ivl_assert(*this, tmp);
83 tmp->set_line(*this);
84 return tmp;
85 }
86
dup_expr() const87 NetEBLogic* NetEBLogic::dup_expr() const
88 {
89 NetEBLogic*tmp = new NetEBLogic(op_, left_->dup_expr(), right_->dup_expr());
90 ivl_assert(*this, tmp);
91 tmp->set_line(*this);
92 return tmp;
93 }
94
dup_expr() const95 NetEBMult* NetEBMult::dup_expr() const
96 {
97 NetEBMult*tmp = new NetEBMult(op_, left_->dup_expr(), right_->dup_expr(),
98 expr_width(), has_sign());
99 ivl_assert(*this, tmp);
100 tmp->set_line(*this);
101 return tmp;
102 }
103
dup_expr() const104 NetEBPow* NetEBPow::dup_expr() const
105 {
106 NetEBPow*tmp = new NetEBPow(op_, left_->dup_expr(), right_->dup_expr(),
107 expr_width(), has_sign());
108 ivl_assert(*this, tmp);
109 tmp->set_line(*this);
110 return tmp;
111 }
112
dup_expr() const113 NetEBShift* NetEBShift::dup_expr() const
114 {
115 NetEBShift*tmp = new NetEBShift(op_, left_->dup_expr(), right_->dup_expr(),
116 expr_width(), has_sign());
117 ivl_assert(*this, tmp);
118 tmp->set_line(*this);
119 return tmp;
120 }
121
dup_expr() const122 NetEConcat* NetEConcat::dup_expr() const
123 {
124 NetEConcat*dup = new NetEConcat(parms_.size(), repeat_, expr_type_);
125 ivl_assert(*this, dup);
126 dup->set_line(*this);
127 for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1)
128 if (parms_[idx]) {
129 NetExpr*tmp = parms_[idx]->dup_expr();
130 ivl_assert(*this, tmp);
131 dup->parms_[idx] = tmp;
132 }
133
134 dup->expr_width(expr_width());
135
136 return dup;
137 }
138
dup_expr() const139 NetEConst* NetEConst::dup_expr() const
140 {
141 NetEConst*tmp = new NetEConst(value_);
142 ivl_assert(*this, tmp);
143 tmp->set_line(*this);
144 return tmp;
145 }
146
dup_expr() const147 NetEConstEnum* NetEConstEnum::dup_expr() const
148 {
149 NetEConstEnum*tmp = new NetEConstEnum(scope_, name_, enum_set_, value());
150 ivl_assert(*this, tmp);
151 tmp->set_line(*this);
152 return tmp;
153 }
154
dup_expr() const155 NetEConstParam* NetEConstParam::dup_expr() const
156 {
157 NetEConstParam*tmp = new NetEConstParam(scope_, name_, value());
158 ivl_assert(*this, tmp);
159 tmp->set_line(*this);
160 return tmp;
161 }
162
dup_expr() const163 NetECReal* NetECReal::dup_expr() const
164 {
165 NetECReal*tmp = new NetECReal(value_);
166 ivl_assert(*this, tmp);
167 tmp->set_line(*this);
168 return tmp;
169 }
170
dup_expr() const171 NetECRealParam* NetECRealParam::dup_expr() const
172 {
173 NetECRealParam*tmp = new NetECRealParam(scope_, name_, value());
174 ivl_assert(*this, tmp);
175 tmp->set_line(*this);
176 return tmp;
177 }
178
dup_expr() const179 NetEEvent* NetEEvent::dup_expr() const
180 {
181 ivl_assert(*this, 0);
182 return 0;
183 }
184
dup_expr() const185 NetELast* NetELast::dup_expr() const
186 {
187 NetELast*tmp = new NetELast(sig_);
188 ivl_assert(*this, tmp);
189 tmp->set_line(*this);
190 return tmp;
191 }
192
dup_expr() const193 NetENetenum* NetENetenum::dup_expr() const
194 {
195 ivl_assert(*this, 0);
196 return 0;
197 }
198
dup_expr() const199 NetENew* NetENew::dup_expr() const
200 {
201 ivl_assert(*this, 0);
202 return 0;
203 }
204
dup_expr() const205 NetENull* NetENull::dup_expr() const
206 {
207 ivl_assert(*this, 0);
208 return 0;
209 }
210
dup_expr() const211 NetEProperty* NetEProperty::dup_expr() const
212 {
213 ivl_assert(*this, 0);
214 return 0;
215 }
216
dup_expr() const217 NetEScope* NetEScope::dup_expr() const
218 {
219 ivl_assert(*this, 0);
220 return 0;
221 }
222
dup_expr() const223 NetESelect* NetESelect::dup_expr() const
224 {
225 NetESelect*tmp = new NetESelect(expr_->dup_expr(),
226 base_? base_->dup_expr() : 0,
227 expr_width(), sel_type_);
228 ivl_assert(*this, tmp);
229 tmp->cast_signed(has_sign());
230 tmp->set_line(*this);
231 return tmp;
232 }
233
dup_expr() const234 NetESFunc* NetESFunc::dup_expr() const
235 {
236 NetESFunc*tmp = new NetESFunc(name_, type_, expr_width(), nparms(), is_overridden_);
237 ivl_assert(*this, tmp);
238
239 tmp->cast_signed(has_sign());
240 for (unsigned idx = 0 ; idx < nparms() ; idx += 1) {
241 ivl_assert(*this, parm(idx));
242 tmp->parm(idx, parm(idx)->dup_expr());
243 }
244
245 tmp->set_line(*this);
246 return tmp;
247 }
248
dup_expr() const249 NetEShallowCopy* NetEShallowCopy::dup_expr() const
250 {
251 ivl_assert(*this, 0);
252 return 0;
253 }
254
dup_expr() const255 NetESignal* NetESignal::dup_expr() const
256 {
257 NetESignal*tmp = new NetESignal(net_, word_);
258 ivl_assert(*this, tmp);
259 tmp->expr_width(expr_width());
260 tmp->cast_signed(has_sign());
261 tmp->set_line(*this);
262 return tmp;
263 }
264
dup_expr() const265 NetETernary* NetETernary::dup_expr() const
266 {
267 NetETernary*tmp = new NetETernary(cond_->dup_expr(),
268 true_val_->dup_expr(),
269 false_val_->dup_expr(),
270 expr_width(),
271 has_sign());
272 ivl_assert(*this, tmp);
273 tmp->set_line(*this);
274 return tmp;
275 }
276
dup_expr() const277 NetEUFunc* NetEUFunc::dup_expr() const
278 {
279 NetEUFunc*tmp;
280 vector<NetExpr*> tmp_parms (parms_.size());
281
282 for (unsigned idx = 0 ; idx < tmp_parms.size() ; idx += 1) {
283 ivl_assert(*this, parms_[idx]);
284 tmp_parms[idx] = parms_[idx]->dup_expr();
285 }
286
287 tmp = new NetEUFunc(scope_, func_, result_sig_->dup_expr(), tmp_parms,
288 need_const_);
289
290 ivl_assert(*this, tmp);
291 tmp->set_line(*this);
292 return tmp;
293 }
294
dup_expr() const295 NetEUBits* NetEUBits::dup_expr() const
296 {
297 NetEUBits*tmp = new NetEUBits(op_, expr_->dup_expr(), expr_width(), has_sign());
298 ivl_assert(*this, tmp);
299 tmp->set_line(*this);
300 return tmp;
301 }
302
dup_expr() const303 NetEUnary* NetEUnary::dup_expr() const
304 {
305 NetEUnary*tmp = new NetEUnary(op_, expr_->dup_expr(), expr_width(), has_sign());
306 ivl_assert(*this, tmp);
307 tmp->set_line(*this);
308 return tmp;
309 }
310
dup_expr() const311 NetEUReduce* NetEUReduce::dup_expr() const
312 {
313 NetEUReduce*tmp = new NetEUReduce(op_, expr_->dup_expr());
314 ivl_assert(*this, tmp);
315 tmp->set_line(*this);
316 return tmp;
317 }
318
dup_expr() const319 NetECast* NetECast::dup_expr() const
320 {
321 NetECast*tmp = new NetECast(op_, expr_->dup_expr(), expr_width(), has_sign());
322 ivl_assert(*this, tmp);
323 tmp->set_line(*this);
324 return tmp;
325 }
326