|
@@ -38,6 +38,8 @@ public class Gen extends API.Gen {
|
|
|
}
|
|
|
};
|
|
|
private ArrayList<String> returnRegisters;
|
|
|
+ private HashMap<String, Boolean> ctrlDataUpdate = new HashMap<>();
|
|
|
+ private int WORD_INC = 4;
|
|
|
|
|
|
public Gen() {
|
|
|
super("MIPS");
|
|
@@ -45,9 +47,12 @@ public class Gen extends API.Gen {
|
|
|
}
|
|
|
|
|
|
public void Init() {
|
|
|
- BeforeTranslate("live.var", new OcorrenceFinderProcessor());
|
|
|
- BeforeTranslate("register.alloc", allocation);
|
|
|
- AfterTranslate("otimization.1", new OtimizationMips());
|
|
|
+ BeforeTranslateBlock("live.var", new OcorrenceFinderProcessor());
|
|
|
+ BeforeTranslateBlock("register.alloc", allocation);
|
|
|
+
|
|
|
+ AfterTranslateBlock("otimization.1", new OtimizationMips());
|
|
|
+
|
|
|
+ AfterTranslate("update.address", new UpdateAddressProcessor());
|
|
|
getTarget()
|
|
|
.Template(new TemplateMips())
|
|
|
.Formats(new HashMap<String, String>() {
|
|
@@ -339,12 +344,24 @@ public class Gen extends API.Gen {
|
|
|
public void Prolog(String id) throws Exception {
|
|
|
// Copia os dados para block target
|
|
|
DataFrame data = getTarget().Block().Data(getTac().Block().Data());
|
|
|
-
|
|
|
+ //Updata size in 4 bytes
|
|
|
+ Node v;
|
|
|
+ for (Map.Entry<String, Node> x : data.values().entrySet()) {
|
|
|
+ v = x.getValue();
|
|
|
+ if (!ctrlDataUpdate.containsKey(v.G("id"))) {
|
|
|
+ ctrlDataUpdate.put(v.G("id"), Boolean.TRUE);
|
|
|
+ v.S("size", v.getInt("size") * WORD_INC);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// for (Map.Entry<String, Node> x : data.values().entrySet()) {
|
|
|
+// System.out.println("Copy:" + x.getKey() + x.getValue());
|
|
|
+// }
|
|
|
// Adiciona o label
|
|
|
Add(new Instruction()
|
|
|
.S("type", "label")
|
|
|
.S("format", "label")
|
|
|
- .S("label", id));
|
|
|
+ .S("label", id)
|
|
|
+ );
|
|
|
|
|
|
// Aloca o espaco da pilha
|
|
|
Instruction alloc = Copy(Registers.R_SP, Registers.R_SP, "-" + data.Size())
|
|
@@ -357,7 +374,7 @@ public class Gen extends API.Gen {
|
|
|
int newvars = 0;
|
|
|
for (String reg : new String[]{Registers.R_FP, Registers.R_RA}) {
|
|
|
if (call) {
|
|
|
- data.Add(reg, new Node().S("type", "int").set("size", 1));
|
|
|
+ data.Add(reg, new Node().S("type", "int").set("size", 1 * WORD_INC));
|
|
|
newvars--;
|
|
|
StoreWord(reg, Registers.R_SP, data.Offset(reg))
|
|
|
.S("comment", "p| backup " + reg);
|
|
@@ -386,7 +403,8 @@ public class Gen extends API.Gen {
|
|
|
boolean call = getTac().Block().HasCall();
|
|
|
for (String reg : new String[]{Registers.R_FP, Registers.R_RA}) {
|
|
|
if (call) {
|
|
|
- LoadWord(reg, Registers.R_SP, data.Offset(reg)).S("comment", "e| restore " + reg);
|
|
|
+ LoadWord(reg, Registers.R_SP, data.Offset(reg))
|
|
|
+ .S("comment", "e| restore " + reg);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -435,7 +453,8 @@ public class Gen extends API.Gen {
|
|
|
}
|
|
|
|
|
|
// Carrega o conteudo enderecado em rt para rt
|
|
|
- LoadWord(rt, rs, offset).S("tac.position", inst.G("global.position"));
|
|
|
+ LoadWord(rt, rs, offset)
|
|
|
+ .S("tac.position", inst.G("global.position"));
|
|
|
|
|
|
} else {
|
|
|
// Se não é indexada carrega o parametro normalmente
|
|
@@ -520,6 +539,7 @@ public class Gen extends API.Gen {
|
|
|
}
|
|
|
Instruction Ninst = new Instruction();
|
|
|
pname = inst.G(param);
|
|
|
+
|
|
|
if (inst.eq(param + "value", "true")) {
|
|
|
Ninst.S("inst", "addiu") // R[$rt] ← {(imm)[15:0], 0 × 16}
|
|
|
.S("rs", Registers.R_ZERO)
|
|
@@ -529,7 +549,8 @@ public class Gen extends API.Gen {
|
|
|
Ninst.S("inst", "lw") // R[$rt] ← Mem4B(R[$rs] + SignExt16b(imm))
|
|
|
.S("rt", inst.G("reg." + param))
|
|
|
.S("rs", GlobalOrFrameRegister(pname))
|
|
|
- .set("offset", getTac().Block().Data().Offset(pname));
|
|
|
+ .S("comment", "load address stored in " + pname)
|
|
|
+ .set("offset", getTarget().Block().Data().Offset(pname));
|
|
|
}
|
|
|
|
|
|
Add(Ninst.S("tac.position", inst.G("global.position")));
|
|
@@ -576,6 +597,7 @@ public class Gen extends API.Gen {
|
|
|
}
|
|
|
|
|
|
protected Instruction LoadWord(String rt, String rs, int offset) {
|
|
|
+// System.out.println("LoadWord:" + rt + ":" + rs + ":" + "off:" + offset);
|
|
|
return LoadWord(rt, rs, "" + offset);
|
|
|
}
|
|
|
|