forked from congy/chestnut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbolic_context.py
66 lines (56 loc) · 1.71 KB
/
symbolic_context.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import z3
from constants import *
debug_constraint = False
expr_pool = []
tempv_cnt = 0
class SymbolicManager(object):
def __init__(self):
self.param_symbol_map = {}
self.symbolic_tables = {}
self.symbolic_assocs = {}
self.symbolic_struct = None
self.cur_update_ptr_lst = None
self.placeholder_list = None
self.solver = z3.Solver()
self.index_map = []
def register_tables_and_assocs(self,_tables, _assocs):
global tables
global associations
self.tables = [t for t in _tables]
self.associations = [a for a in _assocs]
def get_param_symbol_map(self, p):
if p in self.param_symbol_map:
return self.param_symbol_map[p]
else:
global tempv_cnt
newv = get_symbol_by_field_type(p.get_type(), '{}_{}'.format(p.symbol, tempv_cnt))
tempv_cnt += 1
self.param_symbol_map[p] = newv
def set_global_symbolic_struct(self, r):
self.symbolic_struct = r
def get_global_symbolic_struct(self):
return self.symbolic_struct
def set_cur_update_ptr_lst(self, r):
self.cur_update_ptr_lst = r
def get_cur_update_ptr_lst(self):
return self.cur_update_ptr_lst
def set_placeholder_list(self, r):
self.placeholder_list = r
def get_placeholder_list(self):
return self.placeholder_list
def clear_solver(self):
self.solver = z3.Solver()
def add_to_index_map(self, idx, symbolic_idx):
self.idx_map.append((idx, symbolic_idx))
def exist_symbolic_idx(self, idx):
for k,v in self.idx_map:
if k==idx:
return v
return None
class ThreadCtx(object):
def __init__(self):
self.symbolic_manager = SymbolicManager()
def get_symbs(self):
return self.symbolic_manager
def create_thread_ctx():
return ThreadCtx()