Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subcommands and man pages #15

Merged
merged 10 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions bin/commands/cmd_execute.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
open Whilloc
open Utils
module C_Choice = ListChoice.Make (EvalConcrete.M) (HeapConcrete.M)
module SAF_Choice = ListChoice.Make (EvalSymbolic.M) (HeapArrayFork.M)
module SAITE_Choice = ListChoice.Make (EvalSymbolic.M) (HeapArrayITE.M)
module ST_Choice = ListChoice.Make (EvalSymbolic.M) (HeapTree.M)
module SOPL_Choice = ListChoice.Make (EvalSymbolic.M) (HeapOpList.M)
module C = Interpreter.Make (EvalConcrete.M) (DFS.M) (HeapConcrete.M) (C_Choice)

module SAF =
Interpreter.Make (EvalSymbolic.M) (DFS.M) (HeapArrayFork.M) (SAF_Choice)

module SAITE =
Interpreter.Make (EvalSymbolic.M) (DFS.M) (HeapArrayITE.M) (SAITE_Choice)

module ST = Interpreter.Make (EvalSymbolic.M) (DFS.M) (HeapTree.M) (ST_Choice)

module SOPL =
Interpreter.Make (EvalSymbolic.M) (DFS.M) (HeapOpList.M) (SOPL_Choice)

type options = {
input : Fpath.t;
mode : string;
julianayang777 marked this conversation as resolved.
Show resolved Hide resolved
output : Fpath.t option;
verbose : bool;
}

let run ?(no_values = false) input mode =
let start = Sys.time () in
print_header ();
let program = input |> read_file |> parse_program |> create_program in
Printf.printf "Input file: %s\nExecution mode: %s\n\n" input mode;
(match mode with
| "c" ->
let rets = C.interpret program in
List.iter
(fun (out, _) ->
Format.printf "Outcome: %a@." (Outcome.pp ~no_values) out)
rets
| "saf" ->
let rets = SAF.interpret program in
List.iter
(fun (out, _) ->
Format.printf "Outcome: %a@." (Outcome.pp ~no_values) out)
rets
| "saite" ->
let rets = SAITE.interpret program in
List.iter
(fun (out, _) ->
Format.printf "Outcome: %a@." (Outcome.pp ~no_values) out)
rets
| "st" ->
let rets = ST.interpret program in
List.iter
(fun (out, _) ->
Format.printf "Outcome: %a@." (Outcome.pp ~no_values) out)
rets
| "sopl" ->
let rets = SOPL.interpret program in
List.iter
(fun (out, _) ->
Format.printf "Outcome: %a@." (Outcome.pp ~no_values) out)
rets
| _ -> assert false)
(* ;Printf.printf "Total Execution time of Solver: %f\n" (!Translator.solver_time) *);
if !Utils.verbose then
Printf.printf "Total Execution time: %f\n" (Sys.time () -. start)

let main (opts : options) =
Utils.verbose := opts.verbose;
run (Fpath.to_string opts.input) opts.mode
48 changes: 48 additions & 0 deletions bin/commands/cmd_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
open Whilloc

exception Timeout

type options = {
inputs : Fpath.t;
mode : string;
julianayang777 marked this conversation as resolved.
Show resolved Hide resolved
timeout : float option;
verbose : bool;
}

let _max_timeout = ref 0.0
let unset () = Sys.set_signal Sys.sigalrm Sys.Signal_ignore

let set =
let raise n = if n = -2 then raise Timeout in
fun () ->
Sys.set_signal Sys.sigalrm (Sys.Signal_handle raise);
ignore
@@ (Unix.setitimer Unix.ITIMER_REAL
{ Unix.it_interval = 0.; Unix.it_value = !_max_timeout }
: Unix.interval_timer_status)

let run_single mode file =
try
Fun.protect ~finally:unset (fun () ->
set ();
try Cmd_execute.run file mode ~no_values:true with
| Timeout ->
Printf.printf
"Timeout occurred while processing file: %s (Max Timeout: %f \
seconds)\n"
file !_max_timeout
(* maybe is not the best way to treat exceptions *)
| ex ->
Printf.printf "Fatal error: exception %s\n" (Printexc.to_string ex))
with Timeout -> Printf.printf "General timeout\n"

let run (opts : options) : unit =
let files = Dir.get_files opts.inputs in
List.iter (run_single opts.mode)
(List.map Fpath.to_string (List.sort Fpath.compare files));
Printf.printf "Total number of files tested: %d\n" (List.length files)

let main (opts : options) =
_max_timeout := Option.value ~default:0.0 opts.timeout;
Utils.verbose := opts.verbose;
run opts
60 changes: 0 additions & 60 deletions bin/concolic.ml

This file was deleted.

34 changes: 34 additions & 0 deletions bin/docs/doc_execute.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
open Cmdliner

let doc = "Executes a program concretely or symbolically depending on the mode"
let sdocs = Manpage.s_common_options

let description =
[
"Given a program in the simple \"While\" language, executes the program \
concretely or symbolically depending on the mode.";
"To run the program concretely, use the mode 'c'.";
"To run the program symbolically, there are several modes to choose from. \
These modes differs on the memory model that it uses to execute the \
program.";
]

let man =
[
`S Manpage.s_description;
`P (List.nth description 0);
`P (List.nth description 1);
`P (List.nth description 2);
]

let man_xrefs = []

let cmd_options input mode output verbose : Cmd_execute.options =
{ input; mode; output; verbose }

let options =
Term.(
const cmd_options $ Options.File.input $ Options.mode $ Options.File.output
$ Options.verbose)

let term = Term.(const Cmd_execute.main $ options)
37 changes: 37 additions & 0 deletions bin/docs/doc_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
open Cmdliner

let doc =
"Executes all programs with the extension .wl in the given directory and \
mode."

let sdocs = Manpage.s_common_options

let description =
[
"Executes all programs with the extension .wl in the given directory and \
mode.";
"The difference of running programs using this command and command 'wl \
execute' is that this command will run all programs in the given \
directory. In addition, this command have the option to set a time limit \
for each program's execution. When the time limit is exceeded, the \
execution is killed.";
]

let man =
[
`S Manpage.s_description;
`P (List.nth description 0);
`P (List.nth description 1);
]

let man_xrefs = [ `Page ("wl execute", 2) ]

let cmd_options inputs mode timeout verbose : Cmd_test.options =
{ inputs; mode; timeout; verbose }

let options =
Term.(
const cmd_options $ Options.File.inputs $ Options.mode $ Options.timeout
$ Options.verbose)

let term = Term.(const Cmd_test.main $ options)
6 changes: 4 additions & 2 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(include_subdirs unqualified)

(executable
(public_name wl)
(name main)
(modules main)
(libraries whilloc))
(modules main options dir cmd_execute cmd_test doc_execute doc_test)
(libraries whilloc cmdliner bos))
Loading