scc 2025.09
SystemC components library
signal_opt_ports.h
1/*******************************************************************************
2 * Copyright 2001 - 2023 Accellera Systems Initiative Inc. (Accellera)
3 * Copyright 2023 MINRES Technologies GmbH
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17/*
18 * Created on: Dec 17, 2023
19 * Author: eyck
20 */
21
22#ifndef _SYSC_SCC_OPT_SIGNAL_PORTS_H_
23#define _SYSC_SCC_OPT_SIGNAL_PORTS_H_
24
25#include <systemc>
26
27#if !defined(SC_DISABLE_VIRTUAL_BIND)
28#define SCC_VIRT virtual
29#else
30#define SCC_VIRT /* non-virtual */
31#endif
32
33#ifdef NCSC
34#define SC_API_TEMPLATE_DECL_ _TEMPLATE_DECL_
35#endif
36
37namespace scc {
46template <class T> class sc_in_opt : public sc_core::sc_port<sc_core::sc_signal_in_if<T>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
47public:
48 using data_type = T;
49 using if_type = sc_core::sc_signal_in_if<data_type>;
50 using base_type = sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
51 using this_type = sc_in_opt<data_type>;
52 using base_port_type = typename base_type::port_type;
53
54 using in_if_type = if_type;
55 using in_port_type = base_type;
56 using inout_if_type = sc_core::sc_signal_inout_if<data_type>;
57 using inout_port_type = sc_core::sc_port<inout_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
58
59public:
60 sc_in_opt()
61 : base_type() {}
62
63 explicit sc_in_opt(const char* name_)
64 : base_type(name_) {}
65
66 explicit sc_in_opt(const in_if_type& interface_)
67 : base_type(const_cast<in_if_type&>(interface_)) {}
68
69 sc_in_opt(const char* name_, const in_if_type& interface_)
70 : base_type(name_, const_cast<in_if_type&>(interface_)) {}
71
72 explicit sc_in_opt(in_port_type& parent_)
73 : base_type(parent_) {}
74
75 sc_in_opt(const char* name_, in_port_type& parent_)
76 : base_type(name_, parent_) {}
77
78 explicit sc_in_opt(inout_port_type& parent_)
79 : base_type() {
80 sc_core::sc_port_base::bind(parent_);
81 }
82
83 sc_in_opt(const char* name_, inout_port_type& parent_)
84 : base_type(name_) {
85 sc_core::sc_port_base::bind(parent_);
86 }
87
88 sc_in_opt(this_type& parent_)
89 : base_type(parent_) {}
90
91 sc_in_opt(const char* name_, this_type& parent_)
92 : base_type(name_, parent_) {}
93
94 sc_in_opt(const this_type&) = delete;
95
96 virtual ~sc_in_opt() {}
97
98 this_type& operator=(const this_type&) = delete;
99
100 SCC_VIRT void bind(const in_if_type& interface_) { sc_core::sc_port_base::bind(const_cast<in_if_type&>(interface_)); }
101
102 SCC_VIRT void bind(in_if_type& interface_) override { this->bind(const_cast<const in_if_type&>(interface_)); }
103
104 void operator()(const in_if_type& interface_) { this->bind(interface_); }
105
106 SCC_VIRT void bind(in_port_type& parent_) { sc_core::sc_port_base::bind(parent_); }
107
108 void operator()(in_port_type& parent_) { this->bind(parent_); }
109
110 SCC_VIRT void bind(sc_core::sc_port<if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { sc_core::sc_port_base::bind(parent_); }
111
112 void operator()(sc_core::sc_port<if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { this->bind(parent_); }
113
114 SCC_VIRT void bind(inout_port_type& parent_) { sc_core::sc_port_base::bind(parent_); }
115
116 void operator()(inout_port_type& parent_) { this->bind(parent_); }
117
118 SCC_VIRT void bind(sc_core::sc_port<inout_if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { sc_core::sc_port_base::bind(parent_); }
119
120 void operator()(sc_core::sc_port<inout_if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { this->bind(parent_); }
121
122 const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
123
124 const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
125
126 const data_type& read() const { return (*this)->read(); }
127
128 operator const data_type&() const { return (*this)->read(); }
129
130 bool event() const { return (*this)->event(); }
131
132 virtual const char* kind() const override { return "sc_in"; }
133};
134
135template <typename T>::std::ostream& operator<<(::std::ostream& os, const sc_in_opt<T>& a) { return os << a->read(); }
136} // namespace scc
137
138SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_in_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
139
140namespace scc {
141template <> class SC_API sc_in_opt<bool> : public sc_core::sc_port<sc_core::sc_signal_in_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
142public:
143 typedef bool data_type;
144
145 typedef sc_core::sc_signal_in_if<data_type> if_type;
146 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
147 typedef sc_in_opt<data_type> this_type;
148 typedef /* typename */ base_type::port_type base_port_type;
149
150 typedef if_type in_if_type;
151 typedef base_type in_port_type;
152 typedef sc_core::sc_signal_inout_if<data_type> inout_if_type;
153 typedef sc_core::sc_port<inout_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> inout_port_type;
154
155public:
156 sc_in_opt()
157 : base_type() {}
158
159 explicit sc_in_opt(const char* name_)
160 : base_type(name_) {}
161
162 explicit sc_in_opt(const in_if_type& interface_)
163 : base_type(const_cast<in_if_type&>(interface_)) {}
164
165 sc_in_opt(const char* name_, const in_if_type& interface_)
166 : base_type(name_, const_cast<in_if_type&>(interface_)) {}
167
168 explicit sc_in_opt(in_port_type& parent_)
169 : base_type(parent_) {}
170
171 sc_in_opt(const char* name_, in_port_type& parent_)
172 : base_type(name_, parent_) {}
173
174 explicit sc_in_opt(inout_port_type& parent_)
175 : base_type() {
176 sc_port_base::bind(parent_);
177 }
178
179 sc_in_opt(const char* name_, inout_port_type& parent_)
180 : base_type(name_) {
181 sc_port_base::bind(parent_);
182 }
183
184 sc_in_opt(this_type& parent_)
185 : base_type(parent_) {}
186
187 sc_in_opt(const char* name_, this_type& parent_)
188 : base_type(name_, parent_) {}
189
190 sc_in_opt(const this_type&) = delete;
191
192 virtual ~sc_in_opt() = default;
193
194 this_type& operator=(const this_type&) = delete;
195
196 SCC_VIRT void bind(const in_if_type& interface_) { sc_port_base::bind(const_cast<in_if_type&>(interface_)); }
197
198 SCC_VIRT void bind(in_if_type& interface_) override { this->bind(const_cast<const in_if_type&>(interface_)); }
199
200 void operator()(const in_if_type& interface_) { this->bind(interface_); }
201
202 SCC_VIRT void bind(in_port_type& parent_) { sc_port_base::bind(parent_); }
203
204 void operator()(in_port_type& parent_) { this->bind(parent_); }
205
206 SCC_VIRT void bind(inout_port_type& parent_) { sc_port_base::bind(parent_); }
207
208 void operator()(inout_port_type& parent_) { this->bind(parent_); }
209
210 const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
211
212 const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
213
214 const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
215
216 const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
217
218 const data_type& read() const { return (*this)->read(); }
219
220 operator const data_type&() const { return (*this)->read(); }
221
222 bool event() const { return (*this)->event(); }
223
224 bool posedge() const { return (*this)->posedge(); }
225
226 bool negedge() const { return (*this)->negedge(); }
227
228 virtual const char* kind() const override { return "sc_in"; }
229};
230
231} // namespace scc
232
233SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_in_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
234
235namespace scc {
236template <>
237class SC_API sc_in_opt<sc_dt::sc_logic>
238: public sc_core::sc_port<sc_core::sc_signal_in_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
239public:
240 typedef sc_dt::sc_logic data_type;
241
242 typedef sc_core::sc_signal_in_if<data_type> if_type;
243 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
244 typedef sc_in_opt<data_type> this_type;
245 typedef /* typename */ base_type::port_type base_port_type;
246
247 typedef if_type in_if_type;
248 typedef base_type in_port_type;
249 typedef sc_core::sc_signal_inout_if<data_type> inout_if_type;
250 typedef sc_core::sc_port<inout_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> inout_port_type;
251
252public:
253 sc_in_opt()
254 : base_type() {}
255
256 explicit sc_in_opt(const char* name_)
257 : base_type(name_) {}
258
259 explicit sc_in_opt(const in_if_type& interface_)
260 : base_type(const_cast<in_if_type&>(interface_)) {}
261
262 sc_in_opt(const char* name_, const in_if_type& interface_)
263 : base_type(name_, const_cast<in_if_type&>(interface_)) {}
264
265 explicit sc_in_opt(in_port_type& parent_)
266 : base_type(parent_) {}
267
268 sc_in_opt(const char* name_, in_port_type& parent_)
269 : base_type(name_, parent_) {}
270
271 explicit sc_in_opt(inout_port_type& parent_)
272 : base_type() {
273 sc_port_base::bind(parent_);
274 }
275
276 sc_in_opt(const char* name_, inout_port_type& parent_)
277 : base_type(name_) {
278 sc_port_base::bind(parent_);
279 }
280
281 sc_in_opt(this_type& parent_)
282 : base_type(parent_) {}
283
284 sc_in_opt(const char* name_, this_type& parent_)
285 : base_type(name_, parent_) {}
286
287 sc_in_opt(const this_type&) = delete;
288
289 virtual ~sc_in_opt() = default;
290
291 this_type& operator=(const this_type&) = delete;
292
293 SCC_VIRT void bind(const in_if_type& interface_) { sc_port_base::bind(const_cast<in_if_type&>(interface_)); }
294
295 SCC_VIRT void bind(in_if_type& interface_) override { this->bind(const_cast<const in_if_type&>(interface_)); }
296
297 void operator()(const in_if_type& interface_) { this->bind(interface_); }
298
299 SCC_VIRT void bind(in_port_type& parent_) { sc_port_base::bind(parent_); }
300
301 void operator()(in_port_type& parent_) { this->bind(parent_); }
302
303 SCC_VIRT void bind(inout_port_type& parent_) { sc_port_base::bind(parent_); }
304
305 void operator()(inout_port_type& parent_) { this->bind(parent_); }
306
307 const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
308
309 const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
310
311 const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
312
313 const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
314
315 const data_type& read() const { return (*this)->read(); }
316
317 operator const data_type&() const { return (*this)->read(); }
318
319 bool event() const { return (*this)->event(); }
320
321 bool posedge() const { return (*this)->posedge(); }
322
323 bool negedge() const { return (*this)->negedge(); }
324
325 virtual const char* kind() const override { return "sc_in"; }
326};
327
335template <class T> class sc_inout_opt : public sc_core::sc_port<sc_core::sc_signal_inout_if<T>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
336public:
337 typedef T data_type;
338
339 typedef sc_core::sc_signal_inout_if<data_type> if_type;
340 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
341 typedef sc_inout_opt<data_type> this_type;
342
343 typedef sc_core::sc_signal_in_if<data_type> in_if_type;
344 typedef sc_core::sc_port<in_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> in_port_type;
345 typedef if_type inout_if_type;
346 typedef base_type inout_port_type;
347
348public:
349 sc_inout_opt()
350 : base_type()
351 , m_init_val(0) {}
352
353 explicit sc_inout_opt(const char* name_)
354 : base_type(name_)
355 , m_init_val(0) {}
356
357 explicit sc_inout_opt(inout_if_type& interface_)
358 : base_type(interface_)
359 , m_init_val(0) {}
360
361 sc_inout_opt(const char* name_, inout_if_type& interface_)
362 : base_type(name_, interface_)
363 , m_init_val(0) {}
364
365 explicit sc_inout_opt(inout_port_type& parent_)
366 : base_type(parent_)
367 , m_init_val(0) {}
368
369 sc_inout_opt(const char* name_, inout_port_type& parent_)
370 : base_type(name_, parent_)
371 , m_init_val(0) {}
372
373 sc_inout_opt(this_type& parent_)
374 : base_type(parent_)
375 , m_init_val(0) {}
376
377 sc_inout_opt(const char* name_, this_type& parent_)
378 : base_type(name_, parent_)
379 , m_init_val(0) {}
380
381 sc_inout_opt(const this_type&) = delete;
382
383 virtual ~sc_inout_opt() = default;
384
385 const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
386
387 const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
388
389 const data_type& read() const { return (*this)->read(); }
390
391 operator const data_type&() const { return (*this)->read(); }
392
393 bool event() const { return (*this)->event(); }
394
395 void write(const data_type& value_) { (*this)->write(value_); }
396
397 this_type& operator=(const data_type& value_) {
398 (*this)->write(value_);
399 return *this;
400 }
401
402 this_type& operator=(const in_if_type& interface_) {
403 (*this)->write(interface_.read());
404 return *this;
405 }
406
407 this_type& operator=(const in_port_type& port_) {
408 (*this)->write(port_->read());
409 return *this;
410 }
411
412 this_type& operator=(const inout_port_type& port_) {
413 (*this)->write(port_->read());
414 return *this;
415 }
416
417 this_type& operator=(const this_type& port_) {
418 (*this)->write(port_->read());
419 return *this;
420 }
421
422 void initialize(const data_type& value_);
423
424 void initialize(const in_if_type& interface_) { initialize(interface_.read()); }
425
426 void end_of_elaboration() override;
427
428 virtual const char* kind() const override { return "sc_inout"; }
429
430protected:
431 data_type* m_init_val;
432};
433
434template <typename T>::std::ostream& operator<<(::std::ostream& os, const sc_inout_opt<T>& a) { return os << a->read(); }
435
436template <class T> inline void sc_inout_opt<T>::initialize(const data_type& value_) {
437 inout_if_type* iface = dynamic_cast<inout_if_type*>(this->get_interface());
438 if(iface != 0) {
439 iface->write(value_);
440 } else {
441 if(m_init_val == 0) {
442 m_init_val = new data_type;
443 }
444 *m_init_val = value_;
445 }
446}
447
448template <class T> inline void sc_inout_opt<T>::end_of_elaboration() {
449 if(m_init_val != 0) {
450 write(*m_init_val);
451 delete m_init_val;
452 m_init_val = 0;
453 }
454}
455} // namespace scc
456
457#ifndef CWR_SYSTEMC
458SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_inout_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
459#endif
460
461namespace scc {
462template <>
463class SC_API sc_inout_opt<bool> : public sc_core::sc_port<sc_core::sc_signal_inout_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
464public:
465 typedef bool data_type;
466
467 typedef sc_core::sc_signal_inout_if<data_type> if_type;
468 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
469 typedef sc_inout_opt<data_type> this_type;
470
471 typedef sc_core::sc_signal_in_if<data_type> in_if_type;
472 typedef sc_core::sc_port<in_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> in_port_type;
473 typedef if_type inout_if_type;
474 typedef base_type inout_port_type;
475
476public:
477 sc_inout_opt()
478 : base_type()
479 , m_init_val(0) {}
480
481 explicit sc_inout_opt(const char* name_)
482 : base_type(name_)
483 , m_init_val(0) {}
484
485 explicit sc_inout_opt(inout_if_type& interface_)
486 : base_type(interface_)
487 , m_init_val(0) {}
488
489 sc_inout_opt(const char* name_, inout_if_type& interface_)
490 : base_type(name_, interface_)
491 , m_init_val(0) {}
492
493 explicit sc_inout_opt(inout_port_type& parent_)
494 : base_type(parent_)
495 , m_init_val(0) {}
496
497 sc_inout_opt(const char* name_, inout_port_type& parent_)
498 : base_type(name_, parent_)
499 , m_init_val(0) {}
500
501 sc_inout_opt(this_type& parent_)
502 : base_type(parent_)
503 , m_init_val(0) {}
504
505 sc_inout_opt(const char* name_, this_type& parent_)
506 : base_type(name_, parent_)
507 , m_init_val(0) {}
508
509 sc_inout_opt(const this_type&) = delete;
510
511 virtual ~sc_inout_opt() = default;
512
513 const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
514
515 const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
516
517 const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
518
519 const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
520
521 const data_type& read() const { return (*this)->read(); }
522
523 operator const data_type&() const { return (*this)->read(); }
524
525 bool event() const { return (*this)->event(); }
526
527 bool posedge() const { return (*this)->posedge(); }
528
529 bool negedge() const { return (*this)->negedge(); }
530
531 void write(const data_type& value_) { (*this)->write(value_); }
532
533 this_type& operator=(const data_type& value_) {
534 (*this)->write(value_);
535 return *this;
536 }
537
538 this_type& operator=(const in_if_type& interface_) {
539 (*this)->write(interface_.read());
540 return *this;
541 }
542
543 this_type& operator=(const in_port_type& port_) {
544 (*this)->write(port_->read());
545 return *this;
546 }
547
548 this_type& operator=(const inout_port_type& port_) {
549 (*this)->write(port_->read());
550 return *this;
551 }
552
553 this_type& operator=(const this_type& port_) {
554 (*this)->write(port_->read());
555 return *this;
556 }
557
558 void initialize(const data_type& value_);
559
560 void initialize(const in_if_type& interface_) { initialize(interface_.read()); }
561
562 void end_of_elaboration() override {
563 if(m_init_val != 0) {
564 write(*m_init_val);
565 delete m_init_val;
566 m_init_val = 0;
567 }
568 }
569
570 virtual const char* kind() const override { return "sc_inout"; }
571
572protected:
573 data_type* m_init_val;
574};
575} // namespace scc
576
577#ifndef CWR_SYSTEMC
578SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_inout_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
579#endif
580
581namespace scc {
582template <>
583class SC_API sc_inout_opt<sc_dt::sc_logic>
584: public sc_core::sc_port<sc_core::sc_signal_inout_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
585public:
586 typedef sc_dt::sc_logic data_type;
587
588 typedef sc_core::sc_signal_inout_if<data_type> if_type;
589 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
590 typedef sc_inout_opt<data_type> this_type;
591
592 typedef sc_core::sc_signal_in_if<data_type> in_if_type;
593 typedef sc_core::sc_port<in_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> in_port_type;
594 typedef if_type inout_if_type;
595 typedef base_type inout_port_type;
596
597public:
598 sc_inout_opt()
599 : base_type()
600 , m_init_val(0) {}
601
602 explicit sc_inout_opt(const char* name_)
603 : base_type(name_)
604 , m_init_val(0) {}
605
606 explicit sc_inout_opt(inout_if_type& interface_)
607 : base_type(interface_)
608 , m_init_val(0) {}
609
610 sc_inout_opt(const char* name_, inout_if_type& interface_)
611 : base_type(name_, interface_)
612 , m_init_val(0) {}
613
614 explicit sc_inout_opt(inout_port_type& parent_)
615 : base_type(parent_)
616 , m_init_val(0) {}
617
618 sc_inout_opt(const char* name_, inout_port_type& parent_)
619 : base_type(name_, parent_)
620 , m_init_val(0) {}
621
622 sc_inout_opt(this_type& parent_)
623 : base_type(parent_)
624 , m_init_val(0) {}
625
626 sc_inout_opt(const char* name_, this_type& parent_)
627 : base_type(name_, parent_)
628 , m_init_val(0) {}
629
630 sc_inout_opt(const this_type&) = delete;
631
632 virtual ~sc_inout_opt();
633
634 const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
635
636 const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
637
638 const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
639
640 const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
641
642 const data_type& read() const { return (*this)->read(); }
643
644 operator const data_type&() const { return (*this)->read(); }
645
646 bool event() const { return (*this)->event(); }
647
648 bool posedge() const { return (*this)->posedge(); }
649
650 bool negedge() const { return (*this)->negedge(); }
651
652 void write(const data_type& value_) { (*this)->write(value_); }
653
654 this_type& operator=(const data_type& value_) {
655 (*this)->write(value_);
656 return *this;
657 }
658
659 this_type& operator=(const in_if_type& interface_) {
660 (*this)->write(interface_.read());
661 return *this;
662 }
663
664 this_type& operator=(const in_port_type& port_) {
665 (*this)->write(port_->read());
666 return *this;
667 }
668
669 this_type& operator=(const inout_port_type& port_) {
670 (*this)->write(port_->read());
671 return *this;
672 }
673
674 this_type& operator=(const this_type& port_) {
675 (*this)->write(port_->read());
676 return *this;
677 }
678
679 void initialize(const data_type& value_);
680
681 void initialize(const in_if_type& interface_) { initialize(interface_.read()); }
682
683 // called when elaboration is done
684 void end_of_elaboration() override {
685 if(m_init_val != 0) {
686 write(*m_init_val);
687 delete m_init_val;
688 m_init_val = 0;
689 }
690 }
691
692 virtual const char* kind() const override { return "sc_inout"; }
693
694protected:
695 data_type* m_init_val;
696};
697
705template <class T> class sc_out_opt : public sc_inout_opt<T> {
706public:
707 typedef T data_type;
708
709 typedef sc_out_opt<data_type> this_type;
710 typedef sc_inout_opt<data_type> base_type;
711
712 typedef typename base_type::in_if_type in_if_type;
713 typedef typename base_type::in_port_type in_port_type;
714 typedef typename base_type::inout_if_type inout_if_type;
715 typedef typename base_type::inout_port_type inout_port_type;
716
717public:
718 sc_out_opt()
719 : base_type() {}
720
721 explicit sc_out_opt(const char* name_)
722 : base_type(name_) {}
723
724 explicit sc_out_opt(inout_if_type& interface_)
725 : base_type(interface_) {}
726
727 sc_out_opt(const char* name_, inout_if_type& interface_)
728 : base_type(name_, interface_) {}
729
730 explicit sc_out_opt(inout_port_type& parent_)
731 : base_type(parent_) {}
732
733 sc_out_opt(const char* name_, inout_port_type& parent_)
734 : base_type(name_, parent_) {}
735
736 sc_out_opt(this_type& parent_)
737 : base_type(parent_) {}
738
739 sc_out_opt(const char* name_, this_type& parent_)
740 : base_type(name_, parent_) {}
741
742 virtual ~sc_out_opt() {}
743
744 this_type& operator=(const data_type& value_) {
745 (*this)->write(value_);
746 return *this;
747 }
748
749 this_type& operator=(const in_if_type& interface_) {
750 (*this)->write(interface_.read());
751 return *this;
752 }
753
754 this_type& operator=(const in_port_type& port_) {
755 (*this)->write(port_->read());
756 return *this;
757 }
758
759 this_type& operator=(const inout_port_type& port_) {
760 (*this)->write(port_->read());
761 return *this;
762 }
763
764 this_type& operator=(const this_type& port_) {
765 (*this)->write(port_->read());
766 return *this;
767 }
768
769 virtual const char* kind() const override { return "sc_out"; }
770
771private:
772 sc_out_opt(const this_type&) = delete;
773};
774
775template <class T> inline void sc_trace(sc_core::sc_trace_file* tf, const sc_in_opt<T>& port, const std::string& name) {
776 const sc_core::sc_signal_in_if<T>* iface = 0;
777 if(sc_core::sc_get_curr_simcontext()->elaboration_done()) {
778 iface = dynamic_cast<const sc_core::sc_signal_in_if<T>*>(port.get_interface());
779 }
780 if(iface)
781 sc_trace(tf, iface->read(), name);
782 else
783 port.add_trace_internal(tf, name);
784}
785
786template <class T> inline void sc_trace(sc_core::sc_trace_file* tf, const sc_inout_opt<T>& port, const std::string& name) {
787 const sc_core::sc_signal_in_if<T>* iface = 0;
788 if(sc_core::sc_get_curr_simcontext()->elaboration_done()) {
789 iface = dynamic_cast<const sc_core::sc_signal_in_if<T>*>(port.get_interface());
790 }
791
792 if(iface)
793 sc_trace(tf, iface->read(), name);
794 else
795 port.add_trace_internal(tf, name);
796}
797
798} // namespace scc
799
800#undef SCC_VIRT
801
802#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
803#pragma warning(pop)
804#endif
805#endif /* SCC_SRC_SYSC_SCC_OPT_SIGNAL_PORTS_H_ */
A template class for an optional input port with optimized binding.
A template class for an optional input port with optimized binding.
SCC TLM utilities.
std::ostream & operator<<(std::ostream &os, log const &val)
output the textual representation of the log level
Definition report.h:131