[backend] it works 1.0

This commit is contained in:
ladev789
2025-06-22 14:06:14 +08:00
parent 232ed6d023
commit 25a8c72a9b
3 changed files with 64 additions and 70 deletions

View File

@@ -8,10 +8,11 @@
#include <set>
namespace sysy {
class RISCv32CodeGen {
public:
explicit RISCv32CodeGen(Module* mod) : module(mod) {}
std::string code_gen(); // 生成整个模块的汇编代码
std::string code_gen(); // 生成模块的汇编代码
private:
Module* module;
@@ -27,11 +28,13 @@ private:
struct Operand {
enum class Kind { Reg, Imm, Label };
Kind kind;
std::string value; // 寄存器名、立即数或标签
Operand(Kind k, const std::string& v) : kind(k), value(v) {}
Value* value; // 用于寄存器
std::string label; // 用于标签或立即数
Operand(Kind k, Value* v) : kind(k), value(v), label("") {}
Operand(Kind k, const std::string& l) : kind(k), value(nullptr), label(l) {}
};
// RISC-V指令
// RISC-V 指令
struct RISCv32Inst {
std::string opcode;
std::vector<Operand> operands;
@@ -59,5 +62,6 @@ private:
std::string reg_to_string(PhysicalReg reg);
};
#endif // RISCV32_BACKEND_H
}
} // namespace sysy
#endif // RISCV32_BACKEND_H