The Sparta Modeling Framework
Loading...
Searching...
No Matches
Unit.hpp
Go to the documentation of this file.
1// <Unit.hpp> -*- C++ -*-
2
3
11#pragma once
12
13#include <string>
14
19#include "sparta/log/MessageSource.hpp"
20#include "sparta/log/categories/CategoryManager.hpp"
21
22namespace sparta {
23
24 class TreeNode;
25
26
37 class Unit : public Resource
38 {
39 friend class DAG;
40 public:
41
42 static constexpr const char * INFO_LOG = "info";
43 static constexpr const char * WARN_LOG = log::categories::WARN_STR;
44 static constexpr const char * DEBUG_LOG = log::categories::DEBUG_STR;
45
54 Unit(TreeNode* rc, const std::string & name) :
55 Resource(rc, name),
59 info_logger_ (rc, INFO_LOG, rc->getName() + " Info Messages"),
60 warn_logger_ (rc, WARN_LOG, rc->getName() + " Warn Messages"),
61 debug_logger_(rc, DEBUG_LOG, rc->getName() + " Debug Messages")
62 {}
63
72 Unit(rc, rc->getName())
73 {}
74
76 virtual ~Unit() {}
77
90 void setAutoPrecedence(bool auto_p) {
91 auto_precedence_ = auto_p;
92 }
93
96 return &unit_port_set_;
97 }
98
101 return &unit_event_set_;
102 }
103
108
109 protected:
112
115
118
121 virtual void onBindTreeEarly_() override {
122 if(!auto_precedence_) {
123 return;
124 }
125
127 {
128 // This event does not participate in auto precedence.
129 if(!event_node->doesParticipateInAutoPrecedence()) {
130 continue;
131 }
132
133 // Go through all of the registered InPorts and set these
134 // ports to precede any events that are on the Tick phase.
135 // This is for 0-cycle precedence only.
137 InPort * inp = dynamic_cast<InPort *>(pt.second);
138 sparta_assert(inp != nullptr);
140 inp->registerConsumerEvent(event_node->getScheduleable());
141 }
142 }
143
144 // Go through all of the registered OutPorts and set these
145 // ports to succeed any events that are on the Tick phase.
146 // This is for 0-cycle precedence only.
148 OutPort * outp = dynamic_cast<OutPort *>(pt.second);
149 sparta_assert(outp != nullptr);
151 outp->registerProducingEvent(event_node->getScheduleable());
152 }
153 }
154 }
155 }
156
158 virtual void onBindTreeLate_() override;
159
162
165
168
169 private:
171 bool auto_precedence_ = true;
172
173 };
174
175} // namespace sparta
File that defines the EventSet class.
File that defines the PortSet class.
File that defines the Resource class. Consider using sparta::Unit instead.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
File that defines the StatisticSet class.
Set of Events that a unit (or sparta::TreeNode, sparta::Resource) contains and are visible through a ...
Definition EventSet.hpp:26
EventsVector & getEvents(sparta::SchedulingPhase phase)
Definition EventSet.hpp:74
Base class for all InPort types.
Definition Port.hpp:297
void registerConsumerEvent(Scheduleable &consumer)
Add an event "listener" to this port.
Definition Port.hpp:366
Base class for all OutPort types.
Definition Port.hpp:493
void registerProducingEvent(Scheduleable &producer)
Add an event "producer" to this port.
Definition Port.hpp:528
A TreeNode that represents a set of ports used by a Resource.
Definition PortSet.hpp:29
RegisteredPortMap & getPorts(Port::Direction direction)
Get the ports in this PortSet for the given direction.
Definition PortSet.hpp:105
virtual bool doesParticipateInAutoPrecedence() const
Does this Port participate in auto-precedence establishment by sparta::Unit?
Definition Port.hpp:168
The is the base class for all types of resources used by the SPARTA framework.
Definition Resource.hpp:44
std::string getName() const
Set of StatisticDef and CounterBase-derived objects for visiblility through a sparta Tree.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
The is the base class for user defined blocks in simulation.
Definition Unit.hpp:38
sparta::EventSet unit_event_set_
The Unit's event set.
Definition Unit.hpp:114
Unit(TreeNode *rc)
Construct unit with a ResouceContainer.
Definition Unit.hpp:71
log::MessageSource debug_logger_
Default debug logger.
Definition Unit.hpp:167
log::MessageSource info_logger_
Default info logger.
Definition Unit.hpp:161
Unit(TreeNode *rc, const std::string &name)
Construct unit with a ResouceContainer.
Definition Unit.hpp:54
PortSet * getPortSet()
Return the port set.
Definition Unit.hpp:95
log::MessageSource warn_logger_
Default warn logger.
Definition Unit.hpp:164
virtual ~Unit()
Destroy!
Definition Unit.hpp:76
sparta::StatisticSet unit_stat_set_
The Unit's statistic set.
Definition Unit.hpp:117
virtual void onBindTreeLate_() override
Dump a dot.
virtual void onBindTreeEarly_() override
Definition Unit.hpp:121
sparta::PortSet unit_port_set_
The Unit's Ports.
Definition Unit.hpp:111
EventSet * getEventSet()
Return the event set.
Definition Unit.hpp:100
void setAutoPrecedence(bool auto_p)
Turn off auto-precedence.
Definition Unit.hpp:90
StatisticSet * getStatisticSet()
Return the stat set.
Definition Unit.hpp:105
Message source object associated with a sparta TreeNode through which messages can be sent.
Macros for handling exponential backoff.
@ Tick
Most operations (combinational logic) occurs in this phase.