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

Simplify file #310

Merged
merged 10 commits into from
Jul 23, 2024
15 changes: 0 additions & 15 deletions src/concolic/concolic_wasm_ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ module M :
let n = Float64.of_bits n in
(F64 n, Value.pair n (Expr.mk_symbol sym)) )

let symbol_bool () : Value.int32 Choice.t =
Choice.with_new_symbol Ty_bool (fun sym forced_value ->
let b =
match forced_value with
| None -> Random.bool ()
| Some True -> true
| Some False -> false
| _ -> assert false
in
let n = V.Bool.int32 b in
(I32 n, Value.(Bool.int32 (pair b (Expr.mk_symbol sym)))) )

let assume_i32 (i : Value.int32) : unit Choice.t =
let c = Value.I32.to_bool i in
Concolic_choice.assume c
Expand Down Expand Up @@ -158,9 +146,6 @@ let symbolic_extern_module =
; ( "f64_symbol"
, Concolic.P.Extern_func.Extern_func (Func (UArg Res, R1 F64), symbol_f64)
)
; ( "bool_symbol"
, Concolic.P.Extern_func.Extern_func (Func (UArg Res, R1 I32), symbol_bool)
)
; ( "assume"
, Concolic.P.Extern_func.Extern_func
(Func (Arg (I32, Res), R0), assume_i32) )
Expand Down
2 changes: 0 additions & 2 deletions src/intf/wasm_ffi_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ module type S0 = sig

val symbol_f64 : unit -> Value.float64 t

val symbol_bool : unit -> Value.int32 t

val assume_i32 : Value.int32 -> unit t

val assume_positive_i32 : Value.int32 -> unit t
Expand Down
4 changes: 4 additions & 0 deletions src/libc/include/owi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ owi_abort(void);
__attribute__((import_module("summaries"))) __attribute__((import_name("exit"))) void
owi_exit(int);

int and_(int, int);

int or_(int, int);

#endif
22 changes: 22 additions & 0 deletions src/libc/src/owi.c
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
#include <owi.h>

int and_(int a, int b) {
__asm__ __volatile__("local.get 0;"
"i32.const 0;"
"i32.ne;"
"local.get 1;"
"i32.const 0;"
"i32.ne;"
"i32.and;"
"return;");
}
Copy link
Member

@zapashcanon zapashcanon Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can still remove and_ and only keep or_. :)

EDIT: you could actually remove both and inline the definition of or_ inside the definition of _Bool __VERIFIER_nondet_bool(void)


int or_(int a, int b) {
__asm__ __volatile__("local.get 0;"
"i32.const 0;"
"i32.ne;"
"local.get 1;"
"i32.const 0;"
"i32.ne;"
"i32.or;"
"return;");
}
7 changes: 6 additions & 1 deletion src/libc/src/test-comp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <owi.h>

_Bool __VERIFIER_nondet_bool(void) { return owi_bool(); }
_Bool __VERIFIER_nondet_bool(void) {

_Bool var = owi_i32();
owi_assume(or_(var == 0, var == 1));
return var;
}

char __VERIFIER_nondet_char(void) { return (char)owi_i32(); }

Expand Down
8 changes: 0 additions & 8 deletions src/symbolic/symbolic_wasm_ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ module M :

let symbol_f64 () = Choice.with_new_symbol (Ty_fp 64) Expr.symbol

let symbol_bool () =
let open Choice in
let+ sym = symbol Ty_bool () in
Expr.make (Cvtop (Ty_bool, Smtml.Ty.OfBool, sym))

open Expr

let abort () : unit Choice.t = Choice.add_pc @@ Value.Bool.const false
Expand Down Expand Up @@ -99,9 +94,6 @@ let symbolic_extern_module =
; ( "f64_symbol"
, Symbolic.P.Extern_func.Extern_func (Func (UArg Res, R1 F64), symbol_f64)
)
; ( "bool_symbol"
, Symbolic.P.Extern_func.Extern_func (Func (UArg Res, R1 I32), symbol_bool)
)
; ( "assume"
, Symbolic.P.Extern_func.Extern_func
(Func (Arg (I32, Res), R0), assume_i32) )
Expand Down
Loading