Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sougou Fadel
infosec-ecomp
Commits
ae855e53
Commit
ae855e53
authored
Mar 04, 2020
by
Wilke Pierre
Browse files
Plus de sujet, commentaires en français dans elang_run, différences mineures...
parent
510c85a7
Changes
6
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
ae855e53
...
...
@@ -7,6 +7,7 @@ tests/**/*.cfg3
tests/**/*.e.dump
tests/**/*.e.html
tests/**/*.exe
tests/**/*.json
tests/**/*.lex
tests/**/*.linear
tests/**/*.linear1
...
...
Sujet.pdf
View file @
ae855e53
No preview for this file type
src/elang_run.ml
View file @
ae855e53
...
...
@@ -24,36 +24,35 @@ let eval_unop (u: unop) : int -> int =
let
rec
eval_eexpr
st
(
e
:
expr
)
:
int
res
=
Error
"eval_eexpr not implemented yet."
(* [eval_einstr oc st ins] evaluates the instruction [ins] in starting state
[st].
(* [eval_einstr oc st ins] évalue l'instrution [ins] en partant de l'état [st].
Th
e param
eter
[oc]
, unused for now, is a
n output channel
in which
f
u
nction
s
like "print" will write their output, when we add them
.
L
e param
ètre
[oc]
est u
n
"
output channel
", dans lequel la
f
o
nction
"print"
écrit sa sortie, au moyen de l'instruction [Format.fprintf]
.
This
f
u
nction re
turns
[(ret, st')] :
Cette
f
o
nction re
nvoie
[(ret, st')] :
- [ret] is an [int option]. [Some v] should be returned when a return
instruction is met. [None] means that execution should continue.
- [ret] est de type [int option]. [Some v] doit être renvoyé lorsqu'une
instruction [return] est évaluée. [None] signifie qu'aucun [return] n'a eu
lieu et que l'exécution doit continuer.
- [st'] is the updated state.
*)
- [st'] est l'état mis à jour. *)
let
rec
eval_einstr
oc
(
st
:
int
state
)
(
ins
:
instr
)
:
(
int
option
*
int
state
)
res
=
Error
"eval_einstr not implemented yet."
(* [eval_efun oc st f fname vargs]
e
valu
ates
f
u
nction [f] (
whose name is
[fname])
starting in s
tat
e
[st],
with
arguments
given in
[vargs].
(* [eval_efun oc st f fname vargs]
é
valu
e la
f
o
nction [f] (
dont le nom est
[fname])
en partant de l'é
tat [st],
avec les
arguments [vargs].
This returns a pair (ret, st') with the same meaning as for [eval_einstr].
*)
Cette fonction renvoie un couple (ret, st') avec la même signification que
pour [eval_einstr].
*)
let
eval_efun
oc
(
st
:
int
state
)
({
funargs
;
funbody
}
:
efun
)
(
fname
:
string
)
(
vargs
:
int
list
)
:
(
int
option
*
int
state
)
res
=
(*
A function's
environment
(mapping from local
variables
to v
al
u
es
) is local
and a
f
u
nction
call should not modify the caller's variables. Hence, we
save the caller's environment in [env_
save
], call the function in a cle
an
environment with only its arguments set, and restore the caller's
environme
nt. *)
(*
L'
environ
ne
ment
d'une fonction (mapping des
variables
loc
ales
vers leurs
valeurs) est local et un appel de
f
o
nction
ne devrait pas modifier les
variables de l'appelant. Donc, on
sa
u
ve
garde l'environnement de l'appel
an
t
dans [env_save], on appelle la fonction dans un environnement propre (Avec
seulement ses arguments), puis on restore l'environnement de l'appela
nt. *)
let
env_save
=
Hashtbl
.
copy
st
.
env
in
let
env
=
Hashtbl
.
create
17
in
match
List
.
iter2
(
fun
a
v
->
Hashtbl
.
replace
env
a
v
)
funargs
vargs
with
...
...
@@ -66,19 +65,22 @@ let eval_efun oc (st: int state) ({ funargs; funbody}: efun)
fname
(
List
.
length
vargs
)
(
List
.
length
funargs
)
)
(* [eval_eprog oc ep memsize params]
e
valu
ates a complete program [ep], with
(* [eval_eprog oc ep memsize params]
é
valu
e un programme complet [ep], avec les
arguments [params].
The [memsize] parameter gives the size of the memory this program will be run
with. This is not useful for now (our programs do not use memory), but it
will when we add memory allocation to our programs.
Le paramètre [memsize] donne la taille de la mémoire dont ce programme va
disposer. Ce n'est pas utile tout de suite (nos programmes n'utilisent pas de
mémoire), mais ça le sera lorsqu'on ajoutera de l'allocation dynamique dans
nos programmes.
Returns:
- [OK (Some v)] when the function evaluation went without problems and
resulted in integer value [v].
- [OK None] when the function evaluation finished without returning a value.
- [Error msg] when an error has occured.
*)
Renvoie:
- [OK (Some v)] lorsque l'évaluation de la fonction a lieu sans problèmes et renvoie une valeur [v].
- [OK None] lorsque l'évaluation de la fonction termine sans renvoyer de valeur.
- [Error msg] lorsqu'une erreur survient.
*)
let
eval_eprog
oc
(
ep
:
eprog
)
(
memsize
:
int
)
(
params
:
int
list
)
:
int
option
res
=
let
st
=
init_state
memsize
in
...
...
src/main.ml
View file @
ae855e53
...
...
@@ -85,7 +85,7 @@ let speclist =
(
"-m32"
,
Arg
.
Unit
(
fun
_
->
Archi
.
archi
:=
A32
)
,
"32bit mode"
);
(
"-f"
,
Arg
.
String
(
fun
s
->
input_file
:=
Some
s
)
,
"file to compile"
);
(
"-alloc-order-ts"
,
Arg
.
Unit
(
fun
_
->
Options
.
alloc_order_st
:=
false
)
,
"Allocate t regs before s regs"
);
(
"-json"
,
Arg
.
S
e
t
output_json
,
"Output JSON summary"
);
(
"-json"
,
Arg
.
St
ring
(
fun
s
->
output_json
:=
s
)
,
"Output JSON summary"
);
(
"-nostart"
,
Arg
.
Set
nostart
,
"Don't output _start code."
);
(
"-nostats"
,
Arg
.
Set
nostats
,
"Don't output stats."
);
(
"-nomul"
,
Arg
.
Unit
(
fun
_
->
has_mul
:=
false
)
,
"Target architecture without mul instruction."
);
...
...
@@ -358,9 +358,7 @@ let _ =
end
;
if
!
output_json
then
begin
let
json_output_string
=
let
open
Yojson
in
let
jstring_of_ostring
o
=
match
o
with
...
...
@@ -380,6 +378,10 @@ let _ =
(
"data"
,
data
)
]
)
!
results
)
in
Format
.
printf
"%s
\n
"
(
Yojson
.
pretty_to_string
j
);
end
;
(
Yojson
.
pretty_to_string
j
)
in
dump
(
Some
!
output_json
)
(
fun
oc
p
->
Format
.
fprintf
oc
"%s
\n
"
p
)
json_output_string
(
fun
_
()
->
()
);
make_report
input
report
()
src/options.ml
View file @
ae855e53
...
...
@@ -24,7 +24,7 @@ let riscv_run = ref false
let
show
=
ref
false
let
params
:
int
list
ref
=
ref
[]
let
input_file
:
string
option
ref
=
ref
None
let
output_json
=
ref
false
let
output_json
:
string
ref
=
ref
"-"
let
nostart
=
ref
false
let
nostats
=
ref
false
let
has_mul
=
ref
true
...
...
tests/test.py
View file @
ae855e53
...
...
@@ -56,7 +56,7 @@ if(args.verbose >= 1):
# construct the set of commands to be launched, one per file
cmds
=
[]
for
f
in
args
.
file
:
cmd
=
"../main.native -json -f {} {} {} -- {}"
.
format
(
f
,
cmd
=
"../main.native -json
{}.json
-f {} {} {} -- {}"
.
format
(
f
,
f
,
" "
.
join
(
map
(
lambda
s
:
"-"
+
s
,
args
.
passes
)),
" "
.
join
(
unknown_args
),
" "
.
join
(
args
.
args
)
...
...
@@ -142,13 +142,15 @@ class CommandExecutor(Thread):
process
=
self
.
run_capture_output_interruptible
(
c
)
self
.
stdout
=
process
[
'stdout'
].
decode
(
'utf8'
)
self
.
stderr
=
process
[
'stderr'
].
decode
(
'utf8'
)
json_file_name
=
self
.
f
+
".json"
j
=
[]
try
:
j
=
json
.
loads
(
self
.
stdout
)
except
:
j
.
append
({
'retval'
:
-
1
,
'output'
:
display_verbatim
(
self
.
stdout
),
'error'
:
display_verbatim
(
self
.
stderr
)})
with
open
(
json_file_name
,
'r'
)
as
jsonfile
:
try
:
j
=
json
.
load
(
jsonfile
)
except
:
j
.
append
({
'retval'
:
-
1
,
'output'
:
display_verbatim
(
self
.
stdout
),
'error'
:
display_verbatim
(
self
.
stderr
)})
old_ret
=
None
old_out
=
None
old_err
=
None
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment