You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

(*
* Copyright (c) 2009-2013, Monoidics ltd.
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
(** State of symbolic execution *)
type t =
{ mutable last_instr: Sil.instr option (** Last instruction seen *)
; mutable last_node: Procdesc.Node.t option (** Last node seen *)
; mutable last_session: int (** Last session seen *) }
let initial () = {last_instr= None; last_node= None; last_session= 0}
(** Global state *)
let gs = ref (initial ())
let get_instr () = !gs.last_instr
let set_instr instr = !gs.last_instr <- Some instr
let get_node_exn () = Option.value_exn !gs.last_node
let get_node () = !gs.last_node
let set_node (node : Procdesc.Node.t) =
!gs.last_instr <- None ;
!gs.last_node <- Some node
let get_session () = !gs.last_session
let set_session (session : int) = !gs.last_session <- session
let get_loc_exn () =
match !gs.last_instr with
| Some instr ->
Sil.location_of_instr instr
| None ->
get_node_exn () |> Procdesc.Node.get_loc
let get_loc () =
match !gs.last_instr with Some instr -> Some (Sil.location_of_instr instr) | None -> None
(** Return the old state, and revert the current state to the initial one. *)
let save () =
let old = !gs in
gs := initial () ;
old
(** Restore the old state. *)
let restore st = gs := st