feat: introduced blocks and better project structure
This commit is contained in:
50
include/ir/op.hpp
Normal file
50
include/ir/op.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include "prelude/string.hpp"
|
||||
#include "ir/value.hpp"
|
||||
|
||||
namespace IR
|
||||
{
|
||||
|
||||
enum class OpType
|
||||
{
|
||||
EXTERN = 0,
|
||||
FN,
|
||||
LOAD_CONST,
|
||||
LOAD,
|
||||
STORE,
|
||||
ADD,
|
||||
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(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;
|
||||
};
|
||||
|
||||
} // namespace IR
|
||||
Reference in New Issue
Block a user