[coco] 'Block' as a child of 'Module' (#755)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 23 Jul 2018 05:31:51 +0000 (14:31 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 23 Jul 2018 05:31:51 +0000 (14:31 +0900)
This commit introduces 'BlockList' alias, and introduces dummy 'head'
implementation required by 'DLinkedList' trait.

This dummy 'head' implementation will be replaced with the concreate one
later.

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

index 1692bd0..1f95aa3 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __COCO_IR_BLOCK_H__
 #define __COCO_IR_BLOCK_H__
 
+#include "coco/IR/Module.forward.h"
+#include "coco/IR/Block.forward.h"
 #include "coco/IR/Instr.h"
 
 #include "coco/ADT/DLinkedList.h"
 namespace coco
 {
 
+using BlockList = DLinkedList<Block, Module>::Head;
+
 /***
  * @brief A unit of (grouped) instructions
  *
  * Block allows backend to manage a set of instructions as one unit, which is useful for H/W that
  * has a restriction on code size
  */
-class Block final
+class Block final : public DLinkedList<Block, Module>::Node
 {
 public:
-  Block(PtrLink<Instr, Block> *instr_link) : _instr{this, instr_link}
+  Block(const PtrLink<Block, Module> *block_link, PtrLink<Instr, Block> *instr_link)
+    : DLinkedList<Block, Module>::Node{block_link}, _instr{this, instr_link}
   {
     // DO NOTHING
   }
@@ -31,6 +36,9 @@ public:
 
 private:
   DLinkedList<Instr, Block>::Head _instr;
+
+public:
+  BlockList *head(void) const override;
 };
 
 } // namespace coco
diff --git a/contrib/coco/core/include/coco/IR/Module.forward.h b/contrib/coco/core/include/coco/IR/Module.forward.h
new file mode 100644 (file)
index 0000000..d043149
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __COCO_IR_MODULE_FORWARD_H__
+#define __COCO_IR_MODULE_FORWARD_H__
+
+namespace coco
+{
+
+class Module;
+
+} // namespace coco
+
+#endif // __COCO_IR_MODULE_FORWARD_H__
diff --git a/contrib/coco/core/src/IR/Block.cpp b/contrib/coco/core/src/IR/Block.cpp
new file mode 100644 (file)
index 0000000..283da58
--- /dev/null
@@ -0,0 +1,14 @@
+#include "coco/IR/Block.h"
+
+#include <stdexcept>
+
+namespace coco
+{
+
+BlockList *Block::head(void) const
+{
+  // TODO Implement this after implemeing 'block()' method in 'Module' class
+  throw std::runtime_error{"NYI"};
+}
+
+} // namespace coco
index e5b4ab6..3a4c689 100644 (file)
@@ -4,8 +4,9 @@
 
 TEST(IR_BLOCK, default_block_has_empty_instr_list)
 {
-  coco::PtrLink<coco::Instr, coco::Block> link;
-  coco::Block blk{&link};
+  coco::PtrLink<coco::Block, coco::Module> block_link;
+  coco::PtrLink<coco::Instr, coco::Block> instr_link;
+  coco::Block blk{&block_link, &instr_link};
 
   ASSERT_TRUE(blk.instr()->empty());
   ASSERT_EQ(blk.instr()->head(), nullptr);