From d104f5e518269d4587bb048348c06547171ce844 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 7 Jun 2019 03:16:14 -0700 Subject: [PATCH] [sledge] Extend Exp.typ to binary and ternary ops Summary: Most binary and ternary operations have the same type as their arguments, so try to compute the type of arguments in these cases. Reviewed By: kren1 Differential Revision: D15706576 fbshipit-source-id: 4749d6e32 --- sledge/src/llair/exp.ml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sledge/src/llair/exp.ml b/sledge/src/llair/exp.ml index 60d33859f..9a07a1b3d 100644 --- a/sledge/src/llair/exp.ml +++ b/sledge/src/llair/exp.ml @@ -354,12 +354,22 @@ let pp_t = pp (** Invariant *) -let typ_of = function +let rec typ_of = function | Add {typ} | Mul {typ} | Integer {typ} | App {op= Convert {dst= typ}} -> Some typ | App {op= App {op= Eq | Dq | Gt | Ge | Lt | Le | Ugt | Uge | Ult | Ule}} -> Some Typ.bool + | App + { op= + App + { op= + Div | Udiv | Rem | Urem | And | Or | Xor | Shl | Lshr | Ashr + ; arg= x } + ; arg= y } -> ( + match typ_of x with Some _ as t -> t | None -> typ_of y ) + | App {op= App {op= App {op= Conditional}; arg= thn}; arg= els} -> ( + match typ_of thn with Some _ as t -> t | None -> typ_of els ) | _ -> None let typ = typ_of