gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_module.cc
Go to the documentation of this file.
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
28#include <memory>
29#include <string>
30#include <vector>
31
32#include "base/logging.hh"
33#include "systemc/core/event.hh"
37#include "systemc/core/port.hh"
49
50namespace sc_gem5
51{
52
53Process *
55{
56 Method *p = new Method(name, func);
58 std::string name = p->name();
59 delete p;
61 name.c_str());
62 return nullptr;
63 }
64 scheduler.reg(p);
65 return p;
66}
67
68Process *
70{
71 Thread *p = new Thread(name, func);
73 std::string name = p->name();
74 delete p;
76 name.c_str());
77 return nullptr;
78 }
79 scheduler.reg(p);
80 return p;
81}
82
83Process *
85{
86 CThread *p = new CThread(name, func);
88 std::string name = p->name();
89 delete p;
91 name.c_str());
92 return nullptr;
93 }
94 scheduler.reg(p);
95 p->dontInitialize(true);
96 return p;
97}
98
99} // namespace sc_gem5
100
101namespace sc_core
102{
103
104sc_bind_proxy::sc_bind_proxy() : _interface(nullptr), _port(nullptr) {}
105
107 _interface(&_interface), _port(nullptr)
108{}
109
111 _interface(nullptr), _port(&_port)
112{}
113
115
117sc_module::gem5_getPort(const std::string &if_name, int idx)
118{
119 fatal("%s does not have any port named %s\n", name(), if_name);
120}
121
123
124void
126 const sc_bind_proxy &p002,
127 const sc_bind_proxy &p003,
128 const sc_bind_proxy &p004,
129 const sc_bind_proxy &p005,
130 const sc_bind_proxy &p006,
131 const sc_bind_proxy &p007,
132 const sc_bind_proxy &p008,
133 const sc_bind_proxy &p009,
134 const sc_bind_proxy &p010,
135 const sc_bind_proxy &p011,
136 const sc_bind_proxy &p012,
137 const sc_bind_proxy &p013,
138 const sc_bind_proxy &p014,
139 const sc_bind_proxy &p015,
140 const sc_bind_proxy &p016,
141 const sc_bind_proxy &p017,
142 const sc_bind_proxy &p018,
143 const sc_bind_proxy &p019,
144 const sc_bind_proxy &p020,
145 const sc_bind_proxy &p021,
146 const sc_bind_proxy &p022,
147 const sc_bind_proxy &p023,
148 const sc_bind_proxy &p024,
149 const sc_bind_proxy &p025,
150 const sc_bind_proxy &p026,
151 const sc_bind_proxy &p027,
152 const sc_bind_proxy &p028,
153 const sc_bind_proxy &p029,
154 const sc_bind_proxy &p030,
155 const sc_bind_proxy &p031,
156 const sc_bind_proxy &p032,
157 const sc_bind_proxy &p033,
158 const sc_bind_proxy &p034,
159 const sc_bind_proxy &p035,
160 const sc_bind_proxy &p036,
161 const sc_bind_proxy &p037,
162 const sc_bind_proxy &p038,
163 const sc_bind_proxy &p039,
164 const sc_bind_proxy &p040,
165 const sc_bind_proxy &p041,
166 const sc_bind_proxy &p042,
167 const sc_bind_proxy &p043,
168 const sc_bind_proxy &p044,
169 const sc_bind_proxy &p045,
170 const sc_bind_proxy &p046,
171 const sc_bind_proxy &p047,
172 const sc_bind_proxy &p048,
173 const sc_bind_proxy &p049,
174 const sc_bind_proxy &p050,
175 const sc_bind_proxy &p051,
176 const sc_bind_proxy &p052,
177 const sc_bind_proxy &p053,
178 const sc_bind_proxy &p054,
179 const sc_bind_proxy &p055,
180 const sc_bind_proxy &p056,
181 const sc_bind_proxy &p057,
182 const sc_bind_proxy &p058,
183 const sc_bind_proxy &p059,
184 const sc_bind_proxy &p060,
185 const sc_bind_proxy &p061,
186 const sc_bind_proxy &p062,
187 const sc_bind_proxy &p063,
188 const sc_bind_proxy &p064)
189{
191 auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool {
192 if (!p.port() && !p.interface())
193 return false;
194 proxies.push_back(&p);
195 return true;
196 };
197 insert(p001) && insert(p002) && insert(p003) && insert(p004) &&
198 insert(p005) && insert(p006) && insert(p007) && insert(p008) &&
199 insert(p009) && insert(p010) && insert(p011) && insert(p012) &&
200 insert(p013) && insert(p014) && insert(p015) && insert(p016) &&
201 insert(p017) && insert(p018) && insert(p019) && insert(p020) &&
202 insert(p021) && insert(p022) && insert(p023) && insert(p024) &&
203 insert(p025) && insert(p026) && insert(p027) && insert(p028) &&
204 insert(p029) && insert(p030) && insert(p031) && insert(p032) &&
205 insert(p033) && insert(p034) && insert(p035) && insert(p036) &&
206 insert(p037) && insert(p038) && insert(p039) && insert(p040) &&
207 insert(p041) && insert(p042) && insert(p043) && insert(p044) &&
208 insert(p045) && insert(p046) && insert(p047) && insert(p048) &&
209 insert(p049) && insert(p050) && insert(p051) && insert(p052) &&
210 insert(p053) && insert(p054) && insert(p055) && insert(p056) &&
211 insert(p057) && insert(p058) && insert(p059) && insert(p060) &&
212 insert(p061) && insert(p062) && insert(p063) && insert(p064);
213 _gem5_module->bindPorts(proxies);
214}
215
218{
219 (*this)(iface);
220 return *this;
221}
222
225{
226 (*this)(pb);
227 return *this;
228}
229
230sc_module &
232{
233 (*this)(iface);
234 return *this;
235}
236
237sc_module &
239{
240 (*this)(pb);
241 return *this;
242}
243
249
255
257 sc_object(sc_gem5::newModuleChecked()->name()),
258 _gem5_module(sc_gem5::currentModule())
259{
260 if (sc_is_running())
261 SC_REPORT_ERROR(SC_ID_INSERT_MODULE_, "simulation running");
262 if (::sc_gem5::scheduler.elaborationDone())
263 SC_REPORT_ERROR(SC_ID_INSERT_MODULE_, "elaboration done");
264}
265
268{
270 SC_REPORT_WARNING(SC_ID_BAD_SC_MODULE_CONSTRUCTOR_, _name);
271}
272sc_module::sc_module(const std::string &_name) :
273 sc_module(sc_module_name(_name.c_str()))
274{
276 SC_REPORT_WARNING(SC_ID_BAD_SC_MODULE_CONSTRUCTOR_, _name.c_str());
277}
278
279void
284
285void
287{
289}
290
291void
293{
295}
296
297void
299{
301}
302
303void
305{
306 ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), true, val);
307}
308
309
310void
312{
314}
315
316void
318{
320}
321
322void
324{
326}
327
328void
330{
331 ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), false, val);
332}
333
334
335void
337{
339 if (p->procKind() == SC_CTHREAD_PROC_)
340 SC_REPORT_WARNING(SC_ID_DONT_INITIALIZE_, "");
341 p->dontInitialize(true);
342}
343
344void
349
350
352
353void
358
359void
364
365void
370
371void
376
377void
382
383void
385{
387}
388
389void
391{
393}
394
395void
397{
399}
400
401void
403{
404 ::sc_core::next_trigger(d, u, eol);
405}
406
407void
412
413void
415{
416 ::sc_core::next_trigger(d, u, eal);
417}
418
419
420bool
422{
423 return ::sc_core::timed_out();
424}
425
426
427void
432
433void
435{
437}
438
439void
441{
443}
444
445void
447{
448 ::sc_core::wait(eol);
449}
450
451void
453{
454 ::sc_core::wait(eal);
455}
456
457void
459{
461}
462
463void
465{
466 ::sc_core::wait(d, u);
467}
468
469void
471{
472 ::sc_core::wait(t, e);
473}
474
475void
477{
478 ::sc_core::wait(d, u, e);
479}
480
481void
483{
484 ::sc_core::wait(t, eol);
485}
486
487void
489{
490 ::sc_core::wait(d, u, eol);
491}
492
493void
495{
496 ::sc_core::wait(t, eal);
497}
498
499void
501{
502 ::sc_core::wait(d, u, eal);
503}
504
505
506void
511
512void
517
518void
523
524void
529
530void
535
536
537void
539{
541 p->cancelTimeout();
542 p->clearDynamic();
543}
544
545void
547{
549 p->cancelTimeout();
551}
552
553void
555{
557 p->cancelTimeout();
559}
560
561void
568
569void
571{
573 p->setTimeout(t);
574 p->clearDynamic();
575}
576
577void
579{
580 next_trigger(sc_time(d, u));
581}
582
583void
584next_trigger(const sc_time &t, const sc_event &e)
585{
587 p->setTimeout(t);
589}
590
591void
592next_trigger(double d, sc_time_unit u, const sc_event &e)
593{
594 next_trigger(sc_time(d, u), e);
595}
596
597void
599{
601 p->setTimeout(t);
603}
604
605void
607{
608 next_trigger(sc_time(d, u), eol);
609}
610
611void
613{
615 p->setTimeout(t);
617}
618
619void
621{
622 next_trigger(sc_time(d, u), eal);
623}
624
625bool
627{
629 if (!p)
630 return false;
631 else
632 return p->timedOut();
633}
634
635
636namespace
637{
638
639bool
640waitErrorCheck(sc_gem5::Process *p)
641{
642 if (p->procKind() == SC_METHOD_PROC_) {
643 SC_REPORT_ERROR(SC_ID_WAIT_NOT_ALLOWED_,
644 "\n in SC_METHODs use next_trigger() instead");
645 return true;
646 }
647 return false;
648}
649
650} // anonymous namespace
651
652void
654{
656 if (waitErrorCheck(p))
657 return;
658 p->cancelTimeout();
659 p->clearDynamic();
661}
662
663void
664wait(int n)
665{
666 if (n <= 0) {
667 std::string msg = gem5::csprintf("n = %d", n);
668 SC_REPORT_ERROR(SC_ID_WAIT_N_INVALID_, msg.c_str());
669 }
671 p->waitCount(n - 1);
672 wait();
673}
674
675void
676wait(const sc_event &e)
677{
679 if (waitErrorCheck(p))
680 return;
681 p->cancelTimeout();
684}
685
686void
688{
690 if (waitErrorCheck(p))
691 return;
692 p->cancelTimeout();
695}
696
697void
699{
701 if (waitErrorCheck(p))
702 return;
703 p->cancelTimeout();
706}
707
708void
709wait(const sc_time &t)
710{
712 if (waitErrorCheck(p))
713 return;
714 p->setTimeout(t);
715 p->clearDynamic();
717}
718
719void
720wait(double d, sc_time_unit u)
721{
722 wait(sc_time(d, u));
723}
724
725void
726wait(const sc_time &t, const sc_event &e)
727{
729 if (waitErrorCheck(p))
730 return;
731 p->setTimeout(t);
734}
735
736void
737wait(double d, sc_time_unit u, const sc_event &e)
738{
739 wait(sc_time(d, u), e);
740}
741
742void
743wait(const sc_time &t, const sc_event_or_list &eol)
744{
746 if (waitErrorCheck(p))
747 return;
748 p->setTimeout(t);
751}
752
753void
754wait(double d, sc_time_unit u, const sc_event_or_list &eol)
755{
756 wait(sc_time(d, u), eol);
757}
758
759void
760wait(const sc_time &t, const sc_event_and_list &eal)
761{
763 if (waitErrorCheck(p))
764 return;
765 p->setTimeout(t);
768}
769
770void
771wait(double d, sc_time_unit u, const sc_event_and_list &eal)
772{
773 wait(sc_time(d, u), eal);
774}
775
776void
778{
780 throw ::sc_gem5::ScHalt();
781}
782
783void
785{
786 while (s.read())
787 wait();
788 while (!s.read())
789 wait();
790}
791
792void
794{
795 while (s.read() == sc_dt::Log_1)
796 wait();
797 while (s.read() == sc_dt::Log_0)
798 wait();
799}
800
801void
803{
804 while (!s.read())
805 wait();
806 while (s.read())
807 wait();
808}
809
810void
812{
813 while (s.read() == sc_dt::Log_0)
814 wait();
815 while (s.read() == sc_dt::Log_1)
816 wait();
817}
818
819const char *
820sc_gen_unique_name(const char *seed)
821{
822 if (!seed || seed[0] == '\0') {
823 SC_REPORT_ERROR(SC_ID_GEN_UNIQUE_NAME_, "");
824 seed = "unnamed";
825 }
826
827 auto mod = sc_gem5::pickParentModule();
828 if (mod)
829 return mod->uniqueName(seed);
830
832 if (p)
833 return p->uniqueName(seed);
834
835 return ::sc_gem5::globalNameGen.gen(seed);
836}
837
838bool
844
845bool
847{
848 return ::sc_gem5::kernel->startOfSimulationComplete();
849}
850
851bool
853{
854 return ::sc_gem5::kernel->endOfSimulationComplete();
855}
856
857sc_module *
859{
861 modules.emplace_back(mod);
862 return mod;
863}
864
865} // namespace sc_core
Ports are used to interface objects to each other.
Definition port.hh:62
virtual ~sc_module()
Definition sc_module.cc:122
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)
Definition sc_module.cc:125
virtual const std::vector< sc_object * > & get_child_objects() const
Definition sc_module.cc:245
void async_reset_signal_is(const sc_in< bool > &, bool)
Definition sc_module.cc:311
virtual const std::vector< sc_event * > & get_child_events() const
Definition sc_module.cc:251
void set_stack_size(size_t)
Definition sc_module.cc:345
void reset_signal_is(const sc_in< bool > &, bool)
Definition sc_module.cc:286
void at_posedge(const sc_signal_in_if< bool > &)
Definition sc_module.cc:513
sc_module & operator<<(sc_interface &)
Definition sc_module.cc:217
sc_gem5::Module * _gem5_module
Definition sc_module.hh:258
virtual gem5::Port & gem5_getPort(const std::string &if_name, int idx=-1)
Definition sc_module.cc:117
sc_module & operator,(sc_interface &)
Definition sc_module.cc:231
void at_negedge(const sc_signal_in_if< bool > &)
Definition sc_module.cc:525
const char * name() const
Definition sc_object.cc:44
void endModule()
Definition module.hh:95
void deprecatedConstructor()
Definition module.hh:96
void bindPorts(std::vector< const ::sc_core::sc_bind_proxy * > &proxies)
Definition module.cc:107
Object * obj()
Definition module.hh:113
const std::vector< sc_core::sc_event * > & get_child_events() const
Definition object.cc:189
const std::vector< sc_core::sc_object * > & get_child_objects() const
Definition object.cc:183
static Process * newest()
Definition process.hh:123
void setStackSize(size_t size)
Definition process.hh:104
Process * current()
Definition scheduler.hh:185
void reg(Process *p)
Definition scheduler.cc:146
STL vector class.
Definition stl.hh:37
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
bool sc_start_of_simulation_invoked()
Definition sc_module.cc:846
const sc_bind_proxy SC_BIND_PROXY_NIL
Definition sc_module.cc:114
sc_module * sc_module_sc_new(sc_module *mod)
Definition sc_module.cc:858
void at_negedge(const sc_signal_in_if< bool > &s)
Definition sc_module.cc:802
bool sc_end_of_simulation_invoked()
Definition sc_module.cc:852
void next_trigger()
Definition sc_module.cc:538
bool sc_is_running()
Definition sc_main.cc:141
bool timed_out()
Definition sc_module.cc:626
void halt()
Definition sc_module.cc:777
void at_posedge(const sc_signal_in_if< bool > &s)
Definition sc_module.cc:784
bool sc_hierarchical_name_exists(const char *name)
Definition sc_module.cc:839
sc_time_unit
Definition sc_time.hh:40
const char * sc_gen_unique_name(const char *seed)
Definition sc_module.cc:820
const char SC_ID_MODULE_THREAD_AFTER_START_[]
Definition messages.cc:103
const char SC_ID_MODULE_METHOD_AFTER_START_[]
Definition messages.cc:101
const char SC_ID_MODULE_CTHREAD_AFTER_START_[]
Definition messages.cc:105
void wait()
Definition sc_module.cc:653
@ Log_1
Definition sc_logic.hh:87
@ Log_0
Definition sc_logic.hh:86
Objects allObjects
Definition object.cc:287
static Module * pickParentModule()
Definition module.hh:141
void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
Definition process.cc:425
sc_core::sc_object * findObject(const char *name, const Objects &objects)
Definition object.cc:296
void newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
void newDynamicSensitivityEventAndList(Process *p, const sc_core::sc_event_and_list *eal)
Process * newCThreadProcess(const char *name, ProcessFuncWrapper *func)
Definition sc_module.cc:84
Scheduler scheduler
Definition scheduler.cc:494
Events allEvents
Definition event.cc:218
Process * newMethodProcess(const char *name, ProcessFuncWrapper *func)
Definition sc_module.cc:54
void newDynamicSensitivityEventOrList(Process *p, const sc_core::sc_event_or_list *eol)
Process * newThreadProcess(const char *name, ProcessFuncWrapper *func)
Definition sc_module.cc:69
EventsIt findEvent(const std::string &name)
Definition event.cc:221
#define SC_REPORT_WARNING(msg_type, msg)
#define SC_REPORT_ERROR(msg_type, msg)
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0