summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlasdair Armstrong2019-05-07 19:59:46 +0100
committerAlasdair Armstrong2019-05-07 19:59:46 +0100
commit868e719ec512d79ffb131356eb7225bea960b411 (patch)
tree724a24035289c92ead0174a5470be6c743961667 /src
parente70f5f2069177eb980f31eab5819346872d0af3b (diff)
Move parser combinators shared by property and model parsing to separate file
Diffstat (limited to 'src')
-rw-r--r--src/jib/c_backend.ml22
-rw-r--r--src/jib/jib_compile.ml2
-rw-r--r--src/jib/jib_ssa.ml1
-rw-r--r--src/jib/jib_util.ml14
-rw-r--r--src/parser_combinators.ml102
-rw-r--r--src/property.ml2
-rw-r--r--src/smtlib.ml53
7 files changed, 113 insertions, 83 deletions
diff --git a/src/jib/c_backend.ml b/src/jib/c_backend.ml
index d21d219c..b98c53c4 100644
--- a/src/jib/c_backend.ml
+++ b/src/jib/c_backend.ml
@@ -86,7 +86,7 @@ let optimize_primops = ref false
let optimize_hoist_allocations = ref false
let optimize_struct_updates = ref false
let optimize_alias = ref false
-let optimize_int128 = ref false
+let optimize_int128 = ref false
let c_debug str =
if !c_verbosity > 0 then prerr_endline (Lazy.force str) else ()
@@ -522,26 +522,6 @@ let analyze_primop' ctx id args typ =
no_change
end
- (*
- | "undefined_vector", [AV_C_fragment (len, _, _); _] ->
- begin match destruct_vector ctx.tc_env typ with
- | Some (Nexp_aux (Nexp_constant n, _), _, Typ_aux (Typ_id id, _))
- when string_of_id id = "bit" && Big_int.less_equal n (Big_int.of_int 64) ->
- AE_val (AV_C_fragment (F_lit (V_bit Sail2_values.B0), typ, ctyp_of_typ ctx typ))
- | _ -> no_change
- end
-
- | "neg_int", [AV_C_fragment (frag, _, _)] ->
- AE_val (AV_C_fragment (F_op (v_int 0, "-", frag), typ, CT_fint 64))
-
- | "vector_update_subrange", [AV_C_fragment (xs, _, CT_fbits (n, true));
- AV_C_fragment (hi, _, CT_fint 64);
- AV_C_fragment (lo, _, CT_fint 64);
- AV_C_fragment (ys, _, CT_fbits (m, true))] ->
- AE_val (AV_C_fragment (F_call ("fast_update_subrange", [xs; hi; lo; ys]), typ, CT_fbits (n, true)))
-
- *)
-
| "undefined_bit", _ ->
AE_val (AV_cval (V_lit (VL_bit Sail2_values.B0, CT_bit), typ))
diff --git a/src/jib/jib_compile.ml b/src/jib/jib_compile.ml
index a5a411f5..ad60d224 100644
--- a/src/jib/jib_compile.ml
+++ b/src/jib/jib_compile.ml
@@ -435,7 +435,7 @@ let optimize_call l ctx clexp id args arg_ctyps ret_ctyp =
if not ctx.specialize_calls && Env.is_extern id ctx.tc_env "c" then
let extern = Env.get_extern id ctx.tc_env "c" in
begin match extern, List.map cval_ctyp args, clexp_ctyp clexp with
- | "slice", [CT_fbits _; _; _], CT_fbits (n, _) ->
+ | "slice", [CT_fbits _; CT_lint; _], CT_fbits (n, _) ->
let start = ngensym () in
[iinit (CT_fint 64) start (List.nth args 1);
icopy l clexp (V_call (Slice n, [List.nth args 0; V_id (start, CT_fint 64)]))]
diff --git a/src/jib/jib_ssa.ml b/src/jib/jib_ssa.ml
index 19dff7b1..c8027ee5 100644
--- a/src/jib/jib_ssa.ml
+++ b/src/jib/jib_ssa.ml
@@ -672,7 +672,6 @@ let ssa instrs =
place_phi_functions cfg df;
rename_variables cfg start children;
place_pi_functions cfg start idom children;
- (* remove_guard_nodes (function CF_guard _ -> true | CF_label _ -> true | _ -> false) cfg; *)
start, cfg
(* Debugging utilities for outputing Graphviz files. *)
diff --git a/src/jib/jib_util.ml b/src/jib/jib_util.ml
index 1c2e9530..c98c325c 100644
--- a/src/jib/jib_util.ml
+++ b/src/jib/jib_util.ml
@@ -295,13 +295,13 @@ let string_of_op = function
| Igteq -> "@gteq"
| Iadd -> "@iadd"
| Isub -> "@isub"
- | Unsigned n -> "@unsigned::<" ^ string_of_int n ^ "@>"
- | Signed n -> "@signed::<" ^ string_of_int n ^ "@>"
- | Zero_extend n -> "@zero_extend::<" ^ string_of_int n ^ "@>"
- | Sign_extend n -> "@sign_extend::<" ^ string_of_int n ^ "@>"
- | Slice n -> "@slice::<" ^ string_of_int n ^ "@>"
- | Sslice n -> "@sslice::<" ^ string_of_int n ^ "@>"
- | Replicate n -> "@replicate::<" ^ string_of_int n ^ "@>"
+ | Unsigned n -> "@unsigned::<" ^ string_of_int n ^ ">"
+ | Signed n -> "@signed::<" ^ string_of_int n ^ ">"
+ | Zero_extend n -> "@zero_extend::<" ^ string_of_int n ^ ">"
+ | Sign_extend n -> "@sign_extend::<" ^ string_of_int n ^ ">"
+ | Slice n -> "@slice::<" ^ string_of_int n ^ ">"
+ | Sslice n -> "@sslice::<" ^ string_of_int n ^ ">"
+ | Replicate n -> "@replicate::<" ^ string_of_int n ^ ">"
| Set_slice -> "@set_slice"
| Concat -> "@concat"
diff --git a/src/parser_combinators.ml b/src/parser_combinators.ml
new file mode 100644
index 00000000..97ad1827
--- /dev/null
+++ b/src/parser_combinators.ml
@@ -0,0 +1,102 @@
+(**************************************************************************)
+(* Sail *)
+(* *)
+(* Copyright (c) 2013-2017 *)
+(* Kathyrn Gray *)
+(* Shaked Flur *)
+(* Stephen Kell *)
+(* Gabriel Kerneis *)
+(* Robert Norton-Wright *)
+(* Christopher Pulte *)
+(* Peter Sewell *)
+(* Alasdair Armstrong *)
+(* Brian Campbell *)
+(* Thomas Bauereiss *)
+(* Anthony Fox *)
+(* Jon French *)
+(* Dominic Mulligan *)
+(* Stephen Kell *)
+(* Mark Wassell *)
+(* *)
+(* All rights reserved. *)
+(* *)
+(* This software was developed by the University of Cambridge Computer *)
+(* Laboratory as part of the Rigorous Engineering of Mainstream Systems *)
+(* (REMS) project, funded by EPSRC grant EP/K008528/1. *)
+(* *)
+(* Redistribution and use in source and binary forms, with or without *)
+(* modification, are permitted provided that the following conditions *)
+(* are met: *)
+(* 1. Redistributions of source code must retain the above copyright *)
+(* notice, this list of conditions and the following disclaimer. *)
+(* 2. Redistributions in binary form must reproduce the above copyright *)
+(* notice, this list of conditions and the following disclaimer in *)
+(* the documentation and/or other materials provided with the *)
+(* distribution. *)
+(* *)
+(* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' *)
+(* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *)
+(* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *)
+(* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR *)
+(* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *)
+(* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *)
+(* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *)
+(* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *)
+(* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *)
+(* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *)
+(* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *)
+(* SUCH DAMAGE. *)
+(**************************************************************************)
+
+type 'a parse_result =
+ | Ok of 'a * Str.split_result list
+ | Fail
+
+type 'a parser = Str.split_result list -> 'a parse_result
+
+let (>>=) (m : 'a parser) (f : 'a -> 'b parser) (toks : Str.split_result list) =
+ match m toks with
+ | Ok (r, toks) -> f r toks
+ | Fail -> Fail
+
+let pmap f m toks =
+ match m toks with
+ | Ok (r, toks) -> Ok (f r, toks)
+ | Fail -> Fail
+
+let token f = function
+ | tok :: toks ->
+ begin match f tok with
+ | Some x -> Ok (x, toks)
+ | None -> Fail
+ end
+ | [] -> Fail
+
+let preturn x toks = Ok (x, toks)
+
+let rec plist m toks =
+ match m toks with
+ | Ok (x, toks) ->
+ begin match plist m toks with
+ | Ok (xs, toks) -> Ok (x :: xs, toks)
+ | Fail -> Fail
+ end
+ | Fail -> Ok ([], toks)
+
+let pchoose m n toks =
+ match m toks with
+ | Fail -> n toks
+ | Ok (x, toks) -> Ok (x, toks)
+
+let parse p delim_regexp input =
+ let delim = Str.regexp delim_regexp in
+ let tokens = Str.full_split delim input in
+ let non_whitespace = function
+ | Str.Delim d when String.trim d = "" -> false
+ | _ -> true
+ in
+ let tokens = List.filter non_whitespace tokens in
+ match p tokens with
+ | Ok (result, []) -> Some result
+ | Ok (result, _) -> None
+ | Fail -> None
diff --git a/src/property.ml b/src/property.ml
index 9ef546a2..8dbc31fe 100644
--- a/src/property.ml
+++ b/src/property.ml
@@ -50,7 +50,7 @@
open Ast
open Ast_util
-open Smtlib
+open Parser_combinators
let find_properties (Defs defs) =
let rec find_prop acc = function
diff --git a/src/smtlib.ml b/src/smtlib.ml
index 65e73791..72421b8a 100644
--- a/src/smtlib.ml
+++ b/src/smtlib.ml
@@ -267,45 +267,7 @@ let rec string_of_sexpr = function
| List sexprs -> "(" ^ Util.string_of_list " " string_of_sexpr sexprs ^ ")"
| Atom str -> str
-type 'a parse_result =
- | Ok of 'a * Str.split_result list
- | Fail
-
-type 'a parser = Str.split_result list -> 'a parse_result
-
-let (>>=) (m : 'a parser) (f : 'a -> 'b parser) (toks : Str.split_result list) =
- match m toks with
- | Ok (r, toks) -> f r toks
- | Fail -> Fail
-
-let pmap f m toks =
- match m toks with
- | Ok (r, toks) -> Ok (f r, toks)
- | Fail -> Fail
-
-let token f = function
- | tok :: toks ->
- begin match f tok with
- | Some x -> Ok (x, toks)
- | None -> Fail
- end
- | [] -> Fail
-
-let preturn x toks = Ok (x, toks)
-
-let rec plist m toks =
- match m toks with
- | Ok (x, toks) ->
- begin match plist m toks with
- | Ok (xs, toks) -> Ok (x :: xs, toks)
- | Fail -> Fail
- end
- | Fail -> Ok ([], toks)
-
-let pchoose m n toks =
- match m toks with
- | Fail -> n toks
- | Ok (x, toks) -> Ok (x, toks)
+open Parser_combinators
let lparen = token (function Str.Delim "(" -> Some () | _ -> None)
let rparen = token (function Str.Delim ")" -> Some () | _ -> None)
@@ -322,19 +284,6 @@ let rec sexp toks =
in
parse toks
-let parse p delim_regexp input =
- let delim = Str.regexp delim_regexp in
- let tokens = Str.full_split delim input in
- let non_whitespace = function
- | Str.Delim d when String.trim d = "" -> false
- | _ -> true
- in
- let tokens = List.filter non_whitespace tokens in
- match p tokens with
- | Ok (result, []) -> Some result
- | Ok (result, _) -> None
- | Fail -> None
-
let parse_sexps input =
let delim = Str.regexp "[ \n\t]+\\|(\\|)" in
let tokens = Str.full_split delim input in