diff --git a/web/aslp.js b/web/aslp.js index e312b86f..473018dd 100644 --- a/web/aslp.js +++ b/web/aslp.js @@ -85,3 +85,4 @@ const write = (isError) => s => { libASL_web.init(write(false), write(true)); libASL_web.setDebugLevel(0); + diff --git a/web/dune b/web/dune index 5daaee9b..87f4d3c7 100644 --- a/web/dune +++ b/web/dune @@ -3,7 +3,7 @@ (modes js) (modules js) (libraries libASL libASL_web js_of_ocaml) - (js_of_ocaml (flags --debug-info --no-inline --sourcemap :standard \ --source-map-inline)) + (js_of_ocaml (flags --sourcemap :standard \ --source-map-inline)) (preprocess (pps js_of_ocaml-ppx)) ) diff --git a/web/js.ml b/web/js.ml index f6cab93e..e16fd656 100644 --- a/web/js.ml +++ b/web/js.ml @@ -5,8 +5,15 @@ let init input out err = Js_of_ocaml.Sys_js.set_channel_filler stdin input; () -let env = lazy (Option.get @@ LibASL.Arm_env.aarch64_evaluation_environment ()) -let denv = lazy (LibASL.Dis.build_env @@ Lazy.force env) +let cachedenv : LibASL.Eval.Env.t option ref = ref None +let uncachedenv = lazy (Option.get @@ LibASL.Arm_env.aarch64_evaluation_environment ()) + +let env () = + match !cachedenv with + | Some x -> x + | None -> Lazy.force uncachedenv + +let denv = lazy (LibASL.Dis.build_env @@ env ()) let print_pp = ref true @@ -14,7 +21,7 @@ let pp_stmt () = if !print_pp then Asl_utils.pp_stmt else fun x -> Utils.to_string (Asl_parser_pp.pp_raw_stmt x) let dis (x: string) = - let stmts = LibASL.Dis.retrieveDisassembly Lazy.(force env) Lazy.(force denv) x in + let stmts = LibASL.Dis.retrieveDisassembly (env ()) Lazy.(force denv) x in List.iter (fun s -> print_endline @@ pp_stmt () s) stmts; @@ -30,7 +37,9 @@ let () = (* TODO: support stdin from javascript for repl, possibly converting asli repl to lwt *) method init (out : string -> unit) (err : string -> unit) = init (fun () -> "") out err - method force = let _ = Lazy.force env and _ = Lazy.force denv in () + method force = let env' = env () and _ = Lazy.force denv in fun () -> Js.bytestring @@ Marshal.to_string env' [] + method cache (a: Js.js_string Js.t) = (cachedenv := Some (Marshal.from_string (Js.to_bytestring a) 0)) + method uncache = (cachedenv := None) method dis (x: string) = dis x method setDebugLevel i = (LibASL.Dis.debug_level := i) method setPrettyPrint (x : bool) = (print_pp := x)