[coco] Add 'BlockManager' class (#764)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 23 Jul 2018 07:56:44 +0000 (16:56 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 23 Jul 2018 07:56:44 +0000 (16:56 +0900)
This commit adds 'BlockManager' class which allocates and tracks all the
instrances of 'Block' in coco IR.

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

diff --git a/contrib/coco/core/include/coco/IR/BlockManager.h b/contrib/coco/core/include/coco/IR/BlockManager.h
new file mode 100644 (file)
index 0000000..d52c9c5
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __COCO_IR_BLOCK_MANAGER_H__
+#define __COCO_IR_BLOCK_MANAGER_H__
+
+#include "coco/IR/Block.h"
+
+#include "coco/ADT/PtrManager.h"
+
+namespace coco
+{
+
+class BlockManager final : public PtrManager<Block>
+{
+public:
+  BlockManager(const PtrLink<Block, Module> *block_link, PtrLink<Instr, Block> *instr_link)
+    : _block_link{block_link}, _instr_link{instr_link}
+  {
+    // DO NOTHING
+  }
+
+private:
+  const PtrLink<Block, Module> * const _block_link;
+  PtrLink<Instr, Block> * const _instr_link;
+
+public:
+  Block *create(void);
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_BLOCK_MANAGER_H__
diff --git a/contrib/coco/core/src/IR/BlockManager.cpp b/contrib/coco/core/src/IR/BlockManager.cpp
new file mode 100644 (file)
index 0000000..037bd21
--- /dev/null
@@ -0,0 +1,13 @@
+#include "coco/IR/BlockManager.h"
+
+#include <nncc/foundation/Memory.h>
+
+namespace coco
+{
+
+Block *BlockManager::create(void)
+{
+  return take(nncc::foundation::make_unique<Block>(_block_link, _instr_link));
+}
+
+} // namespace coco
diff --git a/contrib/coco/core/src/IR/BlockManager.test.cpp b/contrib/coco/core/src/IR/BlockManager.test.cpp
new file mode 100644 (file)
index 0000000..4de3d81
--- /dev/null
@@ -0,0 +1,15 @@
+#include "coco/IR/BlockManager.h"
+
+#include <gtest/gtest.h>
+
+TEST(IR_BLOCK_MANAGER, create)
+{
+  coco::PtrLink<coco::Block, coco::Module> block_link;
+  coco::PtrLink<coco::Instr, coco::Block> instr_link;
+
+  coco::BlockManager mgr{&block_link, &instr_link};
+
+  auto blk = mgr.create();
+
+  ASSERT_NE(blk, nullptr);
+}