Skip to content

Commit

Permalink
some code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Dec 19, 2024
1 parent 168af31 commit 8100737
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 50 deletions.
6 changes: 3 additions & 3 deletions example/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ OPTIONS
--no-value
do not display a value for each symbol
-o VAL, --output=VAL (absent=owi-out)
write results to dir
-O VAL (absent=3)
specify which optimization level to use
-o VAL, --outpt=VAL (absent=owi-out)
write results to dir
--optimize
optimize mode
Expand Down
6 changes: 3 additions & 3 deletions example/conc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ OPTIONS
--no-value
do not display a value for each symbol

-o VAL, --outpt=VAL (absent=owi-out)
write results to dir

--optimize
optimize mode

Expand All @@ -90,9 +93,6 @@ OPTIONS
number of workers for symbolic execution. Defaults to the number
of physical cores.

--workspace=VAL (absent=owi-out)
path to the workspace directory

COMMON OPTIONS
--help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of auto,
Expand Down
6 changes: 3 additions & 3 deletions example/sym/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ OPTIONS
--no-value
do not display a value for each symbol

-o VAL, --outpt=VAL (absent=owi-out)
write results to dir

--optimize
optimize mode

Expand All @@ -90,9 +93,6 @@ OPTIONS
number of workers for symbolic execution. Defaults to the number
of physical cores.

--workspace=VAL (absent=owi-out)
path to the workspace directory

COMMON OPTIONS
--help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of auto,
Expand Down
70 changes: 36 additions & 34 deletions src/bin/owi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ open Cmdliner

(* Helpers *)

let existing_non_dir_file =
let existing_file_conv =
let parse s =
let path = Fpath.v s in
match Bos.OS.File.exists path with
| Ok true -> `Ok path
| Ok false -> `Error (Fmt.str "no file '%a'" Fpath.pp path)
| Error (`Msg s) -> `Error s
match Fpath.of_string s with
| Error _ as e -> e
| Ok path -> begin
match Bos.OS.File.exists path with
| Ok true -> Ok path
| Ok false -> Fmt.error_msg "no file '%a'" Fpath.pp path
| Error _ as e -> e
end
in
Arg.conv (parse, Fpath.pp)

let existing_dir_conv =
let parse s =
match Fpath.of_string s with
| Error _ as e -> e
| Ok path -> begin
match Bos.OS.Dir.exists path with
| Ok true -> Ok path
| Ok false -> Fmt.error_msg "no directory '%a'" Fpath.pp path
| Error _ as e -> e
end
in
(parse, Fpath.pp)
Arg.conv (parse, Fpath.pp)

let dir_file =
let parse s = `Ok (Fpath.v s) in
(parse, Fpath.pp)
let path_conv = Arg.conv (Fpath.of_string, Fpath.pp)

let solver_conv =
Arg.conv
Expand Down Expand Up @@ -53,20 +67,16 @@ let deterministic_result_order =

let files =
let doc = "source files" in
let f = existing_non_dir_file in
Arg.(value & pos_all f [] (info [] ~doc))
Arg.(value & pos_all existing_file_conv [] (info [] ~doc))

let source_file =
let doc = "source file" in
Arg.(required & pos 0 (some existing_non_dir_file) None (info [] ~doc))
Arg.(required & pos 0 (some existing_file_conv) None (info [] ~doc))

let out_file =
let doc = "Write output to a file." in
let string_to_path = Arg.conv ~docv:"FILE" (Fpath.of_string, Fpath.pp) in
Arg.(
value
& opt (some string_to_path) None
& info [ "o"; "output" ] ~docv:"FILE" ~doc )
value & opt (some path_conv) None & info [ "o"; "output" ] ~docv:"FILE" ~doc )

let no_stop_at_failure =
let doc = "do not stop when a program failure is encountered" in
Expand Down Expand Up @@ -128,8 +138,8 @@ let workers =
& info [ "workers"; "w" ] ~doc ~absent:"n" )

let workspace =
let doc = "path to the workspace directory" in
Arg.(value & opt dir_file (Fpath.v "owi-out") & info [ "workspace" ] ~doc)
let doc = "write results to dir" in
Arg.(value & opt path_conv (Fpath.v "owi-out") & info [ "outpt"; "o" ] ~doc)

(* owi c *)

Expand All @@ -144,20 +154,17 @@ let c_cmd =
Arg.(value & opt int 32 & info [ "arch"; "m" ] ~doc)
and+ property =
let doc = "property file" in
Arg.(
value & opt (some existing_non_dir_file) None & info [ "property" ] ~doc )
Arg.(value & opt (some existing_file_conv) None & info [ "property" ] ~doc)
and+ includes =
let doc = "headers path" in
Arg.(value & opt_all dir_file [] & info [ "I" ] ~doc)
Arg.(value & opt_all existing_dir_conv [] & info [ "I" ] ~doc)
and+ opt_lvl =
let doc = "specify which optimization level to use" in
Arg.(value & opt string "3" & info [ "O" ] ~doc)
and+ testcomp =
let doc = "test-comp mode" in
Arg.(value & flag & info [ "testcomp" ] ~doc)
and+ workspace =
let doc = "write results to dir" in
Arg.(value & opt string "owi-out" & info [ "output"; "o" ] ~doc)
and+ workspace
and+ concolic =
let doc = "concolic mode" in
Arg.(value & flag & info [ "concolic" ] ~doc)
Expand Down Expand Up @@ -323,16 +330,11 @@ let replay_cmd =
and+ unsafe
and+ optimize
and+ replay_file =
let parse s =
let path = Fpath.v s in
match Bos.OS.File.exists path with
| Ok true -> Ok path
| Ok false -> Error (`Msg (Fmt.str "no file '%a'" Fpath.pp path))
| Error _e as e -> e
in
let replay_file = Cmdliner.Arg.conv (parse, Fpath.pp) in
let doc = "Which replay file to use" in
Arg.(required & opt (some replay_file) None & info [ "replay-file" ] ~doc)
Arg.(
required
& opt (some existing_file_conv) None
& info [ "replay-file" ] ~doc )
and+ source_file in
Cmd_replay.cmd ~profiling ~debug ~unsafe ~optimize ~replay_file ~source_file

Expand Down
1 change: 0 additions & 1 deletion src/cmd/cmd_c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ let cmd ~debug ~arch ~property ~testcomp:_ ~workspace ~workers ~opt_lvl
~includes ~files ~profiling ~unsafe ~optimize ~no_stop_at_failure ~no_value
~no_assert_failure_expression_printing ~deterministic_result_order ~fail_mode
~concolic ~eacsl ~solver : unit Result.t =
let workspace = Fpath.v workspace in
let includes = libc_location @ includes in
let* (_exists : bool) = OS.Dir.create ~path:true workspace in
let* files = eacsl_instrument eacsl debug ~includes files in
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cmd_c.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ val cmd :
-> arch:int
-> property:Fpath.t option
-> testcomp:bool
-> workspace:string
-> workspace:Fpath.t
-> workers:int
-> opt_lvl:string
-> includes:Fpath.t list
Expand Down
6 changes: 1 addition & 5 deletions src/symbolic/symbolic_global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
(* Copyright © 2021-2024 OCamlPro *)
(* Written by the Owi programmers *)

module ITbl = Hashtbl.Make (struct
include Int

let hash x = x
end)
module ITbl = Hashtbl.Make (Int)

type t =
{ mutable value : Symbolic_value.t
Expand Down

0 comments on commit 8100737

Please sign in to comment.