21#include "sparta/utils/Utils.hpp"
22#include "simdb/Errors.hpp"
68 const std::string& name);
130 (void)node; (void)label;
159 virtual void simulationTerminating_();
197 virtual void dumpDebugContent_(std::ostream& output)
const;
211 virtual void onStartingTeardown_();
218 virtual void onBindTreeEarly_() {;}
225 virtual void onBindTreeLate_() {;}
247 GENERATE_HAS_ATTR(getClock)
257 void appendTickData_(std::ostream& ss,
Scheduler * sched)
263 ss <<
"(no scheduler associated)";
270 void appendClockData_(std::ostream& ss,
const Clock* clk)
277 ss <<
"(no clock associated) ";
280 appendTickData_(ss, sched);
288 template <
class CTXT>
290 typename std::enable_if<!std::is_base_of<Resource, CTXT>::value
291 && !std::is_base_of<TreeNode, CTXT>::value
292 && !has_attr_getClock<CTXT>::value>::type* dummy =
nullptr) {
295 std::stringstream ss;
296 ss <<
"(from non-sparta context at ";
297 appendTickData_(ss,
nullptr);
311 template <
class CTXT>
313 typename std::enable_if<!std::is_base_of<Resource, CTXT>::value
314 && !std::is_base_of<TreeNode, CTXT>::value
315 && has_attr_getClock<CTXT>::value>::type* dummy = 0) {
317 std::stringstream ss;
318 static_assert(std::is_pointer<
decltype(ctxt->getClock())>::value,
319 "Type of this pointer is a class having a getClock method, but this "
320 "method does not return a pointer to a sparta::Clock");
322 typename std::remove_pointer<
typename std::remove_cv<
decltype(ctxt->getClock())>::type>::type>::value !=
false,
323 "Type of this pointer is a class having a getClock method, but this "
324 "method doe not return a sparta::Clock");
325 auto clock = ctxt->getClock();
327 appendClockData_(ss, clock);
335 template <
class CTXT>
337 typename std::enable_if<std::is_base_of<Resource, CTXT>::value>::type* dummy = 0) {
339 std::stringstream ss;
342 ss <<
"(within uncontained resource)";
344 ss <<
"within resource at: " << rc->
getLocation() <<
" ";
347 appendClockData_(ss, clock);
356 template <
class CTXT>
358 typename std::enable_if<std::is_base_of<TreeNode, CTXT>::value>::type* dummy = 0) {
360 std::stringstream ss;
362 ss <<
"(within null treenode)";
364 ss <<
"within TreeNode: " << ctxt->
getLocation() <<
" ";
367 appendClockData_(ss, clock);
379 #define ADD_CONTEXT_INFORMATION(ex, thisptr) \
380 sparta::AssertContext ac; \
381 ex << " " << ac.getContextDescription<typename std::remove_pointer<decltype(thisptr)>::type>(thisptr);
402 #define sparta_assert_context(e, insertions) \
403 if(__builtin_expect(!(e), 0)) { sparta::SpartaException ex(std::string(#e) + ": " ); \
405 ADD_FILE_INFORMATION(ex, __FILE__, __LINE__); \
406 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.