From: Andres Noetzli Date: Thu, 17 Jan 2019 00:38:38 +0000 (-0800) Subject: Add option to print BV constants in binary (#2805) X-Git-Tag: cvc5-1.0.0~4280 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78d7485639cdf0769c13606b8ad3f5e9455153f1;p=cvc5.git Add option to print BV constants in binary (#2805) This commit adds the option `--bv-print-consts-in-binary` to print bit-vector constants in binary, e.g. `#b0001`, instead of decimal, e.g. `(_ bv1 4)`). The option is on by default to match the behavior of Z3 and Boolector. --- diff --git a/src/options/bv_options.toml b/src/options/bv_options.toml index 0422ae06f..c4541f4e4 100644 --- a/src/options/bv_options.toml +++ b/src/options/bv_options.toml @@ -232,3 +232,11 @@ header = "options/bv_options.h" type = "bool" default = "true" help = "algebraic inferences for extended functions" + +[[option]] + name = "bvPrintConstsInBinary" + category = "regular" + long = "bv-print-consts-in-binary" + type = "bool" + default = "false" + help = "print bit-vector constants in binary (e.g. #b0001) instead of decimal (e.g. (_ bv1 4)), applies to SMT-LIB 2.x" diff --git a/src/printer/smt2/smt2_printer.cpp b/src/printer/smt2/smt2_printer.cpp index 259f23afc..d6ed07c12 100644 --- a/src/printer/smt2/smt2_printer.cpp +++ b/src/printer/smt2/smt2_printer.cpp @@ -22,6 +22,7 @@ #include #include "expr/node_manager_attributes.h" +#include "options/bv_options.h" #include "options/language.h" #include "options/smt_options.h" #include "printer/dagification_visitor.h" @@ -160,11 +161,14 @@ void Smt2Printer::toStream(std::ostream& out, const BitVector& bv = n.getConst(); const Integer& x = bv.getValue(); unsigned n = bv.getSize(); - if(d_variant == sygus_variant ){ + if (d_variant == sygus_variant || options::bvPrintConstsInBinary()) + { out << "#b" << bv.toString(); - }else{ + } + else + { out << "(_ "; - out << "bv" << x <<" " << n; + out << "bv" << x << " " << n; out << ")"; } diff --git a/test/regress/CMakeLists.txt b/test/regress/CMakeLists.txt index 15dbf0df8..c8b052265 100644 --- a/test/regress/CMakeLists.txt +++ b/test/regress/CMakeLists.txt @@ -570,6 +570,8 @@ set(regress_0_tests regress0/preprocess/preprocess_14.cvc regress0/preprocess/preprocess_15.cvc regress0/print_lambda.cvc + regress0/printer/bv_consts_bin.smt2 + regress0/printer/bv_consts_dec.smt2 regress0/push-pop/boolean/fuzz_12.smt2 regress0/push-pop/boolean/fuzz_13.smt2 regress0/push-pop/boolean/fuzz_14.smt2 @@ -846,10 +848,10 @@ set(regress_0_tests regress0/strings/type001.smt2 regress0/strings/unsound-0908.smt2 regress0/strings/unsound-repl-rewrite.smt2 - regress0/sygus/array-grammar-select.sy - regress0/sygus/array-grammar-store.sy regress0/sygus/General_plus10.sy regress0/sygus/aig-si.sy + regress0/sygus/array-grammar-select.sy + regress0/sygus/array-grammar-store.sy regress0/sygus/c100.sy regress0/sygus/ccp16.lus.sy regress0/sygus/check-generic-red.sy diff --git a/test/regress/regress0/printer/bv_consts_bin.smt2 b/test/regress/regress0/printer/bv_consts_bin.smt2 new file mode 100644 index 000000000..e5c3c2824 --- /dev/null +++ b/test/regress/regress0/printer/bv_consts_bin.smt2 @@ -0,0 +1,9 @@ +; COMMAND-LINE: --bv-print-consts-in-binary +; EXPECT: sat +; EXPECT: ((x #b0001)) +(set-option :produce-models true) +(set-logic QF_BV) +(declare-const x (_ BitVec 4)) +(assert (= x #b0001)) +(check-sat) +(get-value (x)) diff --git a/test/regress/regress0/printer/bv_consts_dec.smt2 b/test/regress/regress0/printer/bv_consts_dec.smt2 new file mode 100644 index 000000000..98d95e822 --- /dev/null +++ b/test/regress/regress0/printer/bv_consts_dec.smt2 @@ -0,0 +1,9 @@ +; COMMAND-LINE: --no-bv-print-consts-in-binary +; EXPECT: sat +; EXPECT: ((x (_ bv1 4))) +(set-option :produce-models true) +(set-logic QF_BV) +(declare-const x (_ BitVec 4)) +(assert (= x #b0001)) +(check-sat) +(get-value (x))