Skip to content

Commit

Permalink
trying to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinafyi committed Jun 24, 2024
1 parent bd0ec31 commit 99d34ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions web/aslp.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ const write = (isError) => s => {

libASL_web.init(write(false), write(true));
libASL_web.setDebugLevel(0);

2 changes: 1 addition & 1 deletion web/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)

Expand Down
17 changes: 13 additions & 4 deletions web/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ 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

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;
Expand All @@ -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)
Expand Down

0 comments on commit 99d34ed

Please sign in to comment.