mips without optimize

This commit is contained in:
colden
2025-12-12 20:14:00 +08:00
parent 84827838e2
commit c94bebf37b
130 changed files with 5462 additions and 4182 deletions

103
midend/llvm/instr/IrInstr.java Normal file → Executable file
View File

@@ -1,28 +1,75 @@
package midend.llvm.instr;
import midend.llvm.use.IrUser;
import midend.llvm.value.IrBasicBlock;
import midend.llvm.type.IrType;
public class IrInstr extends IrUser {
private IrInstrType type;
private IrBasicBlock block;
public IrInstr(IrType type, String name, IrInstrType instrType) {
super(type, name);
this.type = instrType;
this.block = null;
}
public IrInstrType getInstrType() {
return type;
}
public IrBasicBlock getBBlock() {
return block;
}
public void setBBlock(IrBasicBlock block) {
this.block = block;
}
}
package midend.llvm.instr;
import midend.llvm.use.IrUser;
import midend.llvm.value.IrBasicBlock;
import midend.llvm.value.IrGlobalValue;
import midend.llvm.value.IrValue;
import midend.llvm.constant.IrConstantInt;
import backend.mips.MipsBuilder;
import backend.mips.Register;
import backend.mips.instr.MipsLs;
import backend.mips.instr.fake.MipsLa;
import backend.mips.instr.fake.MipsLi;
import backend.mips.instr.fake.MipsMove;
import backend.mips.instr.type.MipsLsType;
import midend.llvm.type.IrType;
public class IrInstr extends IrUser {
private IrInstrType type;
private IrBasicBlock block;
public IrInstr(IrType type, String name, IrInstrType instrType) {
super(type, name);
this.type = instrType;
this.block = null;
}
public IrInstrType getInstrType() {
return type;
}
public IrBasicBlock getBBlock() {
return block;
}
public void setBBlock(IrBasicBlock block) {
this.block = block;
}
public void saveResult(IrValue value, Register reg) {
Register valueReg = MipsBuilder.getRegister(value);
if (valueReg == null) {
Integer offset = MipsBuilder.getOffset(value);
if (offset == null) {
MipsBuilder.allocaOffset(value);
offset = MipsBuilder.getOffset(value);
}
new MipsLs(MipsLsType.SW, reg, Register.SP, offset);
} else {
new MipsMove(valueReg, reg);
}
}
public void loadValueToReg(IrValue value, Register reg) {
if (value instanceof IrGlobalValue) {
new MipsLa(reg, value.getMipsLabel());
return;
}
if (value instanceof IrConstantInt) {
new MipsLi(reg, ((IrConstantInt) value).getValue());
return;
}
Register valueReg = MipsBuilder.getRegister(value);
if (valueReg != null) {
new MipsMove(reg, valueReg);
return;
}
Integer offset = MipsBuilder.getOffset(value);
if (offset == null) {
MipsBuilder.allocaOffset(value);
offset = MipsBuilder.getOffset(value);
}
new MipsLs(MipsLsType.LW, reg, Register.SP, offset);
}
}