49 lines
1.5 KiB
Java
Executable File
49 lines
1.5 KiB
Java
Executable File
package midend.llvm.instr;
|
|
|
|
import midend.llvm.value.IrBasicBlock;
|
|
import midend.llvm.value.IrValue;
|
|
import backend.mips.MipsBuilder;
|
|
import backend.mips.Register;
|
|
import backend.mips.instr.MipsBranch;
|
|
import backend.mips.instr.type.MipsBranchType;
|
|
import backend.mips.instr.type.MipsJumpType;
|
|
import backend.mips.instr.MipsJump;
|
|
import midend.llvm.type.IrInterType;
|
|
|
|
public class BranchInstr extends IrInstr {
|
|
public BranchInstr(String name, IrValue cond, IrBasicBlock trueBB, IrBasicBlock falseBB) {
|
|
super(IrInterType.VOID, name, IrInstrType.BR);
|
|
addUse(cond);
|
|
addUse(trueBB);
|
|
addUse(falseBB);
|
|
}
|
|
|
|
public IrValue getCond() {
|
|
return getUse(0);
|
|
}
|
|
|
|
public IrBasicBlock getTrueBB() {
|
|
return (IrBasicBlock) getUse(1);
|
|
}
|
|
|
|
public IrBasicBlock getFalseBB() {
|
|
return (IrBasicBlock) getUse(2);
|
|
}
|
|
|
|
public String toString() {
|
|
return "br i1 " + getCond().getName() +
|
|
", label %" + getTrueBB().getName() +
|
|
", label %" + getFalseBB().getName();
|
|
}
|
|
|
|
public void toMips() {
|
|
Register condReg = MipsBuilder.getRegister(getCond());
|
|
if (condReg == null) {
|
|
condReg = Register.K0;
|
|
}
|
|
loadValueToReg(getCond(), condReg);
|
|
new MipsBranch(MipsBranchType.BNE, condReg, Register.ZERO, getTrueBB().getMipsLabel());
|
|
new MipsJump(MipsJumpType.J, getFalseBB().getMipsLabel());
|
|
}
|
|
}
|