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.
69 lines
2.1 KiB
69 lines
2.1 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
|
||
8 years ago
|
module L = Logging
|
||
9 years ago
|
|
||
9 years ago
|
(** Module for builtin functions with their symbolic execution handler *)
|
||
|
|
||
8 years ago
|
type args =
|
||
|
{ pdesc: Procdesc.t
|
||
|
; instr: Sil.instr
|
||
|
; tenv: Tenv.t
|
||
|
; prop_: Prop.normal Prop.t
|
||
|
; path: Paths.Path.t
|
||
|
; ret_id: (Ident.t * Typ.t) option
|
||
|
; args: (Exp.t * Typ.t) list
|
||
|
; proc_name: Typ.Procname.t
|
||
7 years ago
|
; loc: Location.t
|
||
|
; exe_env: Exe_env.t }
|
||
9 years ago
|
|
||
|
type ret_typ = (Prop.normal Prop.t * Paths.Path.t) list
|
||
|
|
||
|
type t = args -> ret_typ
|
||
|
|
||
8 years ago
|
type registered = t
|
||
|
|
||
9 years ago
|
(** builtin function names for which we do symbolic execution *)
|
||
8 years ago
|
let builtin_functions = Typ.Procname.Hash.create 4
|
||
9 years ago
|
|
||
8 years ago
|
let check_register_populated () =
|
||
|
(* check if BuiltinDefn were loaded before accessing register *)
|
||
8 years ago
|
if Int.equal (Typ.Procname.Hash.length builtin_functions) 0 then
|
||
8 years ago
|
L.(die InternalError) "Builtins were not initialized"
|
||
8 years ago
|
|
||
7 years ago
|
|
||
9 years ago
|
(** get the symbolic execution handler associated to the builtin function name *)
|
||
8 years ago
|
let get name : t option =
|
||
7 years ago
|
try Some (Typ.Procname.Hash.find builtin_functions name) with Not_found ->
|
||
|
check_register_populated () ; None
|
||
9 years ago
|
|
||
7 years ago
|
|
||
8 years ago
|
(** register a builtin [Typ.Procname.t] and symbolic execution handler *)
|
||
8 years ago
|
let register proc_name sym_exe_fun : registered =
|
||
7 years ago
|
Typ.Procname.Hash.replace builtin_functions proc_name sym_exe_fun ;
|
||
|
sym_exe_fun
|
||
|
|
||
9 years ago
|
|
||
|
(** print the functions registered *)
|
||
|
let pp_registered fmt () =
|
||
|
let builtin_names = ref [] in
|
||
8 years ago
|
Typ.Procname.Hash.iter (fun name _ -> builtin_names := name :: !builtin_names) builtin_functions ;
|
||
|
builtin_names := List.sort ~cmp:Typ.Procname.compare !builtin_names ;
|
||
8 years ago
|
let pp pname = Format.fprintf fmt "%a@\n" Typ.Procname.pp pname in
|
||
8 years ago
|
Format.fprintf fmt "Registered builtins:@\n @[" ;
|
||
|
List.iter ~f:pp !builtin_names ;
|
||
9 years ago
|
Format.fprintf fmt "@]@."
|
||
|
|
||
7 years ago
|
|
||
9 years ago
|
(** print the builtin functions and exit *)
|
||
7 years ago
|
let print_and_exit () =
|
||
|
pp_registered Format.std_formatter () ;
|
||
|
L.exit 0
|