scc  2024.06
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 namespace scc {
34 
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> {
36 public:
37  using data_type = T;
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;
42 
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>;
47 
48 public:
49  sc_in_opt()
50  : base_type() {}
51 
52  explicit sc_in_opt(const char* name_)
53  : base_type(name_) {}
54 
55  explicit sc_in_opt(const in_if_type& interface_)
56  : base_type(const_cast<in_if_type&>(interface_)) {}
57 
58  sc_in_opt(const char* name_, const in_if_type& interface_)
59  : base_type(name_, const_cast<in_if_type&>(interface_)) {}
60 
61  explicit sc_in_opt(in_port_type& parent_)
62  : base_type(parent_) {}
63 
64  sc_in_opt(const char* name_, in_port_type& parent_)
65  : base_type(name_, parent_) {}
66 
67  explicit sc_in_opt(inout_port_type& parent_)
68  : base_type() {
69  sc_core::sc_port_base::bind(parent_);
70  }
71 
72  sc_in_opt(const char* name_, inout_port_type& parent_)
73  : base_type(name_) {
74  sc_core::sc_port_base::bind(parent_);
75  }
76 
77  sc_in_opt(this_type& parent_)
78  : base_type(parent_) {}
79 
80  sc_in_opt(const char* name_, this_type& parent_)
81  : base_type(name_, parent_) {}
82 
83  sc_in_opt(const this_type&) = delete;
84 
85  virtual ~sc_in_opt() {}
86 
87  this_type& operator=(const this_type&) = delete;
88 
89  SCC_VIRT void bind(const in_if_type& interface_) { sc_core::sc_port_base::bind(const_cast<in_if_type&>(interface_)); }
90 
91  SCC_VIRT void bind(in_if_type& interface_) override { this->bind(const_cast<const in_if_type&>(interface_)); }
92 
93  void operator()(const in_if_type& interface_) { this->bind(interface_); }
94 
95  SCC_VIRT void bind(in_port_type& parent_) { sc_core::sc_port_base::bind(parent_); }
96 
97  void operator()(in_port_type& parent_) { this->bind(parent_); }
98 
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_); }
100 
101  void operator()(sc_core::sc_port<if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { this->bind(parent_); }
102 
103  SCC_VIRT void bind(inout_port_type& parent_) { sc_core::sc_port_base::bind(parent_); }
104 
105  void operator()(inout_port_type& parent_) { this->bind(parent_); }
106 
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_); }
108 
109  void operator()(sc_core::sc_port<inout_if_type, 1, sc_core::SC_ONE_OR_MORE_BOUND>& parent_) { this->bind(parent_); }
110 
111  const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
112 
113  const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
114 
115  const data_type& read() const { return (*this)->read(); }
116 
117  operator const data_type&() const { return (*this)->read(); }
118 
119  bool event() const { return (*this)->event(); }
120 
121  virtual const char* kind() const override { return "sc_in"; }
122 };
123 
124 template <typename T>::std::ostream& operator<<(::std::ostream& os, const sc_in_opt<T>& a) { return os << a->read(); }
125 } // namespace scc
126 
127 SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_in_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
128 
129 namespace scc {
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> {
131 public:
132  typedef bool data_type;
133 
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 /* typename */ base_type::port_type base_port_type;
138 
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;
143 
144 public:
145  sc_in_opt()
146  : base_type() {}
147 
148  explicit sc_in_opt(const char* name_)
149  : base_type(name_) {}
150 
151  explicit sc_in_opt(const in_if_type& interface_)
152  : base_type(const_cast<in_if_type&>(interface_)) {}
153 
154  sc_in_opt(const char* name_, const in_if_type& interface_)
155  : base_type(name_, const_cast<in_if_type&>(interface_)) {}
156 
157  explicit sc_in_opt(in_port_type& parent_)
158  : base_type(parent_) {}
159 
160  sc_in_opt(const char* name_, in_port_type& parent_)
161  : base_type(name_, parent_) {}
162 
163  explicit sc_in_opt(inout_port_type& parent_)
164  : base_type() {
165  sc_port_base::bind(parent_);
166  }
167 
168  sc_in_opt(const char* name_, inout_port_type& parent_)
169  : base_type(name_) {
170  sc_port_base::bind(parent_);
171  }
172 
173  sc_in_opt(this_type& parent_)
174  : base_type(parent_) {}
175 
176  sc_in_opt(const char* name_, this_type& parent_)
177  : base_type(name_, parent_) {}
178 
179  sc_in_opt(const this_type&) = delete;
180 
181  virtual ~sc_in_opt() = default;
182 
183  this_type& operator=(const this_type&) = delete;
184 
185  SCC_VIRT void bind(const in_if_type& interface_) { sc_port_base::bind(const_cast<in_if_type&>(interface_)); }
186 
187  SCC_VIRT void bind(in_if_type& interface_) override { this->bind(const_cast<const in_if_type&>(interface_)); }
188 
189  void operator()(const in_if_type& interface_) { this->bind(interface_); }
190 
191  SCC_VIRT void bind(in_port_type& parent_) { sc_port_base::bind(parent_); }
192 
193  void operator()(in_port_type& parent_) { this->bind(parent_); }
194 
195  SCC_VIRT void bind(inout_port_type& parent_) { sc_port_base::bind(parent_); }
196 
197  void operator()(inout_port_type& parent_) { this->bind(parent_); }
198 
199  const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
200 
201  const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
202 
203  const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
204 
205  const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
206 
207  const data_type& read() const { return (*this)->read(); }
208 
209  operator const data_type&() const { return (*this)->read(); }
210 
211  bool event() const { return (*this)->event(); }
212 
213  bool posedge() const { return (*this)->posedge(); }
214 
215  bool negedge() const { return (*this)->negedge(); }
216 
217  virtual const char* kind() const override { return "sc_in"; }
218 };
219 
220 } // namespace scc
221 
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>;
223 
224 namespace scc {
225 template <>
226 class SC_API sc_in_opt<sc_dt::sc_logic>
227 : public sc_core::sc_port<sc_core::sc_signal_in_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
228 public:
229  typedef sc_dt::sc_logic data_type;
230 
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 /* typename */ base_type::port_type base_port_type;
235 
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;
240 
241 public:
242  sc_in_opt()
243  : base_type() {}
244 
245  explicit sc_in_opt(const char* name_)
246  : base_type(name_) {}
247 
248  explicit sc_in_opt(const in_if_type& interface_)
249  : base_type(const_cast<in_if_type&>(interface_)) {}
250 
251  sc_in_opt(const char* name_, const in_if_type& interface_)
252  : base_type(name_, const_cast<in_if_type&>(interface_)) {}
253 
254  explicit sc_in_opt(in_port_type& parent_)
255  : base_type(parent_) {}
256 
257  sc_in_opt(const char* name_, in_port_type& parent_)
258  : base_type(name_, parent_) {}
259 
260  explicit sc_in_opt(inout_port_type& parent_)
261  : base_type() {
262  sc_port_base::bind(parent_);
263  }
264 
265  sc_in_opt(const char* name_, inout_port_type& parent_)
266  : base_type(name_) {
267  sc_port_base::bind(parent_);
268  }
269 
270  sc_in_opt(this_type& parent_)
271  : base_type(parent_) {}
272 
273  sc_in_opt(const char* name_, this_type& parent_)
274  : base_type(name_, parent_) {}
275 
276  sc_in_opt(const this_type&) = delete;
277 
278  virtual ~sc_in_opt() = default;
279 
280  this_type& operator=(const this_type&) = delete;
281 
282  SCC_VIRT void bind(const in_if_type& interface_) { sc_port_base::bind(const_cast<in_if_type&>(interface_)); }
283 
284  SCC_VIRT void bind(in_if_type& interface_) override { this->bind(const_cast<const in_if_type&>(interface_)); }
285 
286  void operator()(const in_if_type& interface_) { this->bind(interface_); }
287 
288  SCC_VIRT void bind(in_port_type& parent_) { sc_port_base::bind(parent_); }
289 
290  void operator()(in_port_type& parent_) { this->bind(parent_); }
291 
292  SCC_VIRT void bind(inout_port_type& parent_) { sc_port_base::bind(parent_); }
293 
294  void operator()(inout_port_type& parent_) { this->bind(parent_); }
295 
296  const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
297 
298  const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
299 
300  const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
301 
302  const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
303 
304  const data_type& read() const { return (*this)->read(); }
305 
306  operator const data_type&() const { return (*this)->read(); }
307 
308  bool event() const { return (*this)->event(); }
309 
310  bool posedge() const { return (*this)->posedge(); }
311 
312  bool negedge() const { return (*this)->negedge(); }
313 
314  virtual const char* kind() const override { return "sc_in"; }
315 };
316 
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> {
318 public:
319  typedef T data_type;
320 
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;
324 
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;
329 
330 public:
331  sc_inout_opt()
332  : base_type()
333  , m_init_val(0) {}
334 
335  explicit sc_inout_opt(const char* name_)
336  : base_type(name_)
337  , m_init_val(0) {}
338 
339  explicit sc_inout_opt(inout_if_type& interface_)
340  : base_type(interface_)
341  , m_init_val(0) {}
342 
343  sc_inout_opt(const char* name_, inout_if_type& interface_)
344  : base_type(name_, interface_)
345  , m_init_val(0) {}
346 
347  explicit sc_inout_opt(inout_port_type& parent_)
348  : base_type(parent_)
349  , m_init_val(0) {}
350 
351  sc_inout_opt(const char* name_, inout_port_type& parent_)
352  : base_type(name_, parent_)
353  , m_init_val(0) {}
354 
355  sc_inout_opt(this_type& parent_)
356  : base_type(parent_)
357  , m_init_val(0) {}
358 
359  sc_inout_opt(const char* name_, this_type& parent_)
360  : base_type(name_, parent_)
361  , m_init_val(0) {}
362 
363  sc_inout_opt(const this_type&) = delete;
364 
365  virtual ~sc_inout_opt() = default;
366 
367  const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
368 
369  const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
370 
371  const data_type& read() const { return (*this)->read(); }
372 
373  operator const data_type&() const { return (*this)->read(); }
374 
375  bool event() const { return (*this)->event(); }
376 
377  void write(const data_type& value_) { (*this)->write(value_); }
378 
379  this_type& operator=(const data_type& value_) {
380  (*this)->write(value_);
381  return *this;
382  }
383 
384  this_type& operator=(const in_if_type& interface_) {
385  (*this)->write(interface_.read());
386  return *this;
387  }
388 
389  this_type& operator=(const in_port_type& port_) {
390  (*this)->write(port_->read());
391  return *this;
392  }
393 
394  this_type& operator=(const inout_port_type& port_) {
395  (*this)->write(port_->read());
396  return *this;
397  }
398 
399  this_type& operator=(const this_type& port_) {
400  (*this)->write(port_->read());
401  return *this;
402  }
403 
404  void initialize(const data_type& value_);
405 
406  void initialize(const in_if_type& interface_) { initialize(interface_.read()); }
407 
408  void end_of_elaboration() override;
409 
410  virtual const char* kind() const override { return "sc_inout"; }
411 
412 protected:
413  data_type* m_init_val;
414 };
415 
416 template <typename T>::std::ostream& operator<<(::std::ostream& os, const sc_inout_opt<T>& a) { return os << a->read(); }
417 
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());
420  if(iface != 0) {
421  iface->write(value_);
422  } else {
423  if(m_init_val == 0) {
424  m_init_val = new data_type;
425  }
426  *m_init_val = value_;
427  }
428 }
429 
430 template <class T> inline void sc_inout_opt<T>::end_of_elaboration() {
431  if(m_init_val != 0) {
432  write(*m_init_val);
433  delete m_init_val;
434  m_init_val = 0;
435  }
436 }
437 } // namespace scc
438 
439 #ifndef CWR_SYSTEMC
440 SC_API_TEMPLATE_DECL_ sc_core::sc_port<sc_core::sc_signal_inout_if<bool>, 1, sc_core::SC_ZERO_OR_MORE_BOUND>;
441 #endif
442 
443 namespace scc {
444 template <>
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> {
446 public:
447  typedef bool data_type;
448 
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;
452 
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;
457 
458 public:
459  sc_inout_opt()
460  : base_type()
461  , m_init_val(0) {}
462 
463  explicit sc_inout_opt(const char* name_)
464  : base_type(name_)
465  , m_init_val(0) {}
466 
467  explicit sc_inout_opt(inout_if_type& interface_)
468  : base_type(interface_)
469  , m_init_val(0) {}
470 
471  sc_inout_opt(const char* name_, inout_if_type& interface_)
472  : base_type(name_, interface_)
473  , m_init_val(0) {}
474 
475  explicit sc_inout_opt(inout_port_type& parent_)
476  : base_type(parent_)
477  , m_init_val(0) {}
478 
479  sc_inout_opt(const char* name_, inout_port_type& parent_)
480  : base_type(name_, parent_)
481  , m_init_val(0) {}
482 
483  sc_inout_opt(this_type& parent_)
484  : base_type(parent_)
485  , m_init_val(0) {}
486 
487  sc_inout_opt(const char* name_, this_type& parent_)
488  : base_type(name_, parent_)
489  , m_init_val(0) {}
490 
491  sc_inout_opt(const this_type&) = delete;
492 
493  virtual ~sc_inout_opt() = default;
494 
495  const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
496 
497  const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
498 
499  const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
500 
501  const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
502 
503  const data_type& read() const { return (*this)->read(); }
504 
505  operator const data_type&() const { return (*this)->read(); }
506 
507  bool event() const { return (*this)->event(); }
508 
509  bool posedge() const { return (*this)->posedge(); }
510 
511  bool negedge() const { return (*this)->negedge(); }
512 
513  void write(const data_type& value_) { (*this)->write(value_); }
514 
515  this_type& operator=(const data_type& value_) {
516  (*this)->write(value_);
517  return *this;
518  }
519 
520  this_type& operator=(const in_if_type& interface_) {
521  (*this)->write(interface_.read());
522  return *this;
523  }
524 
525  this_type& operator=(const in_port_type& port_) {
526  (*this)->write(port_->read());
527  return *this;
528  }
529 
530  this_type& operator=(const inout_port_type& port_) {
531  (*this)->write(port_->read());
532  return *this;
533  }
534 
535  this_type& operator=(const this_type& port_) {
536  (*this)->write(port_->read());
537  return *this;
538  }
539 
540  void initialize(const data_type& value_);
541 
542  void initialize(const in_if_type& interface_) { initialize(interface_.read()); }
543 
544  void end_of_elaboration() override {
545  if(m_init_val != 0) {
546  write(*m_init_val);
547  delete m_init_val;
548  m_init_val = 0;
549  }
550  }
551 
552  virtual const char* kind() const override { return "sc_inout"; }
553 
554 protected:
555  data_type* m_init_val;
556 };
557 } // namespace scc
558 
559 #ifndef CWR_SYSTEMC
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>;
561 #endif
562 
563 namespace scc {
564 template <>
565 class SC_API sc_inout_opt<sc_dt::sc_logic>
566 : public sc_core::sc_port<sc_core::sc_signal_inout_if<sc_dt::sc_logic>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> {
567 public:
568  typedef sc_dt::sc_logic data_type;
569 
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;
573 
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;
578 
579 public:
580  sc_inout_opt()
581  : base_type()
582  , m_init_val(0) {}
583 
584  explicit sc_inout_opt(const char* name_)
585  : base_type(name_)
586  , m_init_val(0) {}
587 
588  explicit sc_inout_opt(inout_if_type& interface_)
589  : base_type(interface_)
590  , m_init_val(0) {}
591 
592  sc_inout_opt(const char* name_, inout_if_type& interface_)
593  : base_type(name_, interface_)
594  , m_init_val(0) {}
595 
596  explicit sc_inout_opt(inout_port_type& parent_)
597  : base_type(parent_)
598  , m_init_val(0) {}
599 
600  sc_inout_opt(const char* name_, inout_port_type& parent_)
601  : base_type(name_, parent_)
602  , m_init_val(0) {}
603 
604  sc_inout_opt(this_type& parent_)
605  : base_type(parent_)
606  , m_init_val(0) {}
607 
608  sc_inout_opt(const char* name_, this_type& parent_)
609  : base_type(name_, parent_)
610  , m_init_val(0) {}
611 
612  sc_inout_opt(const this_type&) = delete;
613 
614  virtual ~sc_inout_opt();
615 
616  const sc_core::sc_event& default_event() const { return (*this)->default_event(); }
617 
618  const sc_core::sc_event& value_changed_event() const { return (*this)->value_changed_event(); }
619 
620  const sc_core::sc_event& posedge_event() const { return (*this)->posedge_event(); }
621 
622  const sc_core::sc_event& negedge_event() const { return (*this)->negedge_event(); }
623 
624  const data_type& read() const { return (*this)->read(); }
625 
626  operator const data_type&() const { return (*this)->read(); }
627 
628  bool event() const { return (*this)->event(); }
629 
630  bool posedge() const { return (*this)->posedge(); }
631 
632  bool negedge() const { return (*this)->negedge(); }
633 
634  void write(const data_type& value_) { (*this)->write(value_); }
635 
636  this_type& operator=(const data_type& value_) {
637  (*this)->write(value_);
638  return *this;
639  }
640 
641  this_type& operator=(const in_if_type& interface_) {
642  (*this)->write(interface_.read());
643  return *this;
644  }
645 
646  this_type& operator=(const in_port_type& port_) {
647  (*this)->write(port_->read());
648  return *this;
649  }
650 
651  this_type& operator=(const inout_port_type& port_) {
652  (*this)->write(port_->read());
653  return *this;
654  }
655 
656  this_type& operator=(const this_type& port_) {
657  (*this)->write(port_->read());
658  return *this;
659  }
660 
661  void initialize(const data_type& value_);
662 
663  void initialize(const in_if_type& interface_) { initialize(interface_.read()); }
664 
665  // called when elaboration is done
666  void end_of_elaboration() override {
667  if(m_init_val != 0) {
668  write(*m_init_val);
669  delete m_init_val;
670  m_init_val = 0;
671  }
672  }
673 
674  virtual const char* kind() const override { return "sc_inout"; }
675 
676 protected:
677  data_type* m_init_val;
678 };
679 
680 template <class T> class sc_out_opt : public sc_inout_opt<T> {
681 public:
682  typedef T data_type;
683 
685  typedef sc_inout_opt<data_type> base_type;
686 
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;
691 
692 public:
693  sc_out_opt()
694  : base_type() {}
695 
696  explicit sc_out_opt(const char* name_)
697  : base_type(name_) {}
698 
699  explicit sc_out_opt(inout_if_type& interface_)
700  : base_type(interface_) {}
701 
702  sc_out_opt(const char* name_, inout_if_type& interface_)
703  : base_type(name_, interface_) {}
704 
705  explicit sc_out_opt(inout_port_type& parent_)
706  : base_type(parent_) {}
707 
708  sc_out_opt(const char* name_, inout_port_type& parent_)
709  : base_type(name_, parent_) {}
710 
711  sc_out_opt(this_type& parent_)
712  : base_type(parent_) {}
713 
714  sc_out_opt(const char* name_, this_type& parent_)
715  : base_type(name_, parent_) {}
716 
717  virtual ~sc_out_opt() {}
718 
719  this_type& operator=(const data_type& value_) {
720  (*this)->write(value_);
721  return *this;
722  }
723 
724  this_type& operator=(const in_if_type& interface_) {
725  (*this)->write(interface_.read());
726  return *this;
727  }
728 
729  this_type& operator=(const in_port_type& port_) {
730  (*this)->write(port_->read());
731  return *this;
732  }
733 
734  this_type& operator=(const inout_port_type& port_) {
735  (*this)->write(port_->read());
736  return *this;
737  }
738 
739  this_type& operator=(const this_type& port_) {
740  (*this)->write(port_->read());
741  return *this;
742  }
743 
744  virtual const char* kind() const override { return "sc_out"; }
745 
746 private:
747  sc_out_opt(const this_type&) = delete;
748 };
749 
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());
754  }
755  if(iface)
756  sc_trace(tf, iface->read(), name);
757  else
758  port.add_trace_internal(tf, name);
759 }
760 
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());
765  }
766 
767  if(iface)
768  sc_trace(tf, iface->read(), name);
769  else
770  port.add_trace_internal(tf, name);
771 }
772 
773 } // namespace scc
774 
775 #undef SCC_VIRT
776 
777 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
778 #pragma warning(pop)
779 #endif
780 #endif /* SCC_SRC_SYSC_SCC_OPT_SIGNAL_PORTS_H_ */
SCC TLM utilities.
std::ostream & operator<<(std::ostream &os, log const &val)
output the textual representation of the log level
Definition: report.h:130