sc_module.hh revision 12928:1746600c4672
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_CORE_EXT_SC_MODULE_HH__
31#define __SYSTEMC_CORE_EXT_SC_MODULE_HH__
32
33#include <vector>
34
35#include "sc_object.hh"
36#include "sc_sensitive.hh"
37#include "sc_time.hh"
38
39namespace sc_dt
40{
41
42class sc_logic;
43
44} // namespace sc_dt
45
46namespace sc_core
47{
48
49template <class T>
50class sc_in;
51template <class T>
52class sc_out;
53template <class T>
54class sc_inout;
55template <class T>
56class sc_signal_in_if;
57
58class sc_event;
59class sc_event_and_list;
60class sc_event_or_list;
61class sc_module_name;
62
63class sc_bind_proxy
64{
65  public:
66    sc_bind_proxy(const sc_interface &interface);
67    sc_bind_proxy(const sc_port_base &port);
68};
69
70extern const sc_bind_proxy SC_BIND_PROXY_NIL;
71
72class sc_module : public sc_object
73{
74  public:
75    virtual ~sc_module();
76
77    virtual const char *kind() const;
78
79    void operator () (const sc_bind_proxy &p001,
80                      const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL,
81                      const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL,
82                      const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL,
83                      const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL,
84                      const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL,
85                      const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL,
86                      const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL,
87                      const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL,
88                      const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL,
89                      const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL,
90                      const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL,
91                      const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL,
92                      const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL,
93                      const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL,
94                      const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL,
95                      const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL,
96                      const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL,
97                      const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL,
98                      const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL,
99                      const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL,
100                      const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL,
101                      const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL,
102                      const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL,
103                      const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL,
104                      const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL,
105                      const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL,
106                      const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL,
107                      const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL,
108                      const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL,
109                      const sc_bind_proxy &p031 = SC_BIND_PROXY_NIL,
110                      const sc_bind_proxy &p032 = SC_BIND_PROXY_NIL,
111                      const sc_bind_proxy &p033 = SC_BIND_PROXY_NIL,
112                      const sc_bind_proxy &p034 = SC_BIND_PROXY_NIL,
113                      const sc_bind_proxy &p035 = SC_BIND_PROXY_NIL,
114                      const sc_bind_proxy &p036 = SC_BIND_PROXY_NIL,
115                      const sc_bind_proxy &p037 = SC_BIND_PROXY_NIL,
116                      const sc_bind_proxy &p038 = SC_BIND_PROXY_NIL,
117                      const sc_bind_proxy &p039 = SC_BIND_PROXY_NIL,
118                      const sc_bind_proxy &p040 = SC_BIND_PROXY_NIL,
119                      const sc_bind_proxy &p041 = SC_BIND_PROXY_NIL,
120                      const sc_bind_proxy &p042 = SC_BIND_PROXY_NIL,
121                      const sc_bind_proxy &p043 = SC_BIND_PROXY_NIL,
122                      const sc_bind_proxy &p044 = SC_BIND_PROXY_NIL,
123                      const sc_bind_proxy &p045 = SC_BIND_PROXY_NIL,
124                      const sc_bind_proxy &p046 = SC_BIND_PROXY_NIL,
125                      const sc_bind_proxy &p047 = SC_BIND_PROXY_NIL,
126                      const sc_bind_proxy &p048 = SC_BIND_PROXY_NIL,
127                      const sc_bind_proxy &p049 = SC_BIND_PROXY_NIL,
128                      const sc_bind_proxy &p050 = SC_BIND_PROXY_NIL,
129                      const sc_bind_proxy &p051 = SC_BIND_PROXY_NIL,
130                      const sc_bind_proxy &p052 = SC_BIND_PROXY_NIL,
131                      const sc_bind_proxy &p053 = SC_BIND_PROXY_NIL,
132                      const sc_bind_proxy &p054 = SC_BIND_PROXY_NIL,
133                      const sc_bind_proxy &p055 = SC_BIND_PROXY_NIL,
134                      const sc_bind_proxy &p056 = SC_BIND_PROXY_NIL,
135                      const sc_bind_proxy &p057 = SC_BIND_PROXY_NIL,
136                      const sc_bind_proxy &p058 = SC_BIND_PROXY_NIL,
137                      const sc_bind_proxy &p059 = SC_BIND_PROXY_NIL,
138                      const sc_bind_proxy &p060 = SC_BIND_PROXY_NIL,
139                      const sc_bind_proxy &p061 = SC_BIND_PROXY_NIL,
140                      const sc_bind_proxy &p062 = SC_BIND_PROXY_NIL,
141                      const sc_bind_proxy &p063 = SC_BIND_PROXY_NIL,
142                      const sc_bind_proxy &p064 = SC_BIND_PROXY_NIL);
143
144    virtual const std::vector<sc_object *> &get_child_objects() const;
145    virtual const std::vector<sc_event *> &get_child_events() const;
146
147  protected:
148    sc_module(const sc_module_name &);
149    sc_module();
150
151    // Deprecated
152    sc_module(const char *);
153    sc_module(const std::string &);
154
155    /* Deprecated, but used in the regression tests. */
156    void end_module() {}
157
158    void reset_signal_is(const sc_in<bool> &, bool);
159    void reset_signal_is(const sc_inout<bool> &, bool);
160    void reset_signal_is(const sc_out<bool> &, bool);
161    void reset_signal_is(const sc_signal_in_if<bool> &, bool);
162
163    void async_reset_signal_is(const sc_in<bool> &, bool);
164    void async_reset_signal_is(const sc_inout<bool> &, bool);
165    void async_reset_signal_is(const sc_out<bool> &, bool);
166    void async_reset_signal_is(const sc_signal_in_if<bool> &, bool);
167
168    sc_sensitive sensitive;
169
170    void dont_initialize();
171    void set_stack_size(size_t);
172
173    void next_trigger();
174    void next_trigger(const sc_event &);
175    void next_trigger(const sc_event_or_list &);
176    void next_trigger(const sc_event_and_list &);
177    void next_trigger(const sc_time &);
178    void next_trigger(double, sc_time_unit);
179    void next_trigger(const sc_time &, const sc_event &);
180    void next_trigger(double, sc_time_unit, const sc_event &);
181    void next_trigger(const sc_time &, const sc_event_or_list &);
182    void next_trigger(double, sc_time_unit, const sc_event_or_list &);
183    void next_trigger(const sc_time &, const sc_event_and_list &);
184    void next_trigger(double, sc_time_unit, const sc_event_and_list &);
185
186    void wait();
187    void wait(int);
188    void wait(const sc_event &);
189    void wait(const sc_event_or_list &);
190    void wait(const sc_event_and_list &);
191    void wait(const sc_time &);
192    void wait(double, sc_time_unit);
193    void wait(const sc_time &, const sc_event &);
194    void wait(double, sc_time_unit, const sc_event &);
195    void wait(const sc_time &, const sc_event_or_list &);
196    void wait(double, sc_time_unit, const sc_event_or_list &);
197    void wait(const sc_time &, const sc_event_and_list &);
198    void wait(double, sc_time_unit, const sc_event_and_list &);
199
200    // Nonstandard
201    void halt();
202    void at_posedge(const sc_signal_in_if<bool> &);
203    void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
204    void at_negedge(const sc_signal_in_if<bool> &);
205    void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);
206
207    virtual void before_end_of_elaboration() {}
208    virtual void end_of_elaboration() {}
209    virtual void start_of_simulation() {}
210    virtual void end_of_simulation() {}
211
212  private:
213    // Disabled
214    sc_module(const sc_module &) : sc_object() {};
215    sc_module &operator = (const sc_module &) { return *this; }
216};
217
218void next_trigger();
219void next_trigger(const sc_event &);
220void next_trigger(const sc_event_or_list &);
221void next_trigger(const sc_event_and_list &);
222void next_trigger(const sc_time &);
223void next_trigger(double, sc_time_unit);
224void next_trigger(const sc_time &, const sc_event &);
225void next_trigger(double, sc_time_unit, const sc_event &);
226void next_trigger(const sc_time &, const sc_event_or_list &);
227void next_trigger(double, sc_time_unit, const sc_event_or_list &);
228void next_trigger(const sc_time &, const sc_event_and_list &);
229void next_trigger(double, sc_time_unit, const sc_event_and_list &);
230
231void wait();
232void wait(int);
233void wait(const sc_event &);
234void wait(const sc_event_or_list &);
235void wait(const sc_event_and_list &);
236void wait(const sc_time &);
237void wait(double, sc_time_unit);
238void wait(const sc_time &, const sc_event &);
239void wait(double, sc_time_unit, const sc_event &);
240void wait(const sc_time &, const sc_event_or_list &);
241void wait(double, sc_time_unit, const sc_event_or_list &);
242void wait(const sc_time &, const sc_event_and_list &);
243void wait(double, sc_time_unit, const sc_event_and_list &);
244
245#define SC_MODULE(name) struct name : ::sc_core::sc_module
246
247#define SC_CTOR(name) \
248    typedef name SC_CURRENT_USER_MODULE; \
249    name(::sc_core::sc_module_name)
250
251#define SC_HAS_PROCESS(name) typedef name SC_CURRENT_USER_MODULE
252
253#define SC_METHOD(name) /* Implementation defined */
254#define SC_THREAD(name) /* Implementation defined */
255#define SC_CTHREAD(name, clk) /* Implementation defined */
256
257// Nonstandard
258// Documentation for this is very scarce, but it looks like it's supposed to
259// stop the currently executing cthread, or if a cthread isn't running report
260// an error.
261void halt();
262void at_posedge(const sc_signal_in_if<bool> &);
263void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
264void at_negedge(const sc_signal_in_if<bool> &);
265void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);
266
267const char *sc_gen_unique_name(const char *);
268
269typedef sc_module sc_behavior;
270typedef sc_module sc_channel;
271
272bool sc_start_of_simulation_invoked();
273bool sc_end_of_simulation_invoked();
274
275// Nonstandard
276// Allocates a module of type x and records a pointer to it so that it gets
277// destructed automatically at the end of the simulation.
278sc_module *sc_module_sc_new(sc_module *);
279#define SC_NEW(x) ::sc_core::sc_module_sc_new(new x);
280
281// Nonstandard
282// In the Accellera implementation, this macro calls sc_set_location to record
283// the current file and line, calls wait, and then calls it again to clear the
284// file and line. We'll ignore the sc_set_location calls for now.
285#define SC_WAIT() ::sc_core::wait();
286
287// Nonstandard
288// Same as above, but passes through an argument.
289#define SC_WAITN(n) ::sc_core::wait(n);
290
291// Nonstandard
292#define SC_WAIT_UNTIL(expr) do { SC_WAIT(); } while (!(expr))
293
294} // namespace sc_core
295
296#endif  //__SYSTEMC_EXT_CORE_SC_MODULE_HH__
297