sc_module.hh revision 13087:1df34ed84a4b
12600SN/A/*
22600SN/A * Copyright 2018 Google, Inc.
32600SN/A *
42600SN/A * Redistribution and use in source and binary forms, with or without
52600SN/A * modification, are permitted provided that the following conditions are
62600SN/A * met: redistributions of source code must retain the above copyright
72600SN/A * notice, this list of conditions and the following disclaimer;
82600SN/A * redistributions in binary form must reproduce the above copyright
92600SN/A * notice, this list of conditions and the following disclaimer in the
102600SN/A * documentation and/or other materials provided with the distribution;
112600SN/A * neither the name of the copyright holders nor the names of its
122600SN/A * contributors may be used to endorse or promote products derived from
132600SN/A * this software without specific prior written permission.
142600SN/A *
152600SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162600SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172600SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182600SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192600SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202600SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212600SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222600SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232600SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242600SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252600SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262600SN/A *
272665Ssaidi@eecs.umich.edu * Authors: Gabe Black
282665Ssaidi@eecs.umich.edu */
292600SN/A
302600SN/A#ifndef __SYSTEMC_CORE_EXT_SC_MODULE_HH__
312600SN/A#define __SYSTEMC_CORE_EXT_SC_MODULE_HH__
322600SN/A
332600SN/A#include <vector>
342600SN/A
352600SN/A#include "sc_object.hh"
362600SN/A#include "sc_process_handle.hh"
372600SN/A#include "sc_sensitive.hh"
382600SN/A#include "sc_time.hh"
392600SN/A
402600SN/Anamespace sc_dt
413113Sgblack@eecs.umich.edu{
422600SN/A
433113Sgblack@eecs.umich.educlass sc_logic;
442600SN/A
452600SN/A} // namespace sc_dt
462600SN/A
472600SN/Anamespace sc_gem5
482600SN/A{
492600SN/A
502600SN/Aclass Kernel;
512600SN/Aclass Module;
523113Sgblack@eecs.umich.educlass Process;
533113Sgblack@eecs.umich.edustruct ProcessFuncWrapper;
542600SN/A
552600SN/AProcess *newMethodProcess(const char *name, ProcessFuncWrapper *func);
562600SN/AProcess *newThreadProcess(const char *name, ProcessFuncWrapper *func);
572600SN/AProcess *newCThreadProcess(const char *name, ProcessFuncWrapper *func);
582600SN/A
593122Sgblack@eecs.umich.edu} // namespace sc_gem5
602600SN/A
612600SN/Anamespace sc_core
622600SN/A{
632600SN/A
642600SN/Atemplate <class T>
652600SN/Aclass sc_in;
662600SN/Atemplate <class T>
672600SN/Aclass sc_out;
683122Sgblack@eecs.umich.edutemplate <class T>
692600SN/Aclass sc_inout;
702600SN/Atemplate <class T>
712600SN/Aclass sc_signal_in_if;
722600SN/A
732600SN/Aclass sc_event;
742600SN/Aclass sc_event_and_list;
752600SN/Aclass sc_event_or_list;
762600SN/Aclass sc_module_name;
772600SN/A
783113Sgblack@eecs.umich.educlass sc_bind_proxy
795543Ssaidi@eecs.umich.edu{
805543Ssaidi@eecs.umich.edu  private:
815543Ssaidi@eecs.umich.edu    const sc_interface *_interface;
825543Ssaidi@eecs.umich.edu    const sc_port_base *_port;
835543Ssaidi@eecs.umich.edu
845543Ssaidi@eecs.umich.edu    friend class sc_module;
855543Ssaidi@eecs.umich.edu
865543Ssaidi@eecs.umich.edu  public:
875543Ssaidi@eecs.umich.edu    sc_bind_proxy(const sc_interface &_interface);
885543Ssaidi@eecs.umich.edu    sc_bind_proxy(const sc_port_base &_port);
895543Ssaidi@eecs.umich.edu};
903113Sgblack@eecs.umich.edu
915543Ssaidi@eecs.umich.eduextern const sc_bind_proxy SC_BIND_PROXY_NIL;
925543Ssaidi@eecs.umich.edu
932600SN/Aclass sc_module : public sc_object
943113Sgblack@eecs.umich.edu{
952600SN/A  public:
962600SN/A    friend class ::sc_gem5::Kernel;
973113Sgblack@eecs.umich.edu
985543Ssaidi@eecs.umich.edu    virtual ~sc_module();
995543Ssaidi@eecs.umich.edu
1005543Ssaidi@eecs.umich.edu    virtual const char *kind() const { return "sc_module"; }
1015543Ssaidi@eecs.umich.edu
1025543Ssaidi@eecs.umich.edu    void operator () (const sc_bind_proxy &p001,
1035543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL,
1045543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL,
1055543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL,
1065543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL,
1075543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL,
1085543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL,
1093113Sgblack@eecs.umich.edu                      const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL,
1105543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL,
1115543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL,
1122600SN/A                      const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL,
1133113Sgblack@eecs.umich.edu                      const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL,
1142600SN/A                      const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL,
1152600SN/A                      const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL,
1162600SN/A                      const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL,
1172600SN/A                      const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL,
1182600SN/A                      const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL,
1193113Sgblack@eecs.umich.edu                      const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL,
1205543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL,
1215543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL,
1225543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL,
1235543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL,
1245543Ssaidi@eecs.umich.edu                      const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL,
1253113Sgblack@eecs.umich.edu                      const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL,
1262600SN/A                      const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL,
1272600SN/A                      const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL,
1282600SN/A                      const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL,
1292600SN/A                      const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL,
1302600SN/A                      const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL,
1312600SN/A                      const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL,
1322600SN/A                      const sc_bind_proxy &p031 = SC_BIND_PROXY_NIL,
133                      const sc_bind_proxy &p032 = SC_BIND_PROXY_NIL,
134                      const sc_bind_proxy &p033 = SC_BIND_PROXY_NIL,
135                      const sc_bind_proxy &p034 = SC_BIND_PROXY_NIL,
136                      const sc_bind_proxy &p035 = SC_BIND_PROXY_NIL,
137                      const sc_bind_proxy &p036 = SC_BIND_PROXY_NIL,
138                      const sc_bind_proxy &p037 = SC_BIND_PROXY_NIL,
139                      const sc_bind_proxy &p038 = SC_BIND_PROXY_NIL,
140                      const sc_bind_proxy &p039 = SC_BIND_PROXY_NIL,
141                      const sc_bind_proxy &p040 = SC_BIND_PROXY_NIL,
142                      const sc_bind_proxy &p041 = SC_BIND_PROXY_NIL,
143                      const sc_bind_proxy &p042 = SC_BIND_PROXY_NIL,
144                      const sc_bind_proxy &p043 = SC_BIND_PROXY_NIL,
145                      const sc_bind_proxy &p044 = SC_BIND_PROXY_NIL,
146                      const sc_bind_proxy &p045 = SC_BIND_PROXY_NIL,
147                      const sc_bind_proxy &p046 = SC_BIND_PROXY_NIL,
148                      const sc_bind_proxy &p047 = SC_BIND_PROXY_NIL,
149                      const sc_bind_proxy &p048 = SC_BIND_PROXY_NIL,
150                      const sc_bind_proxy &p049 = SC_BIND_PROXY_NIL,
151                      const sc_bind_proxy &p050 = SC_BIND_PROXY_NIL,
152                      const sc_bind_proxy &p051 = SC_BIND_PROXY_NIL,
153                      const sc_bind_proxy &p052 = SC_BIND_PROXY_NIL,
154                      const sc_bind_proxy &p053 = SC_BIND_PROXY_NIL,
155                      const sc_bind_proxy &p054 = SC_BIND_PROXY_NIL,
156                      const sc_bind_proxy &p055 = SC_BIND_PROXY_NIL,
157                      const sc_bind_proxy &p056 = SC_BIND_PROXY_NIL,
158                      const sc_bind_proxy &p057 = SC_BIND_PROXY_NIL,
159                      const sc_bind_proxy &p058 = SC_BIND_PROXY_NIL,
160                      const sc_bind_proxy &p059 = SC_BIND_PROXY_NIL,
161                      const sc_bind_proxy &p060 = SC_BIND_PROXY_NIL,
162                      const sc_bind_proxy &p061 = SC_BIND_PROXY_NIL,
163                      const sc_bind_proxy &p062 = SC_BIND_PROXY_NIL,
164                      const sc_bind_proxy &p063 = SC_BIND_PROXY_NIL,
165                      const sc_bind_proxy &p064 = SC_BIND_PROXY_NIL);
166
167    virtual const std::vector<sc_object *> &get_child_objects() const;
168    virtual const std::vector<sc_event *> &get_child_events() const;
169
170  protected:
171    sc_module(const sc_module_name &);
172    sc_module();
173
174    // Deprecated
175    sc_module(const char *);
176    sc_module(const std::string &);
177
178    /* Deprecated, but used in the regression tests. */
179    void end_module() {}
180
181    void reset_signal_is(const sc_in<bool> &, bool);
182    void reset_signal_is(const sc_inout<bool> &, bool);
183    void reset_signal_is(const sc_out<bool> &, bool);
184    void reset_signal_is(const sc_signal_in_if<bool> &, bool);
185
186    void async_reset_signal_is(const sc_in<bool> &, bool);
187    void async_reset_signal_is(const sc_inout<bool> &, bool);
188    void async_reset_signal_is(const sc_out<bool> &, bool);
189    void async_reset_signal_is(const sc_signal_in_if<bool> &, bool);
190
191    sc_sensitive sensitive;
192
193    void dont_initialize();
194    void set_stack_size(size_t);
195
196    void next_trigger();
197    void next_trigger(const sc_event &);
198    void next_trigger(const sc_event_or_list &);
199    void next_trigger(const sc_event_and_list &);
200    void next_trigger(const sc_time &);
201    void next_trigger(double, sc_time_unit);
202    void next_trigger(const sc_time &, const sc_event &);
203    void next_trigger(double, sc_time_unit, const sc_event &);
204    void next_trigger(const sc_time &, const sc_event_or_list &);
205    void next_trigger(double, sc_time_unit, const sc_event_or_list &);
206    void next_trigger(const sc_time &, const sc_event_and_list &);
207    void next_trigger(double, sc_time_unit, const sc_event_and_list &);
208
209    // Nonstandard
210    bool timed_out();
211
212    void wait();
213    void wait(int);
214    void wait(const sc_event &);
215    void wait(const sc_event_or_list &);
216    void wait(const sc_event_and_list &);
217    void wait(const sc_time &);
218    void wait(double, sc_time_unit);
219    void wait(const sc_time &, const sc_event &);
220    void wait(double, sc_time_unit, const sc_event &);
221    void wait(const sc_time &, const sc_event_or_list &);
222    void wait(double, sc_time_unit, const sc_event_or_list &);
223    void wait(const sc_time &, const sc_event_and_list &);
224    void wait(double, sc_time_unit, const sc_event_and_list &);
225
226    // Nonstandard
227    void halt();
228    void at_posedge(const sc_signal_in_if<bool> &);
229    void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
230    void at_negedge(const sc_signal_in_if<bool> &);
231    void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);
232
233    virtual void before_end_of_elaboration() {}
234    virtual void end_of_elaboration() {}
235    virtual void start_of_simulation() {}
236    virtual void end_of_simulation() {}
237
238  private:
239    sc_gem5::Module *_gem5_module;
240
241    // Disabled
242    sc_module(const sc_module &) : sc_object() {};
243    sc_module &operator = (const sc_module &) { return *this; }
244};
245
246void next_trigger();
247void next_trigger(const sc_event &);
248void next_trigger(const sc_event_or_list &);
249void next_trigger(const sc_event_and_list &);
250void next_trigger(const sc_time &);
251void next_trigger(double, sc_time_unit);
252void next_trigger(const sc_time &, const sc_event &);
253void next_trigger(double, sc_time_unit, const sc_event &);
254void next_trigger(const sc_time &, const sc_event_or_list &);
255void next_trigger(double, sc_time_unit, const sc_event_or_list &);
256void next_trigger(const sc_time &, const sc_event_and_list &);
257void next_trigger(double, sc_time_unit, const sc_event_and_list &);
258
259void wait();
260void wait(int);
261void wait(const sc_event &);
262void wait(const sc_event_or_list &);
263void wait(const sc_event_and_list &);
264void wait(const sc_time &);
265void wait(double, sc_time_unit);
266void wait(const sc_time &, const sc_event &);
267void wait(double, sc_time_unit, const sc_event &);
268void wait(const sc_time &, const sc_event_or_list &);
269void wait(double, sc_time_unit, const sc_event_or_list &);
270void wait(const sc_time &, const sc_event_and_list &);
271void wait(double, sc_time_unit, const sc_event_and_list &);
272
273// Nonstandard
274bool timed_out();
275
276#define SC_MODULE(name) struct name : ::sc_core::sc_module
277
278#define SC_CTOR(name) \
279    typedef name SC_CURRENT_USER_MODULE; \
280    name(::sc_core::sc_module_name)
281
282#define SC_HAS_PROCESS(name) typedef name SC_CURRENT_USER_MODULE
283
284#define SC_METHOD(name) \
285    { \
286        ::sc_gem5::Process *p = \
287            ::sc_gem5::newMethodProcess( \
288                #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
289                    SC_CURRENT_USER_MODULE>(this, \
290                        &SC_CURRENT_USER_MODULE::name)); \
291        this->sensitive << p; \
292    }
293#define SC_THREAD(name) \
294    { \
295        ::sc_gem5::Process *p = \
296            ::sc_gem5::newThreadProcess( \
297                #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
298                    SC_CURRENT_USER_MODULE>(this, \
299                        &SC_CURRENT_USER_MODULE::name)); \
300        this->sensitive << p; \
301    }
302#define SC_CTHREAD(name, clk) \
303    { \
304        ::sc_gem5::Process *p = \
305            ::sc_gem5::newCThreadProcess( \
306                #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
307                    SC_CURRENT_USER_MODULE>(this, \
308                        &SC_CURRENT_USER_MODULE::name)); \
309        this->sensitive << p; \
310        this->sensitive << clk; \
311    }
312
313// Nonstandard
314// Documentation for this is very scarce, but it looks like it's supposed to
315// stop the currently executing cthread, or if a cthread isn't running report
316// an error.
317void halt();
318void at_posedge(const sc_signal_in_if<bool> &);
319void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
320void at_negedge(const sc_signal_in_if<bool> &);
321void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);
322
323const char *sc_gen_unique_name(const char *);
324
325// Nonstandard
326bool sc_hierarchical_name_exists(const char *name);
327
328typedef sc_module sc_behavior;
329typedef sc_module sc_channel;
330
331bool sc_start_of_simulation_invoked();
332bool sc_end_of_simulation_invoked();
333
334// Nonstandard
335// Allocates a module of type x and records a pointer to it so that it gets
336// destructed automatically at the end of the simulation.
337sc_module *sc_module_sc_new(sc_module *);
338#define SC_NEW(x) ::sc_core::sc_module_sc_new(new x);
339
340// Nonstandard
341#define SC_WAIT() \
342    ::sc_core::sc_set_location(__FILE__, __LINE__); \
343    ::sc_core::wait(); \
344    ::sc_core::sc_set_location(NULL, 0)
345
346// Nonstandard
347#define SC_WAITN(n) \
348    ::sc_core::sc_set_location(__FILE__, __LINE__); \
349    ::sc_core::wait(n); \
350    ::sc_core::sc_set_location(NULL, 0)
351
352// Nonstandard
353#define SC_WAIT_UNTIL(expr) \
354    do { SC_WAIT(); } while (!(expr))
355
356} // namespace sc_core
357
358#endif  //__SYSTEMC_EXT_CORE_SC_MODULE_HH__
359