Skip to content
Snippets Groups Projects
Commit 802dc1a9 authored by BAUQUIN Niels's avatar BAUQUIN Niels
Browse files

FGS

parent 9144678c
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ public class FgSolution{ ...@@ -22,7 +22,7 @@ public class FgSolution{
this.in = new HashMap< NasmInst, IntSet>(); this.in = new HashMap< NasmInst, IntSet>();
this.out = new HashMap< NasmInst, IntSet>(); this.out = new HashMap< NasmInst, IntSet>();
int intSetSize = nasm.getTempCounter(); int intSetSize = nasm.getTempCounter();
iterNum = intSetSize;
List<NasmInst> forbidden = fg.getForbiddenList(); List<NasmInst> forbidden = fg.getForbiddenList();
for (int i = 1; i < nasm.sectionText.size(); i++) { for (int i = 1; i < nasm.sectionText.size(); i++) {
...@@ -35,25 +35,79 @@ public class FgSolution{ ...@@ -35,25 +35,79 @@ public class FgSolution{
in.put(inst, new IntSet(intSetSize)); in.put(inst, new IntSet(intSetSize));
out.put(inst, new IntSet(intSetSize)); out.put(inst, new IntSet(intSetSize));
if (inst.srcDef) { if (inst.srcDef && inst.source.isGeneralRegister()) {
def.get(inst); NasmRegister source = (NasmRegister) inst.source;
def.get(inst).add(source.val);
}
if (inst.srcUse && inst.source.isGeneralRegister()) {
NasmRegister source = (NasmRegister) inst.source;
use.get(inst).add(source.val);
}
if (inst.destDef && inst.destination.isGeneralRegister()) {
NasmRegister destination = (NasmRegister) inst.destination;
def.get(inst).add(destination.val);
}
if (inst.destUse && inst.destination.isGeneralRegister()) {
NasmRegister destination = (NasmRegister) inst.destination;
use.get(inst).add(destination.val);
} }
if (inst.srcUse){
use.get(inst);
} }
if (inst.destDef){ while (true) {
def.get(inst); Map<NasmInst, IntSet> in2 = getCopy(in);
Map<NasmInst, IntSet> out2 = getCopy(out);
for (int i = 1; i < nasm.sectionText.size(); i++) {
while (fg.secretMethod(nasm.sectionText.get(i), forbidden)) {
i++;
} }
if (inst.destUse){ NasmInst inst = nasm.sectionText.get(i);
use.get(inst);
IntSet temp = out.get(inst).copy();
temp.minus(def.get(inst));
temp.union(use.get(inst));
in.put(inst,temp);
NodeList list = fg.inst2Node.get(inst).succ();
IntSet temp2 = out.get(inst).copy();
if (list != null)
while (true) {
temp2.union(in.get(fg.node2Inst.get(list.head)));
if (list.tail == null)
break;
list = list.tail;
} }
out.put(inst, temp2);
} }
if (inAndOutEquals(in, in2, out, out2))
break;
} }
}
Map<NasmInst, IntSet> getCopy(Map<NasmInst, IntSet> map){
Map<NasmInst, IntSet> copy = new HashMap<>();
for (NasmInst inst : map.keySet())
copy.put(inst, map.get(inst).copy());
return copy;
}
boolean inAndOutEquals(Map<NasmInst, IntSet> in, Map<NasmInst, IntSet> in2, Map<NasmInst, IntSet> out, Map<NasmInst, IntSet> out2) {
for (NasmInst inst : in.keySet())
if ((!in.get(inst).equal(in2.get(inst))) || (!out.get(inst).equal(out2.get(inst))))
return false;
return true;
}
public void affiche(String baseFileName){ public void affiche(String baseFileName){
String fileName; String fileName;
...@@ -70,10 +124,14 @@ public class FgSolution{ ...@@ -70,10 +124,14 @@ public class FgSolution{
System.err.println("Error: " + e.getMessage()); System.err.println("Error: " + e.getMessage());
} }
} }
List<NasmInst> forbidden = fg.getForbiddenList();
out.println("iter num = " + iterNum); out.println("iter num = " + iterNum);
for(NasmInst nasmInst : this.nasm.sectionText){ for (int i = 1; i < nasm.sectionText.size(); i++) {
out.println("use = "+ this.use.get(nasmInst) + " def = "+ this.def.get(nasmInst) + "\tin = " + this.in.get(nasmInst) + "\t \tout = " + this.out.get(nasmInst) + "\t \t" + nasmInst); while (fg.secretMethod(nasm.sectionText.get(i), forbidden)) {
i++;
}
out.println("use = "+ this.use.get(nasm.sectionText.get(i)) + " def = "+ this.def.get(nasm.sectionText.get(i)) + "\tin = " + this.in.get(nasm.sectionText.get(i)) + "\t \tout = " + this.out.get(nasm.sectionText.get(i)) + "\t \t" + nasm.sectionText.get(i));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment