From 49155703677684551fb7d1466775adcac43a84c0 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, 23 Jul 2018 14:31:51 +0900 Subject: [PATCH] [coco] 'Block' as a child of 'Module' (#755) 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 --- contrib/coco/core/include/coco/IR/Block.h | 12 ++++++++++-- contrib/coco/core/include/coco/IR/Module.forward.h | 11 +++++++++++ contrib/coco/core/src/IR/Block.cpp | 14 ++++++++++++++ contrib/coco/core/src/IR/Block.test.cpp | 5 +++-- 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 contrib/coco/core/include/coco/IR/Module.forward.h create mode 100644 contrib/coco/core/src/IR/Block.cpp diff --git a/contrib/coco/core/include/coco/IR/Block.h b/contrib/coco/core/include/coco/IR/Block.h index 1692bd0..1f95aa3 100644 --- a/contrib/coco/core/include/coco/IR/Block.h +++ b/contrib/coco/core/include/coco/IR/Block.h @@ -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" @@ -8,16 +10,19 @@ namespace coco { +using BlockList = DLinkedList::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::Node { public: - Block(PtrLink *instr_link) : _instr{this, instr_link} + Block(const PtrLink *block_link, PtrLink *instr_link) + : DLinkedList::Node{block_link}, _instr{this, instr_link} { // DO NOTHING } @@ -31,6 +36,9 @@ public: private: DLinkedList::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 index 0000000..d043149 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/Module.forward.h @@ -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 index 0000000..283da58 --- /dev/null +++ b/contrib/coco/core/src/IR/Block.cpp @@ -0,0 +1,14 @@ +#include "coco/IR/Block.h" + +#include + +namespace coco +{ + +BlockList *Block::head(void) const +{ + // TODO Implement this after implemeing 'block()' method in 'Module' class + throw std::runtime_error{"NYI"}; +} + +} // namespace coco diff --git a/contrib/coco/core/src/IR/Block.test.cpp b/contrib/coco/core/src/IR/Block.test.cpp index e5b4ab6..3a4c689 100644 --- a/contrib/coco/core/src/IR/Block.test.cpp +++ b/contrib/coco/core/src/IR/Block.test.cpp @@ -4,8 +4,9 @@ TEST(IR_BLOCK, default_block_has_empty_instr_list) { - coco::PtrLink link; - coco::Block blk{&link}; + coco::PtrLink block_link; + coco::PtrLink instr_link; + coco::Block blk{&block_link, &instr_link}; ASSERT_TRUE(blk.instr()->empty()); ASSERT_EQ(blk.instr()->head(), nullptr); -- 2.7.4