Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 558 lines (480 sloc) 13.298 kB
30e8289 Simulate named event trigger and waits.
steve authored
1 /*
2 * Copyright (c) 2000 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 */
52bf4e6 conditional ident string using autoconfig.
steve authored
19 #ifdef HAVE_CVS_IDENT
c7d97f4 Properly evaluate scope path expressions.
steve authored
20 #ident "$Id: net_event.cc,v 1.27 2007/06/02 03:42:13 steve Exp $"
30e8289 Simulate named event trigger and waits.
steve authored
21 #endif
22
badad63 All NetObj objects have lex_string base names.
steve authored
23 # include "config.h"
24 # include "compiler.h"
30e8289 Simulate named event trigger and waits.
steve authored
25 # include "netlist.h"
26
4c67de5 Add the lex_strings string handler, and put
steve authored
27 /*
28 * NOTE: The name_ is perm-allocated by the caller.
29 */
536068b Memory and Event names use perm_string.
steve authored
30 NetEvent::NetEvent(perm_string n)
4c67de5 Add the lex_strings string handler, and put
steve authored
31 : name_(n)
30e8289 Simulate named event trigger and waits.
steve authored
32 {
33 scope_ = 0;
34 snext_ = 0;
4493e96 Finally remove the NetNEvent and NetPEvent classes,
steve authored
35 probes_ = 0;
726f7b8 Synthesis of comparator in expressions.
steve authored
36 trig_ = 0;
37 waitref_ = 0;
f1cc9d8 Support event names as expressions elements.
steve authored
38 exprref_ = 0;
c1c0168 Globally merge redundant event objects.
steve authored
39 wlist_ = 0;
30e8289 Simulate named event trigger and waits.
steve authored
40 }
41
42 NetEvent::~NetEvent()
43 {
726f7b8 Synthesis of comparator in expressions.
steve authored
44 assert(waitref_ == 0);
74c4303 Clean up unneeded NetEvent objects.
steve authored
45 if (scope_) scope_->rem_event(this);
46 while (probes_) {
47 NetEvProbe*tmp = probes_->enext_;
48 delete probes_;
ea53f2b Typo stepping ot next probe in delete.
steve authored
49 probes_ = tmp;
74c4303 Clean up unneeded NetEvent objects.
steve authored
50 }
4c67de5 Add the lex_strings string handler, and put
steve authored
51 /* name_ is lex_strings. */
30e8289 Simulate named event trigger and waits.
steve authored
52 }
53
536068b Memory and Event names use perm_string.
steve authored
54 perm_string NetEvent::name() const
30e8289 Simulate named event trigger and waits.
steve authored
55 {
56 return name_;
57 }
58
c7d97f4 Properly evaluate scope path expressions.
steve authored
59 NetScope* NetEvent::scope()
30e8289 Simulate named event trigger and waits.
steve authored
60 {
61 assert(scope_);
c7d97f4 Properly evaluate scope path expressions.
steve authored
62 return scope_;
30e8289 Simulate named event trigger and waits.
steve authored
63 }
64
a4e528f Add the ivl_event_t to ivl_target, and use that to generate
steve authored
65 const NetScope* NetEvent::scope() const
66 {
67 assert(scope_);
68 return scope_;
69 }
70
4493e96 Finally remove the NetNEvent and NetPEvent classes,
steve authored
71 unsigned NetEvent::nprobe() const
72 {
73 unsigned cnt = 0;
74 NetEvProbe*cur = probes_;
75 while (cur) {
76 cnt += 1;
77 cur = cur->enext_;
78 }
79
80 return cnt;
81 }
82
83 NetEvProbe* NetEvent::probe(unsigned idx)
84 {
85 NetEvProbe*cur = probes_;
86 while (cur && idx) {
87 cur = cur->enext_;
88 idx -= 1;
89 }
90 return cur;
91 }
92
ad8565f Add const probe method to NetEvent.
steve authored
93 const NetEvProbe* NetEvent::probe(unsigned idx) const
94 {
95 NetEvProbe*cur = probes_;
96 while (cur && idx) {
97 cur = cur->enext_;
98 idx -= 1;
99 }
100 return cur;
101 }
102
74c4303 Clean up unneeded NetEvent objects.
steve authored
103 unsigned NetEvent::ntrig() const
104 {
105 unsigned cnt = 0;
106 NetEvTrig*cur = trig_;
107 while (cur) {
108 cnt += 1;
109 cur = cur->enext_;
110 }
111
112 return cnt;
113 }
114
726f7b8 Synthesis of comparator in expressions.
steve authored
115 unsigned NetEvent::nwait() const
116 {
117 return waitref_;
118 }
119
f1cc9d8 Support event names as expressions elements.
steve authored
120 unsigned NetEvent::nexpr() const
121 {
122 return exprref_;
123 }
124
bcbd5b2 Remove limits from the similar events search.
steve authored
125 /*
126 * A "similar" event is one that has an identical non-nil set of
127 * probes.
128 */
58ec62c Rewrite find_similar_event to support doing
steve authored
129 void NetEvent::find_similar_event(list<NetEvent*>&event_list)
fd09bc3 Merge similar probes within a module.
steve authored
130 {
131 if (probes_ == 0)
58ec62c Rewrite find_similar_event to support doing
steve authored
132 return;
bcbd5b2 Remove limits from the similar events search.
steve authored
133
58ec62c Rewrite find_similar_event to support doing
steve authored
134 map<NetEvent*,unsigned> event_matches;
fd09bc3 Merge similar probes within a module.
steve authored
135
58ec62c Rewrite find_similar_event to support doing
steve authored
136 /* First, get a list of all the NetEvProbes that are connected
137 to my first probe. Then use that to create a set of
138 candidate events. These candidate events are a superset of
139 the similar events, so I will be culling this list later. */
140 list<NetEvProbe*>first_probes;
141 probes_->find_similar_probes(first_probes);
bcbd5b2 Remove limits from the similar events search.
steve authored
142
58ec62c Rewrite find_similar_event to support doing
steve authored
143 for (list<NetEvProbe*>::iterator idx = first_probes.begin()
144 ; idx != first_probes.end() ; idx ++) {
145 event_matches[ (*idx)->event() ] = 1;
146 }
fd09bc3 Merge similar probes within a module.
steve authored
147
58ec62c Rewrite find_similar_event to support doing
steve authored
148 /* Now scan the remaining probes, in each case ticking the
149 candidate event. The events that really are similar to this
150 one will turn up in every probe list. */
151 unsigned probe_count = 1;
152 for (NetEvProbe*cur = probes_->enext_ ; cur ; cur = cur->enext_) {
153 list<NetEvProbe*>similar_probes;
154 cur->find_similar_probes(similar_probes);
155
156 for (list<NetEvProbe*>::iterator idx = similar_probes.begin()
157 ; idx != similar_probes.end() ; idx ++) {
158 event_matches[ (*idx)->event() ] += 1;
159 }
fd09bc3 Merge similar probes within a module.
steve authored
160
58ec62c Rewrite find_similar_event to support doing
steve authored
161 probe_count += 1;
fd09bc3 Merge similar probes within a module.
steve authored
162 }
163
58ec62c Rewrite find_similar_event to support doing
steve authored
164 /* Now scan the candidate events. Those events that are
165 connected to all my probes (match_count[x] == probe_count)
166 are possible. If those events have the same number of
167 events, then jackpot. */
168 for (map<NetEvent*,unsigned>::iterator idx = event_matches.begin()
169 ; idx != event_matches.end() ; idx ++) {
bcbd5b2 Remove limits from the similar events search.
steve authored
170
58ec62c Rewrite find_similar_event to support doing
steve authored
171 NetEvent*tmp = (*idx).first;
bcbd5b2 Remove limits from the similar events search.
steve authored
172
58ec62c Rewrite find_similar_event to support doing
steve authored
173 if (tmp == this)
bcbd5b2 Remove limits from the similar events search.
steve authored
174 continue;
175
58ec62c Rewrite find_similar_event to support doing
steve authored
176 if ((*idx).second != probe_count)
54dab22 event find_similar should not find self.
steve authored
177 continue;
178
58ec62c Rewrite find_similar_event to support doing
steve authored
179 unsigned tcnt = 0;
180 for (NetEvProbe*cur = tmp->probes_ ; cur ; cur = cur->enext_)
181 tcnt += 1;
bcbd5b2 Remove limits from the similar events search.
steve authored
182
58ec62c Rewrite find_similar_event to support doing
steve authored
183 if (tcnt == probe_count)
184 event_list .push_back(tmp);
fd09bc3 Merge similar probes within a module.
steve authored
185 }
186
187 }
188
58ec62c Rewrite find_similar_event to support doing
steve authored
189
c1c0168 Globally merge redundant event objects.
steve authored
190 void NetEvent::replace_event(NetEvent*that)
191 {
192 while (wlist_) {
193 wlist_->obj->replace_event(this, that);
194 }
195 }
196
9b6b081 Add structure for asynchronous logic synthesis.
steve authored
197 NexusSet* NetEvent::nex_async_()
198 {
199 /* If there are behavioral trigger statements attached to me,
200 then this is not an asynchronous event. */
201 if (trig_ != 0)
202 return 0;
203
e4ae832 Clean up spurious trailing white space.
steve authored
204
9b6b081 Add structure for asynchronous logic synthesis.
steve authored
205 NexusSet*tmp = new NexusSet;
206 for (NetEvProbe*cur = probes_ ; cur != 0 ; cur = cur->enext_) {
207 if (cur->edge() != NetEvProbe::ANYEDGE) {
208 delete tmp;
209 return 0;
210 }
211
212 for (unsigned idx = 0 ; idx < cur->pin_count() ; idx += 1)
213 tmp->add(cur->pin(idx).nexus());
214
215 }
216
217 return tmp;
218 }
219
30e8289 Simulate named event trigger and waits.
steve authored
220 NetEvTrig::NetEvTrig(NetEvent*ev)
221 : event_(ev)
222 {
726f7b8 Synthesis of comparator in expressions.
steve authored
223 enext_ = event_->trig_;
224 event_->trig_ = this;
30e8289 Simulate named event trigger and waits.
steve authored
225 }
226
227 NetEvTrig::~NetEvTrig()
228 {
726f7b8 Synthesis of comparator in expressions.
steve authored
229 if (event_->trig_ == this) {
230 event_->trig_ = enext_;
231
232 } else {
233 NetEvTrig*cur = event_->trig_;
234 while (cur->enext_ != this) {
235 assert(cur->enext_);
236 cur = cur->enext_;
237 }
238
239 cur->enext_ = this->enext_;
240 }
30e8289 Simulate named event trigger and waits.
steve authored
241 }
242
243 const NetEvent* NetEvTrig::event() const
244 {
245 return event_;
246 }
247
27af95d Use perm_strings for named langiage items.
steve authored
248 NetEvProbe::NetEvProbe(NetScope*s, perm_string n, NetEvent*tgt,
8dbd641 All events now use the NetEvent class.
steve authored
249 edge_t t, unsigned p)
27af95d Use perm_strings for named langiage items.
steve authored
250 : NetNode(s, n, p), event_(tgt), edge_(t)
8dbd641 All events now use the NetEvent class.
steve authored
251 {
252 for (unsigned idx = 0 ; idx < p ; idx += 1) {
253 pin(idx).set_dir(Link::INPUT);
27af95d Use perm_strings for named langiage items.
steve authored
254 pin(idx).set_name(perm_string::literal("P"), idx);
8dbd641 All events now use the NetEvent class.
steve authored
255 }
4493e96 Finally remove the NetNEvent and NetPEvent classes,
steve authored
256
257 enext_ = event_->probes_;
258 event_->probes_ = this;
8dbd641 All events now use the NetEvent class.
steve authored
259 }
260
261 NetEvProbe::~NetEvProbe()
262 {
726f7b8 Synthesis of comparator in expressions.
steve authored
263 if (event_->probes_ == this) {
264 event_->probes_ = enext_;
265
266 } else {
267 NetEvProbe*cur = event_->probes_;
268 while (cur->enext_ != this) {
269 assert(cur->enext_);
270 cur = cur->enext_;
271 }
272
273 cur->enext_ = this->enext_;
274 }
8dbd641 All events now use the NetEvent class.
steve authored
275 }
276
277 NetEvProbe::edge_t NetEvProbe::edge() const
278 {
279 return edge_;
280 }
281
fd09bc3 Merge similar probes within a module.
steve authored
282 NetEvent* NetEvProbe::event()
283 {
284 return event_;
285 }
286
8dbd641 All events now use the NetEvent class.
steve authored
287 const NetEvent* NetEvProbe::event() const
288 {
289 return event_;
290 }
291
58ec62c Rewrite find_similar_event to support doing
steve authored
292 /*
293 * A similar NetEvProbe is one that is connected to all the same nexa
294 * that this probe is connected to, and also is the same edge
295 * type. Don't count myself as a similar probe.
296 */
297 void NetEvProbe::find_similar_probes(list<NetEvProbe*>&plist)
298 {
299 Nexus*nex = pin(0).nexus();
300
301 for (Link*lcur = nex->first_nlink(); lcur; lcur = lcur->next_nlink()) {
302 NetObj*obj = lcur->get_obj();
303 if (obj->pin_count() != pin_count())
304 continue;
305
306 NetEvProbe*tmp = dynamic_cast<NetEvProbe*>(obj);
307 if (tmp == 0)
308 continue;
309
310 if (tmp == this)
311 continue;
312
313 if (edge() != tmp->edge())
314 continue;
315
316 bool ok_flag = true;
317 for (unsigned idx = 1 ; idx < pin_count() ; idx += 1)
318 if (pin(idx).nexus() != tmp->pin(idx).nexus()) {
319 ok_flag = false;
320 break;
321 }
322
323 if (ok_flag == true)
324 plist .push_back(tmp);
325 }
326 }
327
b1fd927 Named events really should be expressed with PEIdent
steve authored
328 NetEvWait::NetEvWait(NetProc*pr)
329 : statement_(pr), nevents_(0), events_(0)
30e8289 Simulate named event trigger and waits.
steve authored
330 {
331 }
332
333 NetEvWait::~NetEvWait()
334 {
726f7b8 Synthesis of comparator in expressions.
steve authored
335 if (events_) {
336 for (unsigned idx = 0 ; idx < nevents_ ; idx += 1) {
337 NetEvent*tgt = events_[idx];
338 tgt->waitref_ -= 1;
c1c0168 Globally merge redundant event objects.
steve authored
339
340 struct NetEvent::wcell_*tmp = tgt->wlist_;
341 if (tmp->obj == this) {
342 tgt->wlist_ = tmp->next;
343 delete tmp;
344 } else {
345 assert(tmp->next);
346 while (tmp->next->obj != this) {
347 tmp = tmp->next;
348 assert(tmp->next);
349 }
350 tmp->next = tmp->next->next;
351 delete tmp;
352 }
726f7b8 Synthesis of comparator in expressions.
steve authored
353 }
354 delete[]events_;
355 }
30e8289 Simulate named event trigger and waits.
steve authored
356 delete statement_;
357 }
358
b1fd927 Named events really should be expressed with PEIdent
steve authored
359 void NetEvWait::add_event(NetEvent*tgt)
30e8289 Simulate named event trigger and waits.
steve authored
360 {
b1fd927 Named events really should be expressed with PEIdent
steve authored
361 assert(tgt);
362 if (nevents_ == 0) {
363 events_ = new NetEvent*[1];
364
365 } else {
366 NetEvent**tmp = new NetEvent*[nevents_+1];
367 for (unsigned idx = 0 ; idx < nevents_ ; idx += 1) {
368 tmp[idx] = events_[idx];
369 assert(tmp[idx] != tgt);
370 }
371 delete[]events_;
372 events_ = tmp;
373 }
374
375 events_[nevents_] = tgt;
376 nevents_ += 1;
726f7b8 Synthesis of comparator in expressions.
steve authored
377
378 // Remember to tell the NetEvent that there is someone
379 // pointing to it.
380 tgt->waitref_ += 1;
c1c0168 Globally merge redundant event objects.
steve authored
381
382 struct NetEvent::wcell_*tmp = new NetEvent::wcell_;
383 tmp->obj = this;
384 tmp->next = tgt->wlist_;
385 tgt->wlist_ = tmp;
386 }
387
388 void NetEvWait::replace_event(NetEvent*src, NetEvent*repl)
389 {
390 unsigned idx;
391 for (idx = 0 ; idx < nevents_ ; idx += 1) {
392 if (events_[idx] == src)
393 break;
394 }
395
396 assert(idx < nevents_);
397
398 /* First, remove me from the list held by the src NetEvent. */
399 assert(src->waitref_ > 0);
400 src->waitref_ -= 1;
401 struct NetEvent::wcell_*tmp = src->wlist_;
402 if (tmp->obj == this) {
403 src->wlist_ = tmp->next;
404 delete tmp;
405 } else {
406 assert(tmp->next);
407 while (tmp->next->obj != this) {
408 tmp = tmp->next;
409 assert(tmp->next);
410 }
411 tmp->next = tmp->next->next;
412 delete tmp;
413 }
414
415 events_[idx] = repl;
416
417 // Remember to tell the replacement NetEvent that there is
418 // someone pointing to it.
419 repl->waitref_ += 1;
420
421 tmp = new NetEvent::wcell_;
422 tmp->obj = this;
423 tmp->next = repl->wlist_;
424 repl->wlist_ = tmp;
425
b1fd927 Named events really should be expressed with PEIdent
steve authored
426 }
427
428 unsigned NetEvWait::nevents() const
429 {
430 return nevents_;
431 }
432
433 const NetEvent* NetEvWait::event(unsigned idx) const
434 {
435 assert(idx < nevents_);
436 return events_[idx];
30e8289 Simulate named event trigger and waits.
steve authored
437 }
438
4493e96 Finally remove the NetNEvent and NetPEvent classes,
steve authored
439 NetEvent* NetEvWait::event(unsigned idx)
440 {
441 assert(idx < nevents_);
442 return events_[idx];
443 }
444
445 NetProc* NetEvWait::statement()
446 {
447 return statement_;
448 }
449
30e8289 Simulate named event trigger and waits.
steve authored
450 /*
451 * $Log: net_event.cc,v $
c7d97f4 Properly evaluate scope path expressions.
steve authored
452 * Revision 1.27 2007/06/02 03:42:13 steve
453 * Properly evaluate scope path expressions.
454 *
e4ae832 Clean up spurious trailing white space.
steve authored
455 * Revision 1.26 2004/10/04 01:10:54 steve
456 * Clean up spurious trailing white space.
457 *
536068b Memory and Event names use perm_string.
steve authored
458 * Revision 1.25 2004/02/19 06:57:10 steve
459 * Memory and Event names use perm_string.
460 *
27af95d Use perm_strings for named langiage items.
steve authored
461 * Revision 1.24 2004/02/18 17:11:56 steve
462 * Use perm_strings for named langiage items.
463 *
f1cc9d8 Support event names as expressions elements.
steve authored
464 * Revision 1.23 2003/04/22 04:48:29 steve
465 * Support event names as expressions elements.
466 *
badad63 All NetObj objects have lex_string base names.
steve authored
467 * Revision 1.22 2003/03/06 00:28:41 steve
468 * All NetObj objects have lex_string base names.
469 *
4c67de5 Add the lex_strings string handler, and put
steve authored
470 * Revision 1.21 2003/03/01 06:25:30 steve
471 * Add the lex_strings string handler, and put
472 * scope names and system task/function names
473 * into this table. Also, permallocate event
474 * names from the beginning.
475 *
52bf4e6 conditional ident string using autoconfig.
steve authored
476 * Revision 1.20 2002/08/12 01:34:59 steve
477 * conditional ident string using autoconfig.
478 *
58ec62c Rewrite find_similar_event to support doing
steve authored
479 * Revision 1.19 2002/07/24 16:24:45 steve
480 * Rewrite find_similar_event to support doing
481 * all event matching and replacement in one
482 * shot, saving time in the scans.
483 *
9b6b081 Add structure for asynchronous logic synthesis.
steve authored
484 * Revision 1.18 2002/06/30 02:21:31 steve
485 * Add structure for asynchronous logic synthesis.
486 *
54dab22 event find_similar should not find self.
steve authored
487 * Revision 1.17 2002/02/02 06:13:38 steve
488 * event find_similar should not find self.
489 *
874bab1 NetObj constructor finally requires a scope.
steve authored
490 * Revision 1.16 2001/10/28 01:14:53 steve
491 * NetObj constructor finally requires a scope.
492 *
b825f8d Create a config.h.in file to hold all the config
steve authored
493 * Revision 1.15 2001/07/25 03:10:49 steve
494 * Create a config.h.in file to hold all the config
495 * junk, and support gcc 3.0. (Stephan Boettcher)
496 *
ad8565f Add const probe method to NetEvent.
steve authored
497 * Revision 1.14 2001/03/29 02:52:19 steve
498 * Add const probe method to NetEvent.
499 *
a4e528f Add the ivl_event_t to ivl_target, and use that to generate
steve authored
500 * Revision 1.13 2001/03/28 06:07:39 steve
501 * Add the ivl_event_t to ivl_target, and use that to generate
502 * .event statements in vvp way ahead of the thread that uses it.
503 *
bcbd5b2 Remove limits from the similar events search.
steve authored
504 * Revision 1.12 2000/12/15 17:45:07 steve
505 * Remove limits from the similar events search.
506 *
aac5fc2 Use char8 instead of string to store name.
steve authored
507 * Revision 1.11 2000/10/04 16:30:39 steve
508 * Use char8 instead of string to store name.
509 *
ea53f2b Typo stepping ot next probe in delete.
steve authored
510 * Revision 1.10 2000/09/19 03:00:36 steve
511 * Typo stepping ot next probe in delete.
512 *
39c71ef fix problem coalescing events w/ probes.
steve authored
513 * Revision 1.9 2000/07/29 03:55:38 steve
514 * fix problem coalescing events w/ probes.
515 *
c1c0168 Globally merge redundant event objects.
steve authored
516 * Revision 1.8 2000/05/31 02:26:49 steve
517 * Globally merge redundant event objects.
518 *
fd09bc3 Merge similar probes within a module.
steve authored
519 * Revision 1.7 2000/05/27 19:33:23 steve
520 * Merge similar probes within a module.
521 *
74c4303 Clean up unneeded NetEvent objects.
steve authored
522 * Revision 1.6 2000/04/18 04:50:20 steve
523 * Clean up unneeded NetEvent objects.
524 *
726f7b8 Synthesis of comparator in expressions.
steve authored
525 * Revision 1.5 2000/04/16 23:32:18 steve
526 * Synthesis of comparator in expressions.
527 *
528 * Connect the NetEvent and related classes
529 * together better.
530 *
4493e96 Finally remove the NetNEvent and NetPEvent classes,
steve authored
531 * Revision 1.4 2000/04/12 20:02:53 steve
532 * Finally remove the NetNEvent and NetPEvent classes,
533 * Get synthesis working with the NetEvWait class,
534 * and get started supporting multiple events in a
535 * wait in vvm.
536 *
b1fd927 Named events really should be expressed with PEIdent
steve authored
537 * Revision 1.3 2000/04/12 04:23:58 steve
538 * Named events really should be expressed with PEIdent
539 * objects in the pform,
540 *
541 * Handle named events within the mix of net events
542 * and edges. As a unified lot they get caught together.
543 * wait statements are broken into more complex statements
544 * that include a conditional.
545 *
546 * Do not generate NetPEvent or NetNEvent objects in
547 * elaboration. NetEvent, NetEvWait and NetEvProbe
548 * take over those functions in the netlist.
549 *
8dbd641 All events now use the NetEvent class.
steve authored
550 * Revision 1.2 2000/04/10 05:26:06 steve
551 * All events now use the NetEvent class.
552 *
30e8289 Simulate named event trigger and waits.
steve authored
553 * Revision 1.1 2000/04/04 03:20:15 steve
554 * Simulate named event trigger and waits.
555 *
556 */
557
Something went wrong with that request. Please try again.