Skip to content

Commit f6ddbcb

Browse files
committed
model with entry point: replay
1 parent 86c2294 commit f6ddbcb

File tree

13 files changed

+88
-12
lines changed

13 files changed

+88
-12
lines changed

doc/src/manpages/owi-c.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ OPTIONS
5656
given this is used as a prefix and the ouputed files would have
5757
PREFIX_%d.
5858
59+
--model-with-entry-point
60+
Add the entry point in the generated model for easier replay.
61+
5962
--no-assert-failure-expression-printing
6063
do not display the expression in the assert failure
6164

doc/src/manpages/owi-conc.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ OPTIONS
4141
given this is used as a prefix and the ouputed files would have
4242
PREFIX_%d.
4343

44+
--model-with-entry-point
45+
Add the entry point in the generated model for easier replay.
46+
4447
--no-assert-failure-expression-printing
4548
do not display the expression in the assert failure
4649

doc/src/manpages/owi-cpp.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ OPTIONS
5151
given this is used as a prefix and the ouputed files would have
5252
PREFIX_%d.
5353

54+
--model-with-entry-point
55+
Add the entry point in the generated model for easier replay.
56+
5457
--no-assert-failure-expression-printing
5558
do not display the expression in the assert failure
5659

doc/src/manpages/owi-rust.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ OPTIONS
5151
given this is used as a prefix and the ouputed files would have
5252
PREFIX_%d.
5353

54+
--model-with-entry-point
55+
Add the entry point in the generated model for easier replay.
56+
5457
--no-assert-failure-expression-printing
5558
do not display the expression in the assert failure
5659

doc/src/manpages/owi-sym.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ OPTIONS
4141
given this is used as a prefix and the ouputed files would have
4242
PREFIX_%d.
4343

44+
--model-with-entry-point
45+
Add the entry point in the generated model for easier replay.
46+
4447
--no-assert-failure-expression-printing
4548
do not display the expression in the assert failure
4649

doc/src/manpages/owi-zig.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ OPTIONS
4848
given this is used as a prefix and the ouputed files would have
4949
PREFIX_%d.
5050

51+
--model-with-entry-point
52+
Add the entry point in the generated model for easier replay.
53+
5154
--no-assert-failure-expression-printing
5255
do not display the expression in the assert failure
5356

src/cmd/cmd_replay.ml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,19 @@ let run_file ~unsafe ~optimize ~entry_point ~invoke_with_symbols filename model
261261

262262
let cmd ~unsafe ~optimize ~replay_file ~source_file ~entry_point
263263
~invoke_with_symbols =
264+
let file_ext = Fpath.get_ext replay_file in
264265
let* parse_fn =
265-
let ext = Fpath.get_ext replay_file in
266-
match String.lowercase_ascii ext with
266+
match String.lowercase_ascii file_ext with
267267
| ".json" -> Ok Symbol_scope.model_of_json
268268
| ".scfg" -> Ok Symbol_scope.model_of_scfg
269-
| _ -> Error (`Unsupported_file_extension ext)
269+
| _ -> Error (`Unsupported_file_extension file_ext)
270270
in
271271
let* file_content = Bos.OS.File.read replay_file in
272-
let* model =
272+
let* model_entry_point, model =
273273
match parse_fn file_content with
274274
| Error (`Msg msg) -> Error (`Invalid_model msg)
275275
| Error err -> Error err
276-
| Ok model ->
276+
| Ok (entry_point, model) ->
277277
let bindings = Smtml.Model.get_bindings model in
278278
let+ model =
279279
list_map
@@ -298,8 +298,13 @@ let cmd ~unsafe ~optimize ~replay_file ~source_file ~entry_point
298298
(Fmt.str "unexpected value type: %a" Smtml.Value.pp v) ) )
299299
bindings
300300
in
301-
Array.of_list model
301+
(entry_point, Array.of_list model)
302302
in
303+
let entry_point =
304+
if Option.is_none entry_point then model_entry_point else entry_point
305+
in
306+
Logs.debug (fun m -> m "%s" (Option.value ~default:"na" entry_point));
307+
Logs.debug (fun m -> m "%s" (Option.value ~default:"na" model_entry_point));
303308
let+ () =
304309
run_file ~unsafe ~optimize ~entry_point ~invoke_with_symbols source_file
305310
model

src/symbolic/symbol_scope.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ let model_of_json json_str =
204204
match List.assoc_opt "model" root with
205205
| Some items ->
206206
let+ () = process_json (Util.to_list items) in
207-
tbl
207+
let entry_point =
208+
Option.map Util.to_string (List.assoc_opt "entry_point" root)
209+
in
210+
(entry_point, tbl)
208211
| None -> Fmt.error_msg "JSON does not contain model field" )
209212
| _ ->
210213
Fmt.error_msg "Invalid JSON format for symbol scope:@. %a"
@@ -238,6 +241,10 @@ let model_of_scfg scfg =
238241
match Query.get_dir "model" scfg with
239242
| Some model ->
240243
let+ () = process_dirs model.children in
241-
tbl
244+
let entry_point =
245+
let dir = Query.get_dir "entry_point" model.children in
246+
Option.bind dir (fun dir -> Result.to_option @@ Query.get_param 0 dir)
247+
in
248+
(entry_point, tbl)
242249
| None ->
243250
Fmt.error_msg "Could not find the directive `model` in the scfg config"

src/symbolic/symbol_scope.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ val to_json :
2424
-> t
2525
-> [> `Assoc of (string * Yojson.Basic.t) list ]
2626

27-
val model_of_json : string -> Smtml.Model.t Result.t
27+
val model_of_json : string -> (string option * Smtml.Model.t) Result.t
2828

29-
val model_of_scfg : string -> Smtml.Model.t Result.t
29+
val model_of_scfg : string -> (string option * Smtml.Model.t) Result.t

test/c/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
main.c
1616
malloc_aligned.c
1717
malloc_zero.c
18+
model_with_entry_point.c
1819
multi_model.c
1920
range.c
2021
scopes.c))

0 commit comments

Comments
 (0)