mips without optimize
This commit is contained in:
39
backend/mips/instr/MipsAlu.java
Executable file
39
backend/mips/instr/MipsAlu.java
Executable file
@@ -0,0 +1,39 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.Register;
|
||||
import backend.mips.instr.type.MipsAluType;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsAlu extends MipsInstr {
|
||||
private MipsAluType aluType;
|
||||
private Register rd;
|
||||
private Register rs;
|
||||
private Register rt;
|
||||
private int immediate;
|
||||
private boolean isImInstr;
|
||||
|
||||
public MipsAlu(MipsAluType aluType, Register rd, Register rs, Register rt) {
|
||||
super(MipsType.ALU);
|
||||
this.aluType = aluType;
|
||||
this.rd = rd;
|
||||
this.rs = rs;
|
||||
this.rt = rt;
|
||||
this.immediate = 0;
|
||||
this.isImInstr = false;
|
||||
}
|
||||
|
||||
public MipsAlu(MipsAluType aluType, Register rd, Register rs, int immediate) {
|
||||
super(MipsType.ALU);
|
||||
this.aluType = aluType;
|
||||
this.rd = rd;
|
||||
this.rs = rs;
|
||||
this.rt = null;
|
||||
this.immediate = immediate;
|
||||
this.isImInstr = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return isImInstr ? aluType.toString() + " " + rd + ", " + rs + ", " + immediate + "\n"
|
||||
: aluType.toString() + " " + rd + ", " + rs + ", " + rt + "\n";
|
||||
}
|
||||
}
|
||||
16
backend/mips/instr/MipsAnnotation.java
Executable file
16
backend/mips/instr/MipsAnnotation.java
Executable file
@@ -0,0 +1,16 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsAnnotation extends MipsInstr {
|
||||
private String annotation;
|
||||
|
||||
public MipsAnnotation(String anno) {
|
||||
super(MipsType.ANNOTATION);
|
||||
this.annotation = anno;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "# " + this.annotation + "\n";
|
||||
}
|
||||
}
|
||||
36
backend/mips/instr/MipsBranch.java
Normal file
36
backend/mips/instr/MipsBranch.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsBranchType;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
public class MipsBranch extends MipsInstr{
|
||||
private MipsBranchType branchType;
|
||||
private Register rs;
|
||||
private Register rt;
|
||||
private String label;
|
||||
|
||||
public MipsBranch(MipsBranchType branchType, Register rs, Register rt, String label) {
|
||||
super(MipsType.BRANCH);
|
||||
this.branchType = branchType;
|
||||
this.rs = rs;
|
||||
this.rt = rt;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public MipsBranch(MipsBranchType branchType, Register rs, String label) {
|
||||
super(MipsType.BRANCH);
|
||||
this.branchType = branchType;
|
||||
this.rs = rs;
|
||||
this.rt = null;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.rt == null) {
|
||||
return this.branchType.toString() + " " + this.rs + ", " + this.label + "\n";
|
||||
} else {
|
||||
return this.branchType.toString() + " " + this.rs + ", " + this.rt + ", " + this.label + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
42
backend/mips/instr/MipsComp.java
Normal file
42
backend/mips/instr/MipsComp.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsCompareType;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
public class MipsComp extends MipsInstr {
|
||||
private MipsCompareType compareType;
|
||||
private Register rd;
|
||||
private Register rs;
|
||||
private Register rt;
|
||||
private int immediate;
|
||||
private boolean isImmediate;
|
||||
|
||||
public MipsComp(MipsCompareType compareType, Register rd, Register rs, Register rt) {
|
||||
super(MipsType.COMPARE);
|
||||
this.compareType = compareType;
|
||||
this.rd = rd;
|
||||
this.rs = rs;
|
||||
this.rt = rt;
|
||||
this.immediate = 0;
|
||||
this.isImmediate = false;
|
||||
}
|
||||
|
||||
public MipsComp(MipsCompareType compareType, Register rd, Register rs, int immediate) {
|
||||
super(MipsType.COMPARE);
|
||||
this.compareType = compareType;
|
||||
this.rd = rd;
|
||||
this.rs = rs;
|
||||
this.rt = null;
|
||||
this.immediate = immediate;
|
||||
this.isImmediate = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.isImmediate) {
|
||||
return this.compareType.toString() + " " + this.rd + ", " + this.rs + ", " + this.immediate + "\n";
|
||||
} else {
|
||||
return this.compareType.toString() + " " + this.rd + ", " + this.rs + ", " + this.rt + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
21
backend/mips/instr/MipsInstr.java
Executable file
21
backend/mips/instr/MipsInstr.java
Executable file
@@ -0,0 +1,21 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.MipsBuilder;
|
||||
|
||||
public class MipsInstr {
|
||||
private MipsType mt;
|
||||
|
||||
public MipsInstr(MipsType mt) {
|
||||
this.mt = mt;
|
||||
MipsBuilder.addMipsInstr(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public MipsType getType() {
|
||||
return mt;
|
||||
}
|
||||
}
|
||||
33
backend/mips/instr/MipsJump.java
Normal file
33
backend/mips/instr/MipsJump.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.Register;
|
||||
import backend.mips.instr.type.MipsJumpType;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsJump extends MipsInstr {
|
||||
private MipsJumpType jumpType;
|
||||
private String label;
|
||||
private Register rd;
|
||||
|
||||
public MipsJump(MipsJumpType jumpType, String label) {
|
||||
super(MipsType.JUMP);
|
||||
this.jumpType = jumpType;
|
||||
this.label = label;
|
||||
this.rd = null;
|
||||
}
|
||||
|
||||
public MipsJump(MipsJumpType jumpType, Register rd) {
|
||||
super(MipsType.JUMP);
|
||||
this.jumpType = jumpType;
|
||||
this.label = null;
|
||||
this.rd = rd;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.rd == null) {
|
||||
return this.jumpType.toString() + " " + this.label + "\n";
|
||||
} else {
|
||||
return this.jumpType.toString() + " " + this.rd + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
16
backend/mips/instr/MipsLabel.java
Normal file
16
backend/mips/instr/MipsLabel.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsLabel extends MipsInstr {
|
||||
private String label;
|
||||
|
||||
public MipsLabel(String label) {
|
||||
super(MipsType.LABEL);
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.label + ":\n";
|
||||
}
|
||||
}
|
||||
39
backend/mips/instr/MipsLs.java
Normal file
39
backend/mips/instr/MipsLs.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsLsType;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
public class MipsLs extends MipsInstr {
|
||||
private MipsLsType lsType;
|
||||
private Register rd;
|
||||
private Register rt;
|
||||
private int offset;
|
||||
private String label;
|
||||
|
||||
public MipsLs(MipsLsType lsType, Register rd, Register rt, int offset) {
|
||||
super(MipsType.LS);
|
||||
this.lsType = lsType;
|
||||
this.rd = rd;
|
||||
this.rt = rt;
|
||||
this.offset = offset;
|
||||
this.label = null;
|
||||
}
|
||||
|
||||
public MipsLs(MipsLsType lsType, Register rd, int offset, String label) {
|
||||
super(MipsType.LS);
|
||||
this.lsType = lsType;
|
||||
this.rd = rd;
|
||||
this.rt = null;
|
||||
this.offset = offset;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.label == null) {
|
||||
return this.lsType.toString() + " " + this.rd + ", " + this.offset + "(" + this.rt + ")\n";
|
||||
} else {
|
||||
return this.lsType.toString() + " " + this.rd + ", " + this.label + " + " + this.offset + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
33
backend/mips/instr/MipsMd.java
Normal file
33
backend/mips/instr/MipsMd.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsMdType;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
public class MipsMd extends MipsInstr {
|
||||
private MipsMdType mdType;
|
||||
private Register rd;
|
||||
private Register rt;
|
||||
|
||||
public MipsMd(MipsMdType mdType, Register rd, Register rt) {
|
||||
super(MipsType.MD);
|
||||
this.mdType = mdType;
|
||||
this.rd = rd;
|
||||
this.rt = rt;
|
||||
}
|
||||
|
||||
public MipsMd(MipsMdType mdType, Register rd) {
|
||||
super(MipsType.MD);
|
||||
this.mdType = mdType;
|
||||
this.rd = rd;
|
||||
this.rt = null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (this.rt == null) {
|
||||
return this.mdType.toString() + " " + this.rd + "\n";
|
||||
} else {
|
||||
return this.mdType.toString() + " " + this.rd + ", " + this.rt + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
13
backend/mips/instr/MipsSyscall.java
Normal file
13
backend/mips/instr/MipsSyscall.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package backend.mips.instr;
|
||||
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsSyscall extends MipsInstr {
|
||||
public MipsSyscall() {
|
||||
super(MipsType.SYSCALL);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "syscall\n";
|
||||
}
|
||||
}
|
||||
19
backend/mips/instr/data/MipsAsciiz.java
Normal file
19
backend/mips/instr/data/MipsAsciiz.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package backend.mips.instr.data;
|
||||
|
||||
import backend.mips.instr.MipsInstr;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsAsciiz extends MipsInstr {
|
||||
private String name;
|
||||
private String str;
|
||||
|
||||
public MipsAsciiz(String name, String str) {
|
||||
super(MipsType.DATA);
|
||||
this.name = name;
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name + ": .asciiz \"" + str.replaceAll("\n", "\\n") + "\"\n";
|
||||
}
|
||||
}
|
||||
19
backend/mips/instr/data/MipsSpace.java
Normal file
19
backend/mips/instr/data/MipsSpace.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package backend.mips.instr.data;
|
||||
|
||||
import backend.mips.instr.MipsInstr;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsSpace extends MipsInstr {
|
||||
private int size;
|
||||
private String name;
|
||||
|
||||
public MipsSpace(int size, String name) {
|
||||
super(MipsType.DATA);
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name + ": .space " + size + "\n";
|
||||
}
|
||||
}
|
||||
39
backend/mips/instr/data/MipsWord.java
Normal file
39
backend/mips/instr/data/MipsWord.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package backend.mips.instr.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import backend.mips.instr.MipsInstr;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
|
||||
public class MipsWord extends MipsInstr {
|
||||
private String name;
|
||||
private ArrayList<Integer> valueList;
|
||||
|
||||
public MipsWord(String name, ArrayList<Integer> valueList) {
|
||||
super(MipsType.DATA);
|
||||
this.name = name;
|
||||
this.valueList = valueList;
|
||||
}
|
||||
|
||||
public MipsWord(String name, int value) {
|
||||
super(MipsType.DATA);
|
||||
this.name = name;
|
||||
this.valueList = new ArrayList<Integer>();
|
||||
this.valueList.add(value);
|
||||
}
|
||||
|
||||
public int getValueNum() {
|
||||
return valueList.size();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name).append(": .word ");
|
||||
for (int value : valueList) {
|
||||
sb.append(value).append(", ");
|
||||
}
|
||||
sb.delete(sb.length() - 2, sb.length());
|
||||
sb.append("\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
28
backend/mips/instr/fake/MipsLa.java
Normal file
28
backend/mips/instr/fake/MipsLa.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package backend.mips.instr.fake;
|
||||
|
||||
import backend.mips.instr.MipsInstr;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
public class MipsLa extends MipsInstr {
|
||||
private Register rd;
|
||||
private String label;
|
||||
|
||||
public MipsLa(Register rd, String label) {
|
||||
super(MipsType.FAKE);
|
||||
this.rd = rd;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Register getRd() {
|
||||
return rd;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "la " + rd + ", " + label + "\n";
|
||||
}
|
||||
}
|
||||
29
backend/mips/instr/fake/MipsLi.java
Normal file
29
backend/mips/instr/fake/MipsLi.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package backend.mips.instr.fake;
|
||||
|
||||
import backend.mips.instr.MipsInstr;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
|
||||
public class MipsLi extends MipsInstr {
|
||||
private Register rd;
|
||||
private int value;
|
||||
|
||||
public MipsLi(Register rd, int value) {
|
||||
super(MipsType.FAKE);
|
||||
this.rd = rd;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Register getRd() {
|
||||
return rd;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "li " + rd + ", " + value + "\n";
|
||||
}
|
||||
}
|
||||
28
backend/mips/instr/fake/MipsMove.java
Normal file
28
backend/mips/instr/fake/MipsMove.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package backend.mips.instr.fake;
|
||||
|
||||
import backend.mips.instr.MipsInstr;
|
||||
import backend.mips.instr.type.MipsType;
|
||||
import backend.mips.Register;
|
||||
|
||||
public class MipsMove extends MipsInstr {
|
||||
private Register rd;
|
||||
private Register rt;
|
||||
|
||||
public MipsMove(Register rd, Register rt) {
|
||||
super(MipsType.FAKE);
|
||||
this.rd = rd;
|
||||
this.rt = rt;
|
||||
}
|
||||
|
||||
public Register getDest() {
|
||||
return rd;
|
||||
}
|
||||
|
||||
public Register getSrc() {
|
||||
return rt;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "move " + rd + ", " + rt + "\n";
|
||||
}
|
||||
}
|
||||
16
backend/mips/instr/type/MipsAluType.java
Executable file
16
backend/mips/instr/type/MipsAluType.java
Executable file
@@ -0,0 +1,16 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsAluType {
|
||||
// calc_R
|
||||
ADD, SUB, ADDU, SUBU, AND, OR, NOR, XOR, SLT, SLTU,
|
||||
// shiftv
|
||||
SLLV, SRAV, SRLV,
|
||||
// calc_I
|
||||
ADDI, ADDIU, ANDI, ORI, XORI, SLTI, SLTIU,
|
||||
// shift
|
||||
SLL, SRA, SRL;
|
||||
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
9
backend/mips/instr/type/MipsBranchType.java
Normal file
9
backend/mips/instr/type/MipsBranchType.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsBranchType {
|
||||
BEQ, BNE, BLEZ, BGTZ, BLTZ, BGEZ;
|
||||
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
9
backend/mips/instr/type/MipsCompareType.java
Normal file
9
backend/mips/instr/type/MipsCompareType.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsCompareType {
|
||||
SLT, SLE, SGT, SGE, SEQ, SNE, SLTI;
|
||||
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
9
backend/mips/instr/type/MipsJumpType.java
Normal file
9
backend/mips/instr/type/MipsJumpType.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsJumpType {
|
||||
J, JAL, JR;
|
||||
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
9
backend/mips/instr/type/MipsLsType.java
Normal file
9
backend/mips/instr/type/MipsLsType.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsLsType {
|
||||
LW, SW, LH, SH, LHU, LB, SB, LBU;
|
||||
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
9
backend/mips/instr/type/MipsMdType.java
Normal file
9
backend/mips/instr/type/MipsMdType.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsMdType {
|
||||
MFHI, MFLO, MULT, DIV, MTHI, MTLO;
|
||||
|
||||
public String toString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
15
backend/mips/instr/type/MipsType.java
Executable file
15
backend/mips/instr/type/MipsType.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package backend.mips.instr.type;
|
||||
|
||||
public enum MipsType {
|
||||
ALU,
|
||||
COMPARE,
|
||||
BRANCH,
|
||||
JUMP,
|
||||
SYSCALL,
|
||||
DATA,
|
||||
LABEL,
|
||||
ANNOTATION,
|
||||
LS,
|
||||
MD,
|
||||
FAKE
|
||||
}
|
||||
Reference in New Issue
Block a user