sc_module.hh revision 13087:1df34ed84a4b
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_process_handle.hh" 37#include "sc_sensitive.hh" 38#include "sc_time.hh" 39 40namespace sc_dt 41{ 42 43class sc_logic; 44 45} // namespace sc_dt 46 47namespace sc_gem5 48{ 49 50class Kernel; 51class Module; 52class Process; 53struct ProcessFuncWrapper; 54 55Process *newMethodProcess(const char *name, ProcessFuncWrapper *func); 56Process *newThreadProcess(const char *name, ProcessFuncWrapper *func); 57Process *newCThreadProcess(const char *name, ProcessFuncWrapper *func); 58 59} // namespace sc_gem5 60 61namespace sc_core 62{ 63 64template <class T> 65class sc_in; 66template <class T> 67class sc_out; 68template <class T> 69class sc_inout; 70template <class T> 71class sc_signal_in_if; 72 73class sc_event; 74class sc_event_and_list; 75class sc_event_or_list; 76class sc_module_name; 77 78class sc_bind_proxy 79{ 80 private: 81 const sc_interface *_interface; 82 const sc_port_base *_port; 83 84 friend class sc_module; 85 86 public: 87 sc_bind_proxy(const sc_interface &_interface); 88 sc_bind_proxy(const sc_port_base &_port); 89}; 90 91extern const sc_bind_proxy SC_BIND_PROXY_NIL; 92 93class sc_module : public sc_object 94{ 95 public: 96 friend class ::sc_gem5::Kernel; 97 98 virtual ~sc_module(); 99 100 virtual const char *kind() const { return "sc_module"; } 101 102 void operator () (const sc_bind_proxy &p001, 103 const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL, 104 const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL, 105 const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL, 106 const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL, 107 const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL, 108 const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL, 109 const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL, 110 const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL, 111 const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL, 112 const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL, 113 const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL, 114 const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL, 115 const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL, 116 const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL, 117 const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL, 118 const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL, 119 const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL, 120 const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL, 121 const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL, 122 const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL, 123 const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL, 124 const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL, 125 const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL, 126 const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL, 127 const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL, 128 const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL, 129 const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL, 130 const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL, 131 const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL, 132 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