sc_module.hh revision 13382
17732SAli.Saidi@ARM.com/* 27732SAli.Saidi@ARM.com * Copyright 2018 Google, Inc. 37732SAli.Saidi@ARM.com * 47732SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 57732SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 67732SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 77732SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 87732SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 97732SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 107732SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 117732SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 127732SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 137732SAli.Saidi@ARM.com * this software without specific prior written permission. 147732SAli.Saidi@ARM.com * 157732SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 167732SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 177732SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 187732SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 197732SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 207732SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 217732SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 227732SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 237732SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 247732SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 257732SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 267732SAli.Saidi@ARM.com * 277732SAli.Saidi@ARM.com * Authors: Gabe Black 287732SAli.Saidi@ARM.com */ 297732SAli.Saidi@ARM.com 307732SAli.Saidi@ARM.com#ifndef __SYSTEMC_CORE_EXT_SC_MODULE_HH__ 317732SAli.Saidi@ARM.com#define __SYSTEMC_CORE_EXT_SC_MODULE_HH__ 327732SAli.Saidi@ARM.com 337732SAli.Saidi@ARM.com#include <vector> 347732SAli.Saidi@ARM.com 357732SAli.Saidi@ARM.com#include "sc_object.hh" 367732SAli.Saidi@ARM.com#include "sc_process_handle.hh" 377732SAli.Saidi@ARM.com#include "sc_sensitive.hh" 387732SAli.Saidi@ARM.com#include "sc_time.hh" 397732SAli.Saidi@ARM.com 407732SAli.Saidi@ARM.comnamespace sc_dt 417732SAli.Saidi@ARM.com{ 429821Satgutier@umich.edu 439192SAli.Saidi@ARM.comclass sc_logic; 449192SAli.Saidi@ARM.com 457732SAli.Saidi@ARM.com} // namespace sc_dt 467732SAli.Saidi@ARM.com 477732SAli.Saidi@ARM.comnamespace sc_gem5 487732SAli.Saidi@ARM.com{ 499333Sjames.clarkson@arm.com 507732SAli.Saidi@ARM.comclass Kernel; 518547Sprakash.ramrakhyani@arm.comclass Module; 528547Sprakash.ramrakhyani@arm.comclass Process; 538547Sprakash.ramrakhyani@arm.comstruct ProcessFuncWrapper; 548547Sprakash.ramrakhyani@arm.com 558547Sprakash.ramrakhyani@arm.comProcess *newMethodProcess(const char *name, ProcessFuncWrapper *func); 568547Sprakash.ramrakhyani@arm.comProcess *newThreadProcess(const char *name, ProcessFuncWrapper *func); 5712157Sandreas.sandberg@arm.comProcess *newCThreadProcess(const char *name, ProcessFuncWrapper *func); 5813103Skevin.brodsky@arm.com 5910151Satgutier@umich.edu} // namespace sc_gem5 608547Sprakash.ramrakhyani@arm.com 6112464Sjang.hanhwi@gmail.comnamespace sc_core 629333Sjames.clarkson@arm.com{ 638547Sprakash.ramrakhyani@arm.com 6412464Sjang.hanhwi@gmail.comtemplate <class T> 6512464Sjang.hanhwi@gmail.comclass sc_in; 6612464Sjang.hanhwi@gmail.comtemplate <class T> 6712464Sjang.hanhwi@gmail.comclass sc_out; 6812464Sjang.hanhwi@gmail.comtemplate <class T> 697732SAli.Saidi@ARM.comclass sc_inout; 709333Sjames.clarkson@arm.comtemplate <class T> 717732SAli.Saidi@ARM.comclass sc_signal_in_if; 727732SAli.Saidi@ARM.com 737732SAli.Saidi@ARM.comclass sc_event; 747732SAli.Saidi@ARM.comclass sc_event_and_list; 757732SAli.Saidi@ARM.comclass sc_event_or_list; 767732SAli.Saidi@ARM.comclass sc_module_name; 777732SAli.Saidi@ARM.com 789685Sandreas@sandberg.pp.seclass sc_bind_proxy 7912464Sjang.hanhwi@gmail.com{ 809333Sjames.clarkson@arm.com private: 819333Sjames.clarkson@arm.com sc_interface *_interface; 8212464Sjang.hanhwi@gmail.com sc_port_base *_port; 837732SAli.Saidi@ARM.com 848547Sprakash.ramrakhyani@arm.com public: 858547Sprakash.ramrakhyani@arm.com sc_bind_proxy(); 868547Sprakash.ramrakhyani@arm.com sc_bind_proxy(sc_interface &_interface); 878547Sprakash.ramrakhyani@arm.com sc_bind_proxy(sc_port_base &_port); 888547Sprakash.ramrakhyani@arm.com 898547Sprakash.ramrakhyani@arm.com sc_interface *interface() const { return _interface; } 908547Sprakash.ramrakhyani@arm.com sc_port_base *port() const { return _port; } 918547Sprakash.ramrakhyani@arm.com}; 9212464Sjang.hanhwi@gmail.com 9312464Sjang.hanhwi@gmail.comextern const sc_bind_proxy SC_BIND_PROXY_NIL; 9412464Sjang.hanhwi@gmail.com 9512464Sjang.hanhwi@gmail.comclass sc_module : public sc_object 9612464Sjang.hanhwi@gmail.com{ 9712464Sjang.hanhwi@gmail.com public: 987732SAli.Saidi@ARM.com friend class ::sc_gem5::Kernel; 9910151Satgutier@umich.edu friend class ::sc_gem5::Module; 10012464Sjang.hanhwi@gmail.com 101 virtual ~sc_module(); 102 103 virtual const char *kind() const { return "sc_module"; } 104 105 void operator () (const sc_bind_proxy &p001, 106 const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL, 107 const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL, 108 const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL, 109 const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL, 110 const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL, 111 const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL, 112 const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL, 113 const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL, 114 const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL, 115 const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL, 116 const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL, 117 const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL, 118 const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL, 119 const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL, 120 const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL, 121 const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL, 122 const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL, 123 const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL, 124 const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL, 125 const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL, 126 const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL, 127 const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL, 128 const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL, 129 const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL, 130 const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL, 131 const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL, 132 const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL, 133 const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL, 134 const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL, 135 const sc_bind_proxy &p031 = SC_BIND_PROXY_NIL, 136 const sc_bind_proxy &p032 = SC_BIND_PROXY_NIL, 137 const sc_bind_proxy &p033 = SC_BIND_PROXY_NIL, 138 const sc_bind_proxy &p034 = SC_BIND_PROXY_NIL, 139 const sc_bind_proxy &p035 = SC_BIND_PROXY_NIL, 140 const sc_bind_proxy &p036 = SC_BIND_PROXY_NIL, 141 const sc_bind_proxy &p037 = SC_BIND_PROXY_NIL, 142 const sc_bind_proxy &p038 = SC_BIND_PROXY_NIL, 143 const sc_bind_proxy &p039 = SC_BIND_PROXY_NIL, 144 const sc_bind_proxy &p040 = SC_BIND_PROXY_NIL, 145 const sc_bind_proxy &p041 = SC_BIND_PROXY_NIL, 146 const sc_bind_proxy &p042 = SC_BIND_PROXY_NIL, 147 const sc_bind_proxy &p043 = SC_BIND_PROXY_NIL, 148 const sc_bind_proxy &p044 = SC_BIND_PROXY_NIL, 149 const sc_bind_proxy &p045 = SC_BIND_PROXY_NIL, 150 const sc_bind_proxy &p046 = SC_BIND_PROXY_NIL, 151 const sc_bind_proxy &p047 = SC_BIND_PROXY_NIL, 152 const sc_bind_proxy &p048 = SC_BIND_PROXY_NIL, 153 const sc_bind_proxy &p049 = SC_BIND_PROXY_NIL, 154 const sc_bind_proxy &p050 = SC_BIND_PROXY_NIL, 155 const sc_bind_proxy &p051 = SC_BIND_PROXY_NIL, 156 const sc_bind_proxy &p052 = SC_BIND_PROXY_NIL, 157 const sc_bind_proxy &p053 = SC_BIND_PROXY_NIL, 158 const sc_bind_proxy &p054 = SC_BIND_PROXY_NIL, 159 const sc_bind_proxy &p055 = SC_BIND_PROXY_NIL, 160 const sc_bind_proxy &p056 = SC_BIND_PROXY_NIL, 161 const sc_bind_proxy &p057 = SC_BIND_PROXY_NIL, 162 const sc_bind_proxy &p058 = SC_BIND_PROXY_NIL, 163 const sc_bind_proxy &p059 = SC_BIND_PROXY_NIL, 164 const sc_bind_proxy &p060 = SC_BIND_PROXY_NIL, 165 const sc_bind_proxy &p061 = SC_BIND_PROXY_NIL, 166 const sc_bind_proxy &p062 = SC_BIND_PROXY_NIL, 167 const sc_bind_proxy &p063 = SC_BIND_PROXY_NIL, 168 const sc_bind_proxy &p064 = SC_BIND_PROXY_NIL); 169 170 // Deprecated 171 sc_module &operator << (sc_interface &); 172 sc_module &operator << (sc_port_base &); 173 sc_module &operator , (sc_interface &); 174 sc_module &operator , (sc_port_base &); 175 176 virtual const std::vector<sc_object *> &get_child_objects() const; 177 virtual const std::vector<sc_event *> &get_child_events() const; 178 179 protected: 180 sc_module(const sc_module_name &); 181 sc_module(); 182 183 // Deprecated 184 sc_module(const char *); 185 sc_module(const std::string &); 186 187 /* Deprecated, but used in the regression tests. */ 188 void end_module(); 189 190 void reset_signal_is(const sc_in<bool> &, bool); 191 void reset_signal_is(const sc_inout<bool> &, bool); 192 void reset_signal_is(const sc_out<bool> &, bool); 193 void reset_signal_is(const sc_signal_in_if<bool> &, bool); 194 195 void async_reset_signal_is(const sc_in<bool> &, bool); 196 void async_reset_signal_is(const sc_inout<bool> &, bool); 197 void async_reset_signal_is(const sc_out<bool> &, bool); 198 void async_reset_signal_is(const sc_signal_in_if<bool> &, bool); 199 200 sc_sensitive sensitive; 201 202 void dont_initialize(); 203 void set_stack_size(size_t); 204 205 void next_trigger(); 206 void next_trigger(const sc_event &); 207 void next_trigger(const sc_event_or_list &); 208 void next_trigger(const sc_event_and_list &); 209 void next_trigger(const sc_time &); 210 void next_trigger(double, sc_time_unit); 211 void next_trigger(const sc_time &, const sc_event &); 212 void next_trigger(double, sc_time_unit, const sc_event &); 213 void next_trigger(const sc_time &, const sc_event_or_list &); 214 void next_trigger(double, sc_time_unit, const sc_event_or_list &); 215 void next_trigger(const sc_time &, const sc_event_and_list &); 216 void next_trigger(double, sc_time_unit, const sc_event_and_list &); 217 218 // Nonstandard 219 bool timed_out(); 220 221 void wait(); 222 void wait(int); 223 void wait(const sc_event &); 224 void wait(const sc_event_or_list &); 225 void wait(const sc_event_and_list &); 226 void wait(const sc_time &); 227 void wait(double, sc_time_unit); 228 void wait(const sc_time &, const sc_event &); 229 void wait(double, sc_time_unit, const sc_event &); 230 void wait(const sc_time &, const sc_event_or_list &); 231 void wait(double, sc_time_unit, const sc_event_or_list &); 232 void wait(const sc_time &, const sc_event_and_list &); 233 void wait(double, sc_time_unit, const sc_event_and_list &); 234 235 // Nonstandard 236 void halt(); 237 void at_posedge(const sc_signal_in_if<bool> &); 238 void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &); 239 void at_negedge(const sc_signal_in_if<bool> &); 240 void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &); 241 242 virtual void before_end_of_elaboration() {} 243 virtual void end_of_elaboration() {} 244 virtual void start_of_simulation() {} 245 virtual void end_of_simulation() {} 246 247 private: 248 sc_gem5::Module *_gem5_module; 249 250 // Disabled 251 sc_module(const sc_module &) : sc_object() {}; 252 sc_module &operator = (const sc_module &) { return *this; } 253}; 254 255void next_trigger(); 256void next_trigger(const sc_event &); 257void next_trigger(const sc_event_or_list &); 258void next_trigger(const sc_event_and_list &); 259void next_trigger(const sc_time &); 260void next_trigger(double, sc_time_unit); 261void next_trigger(const sc_time &, const sc_event &); 262void next_trigger(double, sc_time_unit, const sc_event &); 263void next_trigger(const sc_time &, const sc_event_or_list &); 264void next_trigger(double, sc_time_unit, const sc_event_or_list &); 265void next_trigger(const sc_time &, const sc_event_and_list &); 266void next_trigger(double, sc_time_unit, const sc_event_and_list &); 267 268void wait(); 269void wait(int); 270void wait(const sc_event &); 271void wait(const sc_event_or_list &); 272void wait(const sc_event_and_list &); 273void wait(const sc_time &); 274void wait(double, sc_time_unit); 275void wait(const sc_time &, const sc_event &); 276void wait(double, sc_time_unit, const sc_event &); 277void wait(const sc_time &, const sc_event_or_list &); 278void wait(double, sc_time_unit, const sc_event_or_list &); 279void wait(const sc_time &, const sc_event_and_list &); 280void wait(double, sc_time_unit, const sc_event_and_list &); 281 282// Nonstandard 283bool timed_out(); 284 285#define SC_MODULE(name) struct name : ::sc_core::sc_module 286 287#define SC_CTOR(name) \ 288 typedef name SC_CURRENT_USER_MODULE; \ 289 name(::sc_core::sc_module_name) 290 291#define SC_HAS_PROCESS(name) typedef name SC_CURRENT_USER_MODULE 292 293#define SC_METHOD(name) \ 294 { \ 295 ::sc_gem5::Process *p = \ 296 ::sc_gem5::newMethodProcess( \ 297 #name, new ::sc_gem5::ProcessMemberFuncWrapper< \ 298 SC_CURRENT_USER_MODULE>(this, \ 299 &SC_CURRENT_USER_MODULE::name)); \ 300 if (p) \ 301 this->sensitive << p; \ 302 } 303#define SC_THREAD(name) \ 304 { \ 305 ::sc_gem5::Process *p = \ 306 ::sc_gem5::newThreadProcess( \ 307 #name, new ::sc_gem5::ProcessMemberFuncWrapper< \ 308 SC_CURRENT_USER_MODULE>(this, \ 309 &SC_CURRENT_USER_MODULE::name)); \ 310 if (p) \ 311 this->sensitive << p; \ 312 } 313#define SC_CTHREAD(name, clk) \ 314 { \ 315 ::sc_gem5::Process *p = \ 316 ::sc_gem5::newCThreadProcess( \ 317 #name, new ::sc_gem5::ProcessMemberFuncWrapper< \ 318 SC_CURRENT_USER_MODULE>(this, \ 319 &SC_CURRENT_USER_MODULE::name)); \ 320 if (p) \ 321 this->sensitive(p, clk); \ 322 } 323 324// Nonstandard 325// Documentation for this is very scarce, but it looks like it's supposed to 326// stop the currently executing cthread, or if a cthread isn't running report 327// an error. 328void halt(); 329void at_posedge(const sc_signal_in_if<bool> &); 330void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &); 331void at_negedge(const sc_signal_in_if<bool> &); 332void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &); 333 334const char *sc_gen_unique_name(const char *); 335 336// Nonstandard 337bool sc_hierarchical_name_exists(const char *name); 338 339typedef sc_module sc_behavior; 340typedef sc_module sc_channel; 341 342bool sc_start_of_simulation_invoked(); 343bool sc_end_of_simulation_invoked(); 344 345// Nonstandard 346// Allocates a module of type x and records a pointer to it so that it gets 347// destructed automatically at the end of the simulation. 348sc_module *sc_module_sc_new(sc_module *); 349#define SC_NEW(x) ::sc_core::sc_module_sc_new(new x); 350 351// Nonstandard 352#define SC_WAIT() \ 353 ::sc_core::sc_set_location(__FILE__, __LINE__); \ 354 ::sc_core::wait(); \ 355 ::sc_core::sc_set_location(NULL, 0) 356 357// Nonstandard 358#define SC_WAITN(n) \ 359 ::sc_core::sc_set_location(__FILE__, __LINE__); \ 360 ::sc_core::wait(n); \ 361 ::sc_core::sc_set_location(NULL, 0) 362 363// Nonstandard 364#define SC_WAIT_UNTIL(expr) \ 365 do { SC_WAIT(); } while (!(expr)) 366 367} // namespace sc_core 368 369#endif //__SYSTEMC_EXT_CORE_SC_MODULE_HH__ 370