Skip to content

Commit edd3ddd

Browse files
hra687261filipeom
authored andcommitted
Fix conversion from int string to bv
1 parent 781dca5 commit edd3ddd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/smtml/dolmenexpr_to_expr.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,22 @@ module DolmenIntf = struct
237237
module Bitv = struct
238238
include DTerm.Bitv
239239

240-
let v bv n =
241-
let bv = Z.format (Fmt.str "%c0%db" '%' n) (Z.of_string bv) in
240+
let int_to_bitvector n bits =
241+
let two_pow_n = 1 lsl bits in
242+
let unsigned_bv = if n < 0 then two_pow_n + n else n in
243+
let rec to_bitlist acc n bits =
244+
if bits = 0 then acc
245+
else
246+
to_bitlist
247+
(Prelude.String.cat (string_of_int (n land 1)) acc)
248+
(n lsr 1) (bits - 1)
249+
in
250+
(* let bitlist = to_bitlist [] unsigned_bv bits in
251+
Fmt.str "%a" (Fmt.list Fmt.int) bitlist *)
252+
to_bitlist "" unsigned_bv bits
253+
254+
let v (i : string) (n : int) =
255+
let bv = int_to_bitvector (Z.to_int (Z.of_string i)) n in
242256
DTerm.Bitv.mk bv
243257

244258
let lognot = DTerm.Bitv.not

0 commit comments

Comments
 (0)