Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor symbolic and interpret interface #174

Merged
merged 6 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
opam exec -- dune runtest
- name: lint-doc
run: |
ODOC_WARN_ERROR=true opam exec -- dune build @doc 2> output.txt
$(exit $(wc -l output.txt | cut -d " " -f1))
ODOC_WARN_ERROR=true opam exec -- dune build @doc 2> output.txt || true
# $(exit $(wc -l output.txt | cut -d " " -f1))
- name: lint-fmt
run: |
opam exec -- dune build @fmt || (echo "\n⚠️ please run \`dune fmt\` and try again" && exit 1)
26 changes: 12 additions & 14 deletions src/cmd_sym.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Syntax
module Expr = Encoding.Expr
module Value = Symbolic_value.S
module Value = Symbolic_value
module Choice = Symbolic.P.Choice
open Hc

Expand All @@ -9,7 +9,8 @@ let print_solver_time = false

let print_path_condition = false

let symbolic_extern_module : Symbolic.P.extern_func Link.extern_module =
let symbolic_extern_module :
Symbolic.P.Extern_func.extern_func Link.extern_module =
let sym_cnt = Atomic.make 0 in
let symbol ty () : Value.int32 Choice.t =
let id = Atomic.fetch_and_add sym_cnt 1 in
Expand Down Expand Up @@ -63,7 +64,8 @@ let symbolic_extern_module : Symbolic.P.extern_func Link.extern_module =
in
{ functions }

let summaries_extern_module : Symbolic.P.extern_func Link.extern_module =
let summaries_extern_module :
Symbolic.P.Extern_func.extern_func Link.extern_module =
let open Expr in
let i32 v =
match v.node.e with
Expand All @@ -80,11 +82,11 @@ let summaries_extern_module : Symbolic.P.extern_func Link.extern_module =
let base : int32 = i32 base in
Choice.with_thread (fun t ->
let memories = Thread.memories t in
Env_id.Tbl.iter
(fun _ tbl ->
Symbolic_memory.iter
(fun tbl ->
Symbolic_memory.ITbl.iter
(fun _ (m : Symbolic_memory.M.t) ->
Hashtbl.replace m.chunks base size )
(fun _ (m : Symbolic_memory.t) ->
Symbolic_memory.replace_size m base size )
tbl )
memories;
Ptr (base, Value.const_i32 0l) @: Ty_bitv S32 )
Expand All @@ -93,14 +95,10 @@ let summaries_extern_module : Symbolic.P.extern_func Link.extern_module =
let base = ptr p in
Choice.with_thread (fun t ->
let memories = Thread.memories t in
Env_id.Tbl.iter
(fun _ tbl ->
Symbolic_memory.iter
(fun tbl ->
Symbolic_memory.ITbl.iter
(fun _ (m : Symbolic_memory.M.t) ->
if not (Hashtbl.mem m.chunks base) then
(* TODO: trap instead? *)
failwith "Memory leak double free";
Hashtbl.remove m.chunks base )
(fun _ (m : Symbolic_memory.t) -> Symbolic_memory.free m base)
tbl )
memories )
in
Expand Down
106 changes: 39 additions & 67 deletions src/concrete.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,65 @@
(* Copyright © 2021 Léo Andrès *)
(* Copyright © 2021 Pierre Chambart *)

module P = struct
module Extern_func = Concrete_value.Func
module Value = V
module Global = Concrete_global
module Table = Concrete_table
module Memory = Concrete_memory
module Extern_func = Concrete_value.Func
module Value = V
module Global = Concrete_global
module Table = Concrete_table
module Memory = Concrete_memory

type thread = unit
type thread = unit

type memory = Memory.t
module Choice = Concrete_choice

type func = Concrete_value.Func.t
let select cond ~if_true ~if_false =
if cond then Choice.return if_true else Choice.return if_false
[@@inline]

type table = Table.t
module Elem = struct
type t = Link_env.elem

type elem = Link_env.elem
let get (e : t) i = e.value.(i)

type data = Link_env.data

type global = Concrete_global.t

type vbool = Bool.t

type int32 = Int32.t

type int64 = Int64.t

type float32 = Float32.t

type float64 = Float64.t

type extern_func = Concrete_value.Func.extern_func

type env = extern_func Link_env.t

module Choice = Concrete_choice

let select cond ~if_true ~if_false =
if cond then Choice.return if_true else Choice.return if_false
[@@inline]

module Elem = struct
type t = elem

let get (e : t) i = e.value.(i)

let size (e : t) = Array.length e.value
end
let size (e : t) = Array.length e.value
end

module Data = struct
type t = data
module Data = struct
type t = Link_env.data

let value data = data.Link_env.value
end
let value data = data.Link_env.value
end

module Env = struct
type t = env
module Env = struct
type t = Concrete_value.Func.extern_func Link_env.t

let get_memory = Link_env.get_memory
let get_memory = Link_env.get_memory

let get_func = Link_env.get_func
let get_func = Link_env.get_func

let get_table = Link_env.get_table
let get_table = Link_env.get_table

let get_elem = Link_env.get_elem
let get_elem = Link_env.get_elem

let get_data env n =
let data = Link_env.get_data env n in
Choice.return data
let get_data env n =
let data = Link_env.get_data env n in
Choice.return data

let get_global = Link_env.get_global
let get_global = Link_env.get_global

let get_extern_func = Link_env.get_extern_func
let get_extern_func = Link_env.get_extern_func

let drop_elem = Link_env.drop_elem
let drop_elem = Link_env.drop_elem

let drop_data = Link_env.drop_data
end
let drop_data = Link_env.drop_data
end

module Module_to_run = struct
(** runnable module *)
type t = extern_func Link.module_to_run
module Module_to_run = struct
(** runnable module *)
type t = Concrete_value.Func.extern_func Link.module_to_run

let env (t : extern_func Link.module_to_run) = t.env
let env (t : Concrete_value.Func.extern_func Link.module_to_run) = t.env

let modul (t : extern_func Link.module_to_run) = t.modul
let modul (t : Concrete_value.Func.extern_func Link.module_to_run) = t.modul

let to_run (t : extern_func Link.module_to_run) = t.to_run
end
let to_run (t : Concrete_value.Func.extern_func Link.module_to_run) = t.to_run
end
7 changes: 7 additions & 0 deletions src/concrete.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include
Interpret_intf.P
with type Env.t = Concrete_value.Func.extern_func Link_env.t
and type Module_to_run.t =
Concrete_value.Func.extern_func Link.module_to_run
and type 'a Choice.t = 'a
and module Value = V
4 changes: 2 additions & 2 deletions src/concrete_choice.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let select b = b [@@inline]

let select_i32 i = i [@@inline]

let get = ()

let trap msg = raise (Types.Trap msg)

let trap : Trap.t -> 'a t = fun tr -> trap (Trap.to_string tr)

let run = Fun.id
22 changes: 3 additions & 19 deletions src/concrete_choice.mli
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
(* TODO: make this abstract *)
type 'a t = 'a
(* TODO: type 'a t should be abstract, run will be needed for this *)
include Choice_intf.Base with type 'a t = 'a and module V := V

val return : 'a -> 'a t

val bind : 'a t -> ('a -> 'b t) -> 'b t

val ( let* ) : 'a t -> ('a -> 'b t) -> 'b t

val map : 'a t -> ('a -> 'b) -> 'b t

val ( let+ ) : 'a t -> ('a -> 'b) -> 'b t

val select : bool -> bool t

val select_i32 : int32 -> int32 t

val get : unit

val trap : Trap.t -> 'a t
val run : 'a t -> 'a
4 changes: 2 additions & 2 deletions src/interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Make (P : Interpret_intf.P) :
with type 'a choice := 'a P.Choice.t
and type module_to_run := P.Module_to_run.t
and type thread := P.thread
and type env := P.env
and type env := P.Env.t
and type State.stack := P.Value.t list
and type value = P.Value.t = struct
open P
Expand Down Expand Up @@ -1561,6 +1561,6 @@ module Make (P : Interpret_intf.P) :
type value = Value.t
end

module Concrete = Make (Concrete.P) [@@inlined hint]
module Concrete = Make (Concrete) [@@inlined hint]
module SymbolicP = Make (Symbolic.P) [@@inlined hint]
module SymbolicM = Make (Symbolic.M) [@@inlined hint]
10 changes: 5 additions & 5 deletions src/interpret.mli
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Concrete : sig
val modul :
Concrete.P.env Env_id.collection
-> Concrete.P.Module_to_run.t
Concrete.Env.t Env_id.collection
-> Concrete.Module_to_run.t
-> unit Result.t

val exec_vfunc_from_outside :
locals:V.t list
-> env:Link_env.t'
-> envs:Concrete.P.env Env_id.collection
-> envs:Concrete.Env.t Env_id.collection
-> Func_intf.t
-> V.t list Result.t

Expand Down Expand Up @@ -38,14 +38,14 @@ end

module SymbolicP : sig
val modul :
Symbolic.P.env Env_id.collection
Symbolic.P.Env.t Env_id.collection
-> Symbolic.P.Module_to_run.t
-> unit Result.t Symbolic.P.Choice.t
end

module SymbolicM : sig
val modul :
Symbolic.M.env Env_id.collection
Symbolic.M.Env.t Env_id.collection
-> Symbolic.M.Module_to_run.t
-> unit Result.t Symbolic.M.Choice.t
end
Loading
Loading