feat: introduced blocks and better project structure
This commit is contained in:
35
include/ir/block.hpp
Normal file
35
include/ir/block.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "ir/op.hpp"
|
||||
|
||||
namespace IR
|
||||
{
|
||||
|
||||
using OpView = View<Op*>;
|
||||
|
||||
using BlockID = unsigned int;
|
||||
|
||||
class Block
|
||||
{
|
||||
public:
|
||||
Block(BlockID id, OpView&& ops)
|
||||
: m_id(id), m_ops(ops) {}
|
||||
public:
|
||||
const OpView& ops() const { return m_ops; }
|
||||
public:
|
||||
StringView Format(int indent) const
|
||||
{
|
||||
StringBuilder sb;
|
||||
sb.AppendIndent(indent);
|
||||
sb.AppendFormat("b%d:\n", m_id);
|
||||
for (size_t i = 0; i < m_ops.size; ++i)
|
||||
{
|
||||
sb << m_ops.data[i]->Format(indent + 2) << '\n';
|
||||
}
|
||||
return sb.view();
|
||||
}
|
||||
private:
|
||||
BlockID m_id;
|
||||
OpView m_ops;
|
||||
};
|
||||
|
||||
} // namespace IR
|
||||
Reference in New Issue
Block a user