From ad17a59d65e1bf62b4654160d97828c3f2c6bd85 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 1 Jan 2026 16:09:33 +0100 Subject: [PATCH] feat: move allocator and slots into codegen folder --- include/{ir => codegen}/allocator.hpp | 17 +++++++++++------ include/{ir => codegen}/slot.hpp | 0 2 files changed, 11 insertions(+), 6 deletions(-) rename include/{ir => codegen}/allocator.hpp (80%) rename include/{ir => codegen}/slot.hpp (100%) diff --git a/include/ir/allocator.hpp b/include/codegen/allocator.hpp similarity index 80% rename from include/ir/allocator.hpp rename to include/codegen/allocator.hpp index c8ca198..82c9404 100644 --- a/include/ir/allocator.hpp +++ b/include/codegen/allocator.hpp @@ -1,18 +1,19 @@ #pragma once #include "prelude/string.hpp" -#include "ir/slot.hpp" +#include "codegen/slot.hpp" #define AVAILABLE_REGISTERS 4 #define AVAILABLE_STACK_SIZE 4096 -template +template class Allocator { public: virtual ~Allocator() {}; + public: - virtual const Slot& Allocate(SlotAddr addr) = 0; - virtual const Slot& Resolve(SlotAddr addr) = 0; + virtual const Slot &Allocate(SlotAddr addr) = 0; + virtual const Slot &Resolve(SlotAddr addr) = 0; }; class SlotAllocator : public Allocator @@ -20,8 +21,9 @@ class SlotAllocator : public Allocator public: SlotAllocator() = default; ~SlotAllocator() = default; + public: - const IR::IRSlot& Allocate(const StringView& addr) override + const IR::IRSlot &Allocate(const StringView &addr) override { if (m_regs < AVAILABLE_REGISTERS) { @@ -38,7 +40,7 @@ public: assert(0 && "failed to allocate local"); } - const IR::IRSlot& Resolve(const StringView& addr) override + const IR::IRSlot &Resolve(const StringView &addr) override { for (size_t i = 0; i < m_slots.size; ++i) { @@ -50,10 +52,13 @@ public: assert(0 && "could not resolve stack offset for specified address"); } + public: View slots() const { return m_slots.view(); } + public: unsigned int GetStackSize() const { return m_offset_counter; } + public: int m_regs = 0; unsigned int m_offset_counter = 0; diff --git a/include/ir/slot.hpp b/include/codegen/slot.hpp similarity index 100% rename from include/ir/slot.hpp rename to include/codegen/slot.hpp