Skip to content

Commit 00ea4e6

Browse files
committed
More floating point value parsing
1 parent e530321 commit 00ea4e6

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/smtml/smtlib.ml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ module Term = struct
130130
let exponent_shifted = Int64.shift_left exponent 52 in
131131
Int64.logor sign_shifted (Int64.logor exponent_shifted mantissa)
132132

133-
let combine_to_int32 sign_bit exponent_bit mantissa_bit =
134-
let sign = Int32.of_string sign_bit in
135-
let exponent = Int32.of_string exponent_bit in
136-
let mantissa = Int32.of_string mantissa_bit in
133+
let combine_to_int32 sign exponent mantissa =
137134
let sign_shifted = Int32.shift_left sign 31 in
138135
let exponent_shifted = Int32.shift_left exponent 23 in
139136
Int32.logor sign_shifted (Int32.logor exponent_shifted mantissa)
@@ -214,13 +211,27 @@ module Term = struct
214211
| "concat", [ a; b ] -> Expr.raw_concat a b
215212
| "fp", [ s; eb; i ] -> (
216213
match (Expr.view s, Expr.view eb, Expr.view i) with
217-
| Val (Str sign), Val (Str eb), Val (Str i) -> (
214+
| Val (Str sign), Val (Str eb), Val (Str i) -> begin
218215
match (String.length sign, String.length eb, String.length i) with
219216
(* 32 bit float -> sign = 1, eb = 8, i = 24 - 1 = 23 *)
220-
| 3, 10, 25 -> Expr.value (Num (F32 (combine_to_int32 sign eb i)))
217+
| 3, 10, 25 ->
218+
let sign = Int32.of_string sign in
219+
let exponent = Int32.of_string eb in
220+
let mantissa = Int32.of_string i in
221+
Expr.value (Num (F32 (combine_to_int32 sign exponent mantissa)))
221222
(* 64 bit float -> sign = 1, eb = 11, i = 53 - 1 = 52 *)
222223
| 3, 13, 54 -> Expr.value (Num (F64 (combine_to_int64 sign eb i)))
223-
| _ -> Fmt.failwith "%afp size not supported" pp_loc loc )
224+
| _ -> Fmt.failwith "%afp size not supported" pp_loc loc
225+
end
226+
| Val (Str sign), Val (Bitv eb), Val (Str i) -> begin
227+
match (String.length sign, Bitvector.numbits eb, String.length i) with
228+
| 3, 8, 25 ->
229+
let sign = Int32.of_string sign in
230+
let exponent = Bitvector.to_int32 eb in
231+
let mantissa = Int32.of_string i in
232+
Expr.value (Num (F32 (combine_to_int32 sign exponent mantissa)))
233+
| _ -> Fmt.failwith "%afp size not supported" pp_loc loc
234+
end
224235
| _ ->
225236
Fmt.failwith "%acould not parse fp: %a %a %a" pp_loc loc Expr.pp s
226237
Expr.pp eb Expr.pp i )

0 commit comments

Comments
 (0)