Skip to content

Commit c541033

Browse files
committed
Don't rewrite types of well-typed symbols
1 parent 31a0d91 commit c541033

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/smtml/rewrite.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ let rec rewrite_expr (type_map, expr_map) hte =
4747
| Ptr { base; offset } ->
4848
Expr.ptr base (rewrite_expr (type_map, expr_map) offset)
4949
| Symbol sym -> begin
50-
match Symb_map.find_opt sym type_map with
51-
| None -> (
52-
match Symb_map.find_opt sym expr_map with
53-
| None -> Fmt.failwith "Undefined symbol: %a" Symbol.pp sym
54-
| Some expr -> expr )
55-
| Some ty -> Expr.symbol { sym with ty }
50+
(* Avoid rewriting well-typed symbols already *)
51+
if not (Ty.equal Ty_none (Symbol.type_of sym)) then hte
52+
else
53+
match Symb_map.find_opt sym type_map with
54+
| None -> (
55+
match Symb_map.find_opt sym expr_map with
56+
| None -> Fmt.failwith "Undefined symbol: %a" Symbol.pp sym
57+
| Some expr -> expr )
58+
| Some ty -> Expr.symbol { sym with ty }
5659
end
5760
| List htes -> Expr.list (List.map (rewrite_expr (type_map, expr_map)) htes)
5861
| App

src/smtml/smtlib.ml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Term = struct
4848
Expr.symbol id
4949
end
5050
end
51-
| Sort, Indexed { basename; indices } -> (
51+
| Sort, Indexed { basename; indices } -> begin
5252
match (basename, indices) with
5353
| "BitVec", [ n ] -> (
5454
match int_of_string_opt n with
@@ -62,12 +62,18 @@ module Term = struct
6262
Fmt.failwith "%acould not parse indexed sort:%a %a@." pp_loc loc
6363
Fmt.string basename
6464
(Fmt.parens (Fmt.list ~sep:Fmt.sp Fmt.string))
65-
indices )
66-
| Term, Simple name -> (
65+
indices
66+
end
67+
| Term, Simple name -> begin
6768
match name with
6869
| "true" -> Expr.value True
6970
| "false" -> Expr.value False
70-
| _ -> Expr.symbol id )
71+
| "roundNearestTiesToEven" | "RNE" | "roundNearestTiesToAway" | "RNA"
72+
| "roundTowardPositive" | "RTP" | "roundTowardNegative" | "RTN"
73+
| "roundTowardZero" | "RTZ" ->
74+
Expr.symbol { id with ty = Ty_roundingMode }
75+
| _ -> Expr.symbol id
76+
end
7177
| Term, Indexed { basename = base; indices } -> begin
7278
match (base, indices) with
7379
| bv, [ numbits ] when String.starts_with ~prefix:"bv" bv -> begin
@@ -137,7 +143,7 @@ module Term = struct
137143

138144
let apply ?loc (id : t) (args : t list) : t =
139145
match Expr.view id with
140-
| Symbol ({ namespace = Term; name = Simple name; _ } as symbol) -> (
146+
| Symbol ({ namespace = Term; name = Simple name; _ } as symbol) -> begin
141147
match (name, args) with
142148
| "-", [ a ] -> Expr.raw_unop Ty_none Neg a
143149
| "not", [ a ] -> Expr.raw_unop Ty_bool Not a
@@ -259,11 +265,12 @@ module Term = struct
259265
| "fp.eq", [ a; b ] -> Expr.raw_relop Ty_none Eq a b
260266
| _ ->
261267
Log.debug (fun k -> k "apply: unknown %a making app" Symbol.pp symbol);
262-
Expr.app symbol args )
268+
Expr.app symbol args
269+
end
263270
| Symbol ({ name = Simple _; namespace = Attr; _ } as attr) ->
264271
Log.debug (fun k -> k "apply: unknown %a making app" Symbol.pp attr);
265272
Expr.app attr args
266-
| Symbol { name = Indexed { basename; indices }; _ } -> (
273+
| Symbol { name = Indexed { basename; indices }; _ } -> begin
267274
match (basename, indices, args) with
268275
| "extract", [ h; l ], [ a ] ->
269276
let high =
@@ -302,7 +309,8 @@ module Term = struct
302309
] ) ->
303310
Expr.raw_cvtop (Ty_fp 64) PromoteF32 a
304311
| _ ->
305-
Fmt.failwith "%acould not parse indexed app: %a" pp_loc loc Expr.pp id )
312+
Fmt.failwith "%acould not parse indexed app: %a" pp_loc loc Expr.pp id
313+
end
306314
| Symbol id ->
307315
Log.debug (fun k -> k "apply: unknown %a making app" Symbol.pp id);
308316
Expr.app id args

0 commit comments

Comments
 (0)