[backend]重构了后端

This commit is contained in:
Lixuanwang
2025-07-19 16:06:35 +08:00
parent 75e61bf274
commit d4a6996d74
10 changed files with 1336 additions and 1564 deletions

View File

@@ -163,8 +163,11 @@ public:
MachineInstr(RVOpcodes opcode) : opcode(opcode) {}
RVOpcodes getOpcode() const { return opcode; }
// 注意返回const引用因为通常不直接修改指令的操作数列表
const std::vector<std::unique_ptr<MachineOperand>>& getOperands() const { return operands; }
// 提供一个非const版本用于内部修改
std::vector<std::unique_ptr<MachineOperand>>& getOperands() { return operands; }
void addOperand(std::unique_ptr<MachineOperand> operand) {
operands.push_back(std::move(operand));
}
@@ -181,9 +184,12 @@ public:
: name(name), parent(parent) {}
const std::string& getName() const { return name; }
const std::vector<std::unique_ptr<MachineInstr>>& getInstructions() const { return instructions; }
MachineFunction* getParent() const { return parent; }
// 同时提供 const 和 non-const 版本
const std::vector<std::unique_ptr<MachineInstr>>& getInstructions() const { return instructions; }
std::vector<std::unique_ptr<MachineInstr>>& getInstructions() { return instructions; }
void addInstruction(std::unique_ptr<MachineInstr> instr) {
instructions.push_back(std::move(instr));
}
@@ -210,9 +216,12 @@ public:
MachineFunction(const std::string& name) : name(name) {}
const std::string& getName() const { return name; }
const std::vector<std::unique_ptr<MachineBasicBlock>>& getBlocks() const { return blocks; }
StackFrameInfo& getFrameInfo() { return frame_info; }
// 同时提供 const 和 non-const 版本
const std::vector<std::unique_ptr<MachineBasicBlock>>& getBlocks() const { return blocks; }
std::vector<std::unique_ptr<MachineBasicBlock>>& getBlocks() { return blocks; }
void addBlock(std::unique_ptr<MachineBasicBlock> block) {
blocks.push_back(std::move(block));
}