-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.py
More file actions
38 lines (32 loc) · 1.43 KB
/
patch.py
File metadata and controls
38 lines (32 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''
This script is used to patch the OCaml code of the symbolic execution engine
to include a cache for the memory comparison function.
'''
ORIG = """
let po_memory_cmp sstack_val_cmp smem1 smem2 maxidx1 sb1 maxidx2 sb2 instk_height ops =
let n1 = length smem1 in
let n2 = length smem2 in
if eqb n1 n2
then let smem1' = reorder_memory_updates n1 n1 smem1 maxidx1 sb1 in
let smem2' = reorder_memory_updates n2 n2 smem2 maxidx2 sb2 in
basic_memory_cmp sstack_val_cmp smem1' smem2' maxidx1 sb1 maxidx2
sb2 instk_height ops"""
REP = """ let my_hash = Hashtbl.create 123456;;
let po_memory_cmp sstack_val_cmp smem1 smem2 maxidx1 sb1 maxidx2 sb2 instk_height ops =
let key = (smem1,smem2,maxidx1,sb1,maxidx2,sb2,instk_height,ops) in
let n1 = length smem1 in
let n2 = length smem2 in
if eqb n1 n2
then
if (Hashtbl.mem my_hash key) then Hashtbl.find my_hash key
else
let smem1' = reorder_memory_updates n1 n1 smem1 maxidx1 sb1 in
let smem2' = reorder_memory_updates n2 n2 smem2 maxidx2 sb2 in
let r = basic_memory_cmp sstack_val_cmp smem1' smem2' maxidx1 sb1 maxidx2 sb2 instk_height ops in
Hashtbl.add my_hash key r;
r;"""
with open("ocaml_interface/checker.ml", "r", encoding="ascii") as f:
data = f.read()
data = data.replace(ORIG, REP)
with open("ocaml_interface/checker.ml", "w", encoding="ascii") as f:
f.write(data)