From eebd081efa6a76882433f4bad817e9cd7162cbb6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 1 Oct 2018 15:25:47 +0900 Subject: [PATCH] [coco] Introduce Object::Kind (#1690) This commit introduces Object::Kind enum class, which allows us to easily distinguish the kind of each object. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/FeatureObject.h | 3 +++ contrib/coco/core/include/coco/IR/KernelObject.h | 3 +++ contrib/coco/core/include/coco/IR/Object.h | 11 +++++++++++ contrib/coco/core/src/IR/FeatureObject.test.cpp | 1 + contrib/coco/core/src/IR/KernelObject.test.cpp | 2 ++ 5 files changed, 20 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/FeatureObject.h b/contrib/coco/core/include/coco/IR/FeatureObject.h index 23a7434..aa3d890 100644 --- a/contrib/coco/core/include/coco/IR/FeatureObject.h +++ b/contrib/coco/core/include/coco/IR/FeatureObject.h @@ -43,6 +43,9 @@ public: ~FeatureObject(); public: + Object::Kind kind(void) const override { return Object::Kind::Feature; } + +public: FeatureObject *asFeature(void) override { return this; } const FeatureObject *asFeature(void) const override { return this; } diff --git a/contrib/coco/core/include/coco/IR/KernelObject.h b/contrib/coco/core/include/coco/IR/KernelObject.h index 50f5821..2113bff 100644 --- a/contrib/coco/core/include/coco/IR/KernelObject.h +++ b/contrib/coco/core/include/coco/IR/KernelObject.h @@ -40,6 +40,9 @@ public: virtual ~KernelObject(); public: + Object::Kind kind(void) const override { return Object::Kind::Kernel; } + +public: KernelObject *asKernel(void) override { return this; } const KernelObject *asKernel(void) const override { return this; } diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index f000d96..dc47cf2 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -44,6 +44,14 @@ public: friend class Use; public: + enum class Kind + { + Unknown, + Feature, + Kernel, + }; + +public: struct Producer : public Bag::Updater { virtual ~Producer() = default; @@ -63,6 +71,9 @@ public: virtual ~Object() = default; public: + virtual Kind kind(void) const { return Kind::Unknown; } + +public: coco::Bag *bag(void) const { return _dep.bag(); } void bag(coco::Bag *bag) { _dep.bag(bag); } diff --git a/contrib/coco/core/src/IR/FeatureObject.test.cpp b/contrib/coco/core/src/IR/FeatureObject.test.cpp index f5ba997..f545164 100644 --- a/contrib/coco/core/src/IR/FeatureObject.test.cpp +++ b/contrib/coco/core/src/IR/FeatureObject.test.cpp @@ -50,6 +50,7 @@ TEST_F(FeatureObjectTest, ctor) auto o = allocate(shape); ASSERT_EQ(o->shape(), shape); + ASSERT_EQ(o->kind(), coco::Object::Kind::Feature); } // TODO Reimplement this test as a test for GenericFeatureLayout diff --git a/contrib/coco/core/src/IR/KernelObject.test.cpp b/contrib/coco/core/src/IR/KernelObject.test.cpp index e3a6bcc..e578f21 100644 --- a/contrib/coco/core/src/IR/KernelObject.test.cpp +++ b/contrib/coco/core/src/IR/KernelObject.test.cpp @@ -53,6 +53,8 @@ TEST_F(KernelObjectTest, constructor) ASSERT_EQ(o->shape().count(), shape.count()); ASSERT_EQ(o->shape().height(), shape.height()); ASSERT_EQ(o->shape().width(), shape.width()); + + ASSERT_EQ(o->kind(), coco::Object::Kind::Kernel); } TEST_F(KernelObjectTest, asKernel) -- 2.7.4