blob: 08bfe91091cf0db61560c48120fe017a82199c07 (
plain) (
tree)
|
|
open Ast
module Interpret = Interpret.I
(* command line options *)
let dump = ref false
let dumprn = ref false
let test = ref false
let vtest = ref false
let ifile = ref ""
let usage = "usage: analyzer [options] file.scade"
let options = [
"--dump", Arg.Set dump, "Dump program source.";
"--dump-rn", Arg.Set dumprn, "Dump program source, after renaming.";
"--vtest", Arg.Set vtest, "Verbose testing.";
"--test", Arg.Set test, "Simple testing.";
]
let do_test_interpret prog verbose =
let s0 = Interpret.init_state prog "test" in
if verbose then begin
Format.printf "Init state:@.";
Interpret.print_state Format.std_formatter s0;
end;
let rec it i st =
let next_st, out =
Interpret.step st
["i", Interpret.int_value i]
in
if verbose then begin
Format.printf "@.> Step %d:@." i;
Interpret.print_state Format.std_formatter st;
Format.printf "Outputs:@.";
List.iter
(fun (k, v) -> Format.printf "%s = %s@."
k (Interpret.str_repr_of_val v))
out;
end else begin
Format.printf "%d. %s %s %s@." i
(Interpret.str_repr_of_val (List.assoc "a" out))
(Interpret.str_repr_of_val (List.assoc "b" out))
(Interpret.str_repr_of_val (List.assoc "c" out));
end;
if not (Interpret.as_bool (List.assoc "exit" out)) then
it (i+1) next_st
in
it 0 s0
let () =
Arg.parse options (fun f -> ifile := f) usage;
if !ifile = "" then begin
Format.eprintf "No input file...@.";
exit 1
end;
try
let prog = File_parser.parse_file !ifile in
if !dump then Ast_printer.print_prog Format.std_formatter prog;
let prog = Rename.rename_prog prog in
if !dumprn then Ast_printer.print_prog Format.std_formatter prog;
let prog_f = Formula.eliminate_not (Transform.f_of_prog prog "test") in
Formula_printer.print_expr Format.std_formatter prog_f;
Format.printf "@.";
let prog_f_cl = Formula.conslist_of_f prog_f in
Formula_printer.print_conslist Format.std_formatter prog_f_cl;
if !vtest then do_test_interpret prog true
else if !test then do_test_interpret prog false;
with
| Util.NoLocError e -> Format.eprintf "Error: %s@." e
| Util.LocError(l, e) ->
Format.eprintf "Error: %s@." e;
List.iter
(fun loc -> Format.eprintf "At: %s@." (Ast_printer.string_of_extent loc))
l
|