Skip to content

Commit

Permalink
preserves random values in Primus (#958)
Browse files Browse the repository at this point in the history
Primus generates a new random value (of course, if some generator policy
was assigned) every time `Env.get` is called with an unbound variable.

This PR changes this behaviour and makes Primus remember the generated
value, i.e. bind such variable first time it's value was requested.
  • Loading branch information
gitoleg authored and ivg committed Jun 27, 2019
1 parent f595843 commit 52d625c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/bap_primus/bap_primus_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ module Make(Machine : Machine) = struct
| Type.Mem (_,_) -> null
| Type.Imm width -> match Map.find t.random var with
| None -> Machine.raise (Undefined_var var)
| Some gen -> gen_word gen width >>= Value.of_word
| Some gen ->
gen_word gen width >>= Value.of_word >>= fun x ->
set var x >>= fun () ->
!!x

let has var =
Machine.Local.get state >>| fun t ->
Expand Down

0 comments on commit 52d625c

Please sign in to comment.