From db228dcbb9e6fa6b9ff8261fde6ce06fb2b9e5d8 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: Thu, 19 Jul 2018 19:12:03 +0900 Subject: [PATCH] [coco] Add 'Bag' class (#726) This commit adds 'Bag' class which serves as memory allocation in coco IR. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Bag.h | 37 +++++++++++++++++++++++++++++++++ contrib/coco/core/src/IR/Bag.test.cpp | 10 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 contrib/coco/core/include/coco/IR/Bag.h create mode 100644 contrib/coco/core/src/IR/Bag.test.cpp diff --git a/contrib/coco/core/include/coco/IR/Bag.h b/contrib/coco/core/include/coco/IR/Bag.h new file mode 100644 index 0000000..9ca7d01 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/Bag.h @@ -0,0 +1,37 @@ +#ifndef __COCO_IR_BAG_H__ +#define __COCO_IR_BAG_H__ + +#include + +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 index 0000000..1a98d64 --- /dev/null +++ b/contrib/coco/core/src/IR/Bag.test.cpp @@ -0,0 +1,10 @@ +#include "coco/IR/Bag.h" + +#include + +TEST(IR_BAG, ctor_should_set_size) +{ + coco::Bag b{3}; + + ASSERT_EQ(b.size(), 3); +} -- 2.7.4