Skip to content
Snippets Groups Projects
Commit bec92f6a authored by Allan Blanchard's avatar Allan Blanchard
Browse files

[RENAME PLUGIN] Builtin -> Instantiate

parent 135bf06e
No related branches found
No related tags found
No related merge requests found
[kernel] Parsing tests/string/memset_value.c (with preprocessing) [kernel] Parsing tests/string/memset_value.c (with preprocessing)
[builtin] tests/string/memset_value.c:26: Warning: Ignore call: not well typed [instantiate] tests/string/memset_value.c:26: Warning:
[builtin] tests/string/memset_value.c:27: Warning: Ignore call: not well typed Ignore call: not well typed
[builtin] tests/string/memset_value.c:31: Warning: Ignore call: not well typed [instantiate] tests/string/memset_value.c:27: Warning:
[builtin] tests/string/memset_value.c:32: Warning: Ignore call: not well typed Ignore call: not well typed
[builtin] tests/string/memset_value.c:36: Warning: Ignore call: not well typed [instantiate] tests/string/memset_value.c:31: Warning:
[builtin] tests/string/memset_value.c:37: Warning: Ignore call: not well typed Ignore call: not well typed
[builtin] tests/string/memset_value.c:41: Warning: Ignore call: not well typed [instantiate] tests/string/memset_value.c:32: Warning:
[builtin] tests/string/memset_value.c:42: Warning: Ignore call: not well typed Ignore call: not well typed
[builtin] tests/string/memset_value.c:46: Warning: Ignore call: not well typed [instantiate] tests/string/memset_value.c:36: Warning:
[builtin] tests/string/memset_value.c:47: Warning: Ignore call: not well typed Ignore call: not well typed
[builtin] tests/string/memset_value.c:51: Warning: Ignore call: not well typed [instantiate] tests/string/memset_value.c:37: Warning:
[builtin] tests/string/memset_value.c:52: Warning: Ignore call: not well typed Ignore call: not well typed
[instantiate] tests/string/memset_value.c:41: Warning:
Ignore call: not well typed
[instantiate] tests/string/memset_value.c:42: Warning:
Ignore call: not well typed
[instantiate] tests/string/memset_value.c:46: Warning:
Ignore call: not well typed
[instantiate] tests/string/memset_value.c:47: Warning:
Ignore call: not well typed
[instantiate] tests/string/memset_value.c:51: Warning:
Ignore call: not well typed
[instantiate] tests/string/memset_value.c:52: Warning:
Ignore call: not well typed
/* Generated by Frama-C */ /* Generated by Frama-C */
#include "stddef.h" #include "stddef.h"
#include "string.h" #include "string.h"
......
OPT: @PTEST_FILE@ -instantiate -print -check -then -ocode @PTEST_DIR@/result/@PTEST_NAME@.c -print -then -no-instantiate @PTEST_DIR@/result/@PTEST_NAME@.c @PTEST_FILE@ -ocode="" -print
\ No newline at end of file
...@@ -21,24 +21,24 @@ ...@@ -21,24 +21,24 @@
(**************************************************************************) (**************************************************************************)
open Cil_types open Cil_types
open Builtin_builder open Instantiator_builder
let base : (string, (module Builtin)) Hashtbl.t = Hashtbl.create 17 let base : (string, (module Instantiator)) Hashtbl.t = Hashtbl.create 17
let register (module G: Generator_sig) = let register (module G: Generator_sig) =
let module Builtin = Make_builtin(G) in let module Instantiator = Make_instantiator(G) in
Hashtbl.add base G.function_name (module Builtin) Hashtbl.add base G.function_name (module Instantiator)
let mark_as_computed () = let mark_as_computed () =
let mark_as_computed _ builtin = let mark_as_computed _ instantiator =
let module B = (val builtin: Builtin) in B.mark_as_computed () let module I = (val instantiator: Instantiator) in I.mark_as_computed ()
in in
Hashtbl.iter mark_as_computed base Hashtbl.iter mark_as_computed base
let get_kfs () = let get_kfs () =
let get_kfs _ builtin = let get_kfs _ instantiator =
let module B = (val builtin: Builtin) in let module I = (val instantiator: Instantiator) in
let res = B.get_kfs () in let res = I.get_kfs () in
res res
in in
Hashtbl.fold (fun k v l -> (get_kfs k v) @ l) base [] Hashtbl.fold (fun k v l -> (get_kfs k v) @ l) base []
...@@ -48,8 +48,8 @@ module VISet = Cil_datatype.Varinfo.Hptset ...@@ -48,8 +48,8 @@ module VISet = Cil_datatype.Varinfo.Hptset
class transformer = object(self) class transformer = object(self)
inherit Visitor.frama_c_inplace inherit Visitor.frama_c_inplace
val introduced_builtins = ref VISet.empty val introduced_instantiators = ref VISet.empty
val used_builtin_last_kf = Queue.create () val used_instantiator_last_kf = Queue.create ()
method! vfile _ = method! vfile _ =
let post f = let post f =
...@@ -64,13 +64,13 @@ class transformer = object(self) ...@@ -64,13 +64,13 @@ class transformer = object(self)
let post g = let post g =
let loc = Cil.CurrentLoc.get() in let loc = Cil.CurrentLoc.get() in
let folding l fd = let folding l fd =
if VISet.mem fd.svar !introduced_builtins then l if VISet.mem fd.svar !introduced_instantiators then l
else begin else begin
introduced_builtins := VISet.add fd.svar !introduced_builtins ; introduced_instantiators := VISet.add fd.svar !introduced_instantiators ;
GFun (fd, loc) :: l GFun (fd, loc) :: l
end end
in in
Queue.fold folding g used_builtin_last_kf Queue.fold folding g used_instantiator_last_kf
in in
Cil.DoChildrenPost post Cil.DoChildrenPost post
...@@ -81,20 +81,20 @@ class transformer = object(self) ...@@ -81,20 +81,20 @@ class transformer = object(self)
else else
Cil.SkipChildren Cil.SkipChildren
method private find_enabled_builtin fct = method private find_enabled_instantiator fct =
let builtin = Hashtbl.find base fct.vname in let instantiator = Hashtbl.find base fct.vname in
let module B = (val builtin: Builtin) in let module I = (val instantiator: Instantiator) in
if not (B.Enabled.get ()) then raise Not_found ; if not (I.Enabled.get ()) then raise Not_found ;
builtin instantiator
method private replace_call (lval, fct, args) = method private replace_call (lval, fct, args) =
try try
let module B = (val (self#find_enabled_builtin fct): Builtin) in let module I = (val (self#find_enabled_instantiator fct): Instantiator) in
if B.well_typed_call lval args then if I.well_typed_call lval args then
let key = B.key_from_call lval args in let key = I.key_from_call lval args in
let fundec = B.get_override key in let fundec = I.get_override key in
let new_args = B.retype_args key args in let new_args = I.retype_args key args in
Queue.add fundec used_builtin_last_kf ; Queue.add fundec used_instantiator_last_kf ;
(fundec.svar), new_args (fundec.svar), new_args
else begin else begin
Options.warning ~current:true "Ignore call: not well typed" ; Options.warning ~current:true "Ignore call: not well typed" ;
......
...@@ -22,14 +22,13 @@ ...@@ -22,14 +22,13 @@
(** Module for AST transformation *) (** Module for AST transformation *)
(** Registers a new [Builtin] to the visitor from the [Generator_sig] module (** Registers a new [Instantiator] to the visitor from the [Generator_sig]
of this builtin. Each new builtin function generator should call this module. Each new instantiator generator should call this globally.
globally.
*) *)
val register: (module Builtin_builder.Generator_sig) -> unit val register: (module Instantiator_builder.Generator_sig) -> unit
(** In all selected functions of the given file, for all function call, if there (** In all selected functions of the given file, for all function call, if there
exists a builtin module for this function, and the call is well-typed, exists a instantiator module for this function, and the call is well-typed,
replaces it with a call to the generated override function and inserted the replaces it with a call to the generated override function and inserted the
generated function in the AST. generated function in the AST.
*) *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment