mips without optimize
This commit is contained in:
81
midend/llvm/instr/TruncInstr.java
Normal file → Executable file
81
midend/llvm/instr/TruncInstr.java
Normal file → Executable file
@@ -1,31 +1,50 @@
|
||||
package midend.llvm.instr;
|
||||
|
||||
import midend.llvm.type.IrType;
|
||||
import midend.llvm.value.IrValue;
|
||||
|
||||
public class TruncInstr extends IrInstr {
|
||||
private IrType targetType;
|
||||
|
||||
public TruncInstr(IrType targetType, IrValue value, String name) {
|
||||
super(targetType, name, IrInstrType.TRUNC);
|
||||
addUse(value);
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
public IrValue getSrc() {
|
||||
return getUse(0);
|
||||
}
|
||||
|
||||
public IrType getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public IrType getSrcType() {
|
||||
return getSrc().getType();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName() + " = trunc " + getSrcType()
|
||||
+ " " + getSrc().getName() + " to " + getTargetType();
|
||||
}
|
||||
}
|
||||
package midend.llvm.instr;
|
||||
|
||||
import backend.mips.MipsBuilder;
|
||||
import backend.mips.Register;
|
||||
import backend.mips.instr.MipsAlu;
|
||||
import backend.mips.instr.type.MipsAluType;
|
||||
|
||||
import midend.llvm.type.IrType;
|
||||
import midend.llvm.value.IrValue;
|
||||
|
||||
public class TruncInstr extends IrInstr {
|
||||
private IrType targetType;
|
||||
|
||||
public TruncInstr(IrType targetType, IrValue value, String name) {
|
||||
super(targetType, name, IrInstrType.TRUNC);
|
||||
addUse(value);
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
public IrValue getSrc() {
|
||||
return getUse(0);
|
||||
}
|
||||
|
||||
public IrType getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public IrType getSrcType() {
|
||||
return getSrc().getType();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName() + " = trunc " + getSrcType()
|
||||
+ " " + getSrc().getName() + " to " + getTargetType();
|
||||
}
|
||||
|
||||
public void toMips() {
|
||||
Register reg = MipsBuilder.getRegister(getSrc());
|
||||
if (reg == null) {
|
||||
reg = Register.K0;
|
||||
}
|
||||
loadValueToReg(getSrc(), reg);
|
||||
if (this.targetType.isInt8()) {
|
||||
new MipsAlu(MipsAluType.ANDI, reg, reg, 0xFF);
|
||||
} else if (this.targetType.isBool()) {
|
||||
new MipsAlu(MipsAluType.ANDI, reg, reg, 0x1);
|
||||
}
|
||||
saveResult(this, reg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user