回档之后的重写。部分问题修复。添加了什么我也忘了

This commit is contained in:
2026-02-01 15:52:28 +08:00
parent 61bffdc743
commit aea716ced2
50 changed files with 3676 additions and 2997 deletions

62
src/IR/IR.hpp Normal file
View File

@@ -0,0 +1,62 @@
#pragma once
#include <Core/fig_string.hpp>
#include <vector>
#include <cstdint>
namespace Fig::IR
{
using Reg = uint16_t;
using Label = uint32_t;
constexpr Reg INVALID_REG = 0xFFFF;
enum class Op : uint8_t
{
// ---- control ----
Nop,
Jmp,
Br, // conditional branch
Ret,
Call,
// ---- arithmetic ----
Add,
Sub,
Mul,
Div,
// ---- compare ----
Lt,
Le,
Gt,
Ge,
Eq,
// ---- data ----
LoadImm, // immediate -> reg
Mov,
};
struct Inst
{
Op op;
Reg dst; // 结果寄存器
Reg a; // operand a
Reg b; // operand b
int64_t imm; // immediate / jump offset
};
struct Function
{
FString name;
uint16_t paramCount;
uint16_t localCount; // 不含参数
uint16_t regCount; // param + locals + temps
std::vector<Inst> code;
};
};