changing API to take pdesc instead of cfg

Reviewed By: cristianoc

Differential Revision: D3352426

fbshipit-source-id: 290ad1f
master
Sam Blackshear 9 years ago committed by Facebook Github Bot 3
parent ddb7f7724e
commit 83a14a3541

@ -11,7 +11,7 @@
open! Utils open! Utils
(** mutate the cfg/cg to add dynamic dispatch handling *) (** mutate the cfg/cg to add dynamic dispatch handling *)
let add_dispatch_calls cfg cg tenv f_translate_typ_opt = let add_dispatch_calls pdesc cg tenv f_translate_typ_opt =
let pname_translate_types pname = let pname_translate_types pname =
match f_translate_typ_opt with match f_translate_typ_opt with
| Some f_translate_typ -> | Some f_translate_typ ->
@ -78,12 +78,11 @@ let add_dispatch_calls cfg cg tenv f_translate_typ_opt =
if has_dispatch_call instrs then if has_dispatch_call instrs then
IList.map replace_dispatch_calls instrs IList.map replace_dispatch_calls instrs
|> Cfg.Node.replace_instrs node in |> Cfg.Node.replace_instrs node in
let proc_add_dispach_calls pname pdesc = let pname = Cfg.Procdesc.get_proc_name pdesc in
Cfg.Procdesc.iter_nodes (node_add_dispatch_calls pname) pdesc in Cfg.Procdesc.iter_nodes (node_add_dispatch_calls pname) pdesc
Cfg.iter_proc_desc cfg proc_add_dispach_calls
(** add instructions to perform abstraction *) (** add instructions to perform abstraction *)
let add_abstraction_instructions cfg = let add_abstraction_instructions pdesc =
let open Cfg in let open Cfg in
(* true if there is a succ node s.t.: it is an exit node, or the succ of >1 nodes *) (* true if there is a succ node s.t.: it is an exit node, or the succ of >1 nodes *)
let converging_node node = let converging_node node =
@ -106,11 +105,10 @@ let add_abstraction_instructions cfg =
| Node.Prune_node _ | Node.Prune_node _
| Node.Skip_node _ -> | Node.Skip_node _ ->
converging_node node in converging_node node in
let all_nodes = Node.get_all_nodes cfg in
let do_node node = let do_node node =
let loc = Node.get_last_loc node in let loc = Node.get_last_loc node in
if node_requires_abstraction node then Node.append_instrs node [Sil.Abstract loc] in if node_requires_abstraction node then Node.append_instrs node [Sil.Abstract loc] in
IList.iter do_node all_nodes Cfg.Procdesc.iter_nodes do_node pdesc
module BackwardCfg = ProcCfg.Backward(ProcCfg.Exceptional) module BackwardCfg = ProcCfg.Backward(ProcCfg.Exceptional)
@ -180,7 +178,7 @@ module NullifyAnalysis =
(Scheduler.ReversePostorder (ProcCfg.Exceptional)) (Scheduler.ReversePostorder (ProcCfg.Exceptional))
(NullifyTransferFunctions) (NullifyTransferFunctions)
let add_nullify_instrs tenv _ pdesc = let add_nullify_instrs pdesc tenv =
let liveness_proc_cfg = BackwardCfg.from_pdesc pdesc in let liveness_proc_cfg = BackwardCfg.from_pdesc pdesc in
let proc_data_no_extras = ProcData.make_default pdesc tenv in let proc_data_no_extras = ProcData.make_default pdesc tenv in
let liveness_inv_map = LivenessAnalysis.exec_cfg liveness_proc_cfg proc_data_no_extras in let liveness_inv_map = LivenessAnalysis.exec_cfg liveness_proc_cfg proc_data_no_extras in
@ -239,8 +237,8 @@ let add_nullify_instrs tenv _ pdesc =
let exit_node = ProcCfg.Exceptional.exit_node nullify_proc_cfg in let exit_node = ProcCfg.Exceptional.exit_node nullify_proc_cfg in
node_add_nullify_instructions exit_node (AddressTaken.Domain.elements address_taken_vars) node_add_nullify_instructions exit_node (AddressTaken.Domain.elements address_taken_vars)
let doit ?(f_translate_typ=None) cfg cg tenv = let doit ?(f_translate_typ=None) pdesc cg tenv =
Cfg.iter_proc_desc cfg (add_nullify_instrs tenv); add_nullify_instrs pdesc tenv;
if !Config.curr_language = Config.Java if !Config.curr_language = Config.Java
then add_dispatch_calls cfg cg tenv f_translate_typ; then add_dispatch_calls pdesc cg tenv f_translate_typ;
add_abstraction_instructions cfg; add_abstraction_instructions pdesc;

@ -13,5 +13,5 @@ open! Utils
(** Preanalysis for eliminating dead local variables *) (** Preanalysis for eliminating dead local variables *)
(** Perform liveness analysis *) (** Perform liveness analysis *)
val doit : ?f_translate_typ:(Tenv.t -> string -> unit) option -> Cfg.cfg -> Cg.t -> Tenv.t val doit : ?f_translate_typ:(Tenv.t -> string -> unit) option -> Cfg.Procdesc.t -> Cg.t -> Tenv.t
-> unit -> unit

@ -66,7 +66,7 @@ let do_source_file source_file ast =
let tenv_file = DB.source_dir_get_internal_file source_dir ".tenv" in let tenv_file = DB.source_dir_get_internal_file source_dir ".tenv" in
let cfg_file = DB.source_dir_get_internal_file source_dir ".cfg" in let cfg_file = DB.source_dir_get_internal_file source_dir ".cfg" in
let cg_file = DB.source_dir_get_internal_file source_dir ".cg" in let cg_file = DB.source_dir_get_internal_file source_dir ".cg" in
Preanal.doit cfg call_graph tenv; Cfg.iter_proc_desc cfg (fun _ pdesc -> Preanal.doit pdesc call_graph tenv);
Cg.store_to_file cg_file call_graph; Cg.store_to_file cg_file call_graph;
Cfg.store_cfg_to_file cfg_file true cfg; Cfg.store_cfg_to_file cfg_file true cfg;
(*Logging.out "Tenv %a@." Sil.pp_tenv tenv;*) (*Logging.out "Tenv %a@." Sil.pp_tenv tenv;*)

@ -51,7 +51,9 @@ let store_icfg tenv cg cfg program =
let cfg_file = DB.source_dir_get_internal_file source_dir ".cfg" in let cfg_file = DB.source_dir_get_internal_file source_dir ".cfg" in
let cg_file = DB.source_dir_get_internal_file source_dir ".cg" in let cg_file = DB.source_dir_get_internal_file source_dir ".cg" in
if Config.create_harness then Harness.create_harness cfg cg tenv; if Config.create_harness then Harness.create_harness cfg cg tenv;
Preanal.doit ~f_translate_typ:(Some f_translate_typ) cfg cg tenv; Cfg.iter_proc_desc
cfg
(fun _ pdesc -> Preanal.doit ~f_translate_typ:(Some f_translate_typ) pdesc cg tenv);
Cg.store_to_file cg_file cg; Cg.store_to_file cg_file cg;
Cfg.store_cfg_to_file cfg_file true cfg; Cfg.store_cfg_to_file cfg_file true cfg;
if Config.debug_mode then if Config.debug_mode then

@ -35,7 +35,7 @@ let store_icfg tenv cg cfg =
let get_internal_file = DB.source_dir_get_internal_file source_dir in let get_internal_file = DB.source_dir_get_internal_file source_dir in
let cg_file = get_internal_file ".cg" in let cg_file = get_internal_file ".cg" in
let cfg_file = get_internal_file ".cfg" in let cfg_file = get_internal_file ".cfg" in
Preanal.doit cfg cg tenv; Cfg.iter_proc_desc cfg (fun _ pdesc -> Preanal.doit pdesc cg tenv);
Cg.store_to_file cg_file cg; Cg.store_to_file cg_file cg;
Cfg.store_cfg_to_file cfg_file true cfg; Cfg.store_cfg_to_file cfg_file true cfg;
if Config.debug_mode then if Config.debug_mode then

Loading…
Cancel
Save