Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2024_compilation_bauquin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BAUQUIN Niels
2024_compilation_bauquin
Commits
33db0e98
Commit
33db0e98
authored
1 year ago
by
BAUQUIN Niels
Browse files
Options
Downloads
Patches
Plain Diff
geg
parent
995f4b05
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/nasm/C3a2nasm.java
+61
-11
61 additions, 11 deletions
src/nasm/C3a2nasm.java
test/pre-nasm-ref/add1.pre-nasm
+1
-1
1 addition, 1 deletion
test/pre-nasm-ref/add1.pre-nasm
with
62 additions
and
12 deletions
src/nasm/C3a2nasm.java
+
61
−
11
View file @
33db0e98
...
@@ -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
);}
}
}
This diff is collapsed.
Click to expand it.
test/pre-nasm-ref/add1.pre-nasm
+
1
−
1
View file @
33db0e98
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment