21#include "sparta/utils/Utils.hpp"
67 const std::string& name);
129 (void)node; (void)label;
158 virtual void simulationTerminating_();
196 virtual void dumpDebugContent_(std::ostream& output)
const;
210 virtual void onStartingTeardown_();
217 virtual void onBindTreeEarly_() {;}
224 virtual void onBindTreeLate_() {;}
246 GENERATE_HAS_ATTR(getClock)
256 void appendTickData_(std::ostream& ss,
Scheduler * sched)
262 ss <<
"(no scheduler associated)";
269 void appendClockData_(std::ostream& ss,
const Clock* clk)
276 ss <<
"(no clock associated) ";
279 appendTickData_(ss, sched);
287 template <
class CTXT>
289 typename std::enable_if<!std::is_base_of<Resource, CTXT>::value
290 && !std::is_base_of<TreeNode, CTXT>::value
291 && !has_attr_getClock<CTXT>::value>::type* dummy =
nullptr) {
294 std::stringstream ss;
295 ss <<
"(from non-sparta context at ";
296 appendTickData_(ss,
nullptr);
310 template <
class CTXT>
312 typename std::enable_if<!std::is_base_of<Resource, CTXT>::value
313 && !std::is_base_of<TreeNode, CTXT>::value
314 && has_attr_getClock<CTXT>::value>::type* dummy = 0) {
316 std::stringstream ss;
317 static_assert(std::is_pointer<
decltype(ctxt->getClock())>::value,
318 "Type of this pointer is a class having a getClock method, but this "
319 "method does not return a pointer to a sparta::Clock");
321 typename std::remove_pointer<
typename std::remove_cv<
decltype(ctxt->getClock())>::type>::type>::value !=
false,
322 "Type of this pointer is a class having a getClock method, but this "
323 "method doe not return a sparta::Clock");
324 auto clock = ctxt->getClock();
326 appendClockData_(ss, clock);
334 template <
class CTXT>
336 typename std::enable_if<std::is_base_of<Resource, CTXT>::value>::type* dummy = 0) {
338 std::stringstream ss;
341 ss <<
"(within uncontained resource)";
343 ss <<
"within resource at: " << rc->
getLocation() <<
" ";
346 appendClockData_(ss, clock);
355 template <
class CTXT>
357 typename std::enable_if<std::is_base_of<TreeNode, CTXT>::value>::type* dummy = 0) {
359 std::stringstream ss;
361 ss <<
"(within null treenode)";
363 ss <<
"within TreeNode: " << ctxt->
getLocation() <<
" ";
366 appendClockData_(ss, clock);
378 #define ADD_CONTEXT_INFORMATION(ex, thisptr) \
379 sparta::AssertContext ac; \
380 ex << " " << ac.getContextDescription<typename std::remove_pointer<decltype(thisptr)>::type>(thisptr);
401 #define sparta_assert_context(e, insertions) \
402 if(__builtin_expect(!(e), 0)) { sparta::SpartaException ex(std::string(#e) + ": " ); \
404 ADD_FILE_INFORMATION(ex, __FILE__, __LINE__); \
405 ADD_CONTEXT_INFORMATION(ex, this); \
File that defines the Clock class.
Object with a name which holds a Resource.
A simple time-based, event precedence based scheduler.
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
Creates a helper traits class for determining whehther a type has a member named getClock.
std::string getContextDescription(const sparta::Resource *ctxt, typename std::enable_if< std::is_base_of< Resource, CTXT >::value >::type *dummy=0)
Handle case where pointer is a subclass of (or is a) sparta::Resource.
std::string getContextDescription(const sparta::TreeNode *ctxt, typename std::enable_if< std::is_base_of< TreeNode, CTXT >::value >::type *dummy=0)
Handle case where pointer is a subclass of (or is a) sparta::TreeNode.
std::string getContextDescription(CTXT *ctxt, typename std::enable_if<!std::is_base_of< Resource, CTXT >::value &&!std::is_base_of< TreeNode, CTXT >::value &&!has_attr_getClock< CTXT >::value >::type *dummy=nullptr)
Handle default case where pointer is not a sparta::Resource.
std::string getContextDescription(CTXT *ctxt, typename std::enable_if<!std::is_base_of< Resource, CTXT >::value &&!std::is_base_of< TreeNode, CTXT >::value &&has_attr_getClock< CTXT >::value >::type *dummy=0)
Handle case where pointer is a not subclass of (and not a) sparta::Resource, but still has a getClock...
A representation of simulated time.
Cycle currentCycle() const
Get the current cycle (uses current tick from the Scheduler)
Scheduler * getScheduler() const
virtual std::string getLocation() const =0
Returns the location of this node in device tree which can be used to navigate the device tree in met...
Information describing the type of validation being done.
PhasedObject which can hold 0 or 1 Resource pointers to an associatedresource. Contains logic for set...
The is the base class for all types of resources used by the SPARTA framework.
Scheduler * getScheduler(const bool must_exist=true) const
virtual void addLink(TreeNode *node, const std::string &label)
ResourceContainer * getResourceContainer()
Gets the ResourceContainer for this resource (if any)
const Clock * getClock() const
TreeNode * getContainer()
Gets the TreeNode (container) for this resource (if any)
std::string getName() const
virtual ~Resource()
Destroy!
Resource(const Resource &)=delete
Disallow copying.
Resource(const std::string &name, const Clock *clk)
Construct a Resource with the given name and clock having NO association with a resource container....
const ResourceContainer * getResourceContainer() const
Gets the ResourceContainer for this resource (if any)
Resource(TreeNode *rc, const std::string &name)
Construct resource with a specific name and resource container.
friend class TreeNode
Allow TreeNode access to onStartingTeardown_.
Resource(TreeNode *rc)
Construct resource with a resource container.
virtual void activateLink(const std::string &label)
const TreeNode * getContainer() const
Gets the TreeNode (container) for this resource (if any)
A class that lets you schedule events now and in the future.
Tick getCurrentTick() const noexcept
The current tick the Scheduler is working on or just finished.
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
Macros for handling exponential backoff.