From 8967114ab118dafc7d304c8b6a7a4db9044f4b47 Mon Sep 17 00:00:00 2001
From: Niels <niels.bauquin@etu.univ-amu.fr>
Date: Tue, 9 Apr 2024 17:16:37 +0200
Subject: [PATCH] BAHAHHAHAHAHAHAHAHHAHAHAHHAHAHAHHAHAHAHAHHAHAHAH

---
 src/Compiler.java               |   6 +-
 src/fg/Fg.java                  |  81 ++++++--
 src/nasm/C3a2nasm.java          | 329 ++++++++++++++++++++++++++++----
 src/sa/SaEval.java              |   4 +-
 src/sa/SaTypeCheck.java         |  20 +-
 src/ts/Sa2ts.java               |   1 -
 test/c3a-ref/fibo.c3a           |   2 +-
 test/input/fibo.l               |   2 +-
 test/nasm-ref/fibo.nasm         |   2 +-
 test/out-ref/fibo.out           |   2 +-
 test/pre-nasm-ref/add1.pre-nasm |   2 +-
 test/pre-nasm-ref/fibo.pre-nasm |   2 +-
 test/sa-ref/fibo.sa             |   2 +-
 13 files changed, 374 insertions(+), 81 deletions(-)

diff --git a/src/Compiler.java b/src/Compiler.java
index cfc6807..883912e 100644
--- a/src/Compiler.java
+++ b/src/Compiler.java
@@ -44,10 +44,12 @@ public class Compiler
 
 		System.out.println("[BUILD PRE NASM] ");
 		buildPreNasm();
-/*		System.out.println("[BUILD FLOW GRAPH] ");
-		buildFg();
+		//System.out.println("[BUILD FLOW GRAPH] ");
+		//buildFg();
+		/*
 		System.out.println("[SOLVE FLOW GRAPH]");
 		solveFg();
+
 		System.out.println("[BUILD INTERFERENCE GRAPH] ");
 		buildIg();
 		System.out.println("[ALLOCATE REGISTERS]");
diff --git a/src/fg/Fg.java b/src/fg/Fg.java
index c306fd5..a0a1509 100644
--- a/src/fg/Fg.java
+++ b/src/fg/Fg.java
@@ -37,6 +37,14 @@ public class Fg implements NasmVisitor <Void> {
 	
 	for(NasmInst nasmInst : nasm.sectionText){
 	    Node n = this.inst2Node.get(nasmInst);
+        /*
+        graph.addEdge(n,);
+        if (nasmInst instanceof NasmJe || nasmInst instanceof NasmJg || nasmInst instanceof NasmJl || nasmInst instanceof NasmJge || nasmInst instanceof NasmJle || nasmInst instanceof NasmJmp ||nasmInst instanceof NasmJne) {
+            String label = nasmInst.address.toString();
+            Node n3 = inst2Node.get((label2Inst.get(label)));
+            graph.addEdge(n, n3);
+        }
+        */
 	    out.print(n + " : ( ");
 	    for(NodeList q=n.succ(); q!=null; q=q.tail) {
 		out.print(q.head.toString());
@@ -47,24 +55,61 @@ public class Fg implements NasmVisitor <Void> {
 	
     }
 
-    public Void visit(NasmAdd inst){return null;}
-    public Void visit(NasmCall inst){return null;}
-    public Void visit(NasmDiv inst){return null;}
-    public Void visit(NasmJe inst){return null;}
-    public Void visit(NasmJle inst){return null;}
-    public Void visit(NasmJne inst){return null;}
-    public Void visit(NasmMul inst){return null;}
-    public Void visit(NasmOr inst){return null;}
-    public Void visit(NasmCmp inst){return null;}
-    public Void visit(NasmInst inst){return null;}
-    public Void visit(NasmJge inst){return null;}
-    public Void visit(NasmJl inst){return null;}
-    public Void visit(NasmNot inst){return null;}
-    public Void visit(NasmPop inst){return null;}
-    public Void visit(NasmRet inst){return null;}
-    public Void visit(NasmXor inst){return null;}
-    public Void visit(NasmAnd inst){return null;}
-    public Void visit(NasmJg inst){return null;}
+    public Void visit(NasmAdd inst){
+        return null;
+    }
+    public Void visit(NasmCall inst){
+        return null;
+    }
+    public Void visit(NasmDiv inst){
+        return null;
+    }
+    public Void visit(NasmJe inst){
+
+        return null;
+    }
+    public Void visit(NasmJle inst){
+        return null;
+    }
+    public Void visit(NasmJne inst){
+        return null;
+    }
+    public Void visit(NasmMul inst){
+        return null;
+    }
+    public Void visit(NasmOr inst){
+        return null;
+    }
+    public Void visit(NasmCmp inst){
+        return null;
+    }
+    public Void visit(NasmInst inst){
+        return null;
+    }
+    public Void visit(NasmJge inst){
+        return null;
+    }
+    public Void visit(NasmJl inst){
+        return null;
+    }
+    public Void visit(NasmNot inst){
+        return null;
+    }
+    public Void visit(NasmPop inst){
+        return null;
+    }
+    public Void visit(NasmRet inst){
+        return null;
+    }
+    public Void visit(NasmXor inst){
+        return null;
+    }
+    public Void visit(NasmAnd inst){
+        return null;
+    }
+    public Void visit(NasmJg inst){
+        return null;
+    }
     public Void visit(NasmJmp inst){return null;}
     public Void visit(NasmMov inst){return null;}
     public Void visit(NasmPush inst){return null;}
diff --git a/src/nasm/C3a2nasm.java b/src/nasm/C3a2nasm.java
index c159c73..a7c89a1 100644
--- a/src/nasm/C3a2nasm.java
+++ b/src/nasm/C3a2nasm.java
@@ -16,14 +16,14 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
 		this.c3a = c3a;
 		nasm = new Nasm(tableGlobale);
 		nasm.setTempCounter(c3a.getTempCounter());
-
 		this.tableGlobale = tableGlobale;
 		this.currentFct = null;
+
 		esp = new NasmRegister(-1);
 		esp.colorRegister(Nasm.REG_ESP);
-
 		ebp = new NasmRegister(-1);
 		ebp.colorRegister(Nasm.REG_EBP);
+
     }
 
     public Nasm getNasm(){return nasm;}
@@ -32,8 +32,9 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
     public NasmOperand visit(C3a c3a){
         c3a.affiche("caca");
         for (C3aInst c3aInst : c3a.listeInst) {
+            System.out.println("<<<<   " + c3aInst.getClass());
             c3aInst.accept(this);
-            System.out.println(c3aInst.getClass());
+            System.out.println(c3aInst.getClass()+"   >>>>");
         }
         nasm.affichePreNasm("caca");
         return null;
@@ -52,46 +53,77 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
     }
 
     public NasmOperand visit(C3aInstCall inst){
+        System.out.println(inst);
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+
+
+        nasm.ajouteInst(new NasmSub(label, esp, new NasmConstant(4),"allocation mémoire pour la valeur de retour"));
 
 
-        NasmRegister register = nasm.newRegister();
-        register.colorRegister(Nasm.REG_ESP);
-        nasm.ajouteInst(new NasmSub(null, register, new NasmConstant(4),"allocation mémoire pour la valeur de retour"));
         nasm.ajouteInst(new NasmCall(null, inst.op1.accept(this), ""));
         nasm.ajouteInst(new NasmPop(null, inst.result.accept(this),"récupération de la valeur de retour"));
+        if (inst.op1.val.nbArgs != 0) {
+
+            nasm.ajouteInst(new NasmAdd(label, esp, new NasmConstant(NasmSize.DWORD.getValue()*(inst.op1.val.nbArgs)), "désallocation des arguments"));
+        }
         return null;
     }
     public NasmOperand visit(C3aInstFBegin inst){
-        NasmRegister register = nasm.newRegister();
-        register.colorRegister(Nasm.REG_EBP);
-        nasm.ajouteInst(new NasmPush(new NasmLabel(inst.val.getIdentif()), register,"sauvegarde la valeur de ebp"));
+        currentFct = inst.val;
+        NasmOperand nasmOperand = new NasmConstant(NasmSize.DWORD.getValue()*(currentFct.table.variables.size() - currentFct.nbArgs));
 
-        NasmRegister register1 = nasm.newRegister();
-        register1.colorRegister(Nasm.REG_ESP);
-        nasm.ajouteInst(new NasmMov(null, register, register1, "nouvelle valeur de ebp"));
+
+        nasm.ajouteInst(new NasmPush(new NasmLabel(inst.val.getIdentif()), ebp,"sauvegarde la valeur de ebp"));
+
+
+        nasm.ajouteInst(new NasmMov(null, ebp, esp, "nouvelle valeur de ebp"));
 
         NasmRegister register2 = nasm.newRegister();
         register2.colorRegister(Nasm.REG_EAX);
-        nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur de eax"));
+        nasm.ajouteInst(new NasmPush(null, register2,"sauvegarde de eax"));
 
         NasmRegister register3 = nasm.newRegister();
         register3.colorRegister(Nasm.REG_EBX);
-        nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur de ebx"));
+        nasm.ajouteInst(new NasmPush(null, register3,"sauvegarde de ebx"));
 
         NasmRegister register4 = nasm.newRegister();
         register4.colorRegister(Nasm.REG_ECX);
-        nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur de ecx"));
+        nasm.ajouteInst(new NasmPush(null, register4,"sauvegarde de ecx"));
 
         NasmRegister register5 = nasm.newRegister();
         register5.colorRegister(Nasm.REG_EDX);
-        nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur de edx"));
+        nasm.ajouteInst(new NasmPush(null, register5,"sauvegarde de edx"));
+
+        nasm.ajouteInst(new NasmSub(null, esp, nasmOperand, "allocation des variables locales"));
+
+        return nasmOperand;
+    }
+
+    public NasmOperand visit(C3aInst inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        return null;}
+
+    public NasmOperand visit(C3aInstJumpIfLess inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        if (inst.op1 instanceof C3aConstant) {
+            NasmRegister register = nasm.newRegister();
+            nasm.ajouteInst(new NasmMov(label, register, inst.op1.accept(this), "JumpIfLess 1"));
+            nasm.ajouteInst(new NasmCmp(null, register, inst.op2.accept(this), "on passe par un registre temporaire"));
+        }
+        else
+            nasm.ajouteInst(new NasmCmp(label, inst.op1.accept(this), inst.op2.accept(this), "JumpIfLess 1"));
 
-        nasm.ajouteInst(new NasmSub(null, register1, new NasmConstant(0), "allocation des variables locales"));
+        nasm.ajouteInst(new NasmJl(null, inst.result.accept(this),"JumpIfLess 2"));
 
         return null;
     }
-    public NasmOperand visit(C3aInst inst){return null;}
-    public NasmOperand visit(C3aInstJumpIfLess inst){return null;}
+
     public NasmOperand visit(C3aInstMult inst){
         NasmOperand label = (inst.label != null) ?
             inst.label.accept(this)
@@ -104,7 +136,26 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
                 inst.op2.accept(this), ""));
         return null;
     }
-    public NasmOperand visit(C3aInstRead inst){return null;}
+
+    public NasmOperand visit(C3aInstRead inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        NasmRegister register = nasm.newRegister();
+        register.colorRegister(Nasm.REG_EAX);
+        nasm.ajouteInst(new NasmMov (label,
+                register,
+                new NasmLabel("sinput"), ""));
+        nasm.ajouteInst(new NasmCall(null,
+                new NasmLabel("readline"), ""));
+        nasm.ajouteInst(new NasmCall(null,
+                new NasmLabel("atoi"), ""));
+        nasm.ajouteInst(new NasmMov (null,
+                inst.result.accept(this),
+                register , ""));
+        return null;
+    }
+
     public NasmOperand visit(C3aInstSub inst){
         NasmOperand label = (inst.label != null) ?
                 inst.label.accept(this)
@@ -117,67 +168,261 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
                 inst.op2.accept(this), ""));
         return null;
     }
-    public NasmOperand visit(C3aInstAffect inst){return null;}
+
+    public NasmOperand visit(C3aInstAffect inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        nasm.ajouteInst(new NasmMov(label, inst.result.accept(this), inst.op1.accept(this), "Affect"));
+
+        return null;
+    }
+
     public NasmOperand visit(C3aInstDiv inst){
+
         NasmOperand label = (inst.label != null) ?
-            inst.label.accept(this)
-            : null;
-        nasm.ajouteInst(new NasmMov(label,
-                inst.result.accept(this),
-                inst.op1.accept(this), ""));
-        nasm.ajouteInst(new NasmDiv(null,
-                inst.result.accept(this),
-                 ""));
+                inst.label.accept(this)
+                : null;
+
+        NasmRegister registerEDX = nasm.newRegister();
+        registerEDX.colorRegister(Nasm.REG_EDX);
+        nasm.ajouteInst(new NasmMov(label, registerEDX, new NasmConstant(0),"mise à 0 des bits de poids fort du dividende"));
+
+        NasmRegister registerEAX = nasm.newRegister();
+        registerEAX.colorRegister(Nasm.REG_EAX);
+        nasm.ajouteInst(new NasmMov(null, registerEAX, inst.op1.accept(this),"affectation des bits de poids faible du dividende"));
+
+        NasmOperand temp = nasm.newRegister();
+
+        NasmRegister registerEAX2 = nasm.newRegister();
+        registerEAX2.colorRegister(Nasm.REG_EAX);
+
+
+
+        NasmOperand result = (inst.result != null) ?
+                inst.result.accept(this)
+                : null;
+
+        nasm.ajouteInst(new NasmMov(null, temp, inst.op2.accept(this), ""));
+
+        nasm.ajouteInst(new NasmDiv(null, temp, ""));
+
+
+        nasm.ajouteInst(new NasmMov(null, registerEDX, registerEDX,"rend explicite l'utilisation de edx pour ne pas que sa valeur soit modifiée"));
+
+
+
+
+        nasm.ajouteInst(new NasmMov(null, result, registerEAX2,""));
+
         return null;
     }
+
+
     public NasmOperand visit(C3aInstFEnd inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+
+        nasm.ajouteInst(new NasmAdd(label, esp, new NasmConstant(NasmSize.DWORD.getValue()*(currentFct.table.variables.size()  - currentFct.nbArgs)), "désallocation des variables locales"));
+
+        NasmRegister register5 = nasm.newRegister();
+        register5.colorRegister(Nasm.REG_EDX);
+        nasm.ajouteInst(new NasmPop(null, register5,"restaure edx"));
+
+        NasmRegister register4 = nasm.newRegister();
+        register4.colorRegister(Nasm.REG_ECX);
+        nasm.ajouteInst(new NasmPop(null, register4,"restaure ecx"));
+
+        NasmRegister register3 = nasm.newRegister();
+        register3.colorRegister(Nasm.REG_EBX);
+        nasm.ajouteInst(new NasmPop(null, register3,"restaure ebx"));
+
+        NasmRegister register2 = nasm.newRegister();
+        register2.colorRegister(Nasm.REG_EAX);
+        nasm.ajouteInst(new NasmPop(null, register2,"restaure eax"));
+
+
+        nasm.ajouteInst(new NasmPop(null, ebp, "restaure la valeur de ebp"));
+
+        nasm.ajouteInst(new NasmRet(null,""));
 
         return null;
     }
-    public NasmOperand visit(C3aInstJumpIfEqual inst){return null;}
-    public NasmOperand visit(C3aInstJumpIfNotEqual inst){return null;}
-    public NasmOperand visit(C3aInstJump inst){return null;}
-    public NasmOperand visit(C3aInstParam inst){return null;}
-    public NasmOperand visit(C3aInstReturn inst){return null;}
+
+
+    public NasmOperand visit(C3aInstJumpIfEqual inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        if (inst.op1 instanceof C3aConstant) {
+            NasmOperand temp = nasm.newRegister();
+            nasm.ajouteInst(new NasmMov(label, temp, inst.op1.accept(this), "JumpIfEqual 1"));
+            nasm.ajouteInst(new NasmCmp(null, temp, inst.op2.accept(this), "on passe par un registre temporaire"));
+        }
+        else {
+            nasm.ajouteInst(new NasmCmp(label, inst.op1.accept(this), inst.op2.accept(this),"JumpIfEqual 1"));
+        }
+
+
+        NasmOperand address = (inst.result != null) ?
+                inst.result.accept(this)
+                : null;
+
+
+        nasm.ajouteInst(new NasmJe(null, address,"JumpIfEqual 2"));
+        return null;
+    }
+
+
+    public NasmOperand visit(C3aInstJumpIfNotEqual inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        if (inst.op1 instanceof C3aConstant) {
+            NasmRegister register = nasm.newRegister();
+            nasm.ajouteInst(new NasmMov(label, register, inst.op1.accept(this),"jumpIfNotEqual 1"));
+            nasm.ajouteInst(new NasmCmp(null,register,inst.op2.accept(this),"on passe par un registre temporaire"));
+        }
+        else
+            nasm.ajouteInst(new NasmCmp(label, inst.op1.accept(this), inst.op2.accept(this),"jumpIfNotEqual 1"));
+
+
+        nasm.ajouteInst(new NasmJne(null, inst.result.accept(this),"jumpIfNotEqual 2"));
+
+        return null;
+    }
+
+
+    public NasmOperand visit(C3aInstJump inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        NasmOperand address = (inst.result != null) ?
+                inst.result.accept(this)
+                : null;
+        nasm.ajouteInst(new NasmJmp(label, address, "Jump"));
+        return null;
+    }
+
+
+    public NasmOperand visit(C3aInstParam inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+
+        nasm.ajouteInst(new NasmPush(label, inst.op1.accept(this), "Param"));
+        return null;
+    }
+
+
+    public NasmOperand visit(C3aInstReturn inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        if (inst.op1 instanceof C3aVar) {
+            NasmRegister register = nasm.newRegister();
+            nasm.ajouteInst(new NasmMov(label, register, inst.op1.accept(this), "ecriture de la valeur de retour"));
+            nasm.ajouteInst(new NasmMov(null, new NasmAddress(new NasmExpPlus(ebp, new NasmConstant(8)), NasmSize.DWORD),register, "on passe par un registre temporaire"));
+        }
+        else
+            nasm.ajouteInst(new NasmMov(label, new NasmAddress(new NasmExpPlus(ebp, new NasmConstant(8)), NasmSize.DWORD), inst.op1.accept(this), "ecriture de la valeur de retour"));
+
+        return null;
+    }
+
+
     public NasmOperand visit(C3aInstWrite inst){
+        NasmRegister register = nasm.newRegister();
+        register.colorRegister(Nasm.REG_EAX);
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
+        nasm.ajouteInst(new NasmMov(label, register, inst.op1.accept(this), "Write 1"));
+
+        nasm.ajouteInst(new NasmCall(null, new NasmLabel("iprintLF"),"Write 2"));
 
         return null;
     }
     public NasmOperand visit(C3aInstStop inst){
+        NasmOperand label = (inst.label != null) ?
+                inst.label.accept(this)
+                : null;
         NasmRegister register1 = nasm.newRegister();
         register1.colorRegister(Nasm.REG_EBX);
         NasmRegister register2 = nasm.newRegister();
         register2.colorRegister(Nasm.REG_EAX);
-        nasm.ajouteInst(new NasmMov(null, register1, new NasmConstant(0)," valeur de retour du programme"));
+        nasm.ajouteInst(new NasmMov(label, register1, new NasmConstant(0)," valeur de retour du programme"));
         nasm.ajouteInst(new NasmMov(null, register2, new NasmConstant(1)," code de sortie"));
         nasm.ajouteInst(new NasmInt(null,null));
         return null;
     }
 
-    public NasmOperand visit(C3aConstant oper){
 
 
+
+
+
+    public NasmOperand visit(C3aConstant oper){
+
         System.out.println(oper.getClass());
-        return new NasmConstant(oper.val);}
+        return new NasmConstant(oper.val);
+    }
+
+
     public NasmOperand visit(C3aBooleanConstant oper){
         System.out.println(oper.getClass());
-        return null;}
+        return null;
+    }
+
+
     public NasmOperand visit(C3aLabel oper){
         System.out.println(oper.getClass());
-        return null;}
-    public NasmOperand visit(C3aTemp oper){
+        return new NasmLabel("l" + oper.getNumber());
+    }
+
 
+    public NasmOperand visit(C3aTemp oper){
 
+        System.out.println(oper.num);
         System.out.println(oper.getClass());
         return new NasmRegister(oper.num);
     }
+
+
     public NasmOperand visit(C3aVar oper){
         System.out.println(oper.getClass());
-        return null;}
+
+
+
+        if (oper.item.portee == tableGlobale) {
+            if (oper.index != null) {
+                NasmRegister register = nasm.newRegister();
+                nasm.ajouteInst(new NasmMov(null, register, oper.index.accept(this), ""));
+                nasm.ajouteInst(new NasmMul(null, register, new NasmConstant(oper.item.type.taille()), ""));
+                return new NasmAddress(new NasmExpPlus(new NasmLabel(oper.item.identif), register), NasmSize.DWORD);
+            }
+            return new NasmAddress(new NasmLabel(oper.item.identif), NasmSize.DWORD);
+        }
+
+
+        if (oper.item.isParam) {
+            int size = currentFct.table.getAdrArgCourante();
+            int adressOp = oper.item.adresse;
+            return new NasmAddress(new NasmExpPlus(ebp, new NasmConstant(2 * NasmSize.DWORD.getValue() + size - adressOp)), NasmSize.DWORD);
+        }
+
+        return new NasmAddress(new NasmExpMinus(ebp, new NasmConstant(NasmSize.DWORD.getValue() + oper.item.adresse)), NasmSize.DWORD);
+
+
+    }
+
+
     public NasmOperand visit(C3aFunction oper){
 
 
         System.out.println(oper.getClass());
-        return new NasmLabel(oper.val.identif);}
+        return new NasmLabel(oper.val.identif);
+    }
     
 }
diff --git a/src/sa/SaEval.java b/src/sa/SaEval.java
index b66416e..7f284f6 100644
--- a/src/sa/SaEval.java
+++ b/src/sa/SaEval.java
@@ -23,7 +23,9 @@ public class SaEval extends SaDepthFirstVisitor <TypeVal> {
 
 		try{
 			appelMain.accept(this);
-		} catch(Exception e){}
+		} catch(Exception e){
+			e.printStackTrace();
+		}
 	}
 
 	public TypeVal getVar(SaVarSimple saVar){
diff --git a/src/sa/SaTypeCheck.java b/src/sa/SaTypeCheck.java
index 9ab3196..0f96eb9 100644
--- a/src/sa/SaTypeCheck.java
+++ b/src/sa/SaTypeCheck.java
@@ -27,7 +27,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpAdd node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || !Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
 			throw new ErrorException(Error.TYPE, "Veuillez additioner uniquement des entiers");
 		}
 		return null;
@@ -35,7 +35,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaInstTantQue node) throws Exception {
-		if (Type.checkCompatibility(node.getTest().getType(), Type.ENTIER)) {
+		if (!Type.checkCompatibility(node.getTest().getType(), Type.BOOL)) {
 			throw new ErrorException(Error.TYPE, "Le résultat du test de la condition doit être un booléen");
 		}
 		return null;
@@ -52,7 +52,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpSub node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || !Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
 			throw new ErrorException(Error.TYPE, "Veuillez soustraire uniquement des entiers");
 		}
 		return null;
@@ -60,7 +60,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpMult node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || !Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
 			throw new ErrorException(Error.TYPE, "Veuillez multiplier uniquement des entiers");
 		}
 		return null;
@@ -68,7 +68,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpDiv node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || !Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
 			throw new ErrorException(Error.TYPE, "Veuillez diviser uniquement des entiers");
 		}
 		return null;
@@ -76,7 +76,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpInf node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || !Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
 			throw new ErrorException(Error.TYPE, "L'opérateur '<' marche uniquement sur des entiers");
 		}
 		return null;
@@ -92,7 +92,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpAnd node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || !Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
 			throw new ErrorException(Error.TYPE, "Veuillez 'And' uniquement des booléens");
 		}
 		return null;
@@ -100,7 +100,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpOr node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER) || Type.checkCompatibility(node.getOp2().getType(), Type.ENTIER)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.BOOL) || !Type.checkCompatibility(node.getOp2().getType(), Type.BOOL)) {
 			throw new ErrorException(Error.TYPE, "Veuillez 'Or' uniquement des booléens");
 		}
 		return null;
@@ -108,7 +108,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaExpNot node) throws Exception {
-		if (Type.checkCompatibility(node.getOp1().getType(), Type.ENTIER)) {
+		if (!Type.checkCompatibility(node.getOp1().getType(), Type.BOOL)) {
 			throw new ErrorException(Error.TYPE, "Veuillez 'Not' uniquement des booléens");
 		}
 		return null;
@@ -116,7 +116,7 @@ public class SaTypeCheck extends SaDepthFirstVisitor <Void>{
 
 	@Override
 	public Void visit(SaInstSi node) throws Exception {
-		if (Type.checkCompatibility(node.getTest().getType(), Type.ENTIER)) {
+		if (!Type.checkCompatibility(node.getTest().getType(), Type.BOOL)) {
 			throw new ErrorException(Error.TYPE, "Le résultat du test de la condition doit être un booléen");
 		}
 		return null;
diff --git a/src/ts/Sa2ts.java b/src/ts/Sa2ts.java
index 081b6c9..2fb6f2c 100644
--- a/src/ts/Sa2ts.java
+++ b/src/ts/Sa2ts.java
@@ -67,7 +67,6 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
 
         node.tsItem = tableGlobale.addFct(idFct, node.getTypeRetour(), nbArgs, table, node);
 
-        //besoin de rajouter un equals pour le SaInstBloc
 
         SaInstBloc tempCorps = (SaInstBloc) corps;
 
diff --git a/test/c3a-ref/fibo.c3a b/test/c3a-ref/fibo.c3a
index a67a525..54c7eee 100644
--- a/test/c3a-ref/fibo.c3a
+++ b/test/c3a-ref/fibo.c3a
@@ -19,7 +19,7 @@ fibo	fbegin	#entree fonction
 	fend
 1	fend
 main	fbegin	#entree fonction
-	param 9
+	param 3
 	@7 = call fibo
 	write @7	
 	fend
diff --git a/test/input/fibo.l b/test/input/fibo.l
index f67922d..71b4af8 100644
--- a/test/input/fibo.l
+++ b/test/input/fibo.l
@@ -10,5 +10,5 @@ entier fibo( entier n )
 
 main()
 {
-  ecrire( fibo( 9 ) );
+  ecrire( fibo( 3 ) );
 }
diff --git a/test/nasm-ref/fibo.nasm b/test/nasm-ref/fibo.nasm
index ec408a3..21a296f 100644
--- a/test/nasm-ref/fibo.nasm
+++ b/test/nasm-ref/fibo.nasm
@@ -72,7 +72,7 @@ main :	push	ebp	;sauvegarde la valeur de ebp
 	push	ecx	;sauvegarde de ecx
 	push	edx	;sauvegarde de edx
 	sub	esp,	0	;allocation des variables locales
-	push	9	;Param
+	push	3	;Param
 	sub	esp,	4	;allocation mémoire pour la valeur de retour
 	call	fibo
 	pop	eax	;récupération de la valeur de retour
diff --git a/test/out-ref/fibo.out b/test/out-ref/fibo.out
index c3f407c..00750ed 100644
--- a/test/out-ref/fibo.out
+++ b/test/out-ref/fibo.out
@@ -1 +1 @@
-55
+3
diff --git a/test/pre-nasm-ref/add1.pre-nasm b/test/pre-nasm-ref/add1.pre-nasm
index ead0968..a85129f 100644
--- a/test/pre-nasm-ref/add1.pre-nasm
+++ b/test/pre-nasm-ref/add1.pre-nasm
@@ -9,7 +9,7 @@ _start:
 	sub	esp,	4	;allocation mémoire pour la valeur de retour
 	call	main
 	pop	@0	;récupération de la valeur de retour
-	mov	ebx,	0	; valeur de retour du programme>
+	mov	ebx,	0	; valeur de retour du programme
 	mov	eax,	1	; code de sortie
 	int 0x80
 main :	push	ebp	;sauvegarde la valeur de ebp
diff --git a/test/pre-nasm-ref/fibo.pre-nasm b/test/pre-nasm-ref/fibo.pre-nasm
index bea531a..e157dca 100644
--- a/test/pre-nasm-ref/fibo.pre-nasm
+++ b/test/pre-nasm-ref/fibo.pre-nasm
@@ -72,7 +72,7 @@ main :	push	ebp	;sauvegarde la valeur de ebp
 	push	ecx	;sauvegarde de ecx
 	push	edx	;sauvegarde de edx
 	sub	esp,	0	;allocation des variables locales
-	push	9	;Param
+	push	3	;Param
 	sub	esp,	4	;allocation mémoire pour la valeur de retour
 	call	fibo
 	pop	@7	;récupération de la valeur de retour
diff --git a/test/sa-ref/fibo.sa b/test/sa-ref/fibo.sa
index 407ebde..7d661eb 100644
--- a/test/sa-ref/fibo.sa
+++ b/test/sa-ref/fibo.sa
@@ -1 +1 @@
-(SaProg null (SaLDecFonc (SaDecFonc fibo entier (SaLDecVar (SaDecVarSimple n entier) null) null (SaInstBloc (SaLInst (SaInstSi (SaExpInf (SaExpVar (SaVarSimple n)) 2) (SaInstBloc (SaLInst (SaInstRetour 1) null)) (SaInstBloc (SaLInst (SaInstRetour (SaExpAdd (SaExpAppel (SaAppel fibo (SaLExp (SaExpSub (SaExpVar (SaVarSimple n)) 1) null))) (SaExpAppel (SaAppel fibo (SaLExp (SaExpSub (SaExpVar (SaVarSimple n)) 2) null))))) null))) null))) (SaLDecFonc (SaDecFonc main nul null null (SaInstBloc (SaLInst (SaInstEcriture (SaExpAppel (SaAppel fibo (SaLExp 9 null)))) null))) null)))
+(SaProg null (SaLDecFonc (SaDecFonc fibo entier (SaLDecVar (SaDecVarSimple n entier) null) null (SaInstBloc (SaLInst (SaInstSi (SaExpInf (SaExpVar (SaVarSimple n)) 2) (SaInstBloc (SaLInst (SaInstRetour 1) null)) (SaInstBloc (SaLInst (SaInstRetour (SaExpAdd (SaExpAppel (SaAppel fibo (SaLExp (SaExpSub (SaExpVar (SaVarSimple n)) 1) null))) (SaExpAppel (SaAppel fibo (SaLExp (SaExpSub (SaExpVar (SaVarSimple n)) 2) null))))) null))) null))) (SaLDecFonc (SaDecFonc main nul null null (SaInstBloc (SaLInst (SaInstEcriture (SaExpAppel (SaAppel fibo (SaLExp 3 null)))) null))) null)))
\ No newline at end of file
-- 
GitLab