package mopsa

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

C_utils - Utilities to access the simple C AST

module C : sig ... end

Debug

val log_type_unify : bool Stdlib.ref

verbose logging during type unification, for debugging

val log_type_compare : bool

verbose logging during type comparison, for debugging

Location utilities

val range_of_block : C.range Mopsa_utils.ListExt.t -> C.range

From the begining of the first block statement to the end of the last block statement. Raises Invalid_argument for empty blocks.

Size and alignment

val sizeof_int : C.target_info -> C_AST.integer_type -> int

Size (in bytes) of an integer type.

val alignof_int : C.target_info -> C_AST.integer_type -> int

Alignment (in bytes) of an integer type.

val signedness_int : C_AST.integer_type -> C_AST.signedness

Signedness of an integer type.

val sizeof_float : C.target_info -> C_AST.float_type -> int

Size (in bytes) of a float type.

val alignof_float : C.target_info -> C_AST.float_type -> int

Alignment (in bytes) of a float type.

val sizeof_type : C.target_info -> C_AST.typ -> Z.t

Size (in bytes) of a type. Raises an Invalid_argument if the size is not a constant.

Size (in bytes) of a type, as an expression. Handles variable-length ararys.

val alignof_type : C.target_info -> C_AST.typ -> Z.t

Alignment (in bytes) of a type.

val type_declarable : C_AST.typ -> bool
val type_qual_declarable : C_AST.type_qual -> bool

Whether we can declare a variable of this type (sizeof defined).

Useful target-specific types

Converts target int to SAST int types.

val intmax_type : C.target_info -> C_AST.integer_type
val ptrdiff_type : C.target_info -> C_AST.integer_type
val intptr_type : C.target_info -> C_AST.integer_type
val int64_type : C.target_info -> C_AST.integer_type
val wchar_type : C.target_info -> C_AST.integer_type
val char16_type : C.target_info -> C_AST.integer_type
val char32_type : C.target_info -> C_AST.integer_type
val sigatomic_type : C.target_info -> C_AST.integer_type
val processid_type : C.target_info -> C_AST.integer_type

Base integer type of a derived integer type.

Comments

val comment_unify : C_AST.comment list -> C_AST.comment list -> C_AST.comment list

Ensure that comments are not duplicated.

Type compatibility

type type_cmp = {
  1. cmp_ignore_qual : bool;
    (*

    if true, type_compatible does not take qualifiers into account in comparison

    *)
  2. cmp_int_size : bool;
    (*

    if true, type_compatible use integer size and signess instead of name

    *)
  3. cmp_enum_as_int : bool;
    (*

    if true, type_compatible handles an enum as an its integer type

    *)
  4. cmp_ignore_name : bool;
    (*

    if true, type_compatible disregards type names in comparison

    *)
  5. cmp_ignore_undefined : bool;
    (*

    if true, an undefined enum, struct or union compares equal to a defined one

    *)
  6. cmp_ignore_typedef : bool;
    (*

    if true, a typedef is replaced with its defining type during comparison

    *)
  7. cmp_ignore_array_size : bool;
    (*

    if true, arrays with undefined size compare equal to that of defined size

    *)
  8. cmp_ignore_vector_size : bool;
    (*

    if true, the size of vector types is ignored in comparison

    *)
  9. cmp_ignore_vector_kind : bool;
    (*

    if true, the kind of vector types is ignored in comparison

    *)
}

Comfigures the test equality functions, to allow various relaxation.

val cmp_compatible : type_cmp

Type compatibility.

val cmp_unifiable : type_cmp

Unifiable compatibility.

val cmp_equal : type_cmp

Strict type equality.

val type_compare : type_cmp -> (C_AST.uid * C_AST.uid, unit) Stdlib.Hashtbl.t -> C.target_info -> C_AST.typ -> C_AST.typ -> bool
val qual_compare : type_cmp -> C_AST.qualifier -> C_AST.qualifier -> bool
val type_qual_compare : type_cmp -> (C_AST.uid * C_AST.uid, unit) Stdlib.Hashtbl.t -> C.target_info -> C_AST.type_qual -> C_AST.type_qual -> bool
val type_compatible : C.target_info -> C_AST.typ -> C_AST.typ -> bool
val type_qual_compatible : C.target_info -> C_AST.type_qual -> C_AST.type_qual -> bool

Type compatibility. Two declarations for the same object must have compatible types.

val type_equal : C.target_info -> C_AST.typ -> C_AST.typ -> bool
val type_qual_equal : C.target_info -> C_AST.type_qual -> C_AST.type_qual -> bool

Strict type equality, to allow type merging.

val type_unifiable : C.target_info -> C_AST.typ -> C_AST.typ -> bool
val type_qual_unifiable : C.target_info -> C_AST.type_qual -> C_AST.type_qual -> bool

Arguments are eligible to call type_unify.

val type_qual_unify : (C_AST.uid * C_AST.uid, unit) Stdlib.Hashtbl.t -> C.target_info -> C_AST.type_qual -> C_AST.type_qual -> C_AST.type_qual
val type_unify : C.target_info -> C_AST.typ -> C_AST.typ -> C_AST.typ

Type unification.

val is_void : C_AST.type_qual -> bool

Expressions utilities

val expr_type : C_AST.expr -> C_AST.type_qual

Type of an expression.

val expr_integer_cst : C_AST.range -> C_AST.integer_type -> Z.t -> C_AST.expr
val expr_float_cst : C_AST.range -> C_AST.float_type -> float -> C_AST.expr
val expr_complex_cst : C_AST.range -> C_AST.float_type -> float -> C_AST.expr
val expr_int_zero : C_AST.range -> C_AST.expr
val expr_int_one : C_AST.range -> C_AST.expr
val expr_double_zero : C_AST.range -> C_AST.expr
val expr_bool_true : C_AST.range -> C_AST.expr
val expr_bool_false : C_AST.range -> C_AST.expr
val expr_null : C_AST.range -> C_AST.expr

(void* )0

val expr_void : C_AST.range -> C_AST.expr

(void)0

val zero_init : C_AST.range -> C_AST.typ -> C_AST.init

Statement utilities

val make_block : C_AST.statement list -> C_AST.block

Creates a block from a list of statements. Computes the list of local variables declared in the block and not in sub-blocks.

module VarSet : sig ... end
val resolve_scope : C_AST.block -> C_AST.block

Fill-in scope_update information in the AST. The block is modified in-place, and returned. Call after AST transformations that may change variable scopes.

Errors

val error : Clang_AST.range -> string -> string -> 'a
val warning : 'a -> 'b -> 'c -> unit
OCaml

Innovation. Community. Security.