gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_export.hh
Go to the documentation of this file.
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_CORE_SC_EXPORT_HH__
31 #define __SYSTEMC_EXT_CORE_SC_EXPORT_HH__
32 
33 #include "../channel/messages.hh"
34 #include "../utils/sc_report_handler.hh"
35 #include "sc_module.hh" // for sc_gen_unique_name
36 #include "sc_object.hh"
37 
38 namespace sc_core
39 {
40 
41 class sc_interface;
42 
43 class sc_export_base : public sc_object
44 {
45  public:
46  sc_export_base(const char *n);
48 
49  virtual sc_interface *get_iterface() = 0;
50  virtual const sc_interface *get_interface() const = 0;
51 
52  protected:
53  friend class sc_gem5::Module;
54 
55  virtual void before_end_of_elaboration() = 0;
56  virtual void end_of_elaboration() = 0;
57  virtual void start_of_simulation() = 0;
58  virtual void end_of_simulation() = 0;
59 };
60 
61 template <class IF>
62 class sc_export : public sc_export_base
63 {
64  public:
66  sc_export_base(sc_gen_unique_name("export")), interface(nullptr)
67  {}
68  explicit sc_export(const char *n) :
69  sc_export_base(n), interface(nullptr)
70  {}
71  virtual ~sc_export() {}
72 
73  virtual const char *kind() const override { return "sc_export"; }
74 
75  void operator () (IF &i) { bind(i); }
76  virtual void
77  bind(IF &i)
78  {
79  if (interface) {
81  return;
82  }
83  interface = &i;
84  }
85  operator IF & ()
86  {
87  if (!interface)
89  return *interface;
90  }
91  operator const IF & () const { return *interface; }
92 
93  IF *
94  operator -> ()
95  {
96  if (!interface)
98  return interface;
99  }
100  const IF *
101  operator -> () const
102  {
103  if (!interface)
105  return interface;
106  }
107 
108  sc_interface *get_iterface() override { return interface; }
109  const sc_interface *get_interface() const override { return interface; }
110 
111  protected:
112  void before_end_of_elaboration() override {}
113  void
115  {
116  if (!interface) {
117  std::string msg = "export not bound: export '";
118  msg = msg + name() + "' (" + kind() + ")";
119  SC_REPORT_ERROR("(E109) complete binding failed", msg.c_str());
120  }
121  }
122  void start_of_simulation() override {}
123  void end_of_simulation() override {}
124 
125  private:
127 
128  // Disabled
129  sc_export(const sc_export<IF> &);
131 };
132 
133 } // namespace sc_core
134 
135 #endif //__SYSTEMC_EXT_CORE_SC_EXPORT_HH__
virtual ~sc_export()
Definition: sc_export.hh:71
Bitfield< 7 > i
void start_of_simulation() override
Definition: sc_export.hh:122
sc_export_base(const char *n)
Definition: sc_export.cc:58
sc_export(const char *n)
Definition: sc_export.hh:68
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:822
virtual sc_interface * get_iterface()=0
sc_object & operator=(const sc_object &)
Definition: sc_object.cc:151
const char * name() const
Definition: sc_object.cc:46
virtual void before_end_of_elaboration()=0
virtual void end_of_elaboration()=0
Bitfield< 31 > n
virtual void end_of_simulation()=0
void before_end_of_elaboration() override
Definition: sc_export.hh:112
virtual const char * kind() const
Definition: sc_object.hh:58
virtual const char * kind() const override
Definition: sc_export.hh:73
sc_interface * get_iterface() override
Definition: sc_export.hh:108
const sc_interface * get_interface() const override
Definition: sc_export.hh:109
const char SC_ID_SC_EXPORT_ALREADY_BOUND_[]
Definition: messages.cc:73
void end_of_elaboration() override
Definition: sc_export.hh:114
virtual const sc_interface * get_interface() const =0
#define SC_REPORT_ERROR(msg_type, msg)
void end_of_simulation() override
Definition: sc_export.hh:123
const char SC_ID_SC_EXPORT_HAS_NO_INTERFACE_[]
Definition: messages.cc:62
virtual void start_of_simulation()=0
virtual void bind(IF &i)
Definition: sc_export.hh:77

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13