package asli

  1. Overview
  2. Docs

ASL utility functions

module PP = Asl_parser_pp
module AST = Asl_ast

Bindings and IdentSet

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

add association list to bindings

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

create bindings from association list

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

print bindings

module IdentSet : sig ... end
val unionSets : IdentSet.t list -> IdentSet.t

merge a list of sets

add v to set of identifiers mapped to k

val 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

type 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.

class equivalences : object ... end

AST Transformation Utilities

Calculating free variables of expressions and types

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

Calculating assigned variables in statements

class assignedVarsClass : object ... end
val assigned_vars_of_stmts : Asl_ast.stmt list -> IdentSet.t
val assigned_vars_of_decl : Asl_ast.declaration -> IdentSet.t

Collect local bindings (variables and constants)

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

Calculate types used in expressions and statements

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

Calculate functions and procedures called in statements

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

Substitutions

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

Performing variable substitutions in expressions and types

val subst_expr : AST.expr Bindings.t -> AST.expr -> AST.expr
val subst_lexpr : AST.expr Bindings.t -> AST.lexpr -> AST.lexpr
val subst_slice : AST.expr Bindings.t -> AST.slice -> AST.slice
val subst_type : AST.expr Bindings.t -> AST.ty -> AST.ty
class substFunClass : (AST.ident -> AST.expr option) -> object ... end

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

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

Expression transformation

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

Expression transformation class

Resugaring

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

Resugaring transform

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

Pretty printing wrappers

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

Misc

val 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.