{
return _posStamp == getChangeStamp();
}
-bool
+bool
ScSignalBaseBinary::negedge() const
{
return _negStamp == getChangeStamp();
}
+void
+ScSignalBaseBinary::_signalReset(sc_gem5::Reset *r)
+{
+ r->update();
+}
+
+void
+ScSignalBaseBinary::_signalReset()
+{
+ for (auto r: _resets)
+ _signalReset(r);
+}
+
} // namespace sc_gem5
senses.resize(size);
}
-void
-Event::notify(ResetSensitivities &senses)
-{
- for (auto s: senses)
- s->notify(this);
-}
-
void
Event::notify()
{
scheduler.deschedule(&delayedNotify);
_triggeredStamp = scheduler.changeStamp();
- notify(resetSense);
notify(staticSenseMethod);
notify(dynamicSenseMethod);
notify(staticSenseThread);
void notify(StaticSensitivities &senses);
void notify(DynamicSensitivities &senses);
- void notify(ResetSensitivities &senses);
void notify();
void notify(const sc_core::sc_time &t);
}
}
}
- void
- addSensitivity(ResetSensitivity *s) const
- {
- resetSense.push_back(s);
- }
- void
- delSensitivity(ResetSensitivity *s) const
- {
- for (auto &t: resetSense) {
- if (t == s) {
- t = resetSense.back();
- resetSense.pop_back();
- break;
- }
- }
- }
private:
sc_core::sc_event *_sc_event;
mutable StaticSensitivities staticSenseThread;
mutable DynamicSensitivities dynamicSenseMethod;
mutable DynamicSensitivities dynamicSenseThread;
- mutable ResetSensitivities resetSense;
};
extern Events topLevelEvents;
#include "systemc/core/port.hh"
+#include "systemc/core/process.hh"
#include "systemc/core/sensitivity.hh"
#include "systemc/ext/channel/sc_signal_in_if.hh"
}
void
-Port::finalizeReset(ResetSensitivityPort *reset)
+Port::finalizeReset(Reset *reset)
{
assert(size() <= 1);
if (size()) {
auto iface =
dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0));
assert(iface);
- reset->setSignal(iface);
+ if (!reset->install(iface))
+ delete reset;
}
}
}
void
-Port::sensitive(ResetSensitivityPort *reset)
+Port::addReset(Reset *reset)
{
if (finalized)
finalizeReset(reset);
else
- sensitivities.push_back(new Sensitivity(reset));
+ resets.push_back(reset);
}
void
for (auto &s: sensitivities) {
if (s->port)
finalizePort(s->port);
- else if (s->finder)
- finalizeFinder(s->finder);
else
- finalizeReset(s->reset);
+ finalizeFinder(s->finder);
delete s;
}
sensitivities.clear();
+
+ for (auto &r: resets)
+ finalizeReset(r);
+
+ resets.clear();
}
void
class StaticSensitivityPort;
class StaticSensitivityFinder;
-class ResetSensitivityPort;
+class Reset;
class Port;
void finalizePort(StaticSensitivityPort *port);
void finalizeFinder(StaticSensitivityFinder *finder);
- void finalizeReset(ResetSensitivityPort *reset);
+ void finalizeReset(Reset *reset);
void
addInterface(::sc_core::sc_interface *iface)
struct Sensitivity
{
Sensitivity(StaticSensitivityPort *port) :
- port(port), finder(nullptr), reset(nullptr)
+ port(port), finder(nullptr)
{}
Sensitivity(StaticSensitivityFinder *finder) :
- port(nullptr), finder(finder), reset(nullptr)
- {}
-
- Sensitivity(ResetSensitivityPort *reset) :
- port(nullptr), finder(nullptr), reset(reset)
+ port(nullptr), finder(finder)
{}
StaticSensitivityPort *port;
StaticSensitivityFinder *finder;
- ResetSensitivityPort *reset;
};
std::vector<Binding *> bindings;
std::vector<Sensitivity *> sensitivities;
+ std::vector<Reset *> resets;
public:
static Port *
void sensitive(StaticSensitivityPort *port);
void sensitive(StaticSensitivityFinder *finder);
- void sensitive(ResetSensitivityPort *reset);
+ void addReset(Reset *reset);
void finalize();
void regPort();
#include "base/logging.hh"
#include "systemc/core/event.hh"
+#include "systemc/core/port.hh"
#include "systemc/core/scheduler.hh"
#include "systemc/ext/core/sc_join.hh"
#include "systemc/ext/core/sc_main.hh"
}
void
-Process::addReset(ResetSensitivity *s)
+Process::addReset(Reset *reset)
{
- resetSensitivities.push_back(s);
+ resets.push_back(reset);
}
void
p->throw_it(exc, inc_kids);
}
+void
+newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
+{
+ Port *port = Port::fromPort(pb);
+ port->addReset(new Reset(p, s, v));
+}
+
+void
+newReset(const sc_core::sc_signal_in_if<bool> *sig, Process *p, bool s, bool v)
+{
+ Reset *reset = new Reset(p, s, v);
+ if (!reset->install(sig))
+ delete reset;
+}
+
} // namespace sc_gem5
#include "systemc/core/object.hh"
#include "systemc/core/sched_event.hh"
#include "systemc/core/sensitivity.hh"
+#include "systemc/ext/channel/sc_signal_in_if.hh"
#include "systemc/ext/core/sc_event.hh"
#include "systemc/ext/core/sc_module.hh"
#include "systemc/ext/core/sc_process_handle.hh"
class ScHalt
{};
+class Process;
+class Reset;
+
class Process : public ::sc_core::sc_process_b, public ListNode
{
public:
void addStatic(StaticSensitivity *);
void setDynamic(DynamicSensitivity *);
void clearDynamic() { setDynamic(nullptr); }
- void addReset(ResetSensitivity *);
+ void addReset(Reset *);
ScEvent timeoutEvent;
void setTimeout(::sc_core::sc_time t);
StaticSensitivities staticSensitivities;
DynamicSensitivity *dynamicSensitivity;
- ResetSensitivities resetSensitivities;
+ std::vector<Reset *> resets;
std::unique_ptr<::sc_core::sc_report> _lastReport;
UniqueNameGen nameGen;
};
+class Reset
+{
+ public:
+ Reset(Process *p, bool s, bool v) :
+ _process(p), _signal(nullptr), _sync(s), _value(v)
+ {}
+
+ bool
+ install(const sc_core::sc_signal_in_if<bool> *s)
+ {
+ _signal = s;
+
+ if (_signal->_addReset(this)) {
+ _process->addReset(this);
+ if (_signal->read() == _value)
+ update();
+ return true;
+ }
+ return false;
+ }
+ void update() { _process->signalReset(_signal->read() == _value, _sync); }
+
+ Process *process() { return _process; }
+ const sc_core::sc_signal_in_if<bool> *signal() { return _signal; }
+ bool sync() { return _sync; }
+ bool value() { return _value; }
+
+ private:
+ Process *_process;
+ const sc_core::sc_signal_in_if<bool> *_signal;
+ bool _sync;
+ bool _value;
+};
+
+void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v);
+void newReset(const sc_core::sc_signal_in_if<bool> *sig, Process *p,
+ bool s, bool v);
+
} // namespace sc_gem5
#endif //__SYSTEMC_CORE_PROCESS_HH__
#include "systemc/core/kernel.hh"
#include "systemc/core/module.hh"
#include "systemc/core/object.hh"
+#include "systemc/core/port.hh"
#include "systemc/core/process_types.hh"
#include "systemc/core/sensitivity.hh"
+#include "systemc/ext/channel/sc_in.hh"
+#include "systemc/ext/channel/sc_inout.hh"
+#include "systemc/ext/channel/sc_out.hh"
#include "systemc/ext/channel/sc_signal_in_if.hh"
#include "systemc/ext/core/sc_module.hh"
#include "systemc/ext/core/sc_module_name.hh"
void
sc_module::reset_signal_is(const sc_in<bool> &port, bool val)
{
- sc_gem5::newResetSensitivityPort(
- ::sc_gem5::Process::newest(), &port, val, true);
+ ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val);
}
void
sc_module::reset_signal_is(const sc_inout<bool> &port, bool val)
{
- sc_gem5::newResetSensitivityPort(
- ::sc_gem5::Process::newest(), &port, val, true);
+ ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val);
}
void
sc_module::reset_signal_is(const sc_out<bool> &port, bool val)
{
- sc_gem5::newResetSensitivityPort(
- ::sc_gem5::Process::newest(), &port, val, true);
+ ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val);
}
void
sc_module::reset_signal_is(const sc_signal_in_if<bool> &signal, bool val)
{
- sc_gem5::newResetSensitivitySignal(
- ::sc_gem5::Process::newest(), &signal, val, true);
+ ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), true, val);
}
void
sc_module::async_reset_signal_is(const sc_in<bool> &port, bool val)
{
- sc_gem5::newResetSensitivityPort(
- ::sc_gem5::Process::newest(), &port, val, false);
+ ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val);
}
void
sc_module::async_reset_signal_is(const sc_inout<bool> &port, bool val)
{
- sc_gem5::newResetSensitivityPort(
- ::sc_gem5::Process::newest(), &port, val, false);
+ ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val);
}
void
sc_module::async_reset_signal_is(const sc_out<bool> &port, bool val)
{
- sc_gem5::newResetSensitivityPort(
- ::sc_gem5::Process::newest(), &port, val, false);
+ ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val);
}
void
sc_module::async_reset_signal_is(const sc_signal_in_if<bool> &signal, bool val)
{
- sc_gem5::newResetSensitivitySignal(
- ::sc_gem5::Process::newest(), &signal, val, false);
+ ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), false, val);
}
#include "systemc/core/process.hh"
#include "systemc/core/process_types.hh"
#include "systemc/core/scheduler.hh"
+#include "systemc/ext/channel/sc_in.hh"
+#include "systemc/ext/channel/sc_inout.hh"
+#include "systemc/ext/channel/sc_out.hh"
+#include "systemc/ext/channel/sc_signal_in_if.hh"
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/core/sc_module.hh"
#include "systemc/ext/core/sc_spawn.hh"
newStaticSensitivityFinder(proc, f);
for (auto p: opts->_in_resets)
- newResetSensitivityPort(proc, p.target, p.value, p.sync);
+ newReset(p.target, proc, p.sync, p.value);
for (auto p: opts->_inout_resets)
- newResetSensitivityPort(proc, p.target, p.value, p.sync);
+ newReset(p.target, proc, p.sync, p.value);
for (auto p: opts->_out_resets)
- newResetSensitivityPort(proc, p.target, p.value, p.sync);
+ newReset(p.target, proc, p.sync, p.value);
for (auto i: opts->_if_resets)
- newResetSensitivitySignal(proc, i.target, i.value, i.sync);
+ newReset(i.target, proc, i.sync, i.value);
}
if (opts && opts->_dontInitialize &&
#include "systemc/core/sensitivity.hh"
+#include "base/logging.hh"
#include "systemc/core/event.hh"
#include "systemc/core/port.hh"
#include "systemc/core/process.hh"
Event::getFromScEvent(e)->delSensitivity(this);
}
-void
-ResetSensitivity::addToEvent(const ::sc_core::sc_event *e)
-{
- Event::getFromScEvent(e)->addSensitivity(this);
-}
-
-void
-ResetSensitivity::delFromEvent(const ::sc_core::sc_event *e)
-{
- Event::getFromScEvent(e)->delSensitivity(this);
-}
-
/*
* Static sensitivities.
return true;
}
-/*
- * Reset sensitivities.
- */
-
-void
-newResetSensitivitySignal(
- Process *p, const sc_core::sc_signal_in_if<bool> *signal,
- bool val, bool sync)
-{
- auto s = new ResetSensitivitySignal(p, signal, val, sync);
- s->addToEvent(s->event);
- p->addReset(s);
-}
-
-void
-newResetSensitivityPort(Process *p, const sc_core::sc_in<bool> *port,
- bool val, bool sync)
-{
- auto s = new ResetSensitivityPort(p, port, val, sync);
- Port::fromPort(port)->sensitive(s);
- p->addReset(s);
-}
-void
-newResetSensitivityPort(Process *p, const sc_core::sc_inout<bool> *port,
- bool val, bool sync)
-{
- auto s = new ResetSensitivityPort(p, port, val, sync);
- Port::fromPort(port)->sensitive(s);
- p->addReset(s);
-}
-void
-newResetSensitivityPort(Process *p, const sc_core::sc_out<bool> *port,
- bool val, bool sync)
-{
- auto s = new ResetSensitivityPort(p, port, val, sync);
- Port::fromPort(port)->sensitive(s);
- p->addReset(s);
-}
-
-ResetSensitivitySignal::ResetSensitivitySignal(
- Process *p, const sc_core::sc_signal_in_if<bool> *signal,
- bool _val, bool _sync) :
- Sensitivity(p), ResetSensitivity(p, _val, _sync),
- SensitivityEvent(p, signal ? &signal->value_changed_event() : nullptr),
- _signal(signal)
-{
- if (signal && signal->read() == val())
- process->signalReset(true, sync());
-}
-
-bool
-ResetSensitivitySignal::notify(Event *e)
-{
- process->signalReset(_signal->read() == val(), sync());
- return true;
-}
-
-void
-ResetSensitivityPort::setSignal(const ::sc_core::sc_signal_in_if<bool> *signal)
-{
- _signal = signal;
- event = &_signal->value_changed_event();
- addToEvent(event);
- if (signal->read() == val())
- process->signalReset(true, sync());
-}
-
} // namespace sc_gem5
enum Category
{
Static,
- Dynamic,
- Reset
+ Dynamic
};
virtual Category category() = 0;
/*
- * Dynamic vs. static vs. reset sensitivity.
+ * Dynamic vs. static sensitivity.
*/
class DynamicSensitivity : virtual public Sensitivity
typedef std::vector<StaticSensitivity *> StaticSensitivities;
-class ResetSensitivity : virtual public Sensitivity
-{
- private:
- bool _val;
- bool _sync;
-
- protected:
- ResetSensitivity(Process *p, bool _val, bool _sync) :
- Sensitivity(p), _val(_val), _sync(_sync)
- {}
-
- void addToEvent(const ::sc_core::sc_event *e) override;
- void delFromEvent(const ::sc_core::sc_event *e) override;
-
- bool val() { return _val; }
- bool sync() { return _sync; }
-
- public:
- Category category() override { return Reset; }
-};
-
-typedef std::vector<ResetSensitivity *> ResetSensitivities;
-
/*
* Sensitivity to an event or events, which can be static or dynamic.
bool notify(Event *e) override;
};
-/*
- * Reset sensitivities.
- */
-
-void newResetSensitivitySignal(
- Process *p, const sc_core::sc_signal_in_if<bool> *signal,
- bool val, bool sync);
-
-void newResetSensitivityPort(
- Process *p, const sc_core::sc_in<bool> *port, bool val, bool sync);
-void newResetSensitivityPort(
- Process *p, const sc_core::sc_inout<bool> *port, bool val, bool sync);
-void newResetSensitivityPort(
- Process *p, const sc_core::sc_out<bool> *port, bool val, bool sync);
-
-class ResetSensitivitySignal :
- public ResetSensitivity, public SensitivityEvent
-{
- protected:
- const sc_core::sc_signal_in_if<bool> *_signal;
-
- friend void newResetSensitivitySignal(
- Process *p, const sc_core::sc_signal_in_if<bool> *signal,
- bool val, bool sync);
-
- ResetSensitivitySignal(
- Process *p, const sc_core::sc_signal_in_if<bool> *signal,
- bool _val, bool _sync);
-
- bool notify(Event *e) override;
-};
-
-class ResetSensitivityPort : public ResetSensitivitySignal
-{
- private:
- friend void newResetSensitivityPort(
- Process *p, const sc_core::sc_in<bool> *port, bool val, bool sync);
- friend void newResetSensitivityPort(
- Process *p, const sc_core::sc_inout<bool> *port,
- bool val, bool sync);
- friend void newResetSensitivityPort(
- Process *p, const sc_core::sc_out<bool> *port,
- bool val, bool sync);
-
- ResetSensitivityPort(
- Process *p, const sc_core::sc_port_base *port,
- bool _val, bool _sync) :
- Sensitivity(p), ResetSensitivitySignal(p, nullptr, _val, _sync)
- {}
-
- public:
- void setSignal(const ::sc_core::sc_signal_in_if<bool> *signal);
-};
-
} // namespace sc_gem5
#endif //__SYSTEMC_CORE_SENSITIVITY_HH__
{
class Process;
+class Reset;
class ScSignalBase : public sc_core::sc_prim_channel
{
protected:
ScSignalBaseBinary(const char *_name);
+ mutable std::vector<sc_gem5::Reset *> _resets;
+ void _signalReset(sc_gem5::Reset *reset);
+ void _signalReset();
+
const sc_core::sc_event &posedgeEvent() const;
const sc_core::sc_event &negedgeEvent() const;
return;
this->m_cur_val = this->m_new_val;
+ this->_signalReset();
this->_signalChange();
if (this->m_cur_val) {
this->_posStamp = ::sc_gem5::getChangeStamp();
}
private:
+ bool
+ _addReset(sc_gem5::Reset *reset) const
+ {
+ this->_resets.push_back(reset);
+ return true;
+ }
+
// Disabled
sc_signal(const sc_signal<bool, WRITER_POLICY> &);
};
};
+namespace sc_gem5
+{
+
+class Reset;
+
+} // namespace sc_gem5
+
namespace sc_core
{
sc_signal_in_if() : sc_interface() {}
private:
+ friend class sc_gem5::Reset;
+ virtual bool
+ _addReset(sc_gem5::Reset *reset) const
+ {
+ return false;
+ }
+
// Disabled
sc_signal_in_if(const sc_signal_in_if<bool> &) : sc_interface() {}
sc_signal_in_if<bool> &