feat: implement proper IR with value handles with dynamic and transferable types

This commit is contained in:
2026-01-01 15:50:26 +01:00
parent 3b8dfc4dae
commit 6f4ab269e2
8 changed files with 621 additions and 375 deletions

View File

@@ -5,46 +5,52 @@
namespace IR
{
enum class OpType
{
EXTERN = 0,
FN,
LOAD_CONST,
LOAD,
STORE,
ADD,
CALL,
COUNT_OPS,
};
enum class OpType
{
EXTERN = 0,
FN,
ALLOCATE,
LOAD,
STORE,
ADD,
SUB,
MUL,
DIV,
CALL,
COUNT_OPS,
};
#define OP_TYPE(x) \
OpType GetType() const override { return OpType::x; }
class Op
{
public:
virtual OpType GetType() const = 0;
virtual bool Valued() const { return false; };
virtual ~Op() {}
class Op
{
public:
virtual OpType GetType() const = 0;
virtual bool Valued() const { return false; };
virtual ~Op() {}
virtual StringView Format(int indent) const = 0;
};
virtual StringView Format(int indent) const = 0;
};
using OpView = View<Op*>;
using OpBuilder = Builder<Op*>;
using OpView = View<Op *>;
using OpBuilder = Builder<Op *>;
class OpValued : public Op
{
public:
OpValued(Value dest)
: m_dest(dest) {}
~OpValued() = default;
public:
Value result() const { return m_dest; }
protected:
bool Valued() const override { return true; }
private:
Value m_dest;
};
class OpValued : public Op
{
public:
OpValued(ValueHandle *dest)
: m_dest(dest) {}
~OpValued() = default;
public:
ValueHandle *result() const { return m_dest; }
protected:
bool Valued() const override { return true; }
private:
ValueHandle *m_dest;
};
} // namespace IR