package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/core/Core/Context/index.html
Module Core.Context
Source
Context - Storage for flow-insensitive information
The context is a heterogeneous key-value map that stores non-semantical information, such as a description of the program being currently analyzed, the callstack, etc.
For instance, to create a new kind of entries for storing strings, first generate a new context key:
module K = GenContextKey
(struct
type 'a t = string
let print pp fmt s = fprintf fmt "string: %s" s
end)
let string_key = K.key
Then, given a context 'a ctx
, you can add/remove elements as follows:
let ctx' = add_ctx string_key "a" ctx in
let ctx'' = remove_ctx string_key ctx'
Note that the context can contain the abstract state. For instance, to store a cache of input/output states for each function, you can do:
module K = GenContextKey
(struct
type 'a t = (string*'a flow*'a post) list
let print pp fmt cache =
fprintf fmt "functions I/O cache:@, @[<v>%a@]"
(pp_print_list
~pp_sep:(fun fmt () -> fprintf fmt "@,")
(fun (f,input,output) ->
fprintf "%s:@, input:@[%a]@, output:@[%a@]"
f
(Flow.print pp) input
(Post.print pp) output
)
) cache
end)
let cache_key = K.key
Key to access an element in the context
The context
mem_ctx k ctx
returns true
when an element at key k
is in the context ctx
.
find_ctx k ctx
returns the element at key k
in the context ctx
. Raises Not_found
if no element is found.
find_ctx k ctx
returns the element of the key k
in the context ctx
. Returns None
if no element is found.
add_ctx k v ctx
add element v
at key k
in the context ctx
. The previous element is overwritten if present.
add_ctx k v ctx
removes the element at key k
in the context ctx
. If key k
was not in ctx
, ctx
is returned unchanged.
Print a context
type ctx_pool = {
ctx_pool_equal : 'a 'v 'w. ('a, 'v) ctx_key -> ('a, 'w) ctx_key -> ('v, 'w) Mopsa_utils.Eq.eq option;
ctx_pool_print : 'a 'v. (Print.printer -> 'a -> unit) -> Stdlib.Format.formatter -> ('a, 'v) ctx_key -> 'v -> unit;
}
Pool registered keys
type ctx_info = {
ctx_equal : 'a 'v 'w. ctx_pool -> ('a, 'v) ctx_key -> ('a, 'w) ctx_key -> ('v, 'w) Mopsa_utils.Eq.eq option;
ctx_print : 'a 'v. ctx_pool -> (Print.printer -> 'a -> unit) -> Stdlib.Format.formatter -> ('a, 'v) ctx_key -> 'v -> unit;
}
Registration information for a new key
Generate a new key
Key for storing the callstack