sc_fifo.hh revision 12841:22aa7ba47bf9
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_FIFO_HH__
31#define __SYSTEMC_EXT_CHANNEL_SC_FIFO_HH__
32
33#include "../core/sc_module.hh" // for sc_gen_unique_name
34#include "../core/sc_prim.hh"
35#include "sc_fifo_in_if.hh"
36#include "sc_fifo_out_if.hh"
37#include "warn_unimpl.hh"
38
39namespace sc_core
40{
41
42class sc_port_base;
43class sc_event;
44
45template <class T>
46class sc_fifo : public sc_fifo_in_if<T>,
47                public sc_fifo_out_if<T>,
48                public sc_prim_channel
49{
50  public:
51    explicit sc_fifo(int size=16) :
52            sc_fifo_in_if<T>(), sc_fifo_out_if<T>(),
53            sc_prim_channel(sc_gen_unique_name("fifo"))
54    {}
55    explicit sc_fifo(const char *name, int size=16) :
56            sc_fifo_in_if<T>(), sc_fifo_out_if<T>(),
57            sc_prim_channel(name)
58    {}
59    virtual ~sc_fifo() {}
60
61    virtual void
62    register_port(sc_port_base &, const char *)
63    {
64        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
65    }
66
67    virtual void
68    read(T &)
69    {
70        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
71    }
72    virtual T
73    read()
74    {
75        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
76        return *(T *)nullptr;
77    }
78    virtual bool
79    nb_read(T &)
80    {
81        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
82        return false;
83    }
84    operator T()
85    {
86        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
87        return *(T *)nullptr;
88    }
89
90    virtual void
91    write(const T &)
92    {
93        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
94    }
95    virtual bool
96    nb_write(const T&)
97    {
98        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
99        return false;
100    }
101    sc_fifo<T> &
102    operator = (const T &)
103    {
104        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
105        return *this;
106    }
107
108    virtual const sc_event &
109    data_Written_event() const
110    {
111        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
112        return *(const sc_event *)nullptr;
113    }
114    virtual const sc_event &
115    data_read_event() const
116    {
117        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
118        return *(const sc_event *)nullptr;
119    }
120
121    virtual int
122    num_available() const
123    {
124        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
125        return 0;
126    }
127    virtual int
128    num_free() const
129    {
130        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
131        return 0;
132    }
133
134    virtual void
135    print(std::ostream & =std::cout) const
136    {
137        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
138    }
139    virtual void
140    dump(std::ostream & =std::cout) const
141    {
142        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
143    }
144    virtual const char *kind() const { return "sc_fifo"; }
145
146  protected:
147    virtual void
148    update()
149    {
150        sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
151    }
152
153  private:
154    // Disabled
155    sc_fifo(const sc_fifo<T> &) :
156            sc_fifo_in_if<T>(), sc_fifo_in_if<T>(), sc_prim_channel()
157    {}
158    sc_fifo &operator = (const sc_fifo<T> &) { return *this; }
159};
160
161template <class T>
162inline std::ostream &
163operator << (std::ostream &os, const sc_fifo<T> &)
164{
165    sc_channel_warn_unimpl(__PRETTY_FUNCTION__);
166    return os;
167}
168
169} // namespace sc_core
170
171#endif  //__SYSTEMC_EXT_CHANNEL_SC_FIFO_HH__
172