-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbmc.py
More file actions
87 lines (70 loc) · 2.46 KB
/
esbmc.py
File metadata and controls
87 lines (70 loc) · 2.46 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from typing import Generic, List, Dict, Optional, Union, Tuple, Any
import random
import time
# ESBMC verification functions
def nondet_int() -> int:
"""Return a non-deterministic integer."""
return random.randint(-2**31, 2**31-1) # Simulated for Python execution
def nondet_uint64() -> int:
"""Return a non-deterministic integer."""
return random.randint(-2**64, 2**64-1) # Simulated for Python execution
def __ESBMC_assume(cond: bool) -> None:
"""Assume a condition is true."""
if not cond:
raise AssertionError("Assumption violated")
def __ESBMC_assert(cond: bool, msg: str = "") -> None:
"""Assert a condition is true."""
assert cond, msg
def __VERIFIER_nondet_int():
"""Simulates a non-deterministic integer value."""
return random.randint(-100, 100) # Adjust limits if necessary
def __VERIFIER_nondet_bool():
"""Simulates a non-deterministic Boolean value."""
return bool(random.randint(0, 1))
def nondet_bool():
"""Simulates a non-deterministic Boolean value."""
return True
# Dataclass support
def frozen_dataclass(cls):
"""Decorator to create an immutable dataclass."""
return dataclass(frozen=True)(cls)
# List comprehension support
def list_comp(iterable, predicate=None, transform=None):
"""Helper for list comprehensions."""
result = []
for item in iterable:
if predicate is None or predicate(item):
result.append(transform(item) if transform else item)
return result
# Dict comprehension support
def dict_comp(iterable, key_func, value_func, predicate=None):
"""Helper for dictionary comprehensions."""
result = {}
for item in iterable:
if predicate is None or predicate(item):
result[key_func(item)] = value_func(item)
return result
# Thread simulation support
class Thread:
def __init__(self):
self.running = False
def start(self):
self.running = True
self.run()
def run(self):
pass
def join(self):
self.running = False
# Basic publish/subscribe support
class Topic:
def __init__(self, name: str, type_: type):
self.name = name
self.type = type_
self.callbacks = []
def publish(self, msg):
if not isinstance(msg, self.type):
raise TypeError(f"Message must be of type {self.type}")
for callback in self.callbacks:
callback(msg)
def subscribe(self, callback):
self.callbacks.append(callback)