Defined variables module, not fully working

This commit is contained in:
elvis
2024-12-16 05:15:33 +01:00
parent 590123d988
commit 25f9f12525
12 changed files with 435 additions and 50 deletions

View File

@ -5,10 +5,13 @@ let colorred s =
let () =
let program = "
def main with input a output b as
b := 1;
for (i := 1, i <= a, i := i + 1) do
b := b * i;
def main with input n output result as
result := 0;
s := 0;
while (0 == ((n - 1) / (2 ^ s)) % 2) do (
s := s + 1
);
"
in
@ -34,17 +37,22 @@ def main with input a output b as
Printf.printf "%s\n%a" (colorred "Analysis CFG is") DefinedVariables.DVCfg.pp analysiscfg;
Printf.printf "%s%b\n" (colorred "Analysis CFG defined variables: ") (DefinedVariables.check_defined_variables analysiscfg);
Printf.printf "%s\n" (colorred "Undefined Variables are:");
List.iter (fun v -> Printf.printf "%a, " DefinedVariables.Variable.pp v) (DefinedVariables.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 risc = RISC.convert convertedrisccfg 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
(* let computerisc = RISCSemantics.reduce risc in *)
(* Printf.printf "%s\n%d\n" (colorred "Output of RISC code is") computerisc; *)