[coco] Add 'Bag' class (#726)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 19 Jul 2018 10:12:03 +0000 (19:12 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 19 Jul 2018 10:12:03 +0000 (19:12 +0900)
This commit adds 'Bag' class which serves as memory allocation in
coco IR.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Bag.h [new file with mode: 0644]
contrib/coco/core/src/IR/Bag.test.cpp [new file with mode: 0644]

diff --git a/contrib/coco/core/include/coco/IR/Bag.h b/contrib/coco/core/include/coco/IR/Bag.h
new file mode 100644 (file)
index 0000000..9ca7d01
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef __COCO_IR_BAG_H__
+#define __COCO_IR_BAG_H__
+
+#include <cstdint>
+
+namespace coco
+{
+
+/***
+ * @brief A collection of (abstracted) elements of the same type
+ *
+ * When there are N elements in a bag, we refer to N as the size of this bag, and every
+ * element in a bag has a unique numeric ID whose range is [0, N).
+ *
+ * NOTE 'Bag' is not a container (such as std::vector). 'Bag' just assures that there are
+ *      N elements. It does not state about its value.
+ *
+ * NOTE coco IR treats Bag as virtual memory allocation
+ */
+class Bag
+{
+public:
+  Bag(uint32_t size) : _size{size}
+  {
+    // DO NOTHING
+  }
+
+public:
+  uint32_t size(void) const { return _size; }
+
+private:
+  uint32_t const _size;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_BAG_H__
diff --git a/contrib/coco/core/src/IR/Bag.test.cpp b/contrib/coco/core/src/IR/Bag.test.cpp
new file mode 100644 (file)
index 0000000..1a98d64
--- /dev/null
@@ -0,0 +1,10 @@
+#include "coco/IR/Bag.h"
+
+#include <gtest/gtest.h>
+
+TEST(IR_BAG, ctor_should_set_size)
+{
+  coco::Bag b{3};
+
+  ASSERT_EQ(b.size(), 3);
+}