feat: move allocator and slots into codegen folder
This commit is contained in:
48
include/codegen/slot.hpp
Normal file
48
include/codegen/slot.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include "prelude/string.hpp"
|
||||
|
||||
namespace IR
|
||||
{
|
||||
|
||||
struct IRSlot
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
STACK,
|
||||
REGISTRY,
|
||||
};
|
||||
public:
|
||||
IRSlot(StringView addr, unsigned int slot, Type slotType) : m_addr(addr), m_slot(slot), m_slotType(slotType) {}
|
||||
IRSlot() = default;
|
||||
public:
|
||||
Type GetType() const { return m_slotType; }
|
||||
const StringView& GetAddr() const { return m_addr; }
|
||||
unsigned int GetSlot() const { return m_slot; }
|
||||
public:
|
||||
StringView Format() const {
|
||||
StringBuilder sb;
|
||||
switch(GetType())
|
||||
{
|
||||
case Type::REGISTRY:
|
||||
sb << "r" << GetSlot();
|
||||
break;
|
||||
case Type::STACK:
|
||||
sb << "s[" << GetSlot() << "]";
|
||||
break;
|
||||
default:
|
||||
sb << "(UNKNOWN_SLOT_TYPE)";
|
||||
break;
|
||||
}
|
||||
return sb.view();
|
||||
}
|
||||
private:
|
||||
StringView m_addr;
|
||||
unsigned int m_slot;
|
||||
Type m_slotType;
|
||||
};
|
||||
|
||||
using IRSlotBuilder = Builder<IRSlot>;
|
||||
using IRSlotView = View<IRSlot>;
|
||||
|
||||
} // namespace IR
|
||||
Reference in New Issue
Block a user