49 const std::string & strip_str)
const
51 for(
auto & rpi : src_ports)
54 std::string stripped_port_name =
55 sparta::utils::strip_string_pattern(strip_str +
"_", rpi.first);
58 sparta::utils::strip_string_pattern(
"_" + strip_str, stripped_port_name);
61 stripped_port_name.erase(std::remove(stripped_port_name.begin(),
62 stripped_port_name.end(),
'_'),
63 stripped_port_name.end());
64 const auto & it = port_map.find(stripped_port_name);
66 "Error: Cannot discern between port name " << rpi.first
67 <<
" and " << it->second->getName());
68 port_map.emplace(std::make_pair(stripped_port_name, rpi.second));
74 std::string & unbound_ports)
const
78 for(
auto & pm1_pt : port_map1) {
79 const auto & pm2_pt = port_map2.find(pm1_pt.first);
80 if(pm2_pt == port_map2.end()) {
81 unbound_ports += pm1_pt.second->getLocation() +
", ";
84 for(
auto & pm2_pt : port_map2) {
85 const auto & pm1_pt = port_map1.find(pm2_pt.first);
86 if(pm1_pt == port_map1.end()) {
87 unbound_ports += pm2_pt.second->getLocation() +
", ";
96 for(
auto & pm1_pt : port_map1)
98 const auto & pm2_pt = port_map2.find(pm1_pt.first);
107 bool precedence_set_ =
false;
117 const std::string & name,
120 const std::string & desc =
"");
137 "Cannot add ports after any call to set precedence, e.g. inportsPrecede()");
147 p.second->enableCollection(
this);
150 p.second->enableCollection(
this);
160 return port_set_.
getPorts(direction);
169 for(
auto & pi : in_ports) {
172 port->
setPortDelay (
static_cast<sparta::Clock::Cycle
>(delay_cycles));
182 for(
auto & pi : in_ports) {
193 template<
typename EventT>
196 for(
auto & pi : in_ports) {
201 precedence_set_ =
true;
208 template<
typename EventT>
211 for(
auto & pi : out_ports) {
216 precedence_set_ =
true;
242 std::string unbound_ports;
243 checkBinding_(this_bus_in_ports, other_bus_out_ports, unbound_ports);
244 checkBinding_(this_bus_out_ports, other_bus_in_ports, unbound_ports);
246 "When binding bus '" <<
getName()
247 <<
"' to bus '" << other_bus->
getName()
248 <<
"', the following ports will NOT get bound (no equivalence): "
253 bindPorts_(this_bus_in_ports, other_bus_out_ports);
254 bindPorts_(this_bus_out_ports, other_bus_in_ports);
289 Bus * bus =
dynamic_cast<Bus*
>(child);
291 "ERROR: Attempting to add object '" << child->
getName()
292 <<
"' which is not a Bus type to '" <<
getLocation() <<
"'");
298 std::unordered_map<std::string, Bus*> registered_buses_;
303 const std::string & name,
304 const std::string& group,
306 const std::string & desc) :
307 TreeNode(name, group, group_idx, desc),
308 port_set_(this, desc +
" PortSet")
311 if(parent !=
nullptr) {
320 const BusSet * bus_set =
dynamic_cast<const BusSet*
>(parent);
322 "ERROR: Attempting to add Bus '" <<
getName()
323 <<
"' to something that is not a BusSet");
File that defines the PortSet class.
File that defines the Port base class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
A TreeNode that represents a set of Buses.
BusSet(const BusSet &)=delete
Cannot copy BusSets.
BusSet(TreeNode *parent, const std::string &desc)
Construct a BusSet with a given parent. The parent can be nullptr.
BusSet & operator=(const BusSet &)=delete
Cannot assign BusSets.
void onAddingChild_(TreeNode *child) override
Hook for reacting to or rejecting new children. Invoked immediately before adding a child to this nod...
Class that defines a Bus type.
Bus(TreeNode *parent, const std::string &name, const std::string &group=GROUP_NAME_NONE, group_idx_type group_idx=GROUP_IDX_NONE, const std::string &desc="")
Construct a bus given the parent BusSet.
void onSettingParent_(const TreeNode *parent) const override
Sanity checking...
void inportsPrecede(EventT &event)
Make all inports precede the given event.
void setInPortDelay(uint32_t delay_cycles)
Set the port delay to the given value for all IN ports.
void registerPort(Port *port)
Register the given port with the bus.
PortSet::RegisteredPortMap & getPorts(Port::Direction direction)
Get the ports in this PortSet for the given direction.
void bind(Bus *other_bus)
Bind bus1 to bus2.
PortSet & getPortSet()
Get the port set this bus uses to maintain the ports.
void setInPortDelay(double delay_cycles)
Set the port delay to the given value for all IN ports.
void outportsSucceed(EventT &event)
Make all outports succeed the given event.
Base class for all InPort types.
void registerConsumerEvent(Scheduleable &consumer)
Add an event "listener" to this port.
Base class for all OutPort types.
void registerProducingEvent(Scheduleable &producer)
Add an event "producer" to this port.
A TreeNode that represents a set of ports used by a Resource.
RegisteredPortMap & getPorts(Port::Direction direction)
Get the ports in this PortSet for the given direction.
std::unordered_map< std::string, Port * > RegisteredPortMap
Convenience typedef.
The port interface used to bind port types together and defines a port behavior.
Direction
The direction of this port.
virtual void setPortDelay(sparta::Clock::Cycle)
Set the delay for a port.
Node in a composite tree representing a sparta Tree item.
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
std::string getLocation() const override final
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
uint32_t group_idx_type
Index within a group.
const std::string & getName() const override
Gets the name of this node.
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Macros for handling exponential backoff.
void bind(Bus *p1, Bus *p2)
Bind two buses together.