#include "coco/IR/Bag.h"
#include "coco/ADT/PtrManager.h"
+#include "coco/ADT/PtrLink.h"
namespace coco
{
-struct BagManager : public PtrManager<Bag>
+class BagManager : public PtrManager<Bag>
{
+public:
+ BagManager(PtrLink<Bag, BagInfo> *link) : _link{link}
+ {
+ // DO NOTHING
+ }
+
+public:
Bag *create(uint32_t size);
+
+private:
+ PtrLink<Bag, BagInfo> * const _link;
};
} // namespace coco
Bag *BagManager::create(uint32_t size)
{
- return take(nncc::foundation::make_unique<Bag>(size));
+ auto info = nncc::foundation::make_unique<BagInfo>(size);
+ auto info_ptr = info.get();
+
+ auto bag = nncc::foundation::make_unique<Bag>(std::move(info));
+ auto bag_ptr = bag.get();
+
+ _link->set(bag_ptr, info_ptr);
+
+ return take(std::move(bag));
}
} // namespace coco
TEST(IR_BAG_MANAGER, create)
{
- coco::BagManager mgr;
+ coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
+ coco::BagManager mgr{&bag_link};
auto bag = mgr.create(3);
ASSERT_EQ(bag->size(), 3);
+
+ // BagManager SHOULD update Bag->BagInfo link properly
+ ASSERT_NE(bag_link.find(bag), nullptr);
+
+ auto info = bag_link.find(bag);
+
+ ASSERT_EQ(info->size(), 3);
}
class ModuleImpl final : public coco::Module
{
public:
+ std::unique_ptr<coco::PtrLink<coco::Bag, coco::BagInfo>> _bag_link;
std::unique_ptr<coco::PtrLink<coco::Instr, coco::Block>> _instr_link;
std::unique_ptr<coco::PtrLink<coco::Block, coco::Module>> _block_link;
std::unique_ptr<Module> Module::create(void)
{
+ auto bag_link = nncc::foundation::make_unique<coco::PtrLink<Bag, BagInfo>>();
auto ins_link = nncc::foundation::make_unique<coco::PtrLink<Instr, Block>>();
auto blk_link = nncc::foundation::make_unique<coco::PtrLink<Block, Module>>();
auto mgr = nncc::foundation::make_unique<::EntityManagerImpl>();
{
- mgr->_bag = nncc::foundation::make_unique<coco::BagManager>();
+ mgr->_bag = nncc::foundation::make_unique<coco::BagManager>(bag_link.get());
mgr->_object = nncc::foundation::make_unique<coco::ObjectManager>();
mgr->_op = nncc::foundation::make_unique<coco::OpManager>();
mgr->_instr = nncc::foundation::make_unique<coco::InstrManager>(ins_link.get());
m->_input = nncc::foundation::make_unique<coco::InputList>();
m->_output = nncc::foundation::make_unique<coco::OutputList>();
+ m->_bag_link = std::move(bag_link);
m->_instr_link = std::move(ins_link);
m->_block_link = std::move(blk_link);