sim: provide a signal constructor with an init_state

1. The current SignalSinkPort and SignalSourcePort have no
   ways to assign the init value of the state. Add a new constructor
   for them with the param init_state
2. After the source and sink are bound, the state at both side should
   be the same. Set the the state of sink to the state of source in the
   bind() function.

Change-Id: Idde0a12aa0ddd0c9c599ef47059674fb12aa5d68
This commit is contained in:
Johnny
2023-08-17 13:24:43 +08:00
parent f9a4a794b7
commit 6acb687975

View File

@@ -79,6 +79,7 @@ class SignalSinkPort : public Port
_source = dynamic_cast<SignalSourcePort<State> *>(&peer);
fatal_if(!_source, "Attempt to bind signal pin %s to "
"incompatible pin %s", name(), peer.name());
_state = _source->state();
Port::bind(peer);
}
void
@@ -94,12 +95,21 @@ class SignalSourcePort : public Port
{
private:
SignalSinkPort<State> *sink = nullptr;
State _state = {};
State _state;
public:
SignalSourcePort(const std::string &_name, PortID _id=InvalidPortID) :
Port(_name, _id)
{}
SignalSourcePort(const std::string &_name, PortID _id = InvalidPortID)
: Port(_name, _id)
{
_state = {};
}
SignalSourcePort(const std::string &_name, PortID _id,
const State &init_state)
: SignalSourcePort(_name, _id)
{
_state = init_state;
}
void
set(const State &new_state)
@@ -126,6 +136,6 @@ class SignalSourcePort : public Port
}
};
} // namespace gem5
} // namespace gem5
#endif //__SIM_SIGNAL_HH__
#endif //__SIM_SIGNAL_HH__