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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BAUQUIN Niels
2024_compilation_bauquin
Commits
cdbf03c1
Commit
cdbf03c1
authored
Apr 9, 2024
by
BAUQUIN Niels
Browse files
Options
Downloads
Patches
Plain Diff
FG
parent
8967114a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Compiler.java
+3
-4
3 additions, 4 deletions
src/Compiler.java
src/fg/Fg.java
+115
-22
115 additions, 22 deletions
src/fg/Fg.java
src/fg/FgSolution.java
+33
-1
33 additions, 1 deletion
src/fg/FgSolution.java
src/nasm/C3a2nasm.java
+0
-2
0 additions, 2 deletions
src/nasm/C3a2nasm.java
with
151 additions
and
29 deletions
src/Compiler.java
+
3
−
4
View file @
cdbf03c1
...
@@ -44,12 +44,11 @@ public class Compiler
...
@@ -44,12 +44,11 @@ public class Compiler
System
.
out
.
println
(
"[BUILD PRE NASM] "
);
System
.
out
.
println
(
"[BUILD PRE NASM] "
);
buildPreNasm
();
buildPreNasm
();
//System.out.println("[BUILD FLOW GRAPH] ");
System
.
out
.
println
(
"[BUILD FLOW GRAPH] "
);
//buildFg();
buildFg
();
/*
System
.
out
.
println
(
"[SOLVE FLOW GRAPH]"
);
System
.
out
.
println
(
"[SOLVE FLOW GRAPH]"
);
solveFg
();
solveFg
();
/*
System.out.println("[BUILD INTERFERENCE GRAPH] ");
System.out.println("[BUILD INTERFERENCE GRAPH] ");
buildIg();
buildIg();
System.out.println("[ALLOCATE REGISTERS]");
System.out.println("[ALLOCATE REGISTERS]");
...
...
This diff is collapsed.
Click to expand it.
src/fg/Fg.java
+
115
−
22
View file @
cdbf03c1
...
@@ -17,12 +17,93 @@ public class Fg implements NasmVisitor <Void> {
...
@@ -17,12 +17,93 @@ public class Fg implements NasmVisitor <Void> {
this
.
node2Inst
=
new
HashMap
<
Node
,
NasmInst
>();
this
.
node2Inst
=
new
HashMap
<
Node
,
NasmInst
>();
this
.
label2Inst
=
new
HashMap
<
String
,
NasmInst
>();
this
.
label2Inst
=
new
HashMap
<
String
,
NasmInst
>();
this
.
graph
=
new
Graph
();
this
.
graph
=
new
Graph
();
List
<
NasmInst
>
forbidden
=
getForbiddenList
();
for
(
int
i
=
1
;
i
<
nasm
.
sectionText
.
size
();
i
++)
{
while
(
secretMethod
(
nasm
.
sectionText
.
get
(
i
),
forbidden
))
{
i
++;
}
Node
n
=
graph
.
newNode
();
inst2Node
.
put
(
nasm
.
sectionText
.
get
(
i
),
n
);
node2Inst
.
put
(
n
,
nasm
.
sectionText
.
get
(
i
));
String
label
=
nasm
.
sectionText
.
get
(
i
).
label
!=
null
?
nasm
.
sectionText
.
get
(
i
).
label
.
toString
()
:
null
;
if
(
label
!=
null
)
label2Inst
.
put
(
label
,
nasm
.
sectionText
.
get
(
i
));
}
for
(
int
i
=
1
;
i
<
nasm
.
sectionText
.
size
();
i
++)
{
while
(
secretMethod
(
nasm
.
sectionText
.
get
(
i
),
forbidden
))
i
++;
Node
n
=
inst2Node
.
get
(
nasm
.
sectionText
.
get
(
i
));
int
next
=
i
+
1
;
if
(
next
==
nasm
.
sectionText
.
size
())
break
;
while
(
secretMethod
(
nasm
.
sectionText
.
get
(
next
),
forbidden
))
next
++;
if
(
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmCall
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJe
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJg
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJl
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJge
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJle
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJmp
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJne
)
{
String
label
=
nasm
.
sectionText
.
get
(
i
).
address
.
toString
();
Node
n3
=
inst2Node
.
getOrDefault
((
label2Inst
.
get
(
label
)),
null
);
if
(
n3
!=
null
)
graph
.
addEdge
(
n
,
n3
);
if
(!(
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmCall
||
nasm
.
sectionText
.
get
(
i
)
instanceof
NasmJmp
))
graph
.
addEdge
(
n
,
inst2Node
.
get
(
nasm
.
sectionText
.
get
(
next
)));
}
else
graph
.
addEdge
(
n
,
inst2Node
.
get
(
nasm
.
sectionText
.
get
(
next
)));
}
affiche
(
"cacaca"
);
}
List
<
NasmInst
>
getForbiddenList
()
{
List
<
NasmInst
>
forbidden
=
new
ArrayList
<>();
NasmRegister
register2
=
new
NasmRegister
(-
1
);
register2
.
colorRegister
(
Nasm
.
REG_EAX
);
forbidden
.
add
(
new
NasmPush
(
null
,
register2
,
"sauvegarde de eax"
));
NasmRegister
register3
=
new
NasmRegister
(-
1
);
register3
.
colorRegister
(
Nasm
.
REG_EBX
);
forbidden
.
add
(
new
NasmPush
(
null
,
register3
,
"sauvegarde de ebx"
));
NasmRegister
register4
=
new
NasmRegister
(-
1
);
register4
.
colorRegister
(
Nasm
.
REG_ECX
);
forbidden
.
add
(
new
NasmPush
(
null
,
register4
,
"sauvegarde de ecx"
));
NasmRegister
register5
=
new
NasmRegister
(-
1
);
register5
.
colorRegister
(
Nasm
.
REG_EDX
);
forbidden
.
add
(
new
NasmPush
(
null
,
register5
,
"sauvegarde de edx"
));
forbidden
.
add
(
new
NasmPop
(
null
,
register5
,
"restaure edx"
));
forbidden
.
add
(
new
NasmPop
(
null
,
register4
,
"restaure ecx"
));
forbidden
.
add
(
new
NasmPop
(
null
,
register3
,
"restaure ebx"
));
forbidden
.
add
(
new
NasmPop
(
null
,
register2
,
"restaure eax"
));
forbidden
.
add
(
new
NasmPop
(
null
,
new
NasmRegister
(
0
),
"récupération de la valeur de retour"
));
return
forbidden
;
}
boolean
secretMethod
(
NasmInst
inst
,
List
<
NasmInst
>
list
)
{
for
(
NasmInst
nasmInst
:
list
)
if
(
nasmInst
.
toString
().
equals
(
inst
.
toString
()))
return
true
;
return
false
;
}
}
public
void
affiche
(
String
baseFileName
){
public
void
affiche
(
String
baseFileName
){
String
fileName
;
String
fileName
;
PrintStream
out
=
System
.
out
;
PrintStream
out
=
System
.
out
;
if
(
baseFileName
!=
null
){
if
(
baseFileName
!=
null
){
try
{
try
{
baseFileName
=
baseFileName
;
baseFileName
=
baseFileName
;
...
@@ -34,28 +115,26 @@ public class Fg implements NasmVisitor <Void> {
...
@@ -34,28 +115,26 @@ public class Fg implements NasmVisitor <Void> {
System
.
err
.
println
(
"Error: "
+
e
.
getMessage
());
System
.
err
.
println
(
"Error: "
+
e
.
getMessage
());
}
}
}
}
List
<
NasmInst
>
forbidden
=
getForbiddenList
();
for
(
NasmInst
nasmInst
:
nasm
.
sectionText
){
for
(
int
i
=
1
;
i
<
nasm
.
sectionText
.
size
();
i
++)
{
Node
n
=
this
.
inst2Node
.
get
(
nasmInst
);
while
(
secretMethod
(
nasm
.
sectionText
.
get
(
i
),
forbidden
))
{
/*
i
++;
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);
}
}
*/
Node
n
=
this
.
inst2Node
.
get
(
nasm
.
sectionText
.
get
(
i
));
out
.
print
(
n
+
" : ( "
);
out
.
print
(
n
+
" : ( "
);
for
(
NodeList
q
=
n
.
succ
();
q
!=
null
;
q
=
q
.
tail
)
{
for
(
NodeList
q
=
n
.
succ
();
q
!=
null
;
q
=
q
.
tail
)
{
out
.
print
(
q
.
head
.
toString
());
out
.
print
(
q
.
head
.
toString
());
out
.
print
(
" "
);
out
.
print
(
" "
);
}
}
out
.
println
(
")\t"
+
nasm
Inst
);
out
.
println
(
")\t"
+
nasm
.
sectionText
.
get
(
i
)
);
}
}
}
}
public
Void
visit
(
NasmAdd
inst
){
public
Void
visit
(
NasmAdd
inst
){
return
null
;
return
null
;
}
}
public
Void
visit
(
NasmCall
inst
){
public
Void
visit
(
NasmCall
inst
){
...
@@ -96,12 +175,18 @@ public class Fg implements NasmVisitor <Void> {
...
@@ -96,12 +175,18 @@ public class Fg implements NasmVisitor <Void> {
return
null
;
return
null
;
}
}
public
Void
visit
(
NasmPop
inst
){
public
Void
visit
(
NasmPop
inst
){
return
null
;
return
null
;
}
}
public
Void
visit
(
NasmRet
inst
){
public
Void
visit
(
NasmRet
inst
){
return
null
;
return
null
;
}
}
public
Void
visit
(
NasmXor
inst
){
public
Void
visit
(
NasmXor
inst
){
return
null
;
return
null
;
}
}
public
Void
visit
(
NasmAnd
inst
){
public
Void
visit
(
NasmAnd
inst
){
...
@@ -111,11 +196,19 @@ public class Fg implements NasmVisitor <Void> {
...
@@ -111,11 +196,19 @@ public class Fg implements NasmVisitor <Void> {
return
null
;
return
null
;
}
}
public
Void
visit
(
NasmJmp
inst
){
return
null
;}
public
Void
visit
(
NasmJmp
inst
){
return
null
;}
public
Void
visit
(
NasmMov
inst
){
return
null
;}
public
Void
visit
(
NasmMov
inst
){
return
null
;}
public
Void
visit
(
NasmPush
inst
){
return
null
;}
public
Void
visit
(
NasmPush
inst
){
return
null
;}
public
Void
visit
(
NasmSub
inst
){
return
null
;}
public
Void
visit
(
NasmSub
inst
){
public
Void
visit
(
NasmEmpty
inst
){
return
null
;}
public
Void
visit
(
NasmInt
inst
){
return
null
;}
return
null
;}
public
Void
visit
(
NasmEmpty
inst
){
return
null
;}
public
Void
visit
(
NasmInt
inst
){
return
null
;}
public
Void
visit
(
NasmAddress
operand
){
return
null
;}
public
Void
visit
(
NasmAddress
operand
){
return
null
;}
public
Void
visit
(
NasmConstant
operand
){
return
null
;}
public
Void
visit
(
NasmConstant
operand
){
return
null
;}
public
Void
visit
(
NasmLabel
operand
){
return
null
;}
public
Void
visit
(
NasmLabel
operand
){
return
null
;}
...
...
This diff is collapsed.
Click to expand it.
src/fg/FgSolution.java
+
33
−
1
View file @
cdbf03c1
...
@@ -21,7 +21,39 @@ public class FgSolution{
...
@@ -21,7 +21,39 @@ public class FgSolution{
this
.
def
=
new
HashMap
<
NasmInst
,
IntSet
>();
this
.
def
=
new
HashMap
<
NasmInst
,
IntSet
>();
this
.
in
=
new
HashMap
<
NasmInst
,
IntSet
>();
this
.
in
=
new
HashMap
<
NasmInst
,
IntSet
>();
this
.
out
=
new
HashMap
<
NasmInst
,
IntSet
>();
this
.
out
=
new
HashMap
<
NasmInst
,
IntSet
>();
int
intSetSize
=
nasm
.
getTempCounter
();
List
<
NasmInst
>
forbidden
=
fg
.
getForbiddenList
();
for
(
int
i
=
1
;
i
<
nasm
.
sectionText
.
size
();
i
++)
{
while
(
fg
.
secretMethod
(
nasm
.
sectionText
.
get
(
i
),
forbidden
))
{
i
++;
}
NasmInst
inst
=
nasm
.
sectionText
.
get
(
i
);
use
.
put
(
inst
,
new
IntSet
(
intSetSize
));
def
.
put
(
inst
,
new
IntSet
(
intSetSize
));
in
.
put
(
inst
,
new
IntSet
(
intSetSize
));
out
.
put
(
inst
,
new
IntSet
(
intSetSize
));
if
(
inst
.
srcDef
)
{
def
.
get
(
inst
);
}
if
(
inst
.
srcUse
){
use
.
get
(
inst
);
}
if
(
inst
.
destDef
){
def
.
get
(
inst
);
}
if
(
inst
.
destUse
){
use
.
get
(
inst
);
}
}
}
}
public
void
affiche
(
String
baseFileName
){
public
void
affiche
(
String
baseFileName
){
String
fileName
;
String
fileName
;
...
...
This diff is collapsed.
Click to expand it.
src/nasm/C3a2nasm.java
+
0
−
2
View file @
cdbf03c1
...
@@ -53,7 +53,6 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
...
@@ -53,7 +53,6 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
}
}
public
NasmOperand
visit
(
C3aInstCall
inst
){
public
NasmOperand
visit
(
C3aInstCall
inst
){
System
.
out
.
println
(
inst
);
NasmOperand
label
=
(
inst
.
label
!=
null
)
?
NasmOperand
label
=
(
inst
.
label
!=
null
)
?
inst
.
label
.
accept
(
this
)
inst
.
label
.
accept
(
this
)
:
null
;
:
null
;
...
@@ -384,7 +383,6 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
...
@@ -384,7 +383,6 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> {
public
NasmOperand
visit
(
C3aTemp
oper
){
public
NasmOperand
visit
(
C3aTemp
oper
){
System
.
out
.
println
(
oper
.
num
);
System
.
out
.
println
(
oper
.
getClass
());
System
.
out
.
println
(
oper
.
getClass
());
return
new
NasmRegister
(
oper
.
num
);
return
new
NasmRegister
(
oper
.
num
);
}
}
...
...
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