Skip to content

Commit

Permalink
handle Type_Register in redundant slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinafyi committed Feb 15, 2024
1 parent 147b156 commit e3abd32
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions libASL/transforms.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,18 @@ module RedundantSlice = struct
| Some x' -> Some x'
| None -> y

let width_of_slice (slice : slice) : int =
match slice with
| Slice_LoWd (lo, wd) -> int_of_expr wd
| Slice_HiLo (hi, lo) -> int_of_expr hi - int_of_expr lo + 1
| Slice_Single _ -> 1

let width_of_slices slices = List.fold_left (+) 0 (List.map width_of_slice slices)

let bits_type_of_reg_type = function
| Type_Register (wd, _) -> Type_Bits (Expr_LitInt wd)
| x -> x

type ty_option = Just of ty | Clobbered

class expression_walk (vartypes: ty Bindings.t) = object (self)
Expand All @@ -1313,18 +1325,17 @@ module RedundantSlice = struct
| _ -> ()

method var_type (id: ident): ty option =
match Bindings.find_opt id lvartypes with
| (Some (Just x)) -> Some x
| _ -> Bindings.find_opt id vartypes
Option.map bits_type_of_reg_type
(match Bindings.find_opt id lvartypes with
| Some (Just x) -> Some x
| _ -> Bindings.find_opt id vartypes)

method var_type' (e: expr): ty option =
match e with
| Expr_Var id -> self#var_type id
| _ -> None

method array_val_type (id: ident): ty option =
(* XXX: use of Tcheck.env0 global mutable state *)
(* let env = Tcheck.env0 in *)
match self#var_type id with
| Some (Type_Array(_ix,ty)) -> Some ty
| _ -> None
Expand Down

0 comments on commit e3abd32

Please sign in to comment.