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