@@ -94,14 +94,28 @@ let flatten_exp
9494 Bil. Var var, insert blk def
9595 | Bil. Extract (n , p , x ) ->
9696 aux x blk >> = fun (x , blk ) ->
97- new_var (Var. sort_of_typ (get_direct_typ x)) >> = fun var ->
97+ let res_typ = Type. Imm (n - p + 1 ) in
98+ new_var (Var. sort_of_typ (res_typ)) >> = fun var ->
9899 let e = Bil. Extract (n, p, x) in
99100 new_def var e >> | fun def ->
100101 Bil. Var var, insert blk def
101102 | Bil. Concat (x , y ) ->
102103 aux x blk >> = fun (x , blk ) ->
103104 aux y blk >> = fun (y , blk ) ->
104- new_var (Var. sort_of_typ (get_direct_typ y)) >> = fun var ->
105+ let exp_size (e : exp ) : int option =
106+ let typ_size (typ : Type.t ) : (int option) = match typ with
107+ | Type. Imm i -> Some i
108+ | Type. Unk -> None
109+ | _ -> failwith " concating non-immediates"
110+ in
111+ match e with
112+ | Bil. Var v -> typ_size (Var. typ v)
113+ | Bil. Unknown (_ , t ) -> typ_size t
114+ | Bil. Int w -> Some (Word. bitwidth w)
115+ | _ -> failwith " the expression is not flattened"
116+ in
117+ let res_typ = Option. both (exp_size x) (exp_size y) |> Option. value_map ~default: Type. Unk ~f: (fun (x_size , y_size ) -> Type. Imm (x_size + y_size)) in
118+ new_var (Var. sort_of_typ (res_typ)) >> = fun var ->
105119 let e = Bil. Concat (x, y) in
106120 new_def var e >> | fun def ->
107121 Bil. Var var, insert blk def in
0 commit comments