#define __COCO_IR_BAG_INFO_H__
#include "coco/IR/Bag.h"
-#include "coco/IR/ObjectSet.h"
+#include "coco/IR/DepSet.h"
#include <set>
uint32_t const _size;
public:
- ObjectSet *object(void) { return &_object; }
- const ObjectSet *object(void) const { return &_object; }
-
-private:
- ObjectSet _object;
+ DepSet *deps(void) { return &_deps; }
+ const DepSet *deps(void) const { return &_deps; }
public:
Bag::ReaderSet *reads(void) { return &_reads; }
const BagMask *mask(void) const { return &_mask; }
private:
+ /** @brief Links to dependent Object(s) */
+ DepSet _deps;
/** @brief Direct reads (not through Object) */
Bag::ReaderSet _reads;
/** @brief Direct updates (not through Object) */
--- /dev/null
+#ifndef __COCO_IR_DEP_SET_H__
+#define __COCO_IR_DEP_SET_H__
+
+#include "coco/IR/Dep.h"
+
+#include <set>
+
+namespace coco
+{
+
+using DepSet = std::set<Dep *>;
+
+} // namespace coco
+
+#endif // __COCO_IR_DEP_SET_H__
bool Bag::isInput(void) const { return _info->mask()->masked(BagMask::Input); }
bool Bag::isOutput(void) const { return _info->mask()->masked(BagMask::Output); }
-ObjectSet Bag::deps(void) const { return *_info->object(); }
+ObjectSet Bag::deps(void) const
+{
+ ObjectSet res;
+
+ for (const auto &dep : *(_info->deps()))
+ {
+ if (auto obj = dep->object())
+ {
+ res.insert(obj);
+ }
+ }
+
+ return res;
+}
Bag::ReaderSet Bag::reads(void) const
{
{
if (_bag != nullptr)
{
- // Remove bag <-> object link (if possible)
- if (_link && _object)
+ // Remove bag <-> dep link (if possible)
+ if (_link)
{
auto info = _link->find(_bag);
assert(info != nullptr);
- assert(info->object()->find(_object) != info->object()->end());
+ assert(info->deps()->find(this) != info->deps()->end());
- info->object()->erase(_object);
+ info->deps()->erase(this);
}
// Reset _bag
// Set _bag
_bag = bag;
- // Create bag <-> object link (if possible)
- if (_link && _object)
+ // Create bag <-> dep link (if possible)
+ if (_link)
{
auto info = _link->find(bag);
assert(info != nullptr);
- info->object()->insert(_object);
+ info->deps()->insert(this);
}
}
// 'bag(Bag *)' should affect the return of 'bag(void)'
ASSERT_EQ(obj.bag(), bag);
- // The dependent object list of each bag should be updated on 'bag(...)' call.
- auto bag_info = link.find(bag);
-
- ASSERT_EQ(bag_info->object()->size(), 1);
- ASSERT_EQ(bag_info->object()->count(&obj), 1);
-
// User SHOULD be able to access dependent objects through 'bag'
{
auto deps = bag->deps();