package herdtools7

  1. Overview
  2. Docs

Module Asllib.ASTUtilsSource

This module provides some tools to work on ASL ASTs.

Identifiers utils

Sourcemodule ISet : sig ... end

An extended identifier set.

Sourcemodule IMap : sig ... end

An extended identifier map.

Position utils

Sourceval dummy_pos : Lexing.position

A dummy position.

Sourceval annotated : 'a -> AST.position -> AST.position -> 'a AST.annotated

annotated v start end is v with location specified as from start to end.

Sourceval desc : 'a AST.annotated -> 'a

desc v is v.desc

Sourceval add_dummy_pos : 'a -> 'a AST.annotated

Add a dummy location annotation to a value.

Sourceval dummy_annotated : unit AST.annotated

A dummy location

Sourceval to_pos : 'a AST.annotated -> unit AST.annotated

Removes the value from an annotated record.

Sourceval add_pos_from_pos_of : ((string * int * int * int) * 'a) -> 'a AST.annotated

add_pos_from_pos_of (__POS_OF__ e) is annotated s s' e where s and s' correspond to e's position in the ocaml file.

Sourceval with_pos_from : 'a AST.annotated -> 'b AST.annotated -> 'b AST.annotated

add_pos_from loc v is v with the location data from loc.

Sourceval add_pos_from : 'a AST.annotated -> 'b -> 'b AST.annotated

add_pos_from loc v is v with the location data from loc.

Sourceval add_pos_from_st : 'a AST.annotated -> 'a -> 'a AST.annotated

add_pos_from_st a' a is a with the location from a'.

If both arguments are physically equal, then the result is also physically equal.

Sourceval map2_desc : ('a AST.annotated -> 'b AST.annotated -> 'c) -> 'a AST.annotated -> 'b AST.annotated -> 'c AST.annotated

Folder on two annotated types.

Type utils

Sourceval integer : AST.ty

The ASL unconstrained integer type.

Sourceval integer' : AST.type_desc

integer, without the position annotation.

Sourceval integer_exact : AST.expr -> AST.ty

integer_exact e is the integer type constrained to be equal to e.

Sourceval integer_exact' : AST.expr -> AST.type_desc

integer_exact' e is integer_exact e without the position annotation.

Sourceval boolean : AST.ty

The ASL boolean type.

Sourceval string : AST.ty

The ASL string type.

Sourceval real : AST.ty

The ASL real type.

Sourceval default_t_bits : AST.type_desc

Constructor helpers

Sourceval s_pass : AST.stmt

An ASL pass statement.

Sourceval s_then : AST.stmt -> AST.stmt -> AST.stmt

s_then s1 s2 is s1; s2 in ASL.

Sourceval stmt_from_list : AST.stmt list -> AST.stmt

stmt_from_list [s1; ... sn] is s1; ... sn in ASL.

Sourceval expr_of_int : int -> AST.expr

expr_of_int i is the literal expression containing i.

Sourceval literal : AST.literal -> AST.expr

literal v is the expression evaluated to v.

var_ x is the expression x.

Builds a binary operation from to sub-expressions.

Sourceval fresh_var : string -> AST.identifier

fresh_var "doc" is a fresh variable whose name begins with "doc".

Sourceval global_ignored : unit -> AST.identifier

Creates a fresh dummy variable for a global ignored variable.

Sourceval is_global_ignored : AST.identifier -> bool

is_global_ignored s is true iff s has been created with global_ignored ().

constraint_binop PLUS cs1 cs2 is the set of constraints given by the element wise application of PLUS.

Fields, masks and slices handling

Sourceval mask_from_set_bits_positions : int -> int list -> string

Builds a mask from specified positions.

Sourceval inv_mask : string -> string

Flip all the 0/1 in the mask. Doesn't change the 'x'.

Sourceval slices_to_positions : ('a -> int) -> ('a * 'a) list -> int list

slices_to_positions as_int slices evaluates slices and returns a list of all queried positions in the correct order.

Sourceval canonical_fields : (string * 'a) list -> (string * 'a) list

Sorts the fields of a record to allow an element wise comparison.

Sourceval bitfield_get_name : AST.bitfield -> string

Returns the name of the bitfield in question.

Sourceval bitfield_get_slices : AST.bitfield -> AST.slice list

Returns the slices corresponding to this bitfield.

Sourceval find_bitfield_opt : string -> AST.bitfield list -> AST.bitfield option

bitfield_find_opt name bfs is Some (bf) if there exists bf in bfs with name, None otherwise.

Sourceval find_bitfields_slices_opt : string -> AST.bitfield list -> AST.slice list option

bitfields_find_slices_opt name bfs is Some (slices) if there exists a bitfield with name name and slices slices.

Sourcemodule Infix : sig ... end

Infix utils.

Equality helpers

Most of those take a cmp_expr argument that is the static analyser expression comparison.

Sourceval expr_equal : (AST.expr -> AST.expr -> bool) -> AST.expr -> AST.expr -> bool
Sourceval literal_equal : AST.literal -> AST.literal -> bool
Sourceval slice_equal : (AST.expr -> AST.expr -> bool) -> AST.slice -> AST.slice -> bool
Sourceval slices_equal : (AST.expr -> AST.expr -> bool) -> AST.slice list -> AST.slice list -> bool
Sourceval constraints_equal : (AST.expr -> AST.expr -> bool) -> AST.int_constraint list -> AST.int_constraint list -> bool
Sourceval type_equal : (AST.expr -> AST.expr -> bool) -> AST.ty -> AST.ty -> bool
Sourceval bitfield_equal : (AST.expr -> AST.expr -> bool) -> AST.bitfield -> AST.bitfield -> bool
Sourceval bitwidth_equal : (AST.expr -> AST.expr -> bool) -> AST.expr -> AST.expr -> bool
Sourceval scope_equal : AST.scope -> AST.scope -> bool
Sourceval scope_compare : AST.scope -> AST.scope -> int

Transformers

Sourceval lid_of_lexpr : AST.lexpr -> AST.local_decl_item option
Sourceval expr_of_lexpr : AST.lexpr -> AST.expr
Sourceval case_to_conds : AST.stmt -> AST.stmt
Sourceval slice_as_single : AST.slice -> AST.expr
Sourceval patch : src:AST.t -> patches:AST.t -> AST.t

patch ~src ~patches replaces in src the global identifiers defined by patches.

Sourceval subst_expr : (AST.identifier * AST.expr) list -> AST.expr -> AST.expr

subst_expr substs e replaces the variables used inside e by their associated expression in substs, if any.

Warning: constants and statically-evaluated parts are not changed, for example: E_Slice (E_Var "y", [Slice_Single (E_Var "y")]) will become after subst_expr [("y", E_Var "x")]: E_Slice (E_Var "x", [Slice_Single (E_Var "y")])

Sourceval rename_locals : (AST.identifier -> AST.identifier) -> AST.t -> AST.t

rename_locals f ast is ast where all instances of variables x are replaced with f x.

Sourceval is_simple_expr : AST.expr -> bool

is_simple_expr e is true if e does not contain any call to any other subprogram. It has false negative.

Def/use analysis

Sourceval use_e : ISet.t -> AST.expr -> ISet.t
Sourceval use_ty : ISet.t -> AST.ty -> ISet.t
Sourceval use_constant_decl : ISet.t -> AST.decl -> ISet.t

use_constant_decl d is the set of other declared names required to have in the environment to be able to type-check d.

Sourceval used_identifiers : AST.decl list -> ISet.t
Sourceval used_identifiers_stmt : AST.stmt -> ISet.t
Sourceval identifier_of_decl : AST.decl -> AST.identifier

identifier_of_decl d is the name of the global element defined by d.

Standard functions

Sourceval pair : 'a -> 'b -> 'a * 'b

pair a b is (a, b).

Sourceval pair' : 'b -> 'a -> 'a * 'b

pair' b a is (b, a).

Sourceval list_equal : ('a -> 'a -> bool) -> 'a list -> 'a list -> bool

list_equal elt_equal li1 li2 is true iff li1 and li2 are element-wise equal.

Sourceval list_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int

An element wise comparaison for lists.

Sourceval list_cross : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list

list_cross f [a1; ... an] [b1; ... bm] is the list of all f ai bj in a non-specified order.

Sourceval list_concat_map : ('a -> 'b list) -> 'a list -> 'b list

list_concat_map f l gives the same result as List.concat (List.map f l). Tail-recursive. Taken from stdlib 4.10.

Sourceval list_fold_left_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a list -> 'acc * 'b list

fold_left_map is a combination of fold_left and map that threads an accumulator through calls to f. Taken from stdlib 4.11.

OCaml

Innovation. Community. Security.