@@ -10,6 +10,7 @@ and expr =
1010 { base : Bitvector .t
1111 ; offset : t
1212 }
13+ | Loc of Loc. t
1314 | Symbol of Symbol. t
1415 | List of t list
1516 | App of Symbol. t * t list
@@ -33,6 +34,7 @@ module Expr = struct
3334 let equal (e1 : expr ) (e2 : expr ) : bool =
3435 match (e1, e2) with
3536 | Val v1 , Val v2 -> Value. equal v1 v2
37+ | Loc a , Loc b -> Loc. compare a b = 0
3638 | Ptr { base = b1 ; offset = o1 } , Ptr { base = b2 ; offset = o2 } ->
3739 Bitvector. equal b1 b2 && phys_equal o1 o2
3840 | Symbol s1 , Symbol s2 -> Symbol. equal s1 s2
@@ -58,8 +60,9 @@ module Expr = struct
5860 | Concat (e1 , e3 ), Concat (e2 , e4 ) -> phys_equal e1 e2 && phys_equal e3 e4
5961 | Binder (binder1 , vars1 , e1 ), Binder (binder2 , vars2 , e2 ) ->
6062 Binder. equal binder1 binder2 && list_eq vars1 vars2 && phys_equal e1 e2
61- | ( ( Val _ | Ptr _ | Symbol _ | List _ | App _ | Unop _ | Binop _ | Triop _
62- | Relop _ | Cvtop _ | Naryop _ | Extract _ | Concat _ | Binder _ )
63+ | ( ( Val _ | Ptr _ | Loc _ | Symbol _ | List _ | App _ | Unop _ | Binop _
64+ | Triop _ | Relop _ | Cvtop _ | Naryop _ | Extract _ | Concat _
65+ | Binder _ )
6366 , _ ) ->
6467 false
6568
@@ -68,6 +71,7 @@ module Expr = struct
6871 match e with
6972 | Val v -> h v
7073 | Ptr { base; offset } -> h (base, offset.tag)
74+ | Loc l -> h l
7175 | Symbol s -> h s
7276 | List v -> h v
7377 | App (x , es ) -> h (x, es)
@@ -107,6 +111,7 @@ let rec ty (hte : t) : Ty.t =
107111 match view hte with
108112 | Val x -> Value. type_of x
109113 | Ptr _ -> Ty_bitv 32
114+ | Loc _ -> Ty_app
110115 | Symbol x -> Symbol. type_of x
111116 | List _ -> Ty_list
112117 | App (sym , _ ) -> begin match sym.ty with Ty_none -> Ty_app | ty -> ty end
@@ -135,6 +140,7 @@ let rec is_symbolic (v : t) : bool =
135140 match view v with
136141 | Val _ -> false
137142 | Symbol _ -> true
143+ | Loc _ -> false
138144 | Ptr { offset; _ } -> is_symbolic offset
139145 | List vs -> List. exists is_symbolic vs
140146 | App (_ , vs ) -> List. exists is_symbolic vs
@@ -153,7 +159,7 @@ let get_symbols (hte : t list) =
153159 let tbl = Hashtbl. create 64 in
154160 let rec symbols (hte : t ) =
155161 match view hte with
156- | Val _ -> ()
162+ | Val _ | Loc _ -> ()
157163 | Ptr { offset; _ } -> symbols offset
158164 | Symbol s -> Hashtbl. replace tbl s ()
159165 | List es -> List. iter symbols es
@@ -186,6 +192,7 @@ let rec pp fmt (hte : t) =
186192 match view hte with
187193 | Val v -> Value. pp fmt v
188194 | Ptr { base; offset } -> Fmt. pf fmt " (Ptr %a %a)" Bitvector. pp base pp offset
195+ | Loc l -> Fmt. pf fmt " (loc %a)" Loc. pp l
189196 | Symbol s -> Fmt. pf fmt " @[<hov 1>%a@]" Symbol. pp s
190197 | List v -> Fmt. pf fmt " @[<hov 1>[%a]@]" (Fmt. list ~sep: Fmt. comma pp) v
191198 | App (s , v ) ->
@@ -247,7 +254,7 @@ module Set = struct
247254 let tbl = Hashtbl. create 64 in
248255 let rec symbols hte =
249256 match view hte with
250- | Val _ -> ()
257+ | Val _ | Loc _ -> ()
251258 | Ptr { offset; _ } -> symbols offset
252259 | Symbol s -> Hashtbl. replace tbl s ()
253260 | List es -> List. iter symbols es
@@ -281,6 +288,8 @@ let value (v : Value.t) : t = make (Val v) [@@inline]
281288
282289let ptr base offset = make (Ptr { base = Bitvector. of_int32 base; offset })
283290
291+ let loc l = make (Loc l)
292+
284293let list l = make (List l)
285294
286295let app symbol args = make (App (symbol, args))
@@ -574,7 +583,7 @@ let rec concat (msb : t) (lsb : t) : t =
574583
575584let rec simplify_expr ?(in_relop = false ) (hte : t ) : t =
576585 match view hte with
577- | Val _ | Symbol _ -> hte
586+ | Val _ | Symbol _ | Loc _ -> hte
578587 | Ptr { base; offset } ->
579588 let offset = simplify_expr ~in_relop offset in
580589 if not in_relop then make (Ptr { base; offset })
0 commit comments