From 790de19f73f1c164aba2259a6fe3f1a50eeff70c Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Wed, 27 Mar 2019 16:21:05 +0000 Subject: Interactive: Refactor sail.ml Rather than having a separate variable for each backend X, opt_print_X, just have a single variable opt_print_target, where target contains a string option, such as `Some "lem"` or `Some "ocaml"`, then we have a function target that takes that string and invokes the appropriate backend, so the main function in sail.ml goes from being a giant if-then-else block to a single call to target !opt_target ast env This allows us to implement a :compile command in the interactive toplevel Also implement a :rewrites command which performs all the rewrites for a specific target, so rather than doing e.g. > sail -c -O -o out $FILES one could instead interactively do > sail -i :option -undefined_gen :load $FILES :option -O :option -o out :rewrites c :compile c :quit for the same result. To support this the behavior of the interactive mode has changed slightly. It no longer performs any rewrites at all, so a :rewrites interpreter is currently needed to interpret functions in the interactive toplevel, nor does it automatically set any other flags, so -undefined_gen is needed in this case, which is usually implied by the -c flag. --- src/process_file.ml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/process_file.ml') diff --git a/src/process_file.ml b/src/process_file.ml index e7bf8d30..c6d900b4 100644 --- a/src/process_file.ml +++ b/src/process_file.ml @@ -402,14 +402,8 @@ let rewrite env rewriters defs = | Type_check.Type_error (_, l, err) -> raise (Reporting.err_typ l (Type_error.string_of_type_error err)) -let rewrite_ast env = rewrite env [("initial", fun _ -> Rewriter.rewrite_defs)] -let rewrite_ast_lem env = rewrite env Rewrites.rewrite_defs_lem -let rewrite_ast_coq env = rewrite env Rewrites.rewrite_defs_coq -let rewrite_ast_ocaml env = rewrite env Rewrites.rewrite_defs_ocaml -let rewrite_ast_c env ast = - ast - |> rewrite env Rewrites.rewrite_defs_c - |> rewrite env [("constant_fold", fun _ -> Constant_fold.rewrite_constant_function_calls)] - -let rewrite_ast_interpreter env = rewrite env Rewrites.rewrite_defs_interpreter +let rewrite_ast_initial env = rewrite env [("initial", fun _ -> Rewriter.rewrite_defs)] + +let rewrite_ast_target tgt env = rewrite env (Rewrites.rewrite_defs_target tgt) + let rewrite_ast_check env = rewrite env Rewrites.rewrite_defs_check -- cgit v1.2.3