diff --git a/src/fg/FgSolution.java b/src/fg/FgSolution.java index a600132614e44d1b41f50a44a3324534e45ac26f..b24fa94fa970a6adf913b9788bf6068f8bca888b 100644 --- a/src/fg/FgSolution.java +++ b/src/fg/FgSolution.java @@ -22,7 +22,7 @@ public class FgSolution{ this.in = new HashMap< NasmInst, IntSet>(); this.out = new HashMap< NasmInst, IntSet>(); int intSetSize = nasm.getTempCounter(); - + iterNum = intSetSize; List<NasmInst> forbidden = fg.getForbiddenList(); for (int i = 1; i < nasm.sectionText.size(); i++) { @@ -35,25 +35,79 @@ public class FgSolution{ in.put(inst, new IntSet(intSetSize)); out.put(inst, new IntSet(intSetSize)); - if (inst.srcDef) { - def.get(inst); + if (inst.srcDef && inst.source.isGeneralRegister()) { + NasmRegister source = (NasmRegister) inst.source; + def.get(inst).add(source.val); } - if (inst.srcUse){ - use.get(inst); + + if (inst.srcUse && inst.source.isGeneralRegister()) { + NasmRegister source = (NasmRegister) inst.source; + use.get(inst).add(source.val); } - if (inst.destDef){ - def.get(inst); + + if (inst.destDef && inst.destination.isGeneralRegister()) { + NasmRegister destination = (NasmRegister) inst.destination; + def.get(inst).add(destination.val); } - if (inst.destUse){ - use.get(inst); + + if (inst.destUse && inst.destination.isGeneralRegister()) { + NasmRegister destination = (NasmRegister) inst.destination; + use.get(inst).add(destination.val); + } + } + while (true) { + 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++; + } + NasmInst inst = nasm.sectionText.get(i); + + 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){ String fileName; @@ -70,10 +124,14 @@ public class FgSolution{ System.err.println("Error: " + e.getMessage()); } } - - out.println("iter num = " + iterNum); - for(NasmInst nasmInst : this.nasm.sectionText){ - 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); + List<NasmInst> forbidden = fg.getForbiddenList(); + + out.println("iter num = " + iterNum); + for (int i = 1; i < nasm.sectionText.size(); i++) { + 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)); } }