#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
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);
+}