37 lines
1.1 KiB
Java
Executable File
37 lines
1.1 KiB
Java
Executable File
package midend.llvm.instr;
|
|
|
|
import midend.llvm.type.IrInterType;
|
|
import midend.llvm.type.IrPointerType;
|
|
import backend.mips.instr.fake.MipsLa;
|
|
import midend.llvm.constant.IrConstantStr;
|
|
import backend.mips.instr.fake.MipsLi;
|
|
import backend.mips.instr.MipsSyscall;
|
|
import backend.mips.Register;
|
|
|
|
public class PutStrInstr extends IrInstr {
|
|
private IrConstantStr strVal;
|
|
|
|
public PutStrInstr(String name, IrConstantStr putValue) {
|
|
super(IrInterType.VOID, name, IrInstrType.IO);
|
|
addUse(putValue);
|
|
strVal = putValue;
|
|
}
|
|
|
|
public static String putStrDecl() {
|
|
return "declare void @putstr(i8*)";
|
|
}
|
|
|
|
public String toString() {
|
|
IrPointerType ptrType = (IrPointerType) strVal.getType();
|
|
return "call void @putstr(i8* getelementptr inbounds ("
|
|
+ ptrType.getPointeeType() + ", " + ptrType +
|
|
" " + strVal.getName() + ", i32 0, i32 0))";
|
|
}
|
|
|
|
public void toMips() {
|
|
new MipsLa(Register.A0, strVal.getMipsLabel());
|
|
new MipsLi(Register.V0, 4);
|
|
new MipsSyscall();
|
|
}
|
|
}
|