Skip to content
Snippets Groups Projects
Commit 5aa26731 authored by Basile Desloges's avatar Basile Desloges
Browse files

[eacsl] Create a function in Env to call an RTL function and store the result in a new variable

parent 7496a86a
No related branches found
No related tags found
No related merge requests found
...@@ -246,6 +246,21 @@ let new_var_and_mpz_init ~loc ?scope ?name env kf t mk_stmts = ...@@ -246,6 +246,21 @@ let new_var_and_mpz_init ~loc ?scope ?name env kf t mk_stmts =
(Gmp_types.Z.t ()) (Gmp_types.Z.t ())
(fun v e -> Gmp.init ~loc e :: mk_stmts v e) (fun v e -> Gmp.init ~loc e :: mk_stmts v e)
let rtl_call_to_new_var ~loc ?scope ?name env kf t ty func_name args =
let _, exp, env =
new_var
~loc
?scope
?name
env
kf
t
ty
(fun v _ ->
[ Constructor.mk_rtl_call ~loc ~result:(Cil.var v) func_name args ])
in
exp, env
module Logic_binding = struct module Logic_binding = struct
let add_binding env logic_v vi = let add_binding env logic_v vi =
......
...@@ -59,6 +59,15 @@ val new_var_and_mpz_init: ...@@ -59,6 +59,15 @@ val new_var_and_mpz_init:
(** Same as [new_var], but dedicated to mpz_t variables initialized by (** Same as [new_var], but dedicated to mpz_t variables initialized by
{!Mpz.init}. *) {!Mpz.init}. *)
val rtl_call_to_new_var:
loc:location -> ?scope:Varname.scope -> ?name:string ->
t -> kernel_function -> term option -> typ ->
string -> exp list ->
exp * t
(** [rtl_call_to_new_var env t ty name args] Same as [new_var] but initialize
the variable with a call to the RTL function [name] with the given [args].
*)
module Logic_binding: sig module Logic_binding: sig
val add: ?ty:typ -> t -> kernel_function -> logic_var -> varinfo * exp * t val add: ?ty:typ -> t -> kernel_function -> logic_var -> varinfo * exp * t
(* Add a new C binding to the list of bindings for the logic variable. *) (* Add a new C binding to the list of bindings for the logic variable. *)
......
...@@ -116,19 +116,15 @@ let call ~loc kf name ctx env t = ...@@ -116,19 +116,15 @@ let call ~loc kf name ctx env t =
assert (name = "base_addr" || name = "block_length" assert (name = "base_addr" || name = "block_length"
|| name = "offset" || name ="freeable"); || name = "offset" || name ="freeable");
let e, env = !term_to_exp_ref kf (Env.rte env true) t in let e, env = !term_to_exp_ref kf (Env.rte env true) t in
let _, res, env = Env.rtl_call_to_new_var
Env.new_var ~loc
~loc ~name
~name env
env kf
kf None
None ctx
ctx name
(fun v _ -> [ e ]
let name = Functions.RTL.mk_api_name name in
[ Constructor.mk_lib_call ~loc ~result:(Cil.var v) name [ e ] ])
in
res, env
(*****************************************************************************) (*****************************************************************************)
(************************* Calls with Range Elimination **********************) (************************* Calls with Range Elimination **********************)
...@@ -234,24 +230,20 @@ let call_memory_block ~loc kf name ctx env ptr r p = ...@@ -234,24 +230,20 @@ let call_memory_block ~loc kf name ctx env ptr r p =
| _ -> assert false | _ -> assert false
in in
(* generating env *) (* generating env *)
let _, e, env = let args = match name with
Env.new_var | "valid" | "valid_read" -> [ ptr; size; base; base_addr ]
~loc | "initialized" -> [ ptr; size ]
~name | _ -> Error.not_yet ("builtin " ^ name)
env
kf
None
ctx
(fun v _ ->
let fname = Functions.RTL.mk_api_name name in
let args = match name with
| "valid" | "valid_read" -> [ ptr; size; base; base_addr ]
| "initialized" -> [ ptr; size ]
| _ -> Error.not_yet ("builtin " ^ name)
in
[ Constructor.mk_lib_call ~loc ~result:(Cil.var v) fname args ])
in in
e, env Env.rtl_call_to_new_var
~loc
~name
env
kf
None
ctx
name
args
(* [call_with_ranges] handles ranges in [t] when calling builtin [name]. (* [call_with_ranges] handles ranges in [t] when calling builtin [name].
It only supports the following cases for the time being: It only supports the following cases for the time being:
...@@ -342,23 +334,17 @@ let call_with_size ~loc kf name ctx env t p = ...@@ -342,23 +334,17 @@ let call_with_size ~loc kf name ctx env t p =
let call_for_unsupported_constructs ~loc kf name ctx env t = let call_for_unsupported_constructs ~loc kf name ctx env t =
let term_to_exp = !term_to_exp_ref in let term_to_exp = !term_to_exp_ref in
let e, env = term_to_exp kf (Env.rte env true) t in let e, env = term_to_exp kf (Env.rte env true) t in
let _, res, env = let ty = Misc.cty t.term_type in
Env.new_var let sizeof = Misc.mk_ptr_sizeof ty loc in
~loc Env.rtl_call_to_new_var
~name ~loc
env ~name
kf env
None kf
ctx None
(fun v _ -> ctx
let ty = Misc.cty t.term_type in name
let sizeof = Misc.mk_ptr_sizeof ty loc in [ e; sizeof ]
[ Constructor.mk_rtl_call ~loc
~result:(Cil.var v)
name
[ e; sizeof ] ])
in
res, env
in in
call_with_ranges call_with_ranges
~loc ~loc
...@@ -382,21 +368,18 @@ let call_valid ~loc kf name ctx env t p = ...@@ -382,21 +368,18 @@ let call_valid ~loc kf name ctx env t p =
| Lval lv | StartOf lv -> Cil.mkAddrOrStartOf ~loc lv | Lval lv | StartOf lv -> Cil.mkAddrOrStartOf ~loc lv
| _ -> assert false | _ -> assert false
in in
let _, res, env = let ty = Misc.cty t.term_type in
Env.new_var let sizeof = Misc.mk_ptr_sizeof ty loc in
~loc let args = [ e; sizeof; base; base_addr ] in
~name Env.rtl_call_to_new_var
env ~loc
kf ~name
None env
ctx kf
(fun v _ -> None
let ty = Misc.cty t.term_type in ctx
let sizeof = Misc.mk_ptr_sizeof ty loc in name
let args = [ e; sizeof; base; base_addr ] in args
[ Constructor.mk_rtl_call ~loc ~result:(Cil.var v) name args ])
in
res, env
in in
call_with_ranges call_with_ranges
~loc ~loc
......
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