summaryrefslogtreecommitdiff
path: root/src/systemc/ext/core/sc_module.hh
blob: fd4a802b14bf3646190890bd3666b13ca07d15a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
 * Copyright 2018 Google, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Gabe Black
 */

#ifndef __SYSTEMC_CORE_EXT_SC_MODULE_HH__
#define __SYSTEMC_CORE_EXT_SC_MODULE_HH__

#include <vector>

#include "sc_object.hh"
#include "sc_sensitive.hh"
#include "sc_time.hh"

namespace sc_dt
{

class sc_logic;

} // namespace sc_dt

namespace sc_gem5
{

class Module;

} // namespace sc_gem5

namespace sc_core
{

template <class T>
class sc_in;
template <class T>
class sc_out;
template <class T>
class sc_inout;
template <class T>
class sc_signal_in_if;

class sc_event;
class sc_event_and_list;
class sc_event_or_list;
class sc_module_name;

class sc_bind_proxy
{
  private:
    const sc_interface *_interface;
    const sc_port_base *_port;

    friend class sc_module;

  public:
    sc_bind_proxy(const sc_interface &_interface);
    sc_bind_proxy(const sc_port_base &_port);
};

extern const sc_bind_proxy SC_BIND_PROXY_NIL;

class sc_module : public sc_object
{
  public:
    virtual ~sc_module();

    virtual const char *kind() const { return "sc_module"; }

    void operator () (const sc_bind_proxy &p001,
                      const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p031 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p032 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p033 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p034 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p035 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p036 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p037 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p038 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p039 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p040 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p041 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p042 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p043 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p044 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p045 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p046 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p047 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p048 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p049 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p050 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p051 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p052 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p053 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p054 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p055 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p056 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p057 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p058 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p059 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p060 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p061 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p062 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p063 = SC_BIND_PROXY_NIL,
                      const sc_bind_proxy &p064 = SC_BIND_PROXY_NIL);

    virtual const std::vector<sc_object *> &get_child_objects() const;
    virtual const std::vector<sc_event *> &get_child_events() const;

  protected:
    sc_module(const sc_module_name &);
    sc_module();

    // Deprecated
    sc_module(const char *);
    sc_module(const std::string &);

    /* Deprecated, but used in the regression tests. */
    void end_module() {}

    void reset_signal_is(const sc_in<bool> &, bool);
    void reset_signal_is(const sc_inout<bool> &, bool);
    void reset_signal_is(const sc_out<bool> &, bool);
    void reset_signal_is(const sc_signal_in_if<bool> &, bool);

    void async_reset_signal_is(const sc_in<bool> &, bool);
    void async_reset_signal_is(const sc_inout<bool> &, bool);
    void async_reset_signal_is(const sc_out<bool> &, bool);
    void async_reset_signal_is(const sc_signal_in_if<bool> &, bool);

    sc_sensitive sensitive;

    void dont_initialize();
    void set_stack_size(size_t);

    void next_trigger();
    void next_trigger(const sc_event &);
    void next_trigger(const sc_event_or_list &);
    void next_trigger(const sc_event_and_list &);
    void next_trigger(const sc_time &);
    void next_trigger(double, sc_time_unit);
    void next_trigger(const sc_time &, const sc_event &);
    void next_trigger(double, sc_time_unit, const sc_event &);
    void next_trigger(const sc_time &, const sc_event_or_list &);
    void next_trigger(double, sc_time_unit, const sc_event_or_list &);
    void next_trigger(const sc_time &, const sc_event_and_list &);
    void next_trigger(double, sc_time_unit, const sc_event_and_list &);

    // Nonstandard
    bool timed_out();

    void wait();
    void wait(int);
    void wait(const sc_event &);
    void wait(const sc_event_or_list &);
    void wait(const sc_event_and_list &);
    void wait(const sc_time &);
    void wait(double, sc_time_unit);
    void wait(const sc_time &, const sc_event &);
    void wait(double, sc_time_unit, const sc_event &);
    void wait(const sc_time &, const sc_event_or_list &);
    void wait(double, sc_time_unit, const sc_event_or_list &);
    void wait(const sc_time &, const sc_event_and_list &);
    void wait(double, sc_time_unit, const sc_event_and_list &);

    // Nonstandard
    void halt();
    void at_posedge(const sc_signal_in_if<bool> &);
    void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
    void at_negedge(const sc_signal_in_if<bool> &);
    void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);

    virtual void before_end_of_elaboration() {}
    virtual void end_of_elaboration() {}
    virtual void start_of_simulation() {}
    virtual void end_of_simulation() {}

  private:
    sc_gem5::Module *_gem5_module;

    // Disabled
    sc_module(const sc_module &) : sc_object() {};
    sc_module &operator = (const sc_module &) { return *this; }
};

void next_trigger();
void next_trigger(const sc_event &);
void next_trigger(const sc_event_or_list &);
void next_trigger(const sc_event_and_list &);
void next_trigger(const sc_time &);
void next_trigger(double, sc_time_unit);
void next_trigger(const sc_time &, const sc_event &);
void next_trigger(double, sc_time_unit, const sc_event &);
void next_trigger(const sc_time &, const sc_event_or_list &);
void next_trigger(double, sc_time_unit, const sc_event_or_list &);
void next_trigger(const sc_time &, const sc_event_and_list &);
void next_trigger(double, sc_time_unit, const sc_event_and_list &);

void wait();
void wait(int);
void wait(const sc_event &);
void wait(const sc_event_or_list &);
void wait(const sc_event_and_list &);
void wait(const sc_time &);
void wait(double, sc_time_unit);
void wait(const sc_time &, const sc_event &);
void wait(double, sc_time_unit, const sc_event &);
void wait(const sc_time &, const sc_event_or_list &);
void wait(double, sc_time_unit, const sc_event_or_list &);
void wait(const sc_time &, const sc_event_and_list &);
void wait(double, sc_time_unit, const sc_event_and_list &);

// Nonstandard
bool timed_out();

#define SC_MODULE(name) struct name : ::sc_core::sc_module

#define SC_CTOR(name) \
    typedef name SC_CURRENT_USER_MODULE; \
    name(::sc_core::sc_module_name)

#define SC_HAS_PROCESS(name) typedef name SC_CURRENT_USER_MODULE

#define SC_METHOD(name) /* Implementation defined */
#define SC_THREAD(name) /* Implementation defined */
#define SC_CTHREAD(name, clk) /* Implementation defined */

// Nonstandard
// Documentation for this is very scarce, but it looks like it's supposed to
// stop the currently executing cthread, or if a cthread isn't running report
// an error.
void halt();
void at_posedge(const sc_signal_in_if<bool> &);
void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
void at_negedge(const sc_signal_in_if<bool> &);
void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);

const char *sc_gen_unique_name(const char *);

// Nonstandard
bool sc_hierarchical_name_exists(const char *name);

typedef sc_module sc_behavior;
typedef sc_module sc_channel;

bool sc_start_of_simulation_invoked();
bool sc_end_of_simulation_invoked();

// Nonstandard
// Allocates a module of type x and records a pointer to it so that it gets
// destructed automatically at the end of the simulation.
sc_module *sc_module_sc_new(sc_module *);
#define SC_NEW(x) ::sc_core::sc_module_sc_new(new x);

// Nonstandard
// In the Accellera implementation, this macro calls sc_set_location to record
// the current file and line, calls wait, and then calls it again to clear the
// file and line. We'll ignore the sc_set_location calls for now.
#define SC_WAIT() ::sc_core::wait();

// Nonstandard
// Same as above, but passes through an argument.
#define SC_WAITN(n) ::sc_core::wait(n);

// Nonstandard
#define SC_WAIT_UNTIL(expr) do { SC_WAIT(); } while (!(expr))

} // namespace sc_core

#endif  //__SYSTEMC_EXT_CORE_SC_MODULE_HH__