package mopsa
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=9f673f79708b44a7effb3b6bb3618d2c
sha512=cb91cb428e43a22f1abbcb8219710d0c10a5b3756d0da392d4084b3b3a6157350776c596983e63def344f617d39964e91f244f60c07958695ee5c8c809a9f0f4
doc/core/Core/Context/index.html
Module Core.ContextSource
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.keyThen, 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.keyKey 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