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.
53 lines
1.4 KiB
53 lines
1.4 KiB
10 years ago
|
(*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
10 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
10 years ago
|
*)
|
||
10 years ago
|
|
||
8 years ago
|
open! IStd
|
||
9 years ago
|
|
||
5 years ago
|
(** Environment for temporary identifiers used in instructions. Lazy implementation: only created
|
||
|
when actually used. *)
|
||
10 years ago
|
|
||
7 years ago
|
type t = Exp.t Ident.Hash.t Lazy.t
|
||
10 years ago
|
|
||
9 years ago
|
let create_ proc_desc =
|
||
7 years ago
|
let map = Ident.Hash.create 1 in
|
||
6 years ago
|
let do_instr _ = function Sil.Load {id; e} -> Ident.Hash.add map id e | _ -> () in
|
||
7 years ago
|
Procdesc.iter_instrs do_instr proc_desc ;
|
||
|
map
|
||
|
|
||
10 years ago
|
|
||
|
(* lazy implementation, only create when used *)
|
||
9 years ago
|
let create proc_desc =
|
||
7 years ago
|
let map = lazy (create_ proc_desc) in
|
||
9 years ago
|
map
|
||
10 years ago
|
|
||
7 years ago
|
|
||
9 years ago
|
let lookup map_ id =
|
||
|
let map = Lazy.force map_ in
|
||
7 years ago
|
Ident.Hash.find_opt map id
|
||
10 years ago
|
|
||
7 years ago
|
|
||
8 years ago
|
let expand_expr idenv e =
|
||
|
match e with Exp.Var id -> ( match lookup idenv id with Some e' -> e' | None -> e ) | _ -> e
|
||
10 years ago
|
|
||
7 years ago
|
|
||
7 years ago
|
let expand_expr_temps idenv node exp_ =
|
||
|
let exp = expand_expr idenv exp_ in
|
||
10 years ago
|
match exp with
|
||
8 years ago
|
| Exp.Lvar pvar when Pvar.is_frontend_tmp pvar -> (
|
||
5 years ago
|
match Decompile.find_program_variable_assignment node pvar with
|
||
7 years ago
|
| None ->
|
||
|
exp
|
||
|
| Some (_, id) ->
|
||
|
expand_expr idenv (Exp.Var id) )
|
||
|
| _ ->
|
||
|
exp
|
||
|
|
||
10 years ago
|
|
||
|
(** Return true if the expression is a temporary variable introduced by the front-end. *)
|
||
|
let exp_is_temp idenv e =
|
||
8 years ago
|
match expand_expr idenv e with Exp.Lvar pvar -> Pvar.is_frontend_tmp pvar | _ -> false
|