Skip to content

Commit

Permalink
feat(BV): Display BV constants using hexadecimal
Browse files Browse the repository at this point in the history
We currently always print bit-vector constants using binary
representation. This can lead to quite large values in models when using
32- or 64-bit values that are essentially unreadable. When the
bit-vector width is a multiple of 4, this patch uses hexadecimal
notation instead, as allowed by the SMT-LIB specification.

Note that this only applies to bit-vector terms; bit-vector semantic
values are always printed in their binary representation for debugging
purposes.
  • Loading branch information
bclement-ocp committed Mar 29, 2024
1 parent f379389 commit 03d12f7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/structures/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,10 @@ module SmtPrinter = struct
pp_rational ppf q

| Sy.Bitv (n, s), [] ->
Fmt.pf ppf "#b%s" (Z.format (Fmt.str "%%0%db" n) s)
if n mod 4 = 0 then
Fmt.pf ppf "#x%s" (Z.format (Fmt.str "%%0%dx" (n / 4)) s)
else
Fmt.pf ppf "#b%s" (Z.format (Fmt.str "%%0%db" n) s)

| Sy.MapsTo v, [t] ->
Fmt.pf ppf "@[<2>(ae.mapsto %a %a@])" Var.print v pp t
Expand Down

0 comments on commit 03d12f7

Please sign in to comment.