56 lines
1006 B
C++
56 lines
1006 B
C++
#pragma once
|
|
#include "prelude/string.hpp"
|
|
#include "ir/value.hpp"
|
|
|
|
namespace IR
|
|
{
|
|
|
|
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() {}
|
|
|
|
virtual StringView Format(int indent) const = 0;
|
|
};
|
|
|
|
using OpView = View<Op *>;
|
|
using OpBuilder = Builder<Op *>;
|
|
|
|
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
|