22 #ifndef _SYSC_SCC_OPT_SIGNAL_PORTS_H_
23 #define _SYSC_SCC_OPT_SIGNAL_PORTS_H_
27 #if !defined(SC_DISABLE_VIRTUAL_BIND)
28 #define SCC_VIRT virtual
35 template <
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> {
38 using if_type = sc_core::sc_signal_in_if<data_type>;
39 using base_type = sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
41 using base_port_type =
typename base_type::port_type;
43 using in_if_type = if_type;
44 using in_port_type = base_type;
45 using inout_if_type = sc_core::sc_signal_inout_if<data_type>;
46 using inout_port_type = sc_core::sc_port<inout_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
55 explicit sc_in_opt(
const in_if_type& interface_)
56 : base_type(
const_cast<in_if_type&
>(interface_)) {}
58 sc_in_opt(
const char* name_,
const in_if_type& interface_)
59 : base_type(name_,
const_cast<in_if_type&
>(interface_)) {}
62 : base_type(parent_) {}
64 sc_in_opt(
const char* name_, in_port_type& parent_)
65 : base_type(name_, parent_) {}
67 explicit sc_in_opt(inout_port_type& parent_)
69 sc_core::sc_port_base::bind(parent_);
72 sc_in_opt(
const char* name_, inout_port_type& parent_)
74 sc_core::sc_port_base::bind(parent_);
78 : base_type(parent_) {}
81 : base_type(name_, parent_) {}
89 SCC_VIRT
void bind(
const in_if_type& interface_) { sc_core::sc_port_base::bind(
const_cast<in_if_type&
>(interface_)); }
91 SCC_VIRT
void bind(in_if_type& interface_)
override { this->bind(
const_cast<const in_if_type&
>(interface_)); }
93 void operator()(
const in_if_type& interface_) { this->bind(interface_); }
95 SCC_VIRT
void bind(in_port_type& parent_) { sc_core::sc_port_base::bind(parent_); }
97 void operator()(in_port_type& parent_) { this->bind(parent_); }
99 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_); }
101 void operator()(sc_core::sc_port<if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { this->bind(parent_); }
103 SCC_VIRT
void bind(inout_port_type& parent_) { sc_core::sc_port_base::bind(parent_); }
105 void operator()(inout_port_type& parent_) { this->bind(parent_); }
107 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_); }
109 void operator()(sc_core::sc_port<inout_if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { this->bind(parent_); }
111 const sc_core::sc_event& default_event()
const {
return (*this)->default_event(); }
113 const sc_core::sc_event& value_changed_event()
const {
return (*this)->value_changed_event(); }
115 const data_type& read()
const {
return (*this)->read(); }
117 operator const data_type&()
const {
return (*this)->read(); }
119 bool event()
const {
return (*this)->event(); }
121 virtual const char* kind()
const override {
return "sc_in"; }
124 template <typename T>::std::ostream&
operator<<(::std::ostream& os,
const sc_in_opt<T>& a) {
return os << a->read(); }
127 SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_in_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
130 template <>
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> {
132 typedef bool data_type;
134 typedef sc_core::sc_signal_in_if<data_type> if_type;
135 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
137 typedef base_type::port_type base_port_type;
139 typedef if_type in_if_type;
140 typedef base_type in_port_type;
141 typedef sc_core::sc_signal_inout_if<data_type> inout_if_type;
142 typedef sc_core::sc_port<inout_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> inout_port_type;
149 : base_type(name_) {}
151 explicit sc_in_opt(
const in_if_type& interface_)
152 : base_type(
const_cast<in_if_type&
>(interface_)) {}
154 sc_in_opt(
const char* name_,
const in_if_type& interface_)
155 : base_type(name_,
const_cast<in_if_type&
>(interface_)) {}
157 explicit sc_in_opt(in_port_type& parent_)
158 : base_type(parent_) {}
160 sc_in_opt(
const char* name_, in_port_type& parent_)
161 : base_type(name_, parent_) {}
163 explicit sc_in_opt(inout_port_type& parent_)
165 sc_port_base::bind(parent_);
168 sc_in_opt(
const char* name_, inout_port_type& parent_)
170 sc_port_base::bind(parent_);
174 : base_type(parent_) {}
177 : base_type(name_, parent_) {}
185 SCC_VIRT
void bind(
const in_if_type& interface_) { sc_port_base::bind(
const_cast<in_if_type&
>(interface_)); }
187 SCC_VIRT
void bind(in_if_type& interface_)
override { this->bind(
const_cast<const in_if_type&
>(interface_)); }
189 void operator()(
const in_if_type& interface_) { this->bind(interface_); }
191 SCC_VIRT
void bind(in_port_type& parent_) { sc_port_base::bind(parent_); }
193 void operator()(in_port_type& parent_) { this->bind(parent_); }
195 SCC_VIRT
void bind(inout_port_type& parent_) { sc_port_base::bind(parent_); }
197 void operator()(inout_port_type& parent_) { this->bind(parent_); }
199 const sc_core::sc_event& default_event()
const {
return (*this)->default_event(); }
201 const sc_core::sc_event& value_changed_event()
const {
return (*this)->value_changed_event(); }
203 const sc_core::sc_event& posedge_event()
const {
return (*this)->posedge_event(); }
205 const sc_core::sc_event& negedge_event()
const {
return (*this)->negedge_event(); }
207 const data_type& read()
const {
return (*this)->read(); }
209 operator const data_type&()
const {
return (*this)->read(); }
211 bool event()
const {
return (*this)->event(); }
213 bool posedge()
const {
return (*this)->posedge(); }
215 bool negedge()
const {
return (*this)->negedge(); }
217 virtual const char* kind()
const override {
return "sc_in"; }
222 SC_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>;
227 :
public sc_core::sc_port<sc_core::sc_signal_in_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
229 typedef sc_dt::sc_logic data_type;
231 typedef sc_core::sc_signal_in_if<data_type> if_type;
232 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
234 typedef base_type::port_type base_port_type;
236 typedef if_type in_if_type;
237 typedef base_type in_port_type;
238 typedef sc_core::sc_signal_inout_if<data_type> inout_if_type;
239 typedef sc_core::sc_port<inout_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> inout_port_type;
246 : base_type(name_) {}
248 explicit sc_in_opt(
const in_if_type& interface_)
249 : base_type(
const_cast<in_if_type&
>(interface_)) {}
251 sc_in_opt(
const char* name_,
const in_if_type& interface_)
252 : base_type(name_,
const_cast<in_if_type&
>(interface_)) {}
254 explicit sc_in_opt(in_port_type& parent_)
255 : base_type(parent_) {}
257 sc_in_opt(
const char* name_, in_port_type& parent_)
258 : base_type(name_, parent_) {}
260 explicit sc_in_opt(inout_port_type& parent_)
262 sc_port_base::bind(parent_);
265 sc_in_opt(
const char* name_, inout_port_type& parent_)
267 sc_port_base::bind(parent_);
271 : base_type(parent_) {}
274 : base_type(name_, parent_) {}
282 SCC_VIRT
void bind(
const in_if_type& interface_) { sc_port_base::bind(
const_cast<in_if_type&
>(interface_)); }
284 SCC_VIRT
void bind(in_if_type& interface_)
override { this->bind(
const_cast<const in_if_type&
>(interface_)); }
286 void operator()(
const in_if_type& interface_) { this->bind(interface_); }
288 SCC_VIRT
void bind(in_port_type& parent_) { sc_port_base::bind(parent_); }
290 void operator()(in_port_type& parent_) { this->bind(parent_); }
292 SCC_VIRT
void bind(inout_port_type& parent_) { sc_port_base::bind(parent_); }
294 void operator()(inout_port_type& parent_) { this->bind(parent_); }
296 const sc_core::sc_event& default_event()
const {
return (*this)->default_event(); }
298 const sc_core::sc_event& value_changed_event()
const {
return (*this)->value_changed_event(); }
300 const sc_core::sc_event& posedge_event()
const {
return (*this)->posedge_event(); }
302 const sc_core::sc_event& negedge_event()
const {
return (*this)->negedge_event(); }
304 const data_type& read()
const {
return (*this)->read(); }
306 operator const data_type&()
const {
return (*this)->read(); }
308 bool event()
const {
return (*this)->event(); }
310 bool posedge()
const {
return (*this)->posedge(); }
312 bool negedge()
const {
return (*this)->negedge(); }
314 virtual const char* kind()
const override {
return "sc_in"; }
317 template <
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> {
321 typedef sc_core::sc_signal_inout_if<data_type> if_type;
322 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
325 typedef sc_core::sc_signal_in_if<data_type> in_if_type;
326 typedef sc_core::sc_port<in_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> in_port_type;
327 typedef if_type inout_if_type;
328 typedef base_type inout_port_type;
340 : base_type(interface_)
343 sc_inout_opt(
const char* name_, inout_if_type& interface_)
344 : base_type(name_, interface_)
351 sc_inout_opt(
const char* name_, inout_port_type& parent_)
352 : base_type(name_, parent_)
360 : base_type(name_, parent_)
367 const sc_core::sc_event& default_event()
const {
return (*this)->default_event(); }
369 const sc_core::sc_event& value_changed_event()
const {
return (*this)->value_changed_event(); }
371 const data_type& read()
const {
return (*this)->read(); }
373 operator const data_type&()
const {
return (*this)->read(); }
375 bool event()
const {
return (*this)->event(); }
377 void write(
const data_type& value_) { (*this)->write(value_); }
379 this_type& operator=(
const data_type& value_) {
380 (*this)->write(value_);
384 this_type& operator=(
const in_if_type& interface_) {
385 (*this)->write(interface_.read());
389 this_type& operator=(
const in_port_type& port_) {
390 (*this)->write(port_->read());
394 this_type& operator=(
const inout_port_type& port_) {
395 (*this)->write(port_->read());
400 (*this)->write(port_->read());
404 void initialize(
const data_type& value_);
406 void initialize(
const in_if_type& interface_) { initialize(interface_.read()); }
408 void end_of_elaboration()
override;
410 virtual const char* kind()
const override {
return "sc_inout"; }
413 data_type* m_init_val;
416 template <typename T>::std::ostream&
operator<<(::std::ostream& os,
const sc_inout_opt<T>& a) {
return os << a->read(); }
418 template <
class T>
inline void sc_inout_opt<T>::initialize(
const data_type& value_) {
419 inout_if_type* iface =
dynamic_cast<inout_if_type*
>(this->get_interface());
421 iface->write(value_);
423 if(m_init_val == 0) {
424 m_init_val =
new data_type;
426 *m_init_val = value_;
430 template <
class T>
inline void sc_inout_opt<T>::end_of_elaboration() {
431 if(m_init_val != 0) {
440 SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_inout_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
445 class 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> {
447 typedef bool data_type;
449 typedef sc_core::sc_signal_inout_if<data_type> if_type;
450 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
453 typedef sc_core::sc_signal_in_if<data_type> in_if_type;
454 typedef sc_core::sc_port<in_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> in_port_type;
455 typedef if_type inout_if_type;
456 typedef base_type inout_port_type;
468 : base_type(interface_)
471 sc_inout_opt(
const char* name_, inout_if_type& interface_)
472 : base_type(name_, interface_)
479 sc_inout_opt(
const char* name_, inout_port_type& parent_)
480 : base_type(name_, parent_)
488 : base_type(name_, parent_)
495 const sc_core::sc_event& default_event()
const {
return (*this)->default_event(); }
497 const sc_core::sc_event& value_changed_event()
const {
return (*this)->value_changed_event(); }
499 const sc_core::sc_event& posedge_event()
const {
return (*this)->posedge_event(); }
501 const sc_core::sc_event& negedge_event()
const {
return (*this)->negedge_event(); }
503 const data_type& read()
const {
return (*this)->read(); }
505 operator const data_type&()
const {
return (*this)->read(); }
507 bool event()
const {
return (*this)->event(); }
509 bool posedge()
const {
return (*this)->posedge(); }
511 bool negedge()
const {
return (*this)->negedge(); }
513 void write(
const data_type& value_) { (*this)->write(value_); }
515 this_type& operator=(
const data_type& value_) {
516 (*this)->write(value_);
520 this_type& operator=(
const in_if_type& interface_) {
521 (*this)->write(interface_.read());
525 this_type& operator=(
const in_port_type& port_) {
526 (*this)->write(port_->read());
530 this_type& operator=(
const inout_port_type& port_) {
531 (*this)->write(port_->read());
536 (*this)->write(port_->read());
540 void initialize(
const data_type& value_);
542 void initialize(
const in_if_type& interface_) { initialize(interface_.read()); }
544 void end_of_elaboration()
override {
545 if(m_init_val != 0) {
552 virtual const char* kind()
const override {
return "sc_inout"; }
555 data_type* m_init_val;
560 SC_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>;
566 :
public sc_core::sc_port<sc_core::sc_signal_inout_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
568 typedef sc_dt::sc_logic data_type;
570 typedef sc_core::sc_signal_inout_if<data_type> if_type;
571 typedef sc_core::sc_port<if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> base_type;
574 typedef sc_core::sc_signal_in_if<data_type> in_if_type;
575 typedef sc_core::sc_port<in_if_type, 1, sc_core::SC_ZERO_OR_MORE_BOUND> in_port_type;
576 typedef if_type inout_if_type;
577 typedef base_type inout_port_type;
589 : base_type(interface_)
592 sc_inout_opt(
const char* name_, inout_if_type& interface_)
593 : base_type(name_, interface_)
600 sc_inout_opt(
const char* name_, inout_port_type& parent_)
601 : base_type(name_, parent_)
609 : base_type(name_, parent_)
616 const sc_core::sc_event& default_event()
const {
return (*this)->default_event(); }
618 const sc_core::sc_event& value_changed_event()
const {
return (*this)->value_changed_event(); }
620 const sc_core::sc_event& posedge_event()
const {
return (*this)->posedge_event(); }
622 const sc_core::sc_event& negedge_event()
const {
return (*this)->negedge_event(); }
624 const data_type& read()
const {
return (*this)->read(); }
626 operator const data_type&()
const {
return (*this)->read(); }
628 bool event()
const {
return (*this)->event(); }
630 bool posedge()
const {
return (*this)->posedge(); }
632 bool negedge()
const {
return (*this)->negedge(); }
634 void write(
const data_type& value_) { (*this)->write(value_); }
636 this_type& operator=(
const data_type& value_) {
637 (*this)->write(value_);
641 this_type& operator=(
const in_if_type& interface_) {
642 (*this)->write(interface_.read());
646 this_type& operator=(
const in_port_type& port_) {
647 (*this)->write(port_->read());
651 this_type& operator=(
const inout_port_type& port_) {
652 (*this)->write(port_->read());
657 (*this)->write(port_->read());
661 void initialize(
const data_type& value_);
663 void initialize(
const in_if_type& interface_) { initialize(interface_.read()); }
666 void end_of_elaboration()
override {
667 if(m_init_val != 0) {
674 virtual const char* kind()
const override {
return "sc_inout"; }
677 data_type* m_init_val;
687 typedef typename base_type::in_if_type in_if_type;
688 typedef typename base_type::in_port_type in_port_type;
689 typedef typename base_type::inout_if_type inout_if_type;
690 typedef typename base_type::inout_port_type inout_port_type;
697 : base_type(name_) {}
699 explicit sc_out_opt(inout_if_type& interface_)
700 : base_type(interface_) {}
702 sc_out_opt(
const char* name_, inout_if_type& interface_)
703 : base_type(name_, interface_) {}
706 : base_type(parent_) {}
708 sc_out_opt(
const char* name_, inout_port_type& parent_)
709 : base_type(name_, parent_) {}
712 : base_type(parent_) {}
715 : base_type(name_, parent_) {}
719 this_type& operator=(
const data_type& value_) {
720 (*this)->write(value_);
724 this_type& operator=(
const in_if_type& interface_) {
725 (*this)->write(interface_.read());
729 this_type& operator=(
const in_port_type& port_) {
730 (*this)->write(port_->read());
734 this_type& operator=(
const inout_port_type& port_) {
735 (*this)->write(port_->read());
740 (*this)->write(port_->read());
744 virtual const char* kind()
const override {
return "sc_out"; }
750 template <
class T>
inline void sc_trace(sc_core::sc_trace_file* tf,
const sc_in_opt<T>& port,
const std::string& name) {
751 const sc_core::sc_signal_in_if<T>* iface = 0;
752 if(sc_core::sc_get_curr_simcontext()->elaboration_done()) {
753 iface =
dynamic_cast<const sc_core::sc_signal_in_if<T>*
>(port.get_interface());
756 sc_trace(tf, iface->read(), name);
758 port.add_trace_internal(tf, name);
761 template <
class T>
inline void sc_trace(sc_core::sc_trace_file* tf,
const sc_inout_opt<T>& port,
const std::string& name) {
762 const sc_core::sc_signal_in_if<T>* iface = 0;
763 if(sc_core::sc_get_curr_simcontext()->elaboration_done()) {
764 iface =
dynamic_cast<const sc_core::sc_signal_in_if<T>*
>(port.get_interface());
768 sc_trace(tf, iface->read(), name);
770 port.add_trace_internal(tf, name);
777 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
std::ostream & operator<<(std::ostream &os, log const &val)
output the textual representation of the log level