[coco] Implement 'Instr::head' method (#876)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 2 Aug 2018 06:57:38 +0000 (15:57 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 2 Aug 2018 06:57:38 +0000 (15:57 +0900)
This commit implements NYI 'Instr::head' method, and adds related tests.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/src/IR/Instr.cpp
contrib/coco/core/src/IR/Module.test.cpp

index 5a36ffe..6e7ba79 100644 (file)
@@ -1,14 +1,12 @@
 #include "coco/IR/Instr.h"
-
-#include <stdexcept>
+#include "coco/IR/Block.h"
 
 namespace coco
 {
 
 InstrList *Instr::head(void) const
 {
-  // TODO Implement this when 'Block' becomes available
-  throw std::runtime_error{"Not implemented, yet"};
+  return parent()->instr();
 }
 
 } // namespace coco
index 63e926b..4ec3739 100644 (file)
@@ -64,3 +64,26 @@ TEST(IR_MODULE, append_two_blocks)
   ASSERT_EQ(blk_2->prev(), blk_1);
   ASSERT_EQ(blk_2->next(), nullptr);
 }
+
+TEST(IR_MODULE, append_two_instrs)
+{
+  auto m = coco::Module::create();
+
+  auto blk = m->entity()->block()->create();
+  auto ins_1 = m->entity()->instr()->create<coco::UnitF>();
+  auto ins_2 = m->entity()->instr()->create<coco::UnitF>();
+
+  blk->instr()->append(ins_1);
+  blk->instr()->append(ins_2);
+
+  ASSERT_EQ(blk->instr()->head(), ins_1);
+  ASSERT_EQ(blk->instr()->tail(), ins_2);
+
+  ASSERT_EQ(ins_1->parent(), blk);
+  ASSERT_EQ(ins_1->prev(), nullptr);
+  ASSERT_EQ(ins_1->next(), ins_2);
+
+  ASSERT_EQ(ins_2->parent(), blk);
+  ASSERT_EQ(ins_2->prev(), ins_1);
+  ASSERT_EQ(ins_2->next(), nullptr);
+}