Skip to content

Commit d792a33

Browse files
committed
SMT2 parser: implement to_fp_unsigned
This adds an implementation of to_fp_unsigned to the SMT2 parser.
1 parent 7a4328a commit d792a33

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

regression/cbmc/Float12/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-cprover-smt-backend
1+
CORE
22
main.c
33

44
^EXIT=0$

src/solvers/smt2/smt2_parser.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,42 @@ exprt smt2_parsert::function_application()
800800
else
801801
throw error() << "unexpected sort given as operand to to_fp";
802802
}
803+
else if(id == "to_fp_unsigned")
804+
{
805+
if(next_token() != smt2_tokenizert::NUMERAL)
806+
throw error("expected number after to_fp_unsigned");
807+
808+
auto width_e = std::stoll(smt2_tokenizer.get_buffer());
809+
810+
if(next_token() != smt2_tokenizert::NUMERAL)
811+
throw error("expected second number after to_fp_unsigned");
812+
813+
auto width_f = std::stoll(smt2_tokenizer.get_buffer());
814+
815+
if(next_token() != smt2_tokenizert::CLOSE)
816+
throw error("expected ')' after to_fp_unsigned");
817+
818+
// width_f *includes* the hidden bit
819+
const ieee_float_spect spec(width_f - 1, width_e);
820+
821+
auto rounding_mode = expression();
822+
823+
auto source_op = expression();
824+
825+
if(next_token() != smt2_tokenizert::CLOSE)
826+
throw error("expected ')' at the end of to_fp_unsigned");
827+
828+
if(source_op.type().id() == ID_unsignedbv)
829+
{
830+
// The operand is hard-wired to be interpreted
831+
// as an unsigned number.
832+
return floatbv_typecast_exprt(
833+
source_op, rounding_mode, spec.to_type());
834+
}
835+
else
836+
throw error()
837+
<< "unexpected sort given as operand to to_fp_unsigned";
838+
}
803839
else
804840
{
805841
throw error() << "unknown indexed identifier '"

0 commit comments

Comments
 (0)