[sledge] Separate Funsym module

Summary: Funsym does not need to be defined as a submodule of Fol.

Reviewed By: jvillard

Differential Revision: D24306092

fbshipit-source-id: 7875f45f0
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 6b5fc4be3e
commit a0a5cf159a

@ -9,52 +9,7 @@ let pp_boxed fs fmt =
Format.pp_open_box fs 2 ; Format.pp_open_box fs 2 ;
Format.kfprintf (fun fs -> Format.pp_close_box fs ()) fs fmt Format.kfprintf (fun fs -> Format.pp_close_box fs ()) fs fmt
(* module Funsym = Ses.Funsym
* (Uninterpreted) Function Symbols
*)
module Funsym = struct
type t =
| Float of string
| Label of {parent: string; name: string}
| Mul
| Div
| Rem
| EmptyRecord
| RecRecord of int
| BitAnd
| BitOr
| BitXor
| BitShl
| BitLshr
| BitAshr
| Signed of int
| Unsigned of int
| Convert of {src: Llair.Typ.t; dst: Llair.Typ.t}
| External of Ses.Term.Funsym.t
[@@deriving compare, equal, sexp]
let pp fs f =
let pf fmt = pp_boxed fs fmt in
match f with
| Float s -> pf "%s" s
| Label {name} -> pf "%s" name
| Mul -> pf "@<1>×"
| Div -> pf "/"
| Rem -> pf "%%"
| EmptyRecord -> pf "{}"
| RecRecord i -> pf "(rec_record %i)" i
| BitAnd -> pf "&&"
| BitOr -> pf "||"
| BitXor -> pf "xor"
| BitShl -> pf "shl"
| BitLshr -> pf "lshr"
| BitAshr -> pf "ashr"
| Signed n -> pf "(s%i)" n
| Unsigned n -> pf "(u%i)" n
| Convert {src; dst} -> pf "(%a)(%a)" Llair.Typ.pp dst Llair.Typ.pp src
| External sym -> pf "%a" Ses.Term.Funsym.pp sym
end
(* (*
* Terms * Terms
@ -947,9 +902,7 @@ module Term = struct
(* uninterpreted *) (* uninterpreted *)
let apply sym args = let apply sym args =
apNt apNt (fun es -> _Apply sym (_Tuple (Array.of_list es))) args
(fun es -> _Apply (Funsym.External sym) (_Tuple (Array.of_list es)))
args
(** Destruct *) (** Destruct *)
@ -1188,6 +1141,8 @@ let rec t_to_ses : trm -> Ses.Term.t = function
| Apply (Unsigned n, Tuple [|x|]) -> Ses.Term.unsigned n (t_to_ses x) | Apply (Unsigned n, Tuple [|x|]) -> Ses.Term.unsigned n (t_to_ses x)
| Apply (Convert {src; dst}, Tuple [|x|]) -> | Apply (Convert {src; dst}, Tuple [|x|]) ->
Ses.Term.convert src ~to_:dst (t_to_ses x) Ses.Term.convert src ~to_:dst (t_to_ses x)
| Apply (sym, Tuple xs) ->
Ses.Term.apply sym (IArray.of_array (Array.map ~f:t_to_ses xs))
| (Apply _ | Tuple _ | Project _) as t -> | (Apply _ | Tuple _ | Project _) as t ->
fail "cannot translate to Ses: %a" pp_t t () fail "cannot translate to Ses: %a" pp_t t ()

@ -69,7 +69,7 @@ module rec Term : sig
val project : ary:int -> idx:int -> t -> t val project : ary:int -> idx:int -> t -> t
(* uninterpreted *) (* uninterpreted *)
val apply : Ses.Term.Funsym.t -> t array -> t val apply : Ses.Funsym.t -> t array -> t
(* if-then-else *) (* if-then-else *)
val ite : cnd:Formula.t -> thn:t -> els:t -> t val ite : cnd:Formula.t -> thn:t -> els:t -> t

@ -0,0 +1,49 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
(** Function Symbols *)
type t =
| Float of string
| Label of {parent: string; name: string}
| Mul
| Div
| Rem
| EmptyRecord
| RecRecord of int
| BitAnd
| BitOr
| BitXor
| BitShl
| BitLshr
| BitAshr
| Signed of int
| Unsigned of int
| Convert of {src: Llair.Typ.t; dst: Llair.Typ.t}
| Uninterp of string
[@@deriving compare, equal, sexp]
let pp ppf f =
let pf fmt = Format.fprintf ppf fmt in
match f with
| Float s -> pf "%s" s
| Label {name} -> pf "%s" name
| Mul -> pf "@<1>×"
| Div -> pf "/"
| Rem -> pf "%%"
| EmptyRecord -> pf "{}"
| RecRecord i -> pf "(rec_record %i)" i
| BitAnd -> pf "&&"
| BitOr -> pf "||"
| BitXor -> pf "xor"
| BitShl -> pf "shl"
| BitLshr -> pf "lshr"
| BitAshr -> pf "ashr"
| Signed n -> pf "(s%i)" n
| Unsigned n -> pf "(u%i)" n
| Convert {src; dst} -> pf "(%a)(%a)" Llair.Typ.pp dst Llair.Typ.pp src
| Uninterp sym -> pf "%s" sym

@ -0,0 +1,30 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
(** Function Symbols *)
type t =
| Float of string
| Label of {parent: string; name: string}
| Mul
| Div
| Rem
| EmptyRecord
| RecRecord of int
| BitAnd
| BitOr
| BitXor
| BitShl
| BitLshr
| BitAshr
| Signed of int
| Unsigned of int
| Convert of {src: Llair.Typ.t; dst: Llair.Typ.t}
| Uninterp of string
[@@deriving compare, equal, sexp]
val pp : t pp

@ -9,18 +9,6 @@
[@@@warning "+9"] [@@@warning "+9"]
module Funsym : sig
type t [@@deriving compare, equal, sexp]
val make : string -> t
val pp : t pp
end = struct
type t = string [@@deriving compare, equal, sexp]
let make s = s
let pp = Format.pp_print_string
end
type op1 = type op1 =
| Signed of {bits: int} | Signed of {bits: int}
| Unsigned of {bits: int} | Unsigned of {bits: int}

@ -10,13 +10,6 @@
Pure (heap-independent) terms are arithmetic, bitwise-logical, etc. Pure (heap-independent) terms are arithmetic, bitwise-logical, etc.
operations over literal values and variables. *) operations over literal values and variables. *)
module Funsym : sig
type t [@@deriving compare, equal, sexp]
val make : string -> t
val pp : t pp
end
type op1 = type op1 =
| Signed of {bits: int} | Signed of {bits: int}
(** [Ap1 (Signed {bits= n}, arg)] is [arg] interpreted as an [n]-bit (** [Ap1 (Signed {bits= n}, arg)] is [arg] interpreted as an [n]-bit

Loading…
Cancel
Save