sc_port.hh revision 12957:e54f9890363d
12SN/A/*
21762SN/A * Copyright 2018 Google, Inc.
32SN/A *
42SN/A * Redistribution and use in source and binary forms, with or without
52SN/A * modification, are permitted provided that the following conditions are
62SN/A * met: redistributions of source code must retain the above copyright
72SN/A * notice, this list of conditions and the following disclaimer;
82SN/A * redistributions in binary form must reproduce the above copyright
92SN/A * notice, this list of conditions and the following disclaimer in the
102SN/A * documentation and/or other materials provided with the distribution;
112SN/A * neither the name of the copyright holders nor the names of its
122SN/A * contributors may be used to endorse or promote products derived from
132SN/A * this software without specific prior written permission.
142SN/A *
152SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262SN/A *
272665SN/A * Authors: Gabe Black
282665SN/A */
292SN/A
302SN/A#ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__
312SN/A#define __SYSTEMC_EXT_CORE_SC_PORT_HH__
322SN/A
332SN/A#include <vector>
3411263Sandreas.sandberg@arm.com
352SN/A#include "sc_module.hh" // for sc_gen_unique_name
36146SN/A#include "sc_object.hh"
372SN/A
382SN/Anamespace sc_gem5
392SN/A{
402SN/A
41146SN/Aclass BindInfo;
428232SN/Aclass PendingSensitivityPort;
438232SN/A
4411263Sandreas.sandberg@arm.com};
4511263Sandreas.sandberg@arm.com
4611263Sandreas.sandberg@arm.comnamespace sc_core
474762SN/A{
484167SN/A
492SN/Aclass sc_interface;
502SN/A
512SN/Aenum sc_port_policy
524981SN/A{
534981SN/A    SC_ONE_OR_MORE_BOUND, // Default
545606SN/A    SC_ZERO_OR_MORE_BOUND,
551634SN/A    SC_ALL_BOUND
561634SN/A};
572SN/A
582SN/Aclass sc_port_base : public sc_object
592SN/A{
602SN/A  public:
612SN/A    sc_port_base(const char *name, int n, sc_port_policy p);
622SN/A
632SN/A    void warn_unimpl(const char *func) const;
642SN/A
652SN/A    int maxSize() const;
662SN/A    int size() const;
672SN/A
682SN/A  protected:
692SN/A    // Implementation defined, but depended on by the tests.
702SN/A    void bind(sc_interface &);
712SN/A    void bind(sc_port_base &);
722SN/A
732SN/A    // Implementation defined, but depended on by the tests.
742SN/A    virtual int vbind(sc_interface &) = 0;
752SN/A    virtual int vbind(sc_port_base &) = 0;
762SN/A
772SN/A  private:
782SN/A    friend class ::sc_gem5::PendingSensitivityPort;
792SN/A
802SN/A    std::vector<::sc_gem5::BindInfo *> _gem5BindInfo;
812SN/A    int _maxSize;
824981SN/A};
834981SN/A
844981SN/Atemplate <class IF>
854981SN/Aclass sc_port_b : public sc_port_base
864981SN/A{
872SN/A  public:
882SN/A    void
892566SN/A    operator () (IF &)
902SN/A    {
912SN/A        this->warn_unimpl(__PRETTY_FUNCTION__);
927823SN/A    }
932SN/A
942SN/A    void
952SN/A    operator () (sc_port_b<IF> &)
962SN/A    {
972SN/A        this->warn_unimpl(__PRETTY_FUNCTION__);
982SN/A    }
992SN/A
1002SN/A    virtual void
1011634SN/A    bind(IF &)
1022SN/A    {
1031634SN/A        this->warn_unimpl(__PRETTY_FUNCTION__);
1047823SN/A    }
1052SN/A
1062SN/A    virtual void
1072SN/A    bind(sc_port_b<IF> &)
1082SN/A    {
1094762SN/A        this->warn_unimpl(__PRETTY_FUNCTION__);
1104762SN/A    }
1112SN/A
1124981SN/A    int
1132SN/A    size() const
114    {
115        this->warn_unimpl(__PRETTY_FUNCTION__);
116        return 0;
117    }
118
119    IF *
120    operator -> ()
121    {
122        this->warn_unimpl(__PRETTY_FUNCTION__);
123        return (IF *)nullptr;
124    }
125
126    const IF *
127    operator -> () const
128    {
129        this->warn_unimpl(__PRETTY_FUNCTION__);
130        return (IF *)nullptr;
131    }
132
133    IF *
134    operator [] (int)
135    {
136        this->warn_unimpl(__PRETTY_FUNCTION__);
137        return (IF *)nullptr;
138    }
139
140    const IF *
141    operator [] (int) const
142    {
143        this->warn_unimpl(__PRETTY_FUNCTION__);
144        return (IF *)nullptr;
145    }
146
147    virtual sc_interface *
148    get_interface()
149    {
150        this->warn_unimpl(__PRETTY_FUNCTION__);
151        return (sc_interface *)nullptr;
152    }
153
154    virtual const sc_interface *
155    get_interface() const
156    {
157        this->warn_unimpl(__PRETTY_FUNCTION__);
158        return (sc_interface *)nullptr;
159    }
160
161  protected:
162    virtual void before_end_of_elaboration() {}
163    virtual void end_of_elaboration() {}
164    virtual void start_of_elaboration() {}
165    virtual void end_of_simulation() {}
166
167    explicit sc_port_b(int n, sc_port_policy p) :
168            sc_port_base(sc_gen_unique_name("sc_port"), n, p)
169    {}
170    sc_port_b(const char *name, int n, sc_port_policy p) :
171            sc_port_base(name, n, p)
172    {}
173    virtual ~sc_port_b() {}
174
175    // Implementation defined, but depended on by the tests.
176    int
177    vbind(sc_interface &)
178    {
179        this->warn_unimpl(__PRETTY_FUNCTION__);
180        return 0;
181    }
182    int
183    vbind(sc_port_base &)
184    {
185        this->warn_unimpl(__PRETTY_FUNCTION__);
186        return 0;
187    }
188
189  private:
190    // Disabled
191    sc_port_b() {}
192    sc_port_b(const sc_port_b<IF> &) {}
193    sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; }
194};
195
196template <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND>
197class sc_port : public sc_port_b<IF>
198{
199  public:
200    sc_port() : sc_port_b<IF>(N, P) {}
201    explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {}
202    virtual ~sc_port() {}
203
204    // Deprecated binding constructors.
205    explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P)
206    {
207        this->warn_unimpl(__PRETTY_FUNCTION__);
208        // Should warn that these are deprecated. See Accellera sc_port.h.
209        sc_port_b<IF>::bind(const_cast<IF &>(interface));
210    }
211    sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P)
212    {
213        this->warn_unimpl(__PRETTY_FUNCTION__);
214        // Should warn that these are deprecated. See Accellera sc_port.h.
215        sc_port_b<IF>::bind(const_cast<IF &>(interface));
216    }
217    explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P)
218    {
219        this->warn_unimpl(__PRETTY_FUNCTION__);
220        // Should warn that these are deprecated. See Accellera sc_port.h.
221        sc_port_b<IF>::bind(parent);
222    }
223    sc_port(const char *name, sc_port_b<IF> &parent) :
224        sc_port_b<IF>(name, N, P)
225    {
226        this->warn_unimpl(__PRETTY_FUNCTION__);
227        // Should warn that these are deprecated. See Accellera sc_port.h.
228        sc_port_b<IF>::bind(parent);
229    }
230    explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P)
231    {
232        this->warn_unimpl(__PRETTY_FUNCTION__);
233        // Should warn that these are deprecated. See Accellera sc_port.h.
234        sc_port_b<IF>::bind(parent);
235    }
236    sc_port(const char *name, sc_port<IF, N, P> &parent) :
237        sc_port_b<IF>(name, N, P)
238    {
239        this->warn_unimpl(__PRETTY_FUNCTION__);
240        // Should warn that these are deprecated. See Accellera sc_port.h.
241        sc_port_b<IF>::bind(parent);
242    }
243
244    virtual const char *kind() const { return "sc_port"; }
245
246  private:
247    // Disabled
248    sc_port(const sc_port<IF, N, P> &) {}
249    sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; }
250};
251
252} // namespace sc_core
253
254#endif  //__SYSTEMC_EXT_CORE_SC_PORT_HH__
255