var_allocate={}
def IRtoZ3expr(var): # if var is number , return a number , else return a z3expr
x = str(var)
if ("0x" in x):
return int(x, 16)
else:
if (x not in var_allocate):
strcmd = "%s = Int('%s')" % (x, x)
exec strcmd
var_allocate["%s" % x] = eval(x)
return eval(x)
else:
return var_allocate["%s" % x]
1
a = IRtoZ3expr('a')
b = IRtoZ3expr('a')
c = IRtoZ3expr('a')
print a.__hash__()
print b.__hash__()
print c.__hash__()
from z3 import *
var_allocate={}
def IRtoZ3expr(var): # if var is number , return a number , else return a z3expr
x = str(var)
if ("0x" in x):
return int(x, 16)
else:
if (x not in var_allocate):
strcmd = "%s = Int('%s')" % (x, x)
exec strcmd
var_allocate["%s" % x] = eval(x)
return eval(x)
else:
return var_allocate["%s" % x]
1
a = IRtoZ3expr('a')
b = IRtoZ3expr('a')
c = IRtoZ3expr('a')
print a.__hash__()
print b.__hash__()
print c.__hash__()
輸出 的 變量hash值相同,證明我們生成名字爲 a 的 Int 值是同一個,沒有被覆蓋!