Skip to content
Snippets Groups Projects
Commit 5c49e733 authored by ZaynouneFatimaZahrae's avatar ZaynouneFatimaZahrae
Browse files

Fg

parent e4ecba3e
No related branches found
No related tags found
No related merge requests found
...@@ -48,15 +48,73 @@ public class Fg implements NasmVisitor <Void> { ...@@ -48,15 +48,73 @@ public class Fg implements NasmVisitor <Void> {
} }
public Void visit(NasmAdd inst){ public Void visit(NasmAdd inst){
for(int i = 0; i < inst2Node.size();i++) return null;
{
NasmInst nasmInst = nasm.sectionText.get(i);
if(nasmInst instanceof NasmAdd) {
} }
private void initFg() {
int nbInst = nasm.sectionText.size();
for (int i = 0; i < nbInst; i++) {
NasmInst inst = nasm.sectionText.get(i);
if (inst instanceof NasmJg) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) inst.address).val)));
if (nasm.sectionText.get(i + 1) != null) {
NasmInst prochaineInst = nasm.sectionText.get(i + 1);
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(prochaineInst));
}
}
if (inst instanceof NasmJle) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) inst.address).val)));
if (nasm.sectionText.get(i + 1) != null) {
NasmInst prochaineInst = nasm.sectionText.get(i + 1);
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(prochaineInst));
}
}
if (inst instanceof NasmJne) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) inst.address).val)));
if (nasm.sectionText.get(i + 1) != null) {
NasmInst prochaineInst = nasm.sectionText.get(i + 1);
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(prochaineInst));
}
}
if (!this.inst2Node.containsKey(inst)) {
continue;
}
if (inst instanceof NasmJmp) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) (inst).address).val)));
continue;
}
if (inst instanceof NasmJe) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) inst.address).val)));
if (nasm.sectionText.get(i + 1) != null) {
NasmInst prochaineInst = nasm.sectionText.get(i + 1);
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(prochaineInst));
} }
return null;
} }
if (inst instanceof NasmJe) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) inst.address).val)));
if (nasm.sectionText.get(i + 1) != null) {
NasmInst prochaineInst = nasm.sectionText.get(i + 1);
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(prochaineInst));
}
}
if (inst instanceof NasmRet) {
if (i < nbInst - 1) {
NasmLabel destination = (NasmLabel) inst.address;
if (destination != null && !destination.val.equals("iprintLF") && !destination.val.equals("atoi") && !destination.val.equals("readline")) {
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(nasm.sectionText.get(i + 1)));
}
}
continue;
}
if (inst instanceof NasmRet) {
continue;
}
if (i < nasm.sectionText.size() - 1) {
NasmInst InstPro = nasm.sectionText.get(i + 1);
this.graph.addEdge(this.inst2Node.get(inst), this.inst2Node.get(InstPro));
}
}
}
public Void visit(NasmCall inst){ public Void visit(NasmCall inst){
return null; return null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment