#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
}
private:
DLinkedList<Instr, Block>::Head _instr;
+
+public:
+ BlockList *head(void) const override;
};
} // namespace coco
--- /dev/null
+#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
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);