diff --git a/Sujet.pdf b/Sujet.pdf index 3325560c37f3688b60d6c296eec867d6c4c418e3..d0a333f6ea554d0ac0bd55f448225e38f314a9b0 100644 Binary files a/Sujet.pdf and b/Sujet.pdf differ diff --git a/src/cfg.ml b/src/cfg.ml index a174394316f394d4f1b9d8d4bd382d2e99d462e0..3df451950df479a00cda85835f38178410c72b4b 100644 --- a/src/cfg.ml +++ b/src/cfg.ml @@ -26,18 +26,20 @@ type cfg_fun = { type cprog = cfg_fun prog -(* [succs cfg n] gives the successors of a node [n] in a CFG [cfg]. *) +(* [succs cfg n] donne l'ensemble des successeurs d'un nœud [n] dans un CFG + [cfg]. *) let succs cfg n = match Hashtbl.find_option cfg n with - | None -> [] + | None -> Set.empty | Some (Cprint (_, s)) - | Some (Cassign (_, _, s)) -> [s] - | Some (Creturn _) -> [] - | Some (Ccmp (_, s1, s2)) -> [s1;s2] - | Some (Cnop s) -> [s] + | Some (Cassign (_, _, s)) -> Set.singleton s + | Some (Creturn _) -> Set.empty + | Some (Ccmp (_, s1, s2)) -> Set.of_list [s1;s2] + | Some (Cnop s) -> Set.singleton s -(* [preds n] gives the list of predecessors of a node [n]. *) +(* [preds cfg n] donne l'ensemble des prédécesseurs d'un nœud [n] dans un CFG [cfg] + *) let preds cfgfunbody n = Hashtbl.fold (fun m m' acc -> match m' with @@ -73,21 +75,3 @@ let rec size_instr (i: cfg_node) : int = let size_fun f = Hashtbl.fold (fun k v acc -> acc + size_instr v) f 0 -let fixpoint - (transfer: (int, cfg_node) Hashtbl.t -> (int, 'a) Hashtbl.t -> int -> 'a) - (init: (int, cfg_node) Hashtbl.t -> int -> cfg_node -> 'a) - (cfg: (int, cfg_node) Hashtbl.t) : - (int, 'a) Hashtbl.t = - let res = Hashtbl.map (fun k v -> init cfg k v) cfg in - let iter res = - Hashtbl.fold (fun n oldstate changed -> - let newstate = transfer cfg res n in - Hashtbl.replace res n newstate; - changed || not (Set.equal newstate oldstate) - ) res false in - let rec fix () = - if iter res - then fix () - else () in - fix (); - res diff --git a/src/elang_run.ml b/src/elang_run.ml index 96c070fac5f5d7e28824f7b56a8eec6ba2f43f6f..f955cd1f2913dc47d20389d585da570bc124145f 100644 --- a/src/elang_run.ml +++ b/src/elang_run.ml @@ -85,8 +85,7 @@ let eval_eprog oc (ep: eprog) (memsize: int) (params: int list) : int option res = let st = init_state memsize in find_function ep "main" >>= fun f -> - (* trim the parameter list to only take as many as required by the function. - *) + (* ne garde que le nombre nécessaire de paramètres pour la fonction "main". *) let n = List.length f.funargs in let params = take n params in eval_efun oc st f "main" params >>= fun (v, st) -> diff --git a/src/main.ml b/src/main.ml index 21341671187ca08e0d94296534af633244672b00..f53ff78eda9922bf30423bbcb81deffeca546a54 100644 --- a/src/main.ml +++ b/src/main.ml @@ -161,7 +161,7 @@ let dump file dumpf p additional_command = (Format.formatter_of_out_channel oc, fun () -> close_out oc) in dumpf oc p; close (); - additional_command file () + if file <> "-" then additional_command file () end diff --git a/src/rtl_gen.ml b/src/rtl_gen.ml index c8e274e4537e9e0332ea55a31e4c9bfaa589a836..e9b62e058e82d8483fd940ed88e0f01944d63142 100644 --- a/src/rtl_gen.ml +++ b/src/rtl_gen.ml @@ -25,10 +25,9 @@ open Utils *) let find_var (next_reg, var2reg) v = - begin match List.assoc_opt v var2reg with + match List.assoc_opt v var2reg with | Some r -> (r, next_reg, var2reg) | None -> (next_reg, next_reg + 1, assoc_set var2reg v next_reg) - end (* [rtl_instrs_of_cfg_expr (next_reg, var2reg) e] construit une liste d'instructions RTL correspondant à l'évaluation d'une expression E. @@ -52,9 +51,12 @@ let is_cmp_op = | Ecne -> Some Rcne | _ -> None -let is_cmp (e: expr) = +let rtl_cmp_of_cfg_expr (e: expr) = match e with - | Ebinop (b, e1, e2) -> (match is_cmp_op b with | None -> (Rcne, e, Eint 0) | Some rop -> (rop, e1, e2)) + | Ebinop (b, e1, e2) -> + (match is_cmp_op b with + | None -> (Rcne, e, Eint 0) + | Some rop -> (rop, e1, e2)) | _ -> (Rcne, e, Eint 0)