sc_signal.hh revision 12933
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_EXT_CHANNEL_SC_SIGNAL_HH__
31#define __SYSTEMC_EXT_CHANNEL_SC_SIGNAL_HH__
32
33#include <iostream>
34#include <string>
35#include <vector>
36
37#include "../core/sc_module.hh" // for sc_gen_unique_name
38#include "../core/sc_prim.hh"
39#include "sc_signal_inout_if.hh"
40#include "warn_unimpl.hh" // for warn_unimpl
41
42namespace sc_core
43{
44
45class sc_port_base;
46class sc_trace_file;
47
48// Nonstandard
49// Despite having a warning "FOR INTERNAL USE ONLY!" in all caps above this
50// class definition in the Accellera implementation, it appears in their
51// examples and test programs, and so we need to have it here as well.
52struct sc_trace_params
53{
54    sc_trace_file *tf;
55    std::string name;
56
57    sc_trace_params(sc_trace_file *tf, const std::string &name) :
58        tf(tf), name(name)
59    {}
60};
61typedef std::vector<sc_trace_params *> sc_trace_params_vec;
62
63template <class T, sc_writer_policy WRITER_POLICY=SC_ONE_WRITER>
64class sc_signal : public sc_signal_inout_if<T>,
65                  public sc_prim_channel
66{
67  public:
68    sc_signal() : sc_signal_inout_if<T>(),
69                  sc_prim_channel(sc_gen_unique_name("signal"))
70    {}
71    explicit sc_signal(const char *name) : sc_signal_inout_if<T>(),
72                                           sc_prim_channel(name)
73    {}
74    explicit sc_signal(const char *name, const T &initial_value) :
75        sc_signal_inout_if<T>(), sc_prim_channel(name)
76    {
77        // Need to consume initial_value.
78        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
79    }
80    virtual ~sc_signal() {}
81
82    virtual void
83    register_port(sc_port_base &, const char *)
84    {
85        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
86    }
87
88    virtual const T&
89    read() const
90    {
91        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
92        return *(const T *)nullptr;
93    }
94    operator const T&() const
95    {
96        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
97        return *(const T *)nullptr;
98    }
99
100    virtual sc_writer_policy
101    get_writer_policy() const
102    {
103        return WRITER_POLICY;
104    }
105    virtual void
106    write(const T&)
107    {
108        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
109    }
110    sc_signal<T, WRITER_POLICY> &
111    operator = (const T&)
112    {
113        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
114        return *this;
115    }
116    sc_signal<T, WRITER_POLICY> &
117    operator = (const sc_signal<T, WRITER_POLICY> &)
118    {
119        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
120        return *this;
121    }
122
123    virtual const sc_event &
124    default_event() const
125    {
126        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
127        return *(sc_event *)nullptr;
128    }
129    virtual const sc_event &
130    value_changed_event() const
131    {
132        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
133        return *(sc_event *)nullptr;
134    }
135    virtual bool
136    event() const
137    {
138        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
139        return false;
140    }
141
142    virtual void
143    print(std::ostream & =std::cout) const
144    {
145        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
146    }
147    virtual void
148    dump(std::ostream & =std::cout) const
149    {
150        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
151    }
152    virtual const char *kind() const { return "sc_signal"; }
153
154  protected:
155    virtual void
156    update()
157    {
158        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
159    }
160
161  private:
162    // Disabled
163    sc_signal(const sc_signal<T, WRITER_POLICY> &) :
164            sc_signal_inout_if<T>(), sc_prim_channel("")
165    {}
166};
167
168template <class T, sc_writer_policy WRITER_POLICY>
169inline std::ostream &
170operator << (std::ostream &os, const sc_signal<T, WRITER_POLICY> &)
171{
172    sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
173    return os;
174}
175
176template <sc_writer_policy WRITER_POLICY>
177class sc_signal<bool, WRITER_POLICY> :
178    public sc_signal_inout_if<bool>, public sc_prim_channel
179{
180  public:
181    sc_signal()
182    {
183        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
184    }
185    explicit sc_signal(const char *)
186    {
187        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
188    }
189    explicit sc_signal(const char *name, const bool &initial_value) :
190        sc_signal_inout_if<bool>(), sc_prim_channel(name)
191    {
192        // Need to consume initial_value.
193        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
194    }
195    virtual ~sc_signal()
196    {
197        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
198    }
199
200    virtual void
201    register_port(sc_port_base &, const char *)
202    {
203        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
204    }
205
206    virtual const bool &
207    read() const
208    {
209        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
210        return *(const bool *)nullptr;
211    }
212    operator const bool &() const
213    {
214        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
215        return *(const bool *)nullptr;
216    }
217
218    virtual sc_writer_policy
219    get_writer_policy() const
220    {
221        return WRITER_POLICY;
222    }
223    virtual void
224    write(const bool &)
225    {
226        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
227    }
228    sc_signal<bool, WRITER_POLICY> &
229    operator = (const bool &)
230    {
231        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
232        return *this;
233    }
234    sc_signal<bool, WRITER_POLICY> &
235    operator = (const sc_signal<bool, WRITER_POLICY> &)
236    {
237        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
238        return *this;
239    }
240
241    virtual const sc_event &
242    default_event() const
243    {
244        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
245        return *(sc_event *)nullptr;
246    }
247
248    virtual const sc_event &
249    value_changed_event() const
250    {
251        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
252        return *(sc_event *)nullptr;
253    }
254    virtual const sc_event &
255    posedge_event() const
256    {
257        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
258        return *(sc_event *)nullptr;
259    }
260    virtual const sc_event &
261    negedge_event() const
262    {
263        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
264        return *(sc_event *)nullptr;
265    }
266
267    virtual bool
268    event() const
269    {
270        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
271        return false;
272    }
273    virtual bool
274    posedge() const
275    {
276        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
277        return false;
278    }
279    virtual bool
280    negedge() const
281    {
282        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
283        return false;
284    }
285
286    virtual void
287    print(std::ostream & =std::cout) const
288    {
289        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
290    }
291    virtual void
292    dump(std::ostream & =std::cout) const
293    {
294        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
295    }
296    virtual const char *kind() const { return "sc_signal"; }
297
298  protected:
299    virtual void
300    update()
301    {
302        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
303    }
304
305  private:
306    // Disabled
307    sc_signal(const sc_signal<bool, WRITER_POLICY> &) :
308            sc_signal_inout_if<bool>(), sc_prim_channel("")
309    {}
310};
311
312template <sc_writer_policy WRITER_POLICY>
313class sc_signal<sc_dt::sc_logic, WRITER_POLICY> :
314    public sc_signal_inout_if<sc_dt::sc_logic>, public sc_prim_channel
315{
316  public:
317    sc_signal()
318    {
319        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
320    }
321    explicit sc_signal(const char *)
322    {
323        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
324    }
325    explicit sc_signal(const char *name,
326            const sc_dt::sc_logic &initial_value) :
327        sc_signal_inout_if<sc_dt::sc_logic>(), sc_prim_channel(name)
328    {
329        // Need to consume initial_value.
330        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
331    }
332    virtual ~sc_signal()
333    {
334        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
335    }
336
337    virtual void
338    register_port(sc_port_base &, const char *)
339    {
340        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
341    }
342
343    virtual const sc_dt::sc_logic &
344    read() const
345    {
346        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
347        return *(const sc_dt::sc_logic *)nullptr;
348    }
349    operator const sc_dt::sc_logic &() const
350    {
351        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
352        return *(const sc_dt::sc_logic *)nullptr;
353    }
354
355    virtual sc_writer_policy
356    get_writer_policy() const
357    {
358        return WRITER_POLICY;
359    }
360    virtual void
361    write(const sc_dt::sc_logic &)
362    {
363        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
364    }
365    sc_signal<sc_dt::sc_logic, WRITER_POLICY> &
366    operator = (const sc_dt::sc_logic &)
367    {
368        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
369        return *this;
370    }
371    sc_signal<sc_dt::sc_logic, WRITER_POLICY> &
372    operator = (const sc_signal<sc_dt::sc_logic, WRITER_POLICY> &)
373    {
374        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
375        return *this;
376    }
377
378    virtual const sc_event &
379    default_event() const
380    {
381        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
382        return *(sc_event *)nullptr;
383    }
384
385    virtual const sc_event &
386    value_changed_event() const
387    {
388        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
389        return *(sc_event *)nullptr;
390    }
391    virtual const sc_event &
392    posedge_event() const
393    {
394        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
395        return *(sc_event *)nullptr;
396    }
397    virtual const sc_event &
398    negedge_event() const
399    {
400        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
401        return *(sc_event *)nullptr;
402    }
403
404    virtual bool
405    event() const
406    {
407        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
408        return false;
409    }
410    virtual bool
411    posedge() const
412    {
413        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
414        return false;
415    }
416    virtual bool
417    negedge() const
418    {
419        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
420        return false;
421    }
422
423    virtual void
424    print(std::ostream & =std::cout) const
425    {
426        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
427    }
428    virtual void
429    dump(std::ostream & =std::cout) const
430    {
431        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
432    }
433    virtual const char *kind() const { return "sc_signal"; }
434
435  protected:
436    virtual void
437    update()
438    {
439        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
440    }
441
442  private:
443    // Disabled
444    sc_signal(const sc_signal<sc_dt::sc_logic, WRITER_POLICY> &) :
445            sc_signal_inout_if<sc_dt::sc_logic>(), sc_prim_channel("")
446    {}
447};
448
449} // namespace sc_core
450
451#endif  //__SYSTEMC_EXT_CHANNEL_SC_SIGNAL_HH__
452