Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
infosec-ecomp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Putegnat Theo
infosec-ecomp
Commits
20afe797
Commit
20afe797
authored
2 years ago
by
Putegnat Theo
Browse files
Options
Downloads
Patches
Plain Diff
TP4 OK
parent
6b1684c0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cfg_dead_assign.ml
+8
-1
8 additions, 1 deletion
src/cfg_dead_assign.ml
src/cfg_liveness.ml
+40
-13
40 additions, 13 deletions
src/cfg_liveness.ml
with
48 additions
and
14 deletions
src/cfg_dead_assign.ml
+
8
−
1
View file @
20afe797
...
@@ -19,6 +19,12 @@ let dead_assign_elimination_fun ({ cfgfunbody; _ } as f: cfg_fun) =
...
@@ -19,6 +19,12 @@ let dead_assign_elimination_fun ({ cfgfunbody; _ } as f: cfg_fun) =
Hashtbl
.
map
(
fun
(
n
:
int
)
(
m
:
cfg_node
)
->
Hashtbl
.
map
(
fun
(
n
:
int
)
(
m
:
cfg_node
)
->
match
m
with
match
m
with
(* TODO *)
(* TODO *)
|
Cassign
(
var
,
e
,
i
)
->
begin
match
Hashtbl
.
find_option
(
live_cfg_fun
f
)
i
with
|
Some
set_of_var
->
if
Set
.
mem
var
set_of_var
then
m
else
(
changed
:=
true
;
(
Cnop
i
))
|
None
->
(
changed
:=
true
;
Cnop
i
)
end
|
_
->
m
|
_
->
m
)
cfgfunbody
in
)
cfgfunbody
in
({
f
with
cfgfunbody
}
,
!
changed
)
({
f
with
cfgfunbody
}
,
!
changed
)
...
@@ -28,7 +34,8 @@ let dead_assign_elimination_fun ({ cfgfunbody; _ } as f: cfg_fun) =
...
@@ -28,7 +34,8 @@ let dead_assign_elimination_fun ({ cfgfunbody; _ } as f: cfg_fun) =
let
rec
iter_dead_assign_elimination_fun
f
=
let
rec
iter_dead_assign_elimination_fun
f
=
let
f
,
c
=
dead_assign_elimination_fun
f
in
let
f
,
c
=
dead_assign_elimination_fun
f
in
(* TODO *)
(* TODO *)
f
if
c
then
iter_dead_assign_elimination_fun
f
else
f
let
dead_assign_elimination_gdef
=
function
let
dead_assign_elimination_gdef
=
function
Gfun
f
->
Gfun
(
iter_dead_assign_elimination_fun
f
)
Gfun
f
->
Gfun
(
iter_dead_assign_elimination_fun
f
)
...
...
This diff is collapsed.
Click to expand it.
src/cfg_liveness.ml
+
40
−
13
View file @
20afe797
...
@@ -4,24 +4,39 @@ open Cfg
...
@@ -4,24 +4,39 @@ open Cfg
(* Analyse de vivacité *)
(* Analyse de vivacité *)
(* [vars_in_expr e] renvoie l'ensemble des variables qui apparaissent dans [e]. *)
(* [vars_in_expr e] renvoie l'ensemble des variables qui apparaissent dans [e]. *)
let
rec
vars_in_expr
(
e
:
expr
)
=
let
rec
vars_in_expr
(
e
:
expr
)
:
string
Set
.
t
=
(*Type de sortie rajouté par moi*)
(* TODO *)
(* TODO *)
Set
.
empty
match
e
with
|
Ebinop
(
b
,
e1
,
e2
)
->
Set
.
union
(
vars_in_expr
e1
)
(
vars_in_expr
e2
)
(* [live_cfg_node node live_after] renvoie l'ensemble des variables vivantes
|
Eunop
(
u
,
e
)
->
vars_in_expr
e
avant un nœud [node], étant donné l'ensemble [live_after] des variables
|
Eint
i
->
Set
.
empty
vivantes après ce nœud. *)
|
Evar
s
->
Set
.
singleton
s
let
live_cfg_node
(
node
:
cfg_node
)
(
live_after
:
string
Set
.
t
)
=
(* TODO *)
live_after
(* [live_after_node cfg n] renvoie l'ensemble des variables vivantes après le
(* [live_after_node cfg n] renvoie l'ensemble des variables vivantes après le
nœud [n] dans un CFG [cfg]. [lives] est l'état courant de l'analyse,
nœud [n] dans un CFG [cfg]. [lives] est l'état courant de l'analyse,
c'est-à-dire une table dont les clés sont des identifiants de nœuds du CFG et
c'est-à-dire une table dont les clés sont des identifiants de nœuds du CFG et
les valeurs sont les ensembles de variables vivantes avant chaque nœud. *)
les valeurs sont les ensembles de variables vivantes avant chaque nœud. *)
let
live_after_node
cfg
n
(
lives
:
(
int
,
string
Set
.
t
)
Hashtbl
.
t
)
:
string
Set
.
t
=
let
live_after_node
cfg
n
(
lives
:
(
int
,
string
Set
.
t
)
Hashtbl
.
t
)
:
string
Set
.
t
=
(* TODO *)
Set
.
fold
((
fun
x
acc
->
match
Hashtbl
.
find_option
lives
x
with
|
Some
set
->
Set
.
union
acc
set
|
None
->
acc
)
)
(
succs
cfg
n
)
Set
.
empty
(* [live_cfg_node node live_after] renvoie l'ensemble des variables vivantes
avant un nœud [node], étant donné l'ensemble [live_after] des variables
vivantes après ce nœud. *)
let
live_cfg_node
(
node
:
cfg_node
)
(
live_after
:
string
Set
.
t
)
=
(* TODO *)
(* TODO *)
Set
.
empty
match
node
with
|
Cassign
(
s
,
e
,
i
)
->
Set
.
union
(
vars_in_expr
e
)
(
Set
.
diff
live_after
(
Set
.
singleton
s
))
|
Creturn
e
->
vars_in_expr
e
|
Cprint
(
e
,
i
)
->
Set
.
union
(
vars_in_expr
e
)
live_after
|
Ccmp
(
e
,
i1
,
i2
)
->
Set
.
union
(
vars_in_expr
e
)
live_after
|
Cnop
i
->
Set
.
empty
(* [live_cfg_nodes cfg lives] effectue une itération du calcul de point fixe.
(* [live_cfg_nodes cfg lives] effectue une itération du calcul de point fixe.
...
@@ -31,7 +46,16 @@ let live_after_node cfg n (lives: (int, string Set.t) Hashtbl.t) : string Set.t
...
@@ -31,7 +46,16 @@ let live_after_node cfg n (lives: (int, string Set.t) Hashtbl.t) : string Set.t
nœud a changé). *)
nœud a changé). *)
let
live_cfg_nodes
cfg
(
lives
:
(
int
,
string
Set
.
t
)
Hashtbl
.
t
)
=
let
live_cfg_nodes
cfg
(
lives
:
(
int
,
string
Set
.
t
)
Hashtbl
.
t
)
=
(* TODO *)
(* TODO *)
false
List
.
fold
(
fun
acc
(
node_int
,
node
)
->
let
list_out
=
live_after_node
cfg
node_int
lives
in
let
list_in
=
live_cfg_node
node
list_out
in
match
(
Hashtbl
.
find_option
lives
node_int
)
with
|
Some
list_of_nodes
->
if
Set
.
equal
list_in
list_of_nodes
then
acc
else
(
Hashtbl
.
replace
lives
node_int
list_in
;
true
)
|
None
->
Hashtbl
.
replace
lives
node_int
list_in
;
true
)
false
(
List
.
sort
compare
@@
Hashtbl
.
to_list
cfg
)
(* [live_cfg_fun f] calcule l'ensemble des variables vivantes avant chaque nœud
(* [live_cfg_fun f] calcule l'ensemble des variables vivantes avant chaque nœud
du CFG en itérant [live_cfg_nodes] jusqu'à ce qu'un point fixe soit atteint.
du CFG en itérant [live_cfg_nodes] jusqu'à ce qu'un point fixe soit atteint.
...
@@ -39,4 +63,7 @@ let live_cfg_nodes cfg (lives : (int, string Set.t) Hashtbl.t) =
...
@@ -39,4 +63,7 @@ let live_cfg_nodes cfg (lives : (int, string Set.t) Hashtbl.t) =
let
live_cfg_fun
(
f
:
cfg_fun
)
:
(
int
,
string
Set
.
t
)
Hashtbl
.
t
=
let
live_cfg_fun
(
f
:
cfg_fun
)
:
(
int
,
string
Set
.
t
)
Hashtbl
.
t
=
let
lives
=
Hashtbl
.
create
17
in
let
lives
=
Hashtbl
.
create
17
in
(* TODO *)
(* TODO *)
lives
let
rec
boucle_while_cachee
cfg
=
if
live_cfg_nodes
cfg
lives
then
boucle_while_cachee
cfg
else
lives
in
boucle_while_cachee
f
.
cfgfunbody
\ No newline at end of file
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