Files
lci/bin/main.ml
2024-12-21 02:16:04 +01:00

68 lines
2.0 KiB
OCaml

open MiniImp
let colorred s =
"\027[31m" ^ s ^ "\027[0m"
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
"
in
(* Printf.printf "%s\n%s\n" (colorred "Program is") program; *)
let get_result x = Lexing.from_string x |> Parser.prg Lexer.lex in
let p = get_result program in
(* Format.printf "%s\n%a\n@?" (colorred "AST is") Types.pp_p_exp p; *)
let convertedcfg = CfgImp.convert_io 10 p in
(* Printf.printf "%s\n%a" (colorred "Converted CFG is") CfgImp.SSCfg.pp convertedcfg; *)
let convertedrisccfg = CfgRISC.convert convertedcfg in
Printf.printf "%s\n%a" (colorred "Converted RISC CFG is") CfgRISC.RISCCfg.pp convertedrisccfg;
(* ---------------------------------- *)
let analysiscfg = DefinedVariables.compute_defined_variables convertedrisccfg in
(* 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 "\n"; *)
let convertedrisccfg = DefinedVariables.compute_cfg analysiscfg in
(* Printf.printf "%s\n%a" (colorred "Converted RISC after analysis CFG is") CfgRISC.RISCCfg.pp convertedrisccfg; *)
let analysiscfg = LiveVariables.compute_live_variables convertedrisccfg in
Printf.printf "%s\n%a" (colorred "Analysis CFG is") LiveVariables.DVCfg.pp analysiscfg;
let convertedrisccfg = LiveVariables.optimize_cfg analysiscfg |> LiveVariables.compute_cfg in
(* ---------------------------------- *)
let _risc = RISC.convert convertedrisccfg in
(* Printf.printf "%s\n%a" (colorred "RISC code is") RISC.RISCAssembly.pp risc; *)
(* let computerisc = RISCSemantics.reduce risc in *)
(* Printf.printf "%s\n%d\n" (colorred "Output of RISC code is") computerisc; *)
()