CompilerSysY/include/mc_inst.h
2023-05-23 13:58:25 +08:00

69 lines
1.2 KiB
C++

#pragma once
#include "common.h"
namespace codegen{
// a?, t?, ra are caller-saved
// s? are callee-saved
// x0,gp,tp are preserved in user-space
enum class RV64Reg {
x0 = 0, // zero
x1, // ra, caller
x2, // sp, callee
x3, // gp
x4, // tp
x5, // t0, caller
x6,x7, // t1-2, caller
x8, // s0/fp, callee
x9, // s1, callee
x10,x11, // a0-1,caller
x12,x13,x14,x15,x16,x17, // a2-7,caller
x18,x19,x20,x21,x22,x23,x24,x25,x26,x27, // s2-11,callee
x28,x29,x30,x31, // t3-6,caller
};
inline std::string Reg2Name(RV64Reg reg) {
std::string regname = "x" + std::to_string((int)reg);
return regname;
}
class MOperand {
public:
enum class type {
Virt,
Imm,
Reg,
} op_type;
int value;
};
class MInst {
public:
enum class MInstTag {
Add, Sub, Rsb, Mul, Div, Mod, Lt, Le, Ge, Gt, Eq, Ne, And, Or,
LongMul, FMA, Mv, Branch, Jump, Return, Load, Store,Compare, Call, Global,
} tag;
MInst(MInstTag tag) : tag(tag) {}
};
class MBasicBlock {
};
class MFunction {
std::list<uptr(MBasicBlock)> bbs;
};
class MGlobalVar {
};
class MCModule {
std::list<uptr(MFunction)> functions;
std::list<uptr(MGlobalVar)> globals;
};
}