feat: move allocator and slots into codegen folder

This commit is contained in:
2026-01-01 16:09:33 +01:00
parent 7995dd2bdf
commit ad17a59d65
2 changed files with 11 additions and 6 deletions

View File

@@ -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<typename Slot, typename SlotAddr = const StringView&>
template <typename Slot, typename SlotAddr = const StringView &>
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<IR::IRSlot>
@@ -20,8 +21,9 @@ class SlotAllocator : public Allocator<IR::IRSlot>
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<IR::IRSlot> 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;