package asli

  1. Overview
  2. Docs

Module LibASL.Asl_utilsSource

ASL utility functions

Sourcemodule AST = Asl_ast

Bindings and IdentSet

Sourcemodule Bindings : sig ... end
Sourceval add_bindings : 'a Bindings.t -> (AST.ident * 'a) list -> 'a Bindings.t

add association list to bindings

Sourceval mk_bindings : (AST.ident * 'a) list -> 'a Bindings.t

create bindings from association list

Sourceval pp_bindings : ('a -> string) -> 'a Bindings.t -> string

print bindings

Sourcemodule IdentSet : sig ... end
Sourceval unionSets : IdentSet.t list -> IdentSet.t

merge a list of sets

add v to set of identifiers mapped to k

Sourceval to_sorted_list : IdentSet.t -> AST.ident list

convert identifier set to sorted list of identifiers

The implementation is trivial and exists mostly to emphasize that the resulting list is sorted

Equivalence classes

Sourcetype tree = {
  1. mutable parent : tree;
  2. data : AST.ident;
}

Equivalence classes are represented by trees.

The root of the tree is the canonical member of the class. Traversing the parent node takes you closer to the canonical member. The root is its own parent.

Equivalence class support (to support unification, and similar)

The implementation is based on Wikipedia: Union-Find. I have not implemented all the optimizations they suggest because I expect sets to be quite small in practice.

Sourceclass equivalences : object ... end

AST Transformation Utilities

Calculating free variables of expressions and types

Sourceclass freevarClass : object ... end
Sourceval fv_expr : AST.expr -> IdentSet.t
Sourceval fv_type : AST.ty -> IdentSet.t
Sourceval fv_args : (AST.ty * AST.ident) list -> IdentSet.t
Sourceval fv_sformal : AST.sformal -> IdentSet.t
Sourceval fv_sformals : AST.sformal list -> IdentSet.t
Sourceval fv_stmts : Asl_ast.stmt list -> IdentSet.t

Calculating assigned variables in statements

Sourceclass assignedVarsClass : object ... end
Sourceval assigned_vars_of_stmts : Asl_ast.stmt list -> IdentSet.t
Sourceval assigned_vars_of_decl : Asl_ast.declaration -> IdentSet.t

Collect local bindings (variables and constants)

Sourceclass localsClass : object ... end
Sourceval locals_of_stmts : Asl_ast.stmt list -> AST.ty Bindings.t
Sourceval locals_of_decl : Asl_ast.declaration list -> AST.ty Bindings.t

Calculate types used in expressions and statements

Sourceclass typesClass : object ... end
Sourceval types_of_expr : Asl_ast.expr -> IdentSet.t
Sourceval types_of_stmts : Asl_ast.stmt list -> IdentSet.t
Sourceval types_of_decl : Asl_ast.declaration -> IdentSet.t

Calculate functions and procedures called in statements

Sourceclass callsClass : object ... end
Sourceval calls_of_expr : Asl_ast.expr -> IdentSet.t
Sourceval calls_of_stmts : Asl_ast.stmt list -> IdentSet.t
Sourceval calls_of_decl : Asl_ast.declaration -> IdentSet.t

Substitutions

Sourceclass substClass : AST.expr Bindings.t -> object ... end

Performing variable substitutions in expressions and types

Sourceval subst_type : AST.expr Bindings.t -> AST.ty -> AST.ty
Sourceclass substFunClass : (AST.ident -> AST.expr option) -> object ... end

More flexible substitution class - takes a function instead of a binding set.

Sourceval subst_fun_expr : (AST.ident -> AST.expr option) -> AST.expr -> AST.expr
Sourceval subst_fun_lexpr : (AST.ident -> AST.expr option) -> AST.lexpr -> AST.lexpr
Sourceval subst_fun_slice : (AST.ident -> AST.expr option) -> AST.slice -> AST.slice
Sourceval subst_fun_type : (AST.ident -> AST.expr option) -> AST.ty -> AST.ty

Expression transformation

Sourceclass replaceExprClass : (AST.expr -> AST.expr option) -> object ... end

Expression transformation class

Resugaring

Sourceclass resugarClass : AST.binop Bindings.t -> object ... end

Resugaring transform

Sourceval resugar_expr : AST.binop Bindings.t -> AST.expr -> AST.expr
Sourceval resugar_type : AST.binop Bindings.t -> AST.ty -> AST.ty

Pretty printing wrappers

Sourceval pp_type : AST.ty -> string
Sourceval pp_expr : AST.expr -> string
Sourceval pp_lexpr : AST.lexpr -> string
Sourceval pp_stmt : AST.stmt -> string

Misc

Sourceval masklength : string -> int

Length of bitstring or mask literal.

ASL bit and mask literals allow spaces to be included - these do not count towards the length of the literal.

OCaml

Innovation. Community. Security.