forked from steveicarus/iverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_assign.cc
384 lines (319 loc) · 7.23 KB
/
net_assign.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
* Copyright (c) 2000-2021 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "config.h"
# include "netlist.h"
# include "netclass.h"
# include "netdarray.h"
# include "netparray.h"
# include "netenum.h"
# include "ivl_assert.h"
using namespace std;
/*
* NetAssign
*/
unsigned count_lval_width(const NetAssign_*idx)
{
unsigned wid = 0;
while (idx) {
wid += idx->lwidth();
idx = idx->more;
}
return wid;
}
NetAssign_::NetAssign_(NetAssign_*n)
: nest_(n), sig_(0), word_(0), base_(0), sel_type_(IVL_SEL_OTHER)
{
lwid_ = 0;
more = 0;
signed_ = false;
turn_sig_to_wire_on_release_ = false;
}
NetAssign_::NetAssign_(NetNet*s)
: nest_(0), sig_(s), word_(0), base_(0), sel_type_(IVL_SEL_OTHER)
{
lwid_ = sig_->vector_width();
sig_->incr_lref();
more = 0;
signed_ = false;
turn_sig_to_wire_on_release_ = false;
}
NetAssign_::~NetAssign_()
{
if (sig_) {
sig_->decr_lref();
if (turn_sig_to_wire_on_release_ && sig_->peek_lref() == 0)
sig_->type(NetNet::WIRE);
}
ivl_assert(*this, more == 0 );
delete word_;
}
string NetAssign_::get_fileline() const
{
if (sig_) return sig_->get_fileline();
else return nest_->get_fileline();
}
NetScope*NetAssign_::scope() const
{
if (sig_) return sig_->scope();
else return nest_->scope();
}
void NetAssign_::set_word(NetExpr*r)
{
ivl_assert(*this, word_ == 0);
word_ = r;
}
NetExpr* NetAssign_::word()
{
return word_;
}
const NetExpr* NetAssign_::word() const
{
return word_;
}
const NetExpr* NetAssign_::get_base() const
{
return base_;
}
ivl_select_type_t NetAssign_::select_type() const
{
return sel_type_;
}
unsigned NetAssign_::lwidth() const
{
// This gets me the type of the l-value expression, down to
// the type of the member. If this returns nil, then resort to
// the lwid_ value.
ivl_type_t ntype = net_type();
if (ntype)
return ntype->packed_width();
return lwid_;
}
ivl_variable_type_t NetAssign_::expr_type() const
{
ivl_type_t ntype = net_type();
if (ntype)
return ntype->base_type();
ivl_assert(*this, sig_);
return sig_->data_type();
}
ivl_type_t NetAssign_::net_type() const
{
// This is a concatenation, it does not have a type
if (more)
return nullptr;
// Selected sub-vector can have its own data type
if (base_)
return part_data_type_;
ivl_type_t ntype;
if (nest_) {
ntype = nest_->net_type();
} else {
ivl_assert(*this, sig_);
if (sig_->unpacked_dimensions() && !word_)
ntype = sig_->array_type();
else
ntype = sig_->net_type();
}
if (!member_.nil()) {
const netclass_t *class_type = dynamic_cast<const netclass_t*>(ntype);
ivl_assert(*this, class_type);
ntype = class_type->get_prop_type(member_idx_);
}
if (word_) {
if (const netdarray_t *darray = dynamic_cast<const netdarray_t*>(ntype))
ntype = darray->element_type();
else if (const netuarray_t *uarray = dynamic_cast<const netuarray_t*>(ntype))
ntype = uarray->element_type();
}
return ntype;
}
perm_string NetAssign_::name() const
{
if (sig_) {
return sig_->name();
} else {
return perm_string::literal("");
}
}
NetNet* NetAssign_::sig() const
{
ivl_assert(*this, sig_ ? nest_ == 0 : nest_ != 0);
return sig_;
}
void NetAssign_::set_part(NetExpr*base, unsigned wid,
ivl_select_type_t sel_type)
{
base_ = base;
lwid_ = wid;
sel_type_ = sel_type;
}
void NetAssign_::set_part(NetExpr*base, ivl_type_t data_type)
{
part_data_type_ = data_type;
set_part(base, part_data_type_->packed_width());
}
void NetAssign_::set_property(const perm_string&mname, unsigned idx)
{
member_ = mname;
member_idx_ = idx;
}
/*
*/
void NetAssign_::turn_sig_to_wire_on_release()
{
turn_sig_to_wire_on_release_ = true;
}
NetAssignBase::NetAssignBase(NetAssign_*lv, NetExpr*rv)
: lval_(lv), rval_(rv), delay_(0)
{
}
NetAssignBase::~NetAssignBase()
{
delete rval_;
while (lval_) {
NetAssign_*tmp = lval_;
lval_ = tmp->more;
tmp->more = 0;
delete tmp;
}
}
NetExpr* NetAssignBase::rval()
{
return rval_;
}
const NetExpr* NetAssignBase::rval() const
{
return rval_;
}
void NetAssignBase::set_rval(NetExpr*r)
{
delete rval_;
rval_ = r;
}
NetAssign_* NetAssignBase::l_val(unsigned idx)
{
NetAssign_*cur = lval_;
while (idx > 0) {
if (cur == 0)
return cur;
cur = cur->more;
idx -= 1;
}
ivl_assert(*this, idx == 0);
return cur;
}
const NetAssign_* NetAssignBase::l_val(unsigned idx) const
{
const NetAssign_*cur = lval_;
while (idx > 0) {
if (cur == 0)
return cur;
cur = cur->more;
idx -= 1;
}
ivl_assert(*this, idx == 0);
return cur;
}
unsigned NetAssignBase::l_val_count() const
{
const NetAssign_*cur = lval_;
unsigned cnt = 0;
while (cur) {
cnt += 1;
cur = cur->more;
}
return cnt;
}
unsigned NetAssignBase::lwidth() const
{
unsigned sum = 0;
for (NetAssign_*cur = lval_ ; cur ; cur = cur->more)
sum += cur->lwidth();
return sum;
}
void NetAssignBase::set_delay(NetExpr*expr)
{
delay_ = expr;
}
const NetExpr* NetAssignBase::get_delay() const
{
return delay_;
}
NetAssign::NetAssign(NetAssign_*lv, NetExpr*rv)
: NetAssignBase(lv, rv), op_(0)
{
}
NetAssign::NetAssign(NetAssign_*lv, char op, NetExpr*rv)
: NetAssignBase(lv, rv), op_(op)
{
}
NetAssign::~NetAssign()
{
}
NetAssignNB::NetAssignNB(NetAssign_*lv, NetExpr*rv, NetEvWait*ev, NetExpr*cnt)
: NetAssignBase(lv, rv)
{
event_ = ev;
count_ = cnt;
}
NetAssignNB::~NetAssignNB()
{
}
unsigned NetAssignNB::nevents() const
{
if (event_) return event_->nevents();
return 0;
}
const NetEvent*NetAssignNB::event(unsigned idx) const
{
if (event_) return event_->event(idx);
return 0;
}
const NetExpr*NetAssignNB::get_count() const
{
return count_;
}
NetCAssign::NetCAssign(NetAssign_*lv, NetExpr*rv)
: NetAssignBase(lv, rv)
{
}
NetCAssign::~NetCAssign()
{
}
NetDeassign::NetDeassign(NetAssign_*l)
: NetAssignBase(l, 0)
{
}
NetDeassign::~NetDeassign()
{
}
NetForce::NetForce(NetAssign_*lv, NetExpr*rv)
: NetAssignBase(lv, rv)
{
}
NetForce::~NetForce()
{
}
NetRelease::NetRelease(NetAssign_*l)
: NetAssignBase(l, 0)
{
}
NetRelease::~NetRelease()
{
}