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

geg

parent 995f4b05
No related branches found
No related tags found
No related merge requests found
...@@ -52,14 +52,41 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> { ...@@ -52,14 +52,41 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
} }
public NasmOperand visit(C3aInstCall inst){ public NasmOperand visit(C3aInstCall inst){
NasmOperand address = (inst.label != null) ?
inst.label.accept(this)
: null; NasmRegister register = nasm.newRegister();
nasm.ajouteInst(new NasmCall(null, address, "")); 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"));
return null; return null;
} }
public NasmOperand visit(C3aInstFBegin inst){ 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"));
NasmRegister register1 = nasm.newRegister();
register1.colorRegister(Nasm.REG_ESP);
nasm.ajouteInst(new NasmMov(null, register, register1, "nouvelle valeur de ebp"));
NasmRegister register2 = nasm.newRegister();
register2.colorRegister(Nasm.REG_EAX);
nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur de eax"));
NasmRegister register3 = nasm.newRegister();
register3.colorRegister(Nasm.REG_EBX);
nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur de ebx"));
NasmRegister register4 = nasm.newRegister();
register4.colorRegister(Nasm.REG_ECX);
nasm.ajouteInst(new NasmPush(null, register,"sauvegarde la valeur 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 NasmSub(null, register1, new NasmConstant(0), "allocation des variables locales"));
return null; return null;
} }
...@@ -117,17 +144,40 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> { ...@@ -117,17 +144,40 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
return null; return null;
} }
public NasmOperand visit(C3aInstStop inst){ public NasmOperand visit(C3aInstStop inst){
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(null, register2, new NasmConstant(1)," code de sortie"));
nasm.ajouteInst(new NasmInt(null,null));
return null; return null;
} }
public NasmOperand visit(C3aConstant oper){return null;} public NasmOperand visit(C3aConstant oper){
public NasmOperand visit(C3aBooleanConstant oper){return null;}
public NasmOperand visit(C3aLabel oper){return null;}
System.out.println(oper.getClass());
return new NasmConstant(oper.val);}
public NasmOperand visit(C3aBooleanConstant oper){
System.out.println(oper.getClass());
return null;}
public NasmOperand visit(C3aLabel oper){
System.out.println(oper.getClass());
return null;}
public NasmOperand visit(C3aTemp oper){ public NasmOperand visit(C3aTemp oper){
return null;
System.out.println(oper.getClass());
return new NasmRegister(oper.num);
} }
public NasmOperand visit(C3aVar oper){return null;} public NasmOperand visit(C3aVar oper){
public NasmOperand visit(C3aFunction oper){return null;} System.out.println(oper.getClass());
return null;}
public NasmOperand visit(C3aFunction oper){
System.out.println(oper.getClass());
return new NasmLabel(oper.val.identif);}
} }
...@@ -9,7 +9,7 @@ _start: ...@@ -9,7 +9,7 @@ _start:
sub esp, 4 ;allocation mémoire pour la valeur de retour sub esp, 4 ;allocation mémoire pour la valeur de retour
call main call main
pop @0 ;récupération de la valeur de retour 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 mov eax, 1 ; code de sortie
int 0x80 int 0x80
main : push ebp ;sauvegarde la valeur de ebp main : push ebp ;sauvegarde la valeur de ebp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment