feat: introduced blocks and better project structure

This commit is contained in:
2025-12-24 20:13:13 +01:00
parent e8a496d070
commit 7f73b742c2
9 changed files with 525 additions and 453 deletions

35
include/ir/block.hpp Normal file
View 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