gem5  v20.1.0.0
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 
28 #ifndef __SYSTEMC_EXT_CORE_SC_EXPORT_HH__
29 #define __SYSTEMC_EXT_CORE_SC_EXPORT_HH__
30 
31 #include "../channel/messages.hh"
32 #include "../utils/sc_report_handler.hh"
33 #include "sc_module.hh" // for sc_gen_unique_name
34 #include "sc_object.hh"
35 
36 namespace sc_core
37 {
38 
39 class sc_interface;
40 
41 class sc_export_base : public sc_object
42 {
43  public:
44  sc_export_base(const char *n);
46 
47  virtual sc_interface *get_iterface() = 0;
48  virtual const sc_interface *get_interface() const = 0;
49 
50  protected:
51  friend class sc_gem5::Module;
52 
53  virtual void before_end_of_elaboration() = 0;
54  virtual void end_of_elaboration() = 0;
55  virtual void start_of_simulation() = 0;
56  virtual void end_of_simulation() = 0;
57 };
58 
59 template <class IF>
60 class sc_export : public sc_export_base
61 {
62  public:
64  sc_export_base(sc_gen_unique_name("export")), interface(nullptr)
65  {}
66  explicit sc_export(const char *n) :
67  sc_export_base(n), interface(nullptr)
68  {}
69  virtual ~sc_export() {}
70 
71  virtual const char *kind() const override { return "sc_export"; }
72 
73  void operator () (IF &i) { bind(i); }
74  virtual void
75  bind(IF &i)
76  {
77  if (interface) {
79  return;
80  }
81  interface = &i;
82  }
83  operator IF & ()
84  {
85  if (!interface)
87  return *interface;
88  }
89  operator const IF & () const { return *interface; }
90 
91  IF *
93  {
94  if (!interface)
96  return interface;
97  }
98  const IF *
99  operator -> () const
100  {
101  if (!interface)
103  return interface;
104  }
105 
106  sc_interface *get_iterface() override { return interface; }
107  const sc_interface *get_interface() const override { return interface; }
108 
109  protected:
110  void before_end_of_elaboration() override {}
111  void
113  {
114  if (!interface) {
115  std::string msg = "export not bound: export '";
116  msg = msg + name() + "' (" + kind() + ")";
117  SC_REPORT_ERROR("(E109) complete binding failed", msg.c_str());
118  }
119  }
120  void start_of_simulation() override {}
121  void end_of_simulation() override {}
122 
123  private:
125 
126  // Disabled
127  sc_export(const sc_export<IF> &);
129 };
130 
131 } // namespace sc_core
132 
133 #endif //__SYSTEMC_EXT_CORE_SC_EXPORT_HH__
sc_core::sc_export_base::get_interface
virtual const sc_interface * get_interface() const =0
sc_core::sc_export_base::end_of_simulation
virtual void end_of_simulation()=0
sc_core::SC_ID_SC_EXPORT_HAS_NO_INTERFACE_
const char SC_ID_SC_EXPORT_HAS_NO_INTERFACE_[]
Definition: messages.cc:60
sc_core::sc_export_base
Definition: sc_export.hh:41
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
sc_core::sc_export::before_end_of_elaboration
void before_end_of_elaboration() override
Definition: sc_export.hh:110
sc_core
Definition: messages.cc:31
sc_core::sc_interface
Definition: sc_interface.hh:37
sc_core::sc_export::kind
virtual const char * kind() const override
Definition: sc_export.hh:71
sc_core::sc_export::interface
IF * interface
Definition: sc_export.hh:124
sc_core::sc_export_base::start_of_simulation
virtual void start_of_simulation()=0
sc_core::sc_export::~sc_export
virtual ~sc_export()
Definition: sc_export.hh:69
sc_core::sc_export::start_of_simulation
void start_of_simulation() override
Definition: sc_export.hh:120
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
sc_core::sc_export::operator=
sc_export< IF > & operator=(const sc_export< IF > &)
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
sc_core::sc_export::end_of_elaboration
void end_of_elaboration() override
Definition: sc_export.hh:112
sc_core::sc_gen_unique_name
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:820
sc_core::sc_export::end_of_simulation
void end_of_simulation() override
Definition: sc_export.hh:121
sc_core::sc_object
Definition: sc_object.hh:50
sc_module.hh
sc_core::sc_export::bind
virtual void bind(IF &i)
Definition: sc_export.hh:75
sc_core::sc_export_base::sc_export_base
sc_export_base(const char *n)
Definition: sc_export.cc:56
sc_core::sc_export::sc_export
sc_export(const char *n)
Definition: sc_export.hh:66
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_object.hh
sc_core::sc_export::get_iterface
sc_interface * get_iterface() override
Definition: sc_export.hh:106
sc_core::sc_export::get_interface
const sc_interface * get_interface() const override
Definition: sc_export.hh:107
sc_core::sc_export_base::get_iterface
virtual sc_interface * get_iterface()=0
sc_core::sc_export::operator()
void operator()(IF &i)
Definition: sc_export.hh:73
sc_core::sc_export_base::~sc_export_base
~sc_export_base()
Definition: sc_export.cc:71
sc_core::sc_export
Definition: sc_export.hh:60
sc_core::SC_ID_SC_EXPORT_ALREADY_BOUND_
const char SC_ID_SC_EXPORT_ALREADY_BOUND_[]
Definition: messages.cc:71
sc_core::sc_export::operator->
IF * operator->()
Definition: sc_export.hh:92
sc_gem5::Module
Definition: module.hh:71
sc_core::sc_export::sc_export
sc_export()
Definition: sc_export.hh:63
sc_core::sc_export_base::before_end_of_elaboration
virtual void before_end_of_elaboration()=0
sc_core::sc_export_base::end_of_elaboration
virtual void end_of_elaboration()=0

Generated on Wed Sep 30 2020 14:02:15 for gem5 by doxygen 1.8.17