@@ -12,9 +12,22 @@ let pp_loc fmt = function
1212 | None -> ()
1313 | Some loc -> Fmt. pf fmt " %a: " Loc. print_compact loc
1414
15+ let z_of_string_opt str =
16+ match Z. of_string str with
17+ | exception Invalid_argument _ -> None
18+ | z -> Some z
19+
1520module Term = struct
1621 type t = Expr .t
1722
23+ let fp_of_size f ebits sbits =
24+ match (ebits, sbits) with
25+ | "8" , "24" -> Expr. value (Num (F32 (Int32. bits_of_float f)))
26+ | "11" , "53" -> Expr. value (Num (F64 (Int64. bits_of_float f)))
27+ | _ ->
28+ Fmt. failwith " fp_of_size: unsupported %a (fp %a %a)" Fmt. float f
29+ Fmt. string ebits Fmt. string sbits
30+
1831 let const ?loc (id : Symbol.t ) : t =
1932 match (Symbol. namespace id, Symbol. name id) with
2033 | Sort , Simple name -> (
@@ -50,15 +63,24 @@ module Term = struct
5063 | "true" -> Expr. value True
5164 | "false" -> Expr. value False
5265 | _ -> Expr. symbol id )
53- | Term , Indexed { basename = base ; indices } -> (
54- match String. (sub base 0 2 , sub base 2 (length base - 2 ) , indices) with
55- | "bv" , str , [ numbits ] -> begin
56- match (int_of_string_opt str, int_of_string_opt numbits) with
57- | Some n , Some width ->
58- Expr. value (Bitv (Bitvector. make ( Z. of_int n) width))
66+ | Term , Indexed { basename = base ; indices } -> begin
67+ match ( base, indices) with
68+ | bv , [ numbits ] when String. starts_with ~prefix: " bv " bv -> begin
69+ let str = String. sub bv 2 ( String. length bv - 2 ) in
70+ match (z_of_string_opt str, int_of_string_opt numbits) with
71+ | Some z , Some width -> Expr. value (Bitv (Bitvector. make z width))
5972 | (None | Some _ ), _ -> assert false
6073 end
61- | _ -> Expr. symbol id )
74+ | "+oo" , [ ebits; sbits ] -> fp_of_size Float. infinity ebits sbits
75+ | "-oo" , [ ebits; sbits ] -> fp_of_size Float. neg_infinity ebits sbits
76+ | "+zero" , [ ebits; sbits ] -> fp_of_size Float. zero ebits sbits
77+ | "-zero" , [ ebits; sbits ] ->
78+ fp_of_size (Float. neg Float. zero) ebits sbits
79+ | "NaN" , [ ebits; sbits ] -> fp_of_size Float. nan ebits sbits
80+ | _ ->
81+ Log. debug (fun k -> k " const: Unknown %a making app" Symbol. pp id);
82+ Expr. symbol id
83+ end
6284 | Attr , Simple _ -> Expr. symbol id
6385 | Attr , Indexed _ -> assert false
6486 | Var , _ -> Fmt. failwith " %acould not parse var: %a" pp_loc loc Symbol. pp id
@@ -94,6 +116,7 @@ module Term = struct
94116 match Expr. view symbol with
95117 | Symbol s ->
96118 (* Hack: var bindings are 1 argument lambdas *)
119+ Log. debug (fun k -> k " colon: unknown '%a' making app" Expr. pp symbol);
97120 Expr. app s [ term ]
98121 | _ ->
99122 Fmt. failwith " %acould not parse colon: %a %a" pp_loc loc Expr. pp symbol
@@ -257,8 +280,11 @@ module Term = struct
257280 | "fp.geq" , [ a; b ] -> Expr. raw_relop Ty_bool Ge a b
258281 | "fp.gt" , [ a; b ] -> Expr. raw_relop Ty_bool Gt a b
259282 | "fp.eq" , [ a; b ] -> Expr. raw_relop Ty_bool Eq a b
260- | _ , l -> Expr. app symbol l )
283+ | _ , l ->
284+ Log. debug (fun k -> k " apply: unknown %a making app" Symbol. pp symbol);
285+ Expr. app symbol l )
261286 | Symbol ({ name = Simple _ ; namespace = Attr ; _ } as attr ) ->
287+ Log. debug (fun k -> k " apply: unknown %a making app" Symbol. pp attr);
262288 Expr. app attr args
263289 | Symbol { name = Indexed { basename; indices } ; _ } -> (
264290 match (basename, indices, args) with
@@ -291,7 +317,9 @@ module Term = struct
291317 Expr. raw_unop Ty_regexp (Regexp_loop (i1, i2)) a
292318 | _ ->
293319 Fmt. failwith " %acould not parse indexed app: %a" pp_loc loc Expr. pp id )
294- | Symbol id -> Expr. app id args
320+ | Symbol id ->
321+ Log. debug (fun k -> k " apply: unknown %a making app" Symbol. pp id);
322+ Expr. app id args
295323 | _ ->
296324 (* Ids can only be symbols. Any other expr here is super wrong *)
297325 assert false
0 commit comments