Skip to content

Commit

Permalink
add bool symbol in owi.c, whose implementation is the same as i32 sym…
Browse files Browse the repository at this point in the history
…bol for the time being
  • Loading branch information
Laplace-Demon committed Jun 17, 2024
1 parent 5a78349 commit e99e9f1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/concolic/concolic_wasm_ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ 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_bitv 32) (fun sym forced_value ->
let n =
match forced_value with
| None -> Int32.logand 1l (Random.bits32 ())
| Some (Num (I32 n)) -> n
| _ -> assert false
in
let sym_expr =
Expr.make (Cvtop (Ty_bitv 32, Zero_extend 31, Expr.mk_symbol sym))
in
(I32 n, Value.pair n sym_expr) )

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 @@ -160,6 +173,9 @@ 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: 2 additions & 0 deletions src/intf/wasm_ffi_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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
1 change: 1 addition & 0 deletions src/libc/include/owi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ float owi_f32(void) __attribute__((import_module("symbolic"))) __attribute__((im

double owi_f64(void) __attribute__((import_module("symbolic"))) __attribute__((import_name("f64_symbol")));

_Bool owi_bool(void) __attribute__((import_module("symbolic"))) __attribute__((import_name("bool_symbol")));

void owi_assume(int c) __attribute__((import_module("symbolic"))) __attribute__((import_name("assume")));
void owi_assert(int c) __attribute__((import_module("symbolic"))) __attribute__((import_name("assert")));
Expand Down
2 changes: 2 additions & 0 deletions src/libc/src/owi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ __attribute__((import_module("symbolic"), import_name("f32_symbol"))) float
owi_f32(void);
__attribute__((import_module("symbolic"), import_name("f64_symbol"))) double
owi_f64(void);
__attribute__((import_module("symbolic"), import_name("bool_symbol"))) _Bool
owi_bool(void);

__attribute__((import_module("symbolic"), import_name("assume"))) void
owi_assume(int);
Expand Down
12 changes: 7 additions & 5 deletions src/libc/src/test-comp.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <owi.h>

_Bool __VERIFIER_nondet_bool(void) {
_Bool var = owi_i32();
owi_assume(or_(var == 0, var == 1));
return var;
}
// _Bool __VERIFIER_nondet_bool(void) {
// _Bool var = owi_i32();
// owi_assume(var == 0 || var == 1);
// return var;
// }

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

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

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

let symbol_f64 = symbol (Ty_fp 64)

let symbol_bool = symbol (Ty_bitv 32)

open Expr

let abort () : unit Choice.t = Choice.add_pc @@ Value.Bool.const false
Expand Down Expand Up @@ -116,6 +118,9 @@ 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

0 comments on commit e99e9f1

Please sign in to comment.