Fixes defined variables, fixes live variables, implements reduces registers, fixes risc semantic

This commit is contained in:
elvis
2024-12-27 21:11:38 +01:00
parent f1b4c3a17d
commit 3be05222ab
15 changed files with 866 additions and 214 deletions

View File

@ -5,15 +5,11 @@ let colorred s =
let () =
let program = "
def main with input c output m as
a := 0;
b := a + 1;
c := c + b;
a := b * 2;
if a < 3 then
c := 4
else
c := 6
def main with input in output out as
out := in;
a := 1;
b := 2;
c := a + a;
"
in
@ -39,8 +35,12 @@ def main with input c output m as
(* Printf.printf "%s\n%a" (colorred "Analysis CFG is") DefinedVariables.DVCfg.pp analysiscfg; *)
(* Printf.printf "%s\n" (colorred "Undefined Variables are:"); *)
(* List.iter (fun v -> Printf.printf "%a, " DefinedVariables.Variable.pp v) (DefinedVariables.check_undefined_variables analysiscfg); *)
(* Printf.printf "%s" (colorred "Undefined Variables are:"); *)
(* ( *)
(* match DefinedVariables.check_undefined_variables analysiscfg with *)
(* | None -> Printf.printf " none"; *)
(* | Some l -> Printf.printf " %a" DefinedVariables.Variable.pplist l; *)
(* ); *)
(* Printf.printf "\n"; *)
let convertedrisccfg = DefinedVariables.compute_cfg analysiscfg in
@ -48,20 +48,32 @@ def main with input c output m as
(* Printf.printf "%s\n%a" (colorred "Converted RISC after analysis CFG is") CfgRISC.RISCCfg.pp convertedrisccfg; *)
let analysiscfg = LiveVariables.compute_live_variables convertedrisccfg in
(* let analysiscfg = LiveVariables.compute_live_variables convertedrisccfg in *)
Printf.printf "%s\n%a" (colorred "Analysis CFG is") LiveVariables.DVCfg.pp analysiscfg;
(* Printf.printf "%s\n%a" (colorred "Live Analysis CFG is") LiveVariables.DVCfg.pp analysiscfg; *)
(* let convertedrisccfg = LiveVariables.compute_cfg analysiscfg in *)
(* Printf.printf "%s\n%a" (colorred "Converted RISC with no analysis CFG is") CfgRISC.RISCCfg.pp convertedrisccfg; *)
(* let convertedrisccfg = LiveVariables.compute_cfg (LiveVariables.optimize_cfg analysiscfg) in *)
(* Printf.printf "%s\n%a" (colorred "Converted RISC after analysis CFG is") CfgRISC.RISCCfg.pp convertedrisccfg; *)
let convertedrisccfg = ReduceRegisters.reduceregisters 4 convertedrisccfg in
Printf.printf "%s\n%a" (colorred "Converted RISC after reducing registers CFG is") CfgRISC.RISCCfg.pp convertedrisccfg;
let convertedrisccfg = LiveVariables.optimize_cfg analysiscfg |> LiveVariables.compute_cfg in
(* ---------------------------------- *)
let _risc = RISC.convert convertedrisccfg in
let risc = RISC.convert convertedrisccfg in
(* Printf.printf "%s\n%a" (colorred "RISC code is") RISC.RISCAssembly.pp risc; *)
Printf.printf "%s\n%a" (colorred "RISC code is") RISC.RISCAssembly.pp risc;
(* let computerisc = RISCSemantics.reduce risc in *)
let computerisc = RISCSemantics.reduce risc in
(* Printf.printf "%s\n%d\n" (colorred "Output of RISC code is") computerisc; *)
Printf.printf "%s\n%d\n" (colorred "Output of RISC code is") computerisc;
()