gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
33#include "sc_module.hh" // for sc_gen_unique_name
34#include "sc_object.hh"
35
36namespace sc_core
37{
38
39class sc_interface;
40
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
59template <class IF>
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) {
78 SC_REPORT_ERROR(SC_ID_SC_EXPORT_ALREADY_BOUND_, name());
79 return;
80 }
81 interface = &i;
82 }
83 operator IF & ()
84 {
85 if (!interface)
86 SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_, name());
87 return *interface;
88 }
89 operator const IF & () const { return *interface; }
90
91 IF *
93 {
94 if (!interface)
95 SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_, name());
96 return interface;
97 }
98 const IF *
100 {
101 if (!interface)
102 SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_, name());
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
129};
130
131} // namespace sc_core
132
133#endif //__SYSTEMC_EXT_CORE_SC_EXPORT_HH__
virtual void before_end_of_elaboration()=0
sc_export_base(const char *n)
Definition sc_export.cc:56
virtual sc_interface * get_iterface()=0
virtual const sc_interface * get_interface() const =0
virtual void start_of_simulation()=0
virtual void end_of_simulation()=0
virtual void end_of_elaboration()=0
sc_export(const char *n)
Definition sc_export.hh:66
const sc_interface * get_interface() const override
Definition sc_export.hh:107
virtual ~sc_export()
Definition sc_export.hh:69
void end_of_simulation() override
Definition sc_export.hh:121
virtual const char * kind() const override
Definition sc_export.hh:71
void operator()(IF &i)
Definition sc_export.hh:73
sc_interface * get_iterface() override
Definition sc_export.hh:106
void start_of_simulation() override
Definition sc_export.hh:120
void before_end_of_elaboration() override
Definition sc_export.hh:110
sc_export< IF > & operator=(const sc_export< IF > &)
sc_export(const sc_export< IF > &)
void end_of_elaboration() override
Definition sc_export.hh:112
virtual void bind(IF &i)
Definition sc_export.hh:75
const char * name() const
Definition sc_object.cc:44
#define SC_REPORT_ERROR(msg_type, msg)

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0