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.
66 lines
1.7 KiB
66 lines
1.7 KiB
9 years ago
|
(*
|
||
|
* Copyright (c) 2016 - present Facebook, Inc.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* This source code is licensed under the BSD style license found in the
|
||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||
|
*)
|
||
|
|
||
8 years ago
|
open! IStd
|
||
7 years ago
|
module F = Format
|
||
9 years ago
|
|
||
9 years ago
|
(** Single abstraction for all the kinds of variables in SIL *)
|
||
9 years ago
|
|
||
8 years ago
|
type t = LogicalVar of Ident.t | ProgramVar of Pvar.t [@@deriving compare]
|
||
8 years ago
|
|
||
8 years ago
|
let equal = [%compare.equal : t]
|
||
9 years ago
|
|
||
7 years ago
|
let compare_modulo_this x y =
|
||
|
match (x, y) with
|
||
|
| ProgramVar i, ProgramVar j ->
|
||
|
Pvar.compare_modulo_this i j
|
||
|
| _, _ ->
|
||
|
compare x y
|
||
|
|
||
|
|
||
8 years ago
|
let of_id id = LogicalVar id
|
||
9 years ago
|
|
||
8 years ago
|
let of_pvar pvar = ProgramVar pvar
|
||
9 years ago
|
|
||
8 years ago
|
let of_formal_index formal_index = of_id (Ident.create_footprint Ident.name_spec formal_index)
|
||
8 years ago
|
|
||
8 years ago
|
let to_exp = function ProgramVar pvar -> Exp.Lvar pvar | LogicalVar id -> Exp.Var id
|
||
9 years ago
|
|
||
8 years ago
|
let is_global = function ProgramVar pvar -> Pvar.is_global pvar | LogicalVar _ -> false
|
||
8 years ago
|
|
||
8 years ago
|
let is_return = function ProgramVar pvar -> Pvar.is_return pvar | LogicalVar _ -> false
|
||
8 years ago
|
|
||
8 years ago
|
let is_footprint = function ProgramVar _ -> false | LogicalVar id -> Ident.is_footprint id
|
||
8 years ago
|
|
||
7 years ago
|
let appears_in_source_code = function
|
||
|
| LogicalVar _ ->
|
||
|
false
|
||
|
| ProgramVar pvar ->
|
||
|
not (Pvar.is_frontend_tmp pvar)
|
||
|
|
||
7 years ago
|
|
||
|
let pp fmt = function
|
||
|
| ProgramVar pv ->
|
||
|
F.fprintf fmt "%s" (Pvar.get_simplified_name pv)
|
||
|
| LogicalVar id ->
|
||
|
Ident.pp fmt id
|
||
|
|
||
8 years ago
|
|
||
7 years ago
|
let get_footprint_index t =
|
||
|
match t with LogicalVar id when is_footprint t -> Some (Ident.get_stamp id) | _ -> None
|
||
|
|
||
|
|
||
8 years ago
|
module Map = PrettyPrintable.MakePPMap (struct
|
||
|
type nonrec t = t
|
||
|
|
||
|
let compare = compare
|
||
|
|
||
|
let pp = pp
|
||
|
end)
|