From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 13 Sep 2018 02:23:01 +0000 (+0900) Subject: [coco] Remove DefHook (#1483) X-Git-Tag: nncc_backup~1825 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2c92b53acf114b08bbe7781ebe52df736529ec3;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Remove DefHook (#1483) This commit removes DefHook and implements its functionalities directly in DefSlot. This change is a step to revise DefSlot similarly as Dep/Read/Update. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/DefHook.h b/contrib/coco/core/include/coco/IR/DefHook.h deleted file mode 100644 index c544771..0000000 --- a/contrib/coco/core/include/coco/IR/DefHook.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef __COCO_IR_DEF_HOOK_H__ -#define __COCO_IR_DEF_HOOK_H__ - -#include "coco/IR/Object.h" -#include "coco/IR/ObjectInfo.forward.h" - -#include "coco/ADT/PtrLink.h" - -namespace coco -{ - -class DefHook final -{ -public: - DefHook(const PtrLink *obj_link, Object::Producer *def) - : _obj_link{obj_link}, _def{def} - { - // DO NOTHING - } - -private: - ObjectInfo *info(Object *o) const; - -public: - void onTake(Object *o); - void onRelease(Object *o); - -private: - const PtrLink *const _obj_link; - // TODO Rename field - Object::Producer *const _def; -}; - -} // namespace coco - -#endif // __COCO_IR_DEF_HOOK_H__ diff --git a/contrib/coco/core/include/coco/IR/DefSlot.h b/contrib/coco/core/include/coco/IR/DefSlot.h index 7ed5bee..ec0b17b 100644 --- a/contrib/coco/core/include/coco/IR/DefSlot.h +++ b/contrib/coco/core/include/coco/IR/DefSlot.h @@ -1,7 +1,10 @@ #ifndef __COCO_IR_DEF_SLOT_H__ #define __COCO_IR_DEF_SLOT_H__ -#include "coco/IR/DefHook.h" +#include "coco/IR/Object.h" +#include "coco/IR/ObjectInfo.forward.h" + +#include "coco/ADT/PtrLink.h" namespace coco { @@ -9,9 +12,10 @@ namespace coco class DefSlot final { public: - DefSlot(const PtrLink *obj_link, Object::Producer *use) - : _hook{obj_link, use}, _value{nullptr} + DefSlot(const PtrLink *link, Object::Producer *producer) + : _link{link}, _producer{producer} { + // DO NOTHING } public: @@ -21,28 +25,14 @@ public: Object *value(void) const { return _value; } public: - void value(Object *value) - { - if (_value) - { - _hook.onRelease(_value); - _value = nullptr; - } - - assert(_value == nullptr); + void value(Object *value); - if (value) - { - _value = value; - _hook.onTake(_value); - } - - assert(_value == value); - } +private: + const PtrLink *_link = nullptr; private: - DefHook _hook; - Object *_value; + Object *_value = nullptr; + Object::Producer *_producer = nullptr; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/DefHook.cpp b/contrib/coco/core/src/IR/DefHook.cpp deleted file mode 100644 index b6affb9..0000000 --- a/contrib/coco/core/src/IR/DefHook.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "coco/IR/DefHook.h" -#include "coco/IR/ObjectInfo.h" - -#include - -namespace coco -{ - -ObjectInfo *DefHook::info(Object *o) const -{ - auto info = _obj_link->find(o); - assert(info != nullptr); - return info; -} - -void DefHook::onTake(Object *o) { info(o)->def(_def); } -void DefHook::onRelease(Object *o) { info(o)->def(nullptr); } - -} // namespace coco diff --git a/contrib/coco/core/src/IR/DefHook.test.cpp b/contrib/coco/core/src/IR/DefHook.test.cpp deleted file mode 100644 index d36837b..0000000 --- a/contrib/coco/core/src/IR/DefHook.test.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "coco/IR/DefHook.h" -#include "coco/IR/ObjectInfo.h" -#include "coco/IR/ObjectManager.h" - -#include "coco/IR/FeatureObject.h" - -#include "Def.mock.h" - -#include - -namespace -{ -class DefHookTest : public ::testing::Test -{ -protected: - coco::PtrLink bag_link; - coco::PtrLink obj_link; - - coco::ObjectManager obj_mgr{&obj_link, &bag_link}; -}; -} // namespace - -TEST_F(DefHookTest, TakeAndRelease) -{ - auto o = obj_mgr.create(nncc::core::ADT::feature::Shape{1, 1, 1}); - - ::mock::Def use; - - coco::DefHook hook{&obj_link, &use}; - - hook.onTake(o); - hook.onRelease(o); -} diff --git a/contrib/coco/core/src/IR/DefSlot.cpp b/contrib/coco/core/src/IR/DefSlot.cpp new file mode 100644 index 0000000..203d8f4 --- /dev/null +++ b/contrib/coco/core/src/IR/DefSlot.cpp @@ -0,0 +1,36 @@ +#include "coco/IR/DefSlot.h" +#include "coco/IR/ObjectInfo.h" + +#include + +namespace coco +{ + +void DefSlot::value(Object *value) +{ + assert(_link != nullptr); + + if (_value) + { + auto info = _link->find(_value); + assert(info != nullptr); + info->def(nullptr); + + _value = nullptr; + } + + assert(_value == nullptr); + + if (value) + { + _value = value; + + auto info = _link->find(_value); + assert(info != nullptr); + info->def(_producer); + } + + assert(_value == value); +} + +} // namespace coco