35 lines
733 B
C++
35 lines
733 B
C++
#pragma once
|
|
#include "ir/op.hpp"
|
|
#include "prelude/linkedlist.hpp"
|
|
|
|
namespace IR
|
|
{
|
|
|
|
using BlockID = unsigned int;
|
|
|
|
class Block
|
|
{
|
|
public:
|
|
Block(BlockID id, const OpView& ops)
|
|
: m_id(id), m_ops(DoubleLinkedList<Op*>::FromView(ops)) {}
|
|
public:
|
|
DoubleLinkedList<Op*>& ops() { return m_ops; }
|
|
public:
|
|
StringView Format(int indent) const
|
|
{
|
|
StringBuilder sb;
|
|
sb.AppendIndent(indent);
|
|
sb.AppendFormat("b%d:\n", m_id);
|
|
for (ListNode<Op*>* cur = m_ops.Begin(); cur != nullptr; cur = cur->next)
|
|
{
|
|
sb << cur->value->Format(indent + 2) << '\n';
|
|
}
|
|
return sb.view();
|
|
}
|
|
private:
|
|
BlockID m_id;
|
|
DoubleLinkedList<Op*> m_ops;
|
|
};
|
|
|
|
} // namespace IR
|