Skip to content

Commit

Permalink
int2bv and bv2nat: smart constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
bclement-ocp committed Jul 11, 2023
1 parent 17820c9 commit cd4704d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib/structures/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2908,9 +2908,6 @@ module BV = struct
assert (size t = m);
m

let int2bv n t = mk_term (Op (Int2BV n)) [t] (Tbitv n)
let bv2nat t = mk_term (Op BV2Nat) [t] Tint

(* Function symbols for concatenation *)
let concat s t =
let n = size s and m = size t in
Expand Down Expand Up @@ -2952,6 +2949,22 @@ module BV = struct
else
concat (extract (i - 1) 0 t) (extract (m - 1) i t)

(* int2bv and bv2nat *)
let int2bv n t =
match term_view t with
| { f = Op BV2Nat; xs = [ t ]; ty = Tbitv m; _ } ->
if m > n then
extract (n - 1) 0 t
else
zero_extend (n - m) t
| _ -> mk_term (Op (Int2BV n)) [t] (Tbitv n)

let bv2nat t =
match term_view t with
| { f = Op Int2BV n; xs = [ t ]; _ } ->
Ints.(t mod ~$Z.(pow ~$2 n))
| _ -> mk_term (Op BV2Nat) [t] Tint

(* Bit-wise operations *)
let bvnot s = mk_term (Op BVnot) [s] (type_info s)
let bvand s t = mk_term (Op BVand) [s; t] (type_info s)
Expand Down

0 comments on commit cd4704d

Please sign in to comment.