feat: error handling, better prelude, double linked lists usage etc

This commit is contained in:
2026-01-02 22:06:56 +01:00
parent a453603b9b
commit 6176d549c1
10 changed files with 148 additions and 65 deletions

View File

@@ -1,35 +1,34 @@
#pragma once
#include "ir/op.hpp"
#include "prelude/linkedlist.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) {}
Block(BlockID id, const OpView& ops)
: m_id(id), m_ops(DoubleLinkedList<Op*>::FromView(ops)) {}
public:
const OpView& ops() const { return m_ops; }
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 (size_t i = 0; i < m_ops.size; ++i)
for (ListNode<Op*>* cur = m_ops.Begin(); cur != nullptr; cur = cur->next)
{
sb << m_ops.data[i]->Format(indent + 2) << '\n';
sb << cur->value->Format(indent + 2) << '\n';
}
return sb.view();
}
private:
BlockID m_id;
OpView m_ops;
DoubleLinkedList<Op*> m_ops;
};
} // namespace IR