Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asl constant analysis #751

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions asllib/AST.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
type position = Lexing.position
type 'a annotated = { desc : 'a; pos_start : position; pos_end : position }

type identifier = string
(** Type of local identifiers in the AST. *)

type uid = int
(** Unique identifiers *)

(* -------------------------------------------------------------------------

Operations
Expand Down Expand Up @@ -74,9 +80,6 @@ type binop =
| SHL (** Shift left for ints *)
| SHR (** Shift right for ints *)

type identifier = string
(** Type of local identifiers in the AST. *)

(* -------------------------------------------------------------------------

Parsed values
Expand Down Expand Up @@ -162,10 +165,10 @@ and slice =

(** Type descriptors.*)
and type_desc =
(* Begin Constrained *)
| T_Int of int_constraints option
| T_Bits of bits_constraint * bitfield list
(* End Constrained *)
(* Begin Constrained *)
| T_Int of int_constraints
| T_Bits of expr * bitfield list
(* End Constrained *)
| T_Real
| T_String
| T_Bool
Expand All @@ -185,16 +188,15 @@ and int_constraint =
| Constraint_Range of (expr * expr)
(** In the range of these two statically evaluable values.*)

and int_constraints = int_constraint list
(** The int_constraints represent the union of the individual constraints.*)

(** The width of a bitvector can be constrained in multiple ways. *)
and bits_constraint =
| BitWidth_SingleExpr of expr (** Statically evaluable expression. *)
| BitWidth_ConstrainedFormType of ty
(** Constrained by the domain of another type. *)
| BitWidth_Constraints of int_constraints
(** Constrained directly by a constraint on its width. *)
(** The int_constraints constraints the integer type to a certain subset.*)
and int_constraints =
| UnConstrained (** The normal, unconstrained, integer type. *)
| WellConstrained of int_constraint list
(** An integer type constrained from ASL syntax: it is the union of each
constraint in the list. *)
| UnderConstrained of uid
(** An under-constrained integer, the default type for parameters of
function at compile time. *)

(** Represent static slices on a given bitvector type. *)
and bitfield =
Expand Down Expand Up @@ -282,13 +284,13 @@ and catcher = identifier option * ty * stmt
(** {2 Top-level declarations} *)

type subprogram_type = ST_Procedure | ST_Function | ST_Getter | ST_Setter
type 'p subprogram_body = SB_ASL of stmt | SB_Primitive of 'p
type subprogram_body = SB_ASL of stmt | SB_Primitive

type 'p func = {
type func = {
name : identifier;
parameters : (identifier * ty option) list;
args : typed_identifier list;
body : 'p subprogram_body;
body : subprogram_body;
return_type : ty option;
subprogram_type : subprogram_type;
}
Expand All @@ -307,14 +309,14 @@ type global_decl = {
(** Global declaration type *)

(** Declarations, ie. top level statement in a asl file. *)
type 'p decl_desc =
| D_Func of 'p func
type decl_desc =
| D_Func of func
| D_GlobalStorage of global_decl
| D_TypeDecl of identifier * ty * (identifier * field list) option

type 'p decl = 'p decl_desc annotated
type decl = decl_desc annotated

type 'p t = 'p decl list
type t = decl list
(** Main AST type. *)

(* -------------------------------------------------------------------------
Expand All @@ -323,6 +325,5 @@ type 'p t = 'p decl list

------------------------------------------------------------------------- *)

type scope =
| Scope_Local of identifier * int
| Scope_Global (** A scope is an unique identifier of the calling site. *)
(** A scope is an unique identifier of the calling site. *)
type scope = Scope_Local of identifier * uid | Scope_Global
Loading