1 from abc import ABCMeta, abstractmethod
2 from typing import Union, Tuple, Any, Iterable, Optional, Mapping
3 from collections.abc import MutableSequence
6 "Value", "Const", "C", "AnyConst", "AnySeq", "Operator", "Mux", "Part",
7 "Slice", "Cat", "Repl", "Array", "ArrayProxy", "Sample", "Past", "Stable",
8 "Rose", "Fell", "Signal", "ClockSignal", "ResetSignal", "Statement",
9 "Assign", "Assert", "Assume", "Switch", "Delay", "Tick", "Passive",
10 "ValueKey", "ValueDict", "ValueSet", "SignalKey", "SignalDict", "SignalSet"
13 ValueOrLiteral = Union[int, bool, 'Value']
14 ShapeResult = Tuple[int, bool]
17 class Value(metaclass=ABCMeta):
19 def wrap(obj: Any) -> 'Value':
22 def __invert__(self) -> 'Value':
25 def __neg__(self) -> 'Value':
28 def __add__(self, other: ValueOrLiteral) -> 'Value':
31 def __radd__(self, other: ValueOrLiteral) -> 'Value':
34 def __sub__(self, other: ValueOrLiteral) -> 'Value':
37 def __rsub__(self, other: ValueOrLiteral) -> 'Value':
40 def __mul__(self, other: ValueOrLiteral) -> 'Value':
43 def __rmul__(self, other: ValueOrLiteral) -> 'Value':
46 def __mod__(self, other: ValueOrLiteral) -> 'Value':
49 def __rmod__(self, other: ValueOrLiteral) -> 'Value':
52 def __div__(self, other: ValueOrLiteral) -> 'Value':
55 def __rdiv__(self, other: ValueOrLiteral) -> 'Value':
58 def __lshift__(self, other: ValueOrLiteral) -> 'Value':
61 def __rlshift__(self, other: ValueOrLiteral) -> 'Value':
64 def __rshift__(self, other: ValueOrLiteral) -> 'Value':
67 def __rrshift__(self, other: ValueOrLiteral) -> 'Value':
70 def __and__(self, other: ValueOrLiteral) -> 'Value':
73 def __rand__(self, other: ValueOrLiteral) -> 'Value':
76 def __xor__(self, other: ValueOrLiteral) -> 'Value':
79 def __rxor__(self, other: ValueOrLiteral) -> 'Value':
82 def __or__(self, other: ValueOrLiteral) -> 'Value':
85 def __ror__(self, other: ValueOrLiteral) -> 'Value':
88 def __eq__(self, other: Any) -> Any:
91 def __ne__(self, other: Any) -> Any:
94 def __lt__(self, other: ValueOrLiteral) -> 'Value':
97 def __le__(self, other: ValueOrLiteral) -> 'Value':
100 def __gt__(self, other: ValueOrLiteral) -> 'Value':
103 def __ge__(self, other: ValueOrLiteral) -> 'Value':
106 def __len__(self) -> int:
109 def __getitem__(self, key: Union[slice, int, str]) -> 'Value':
112 def bool(self) -> 'Value':
115 def implies(premise: ValueOrLiteral,
116 conclusion: ValueOrLiteral) -> 'Value':
119 def part(self, offset: ValueOrLiteral, width: int) -> 'Value':
122 def eq(self, value: ValueOrLiteral) -> 'Assign':
126 def shape(self) -> ShapeResult:
130 ShapeArgument = Union[int, Tuple[int, bool]]
138 def normalize(value: int, shape: Tuple[int, bool]) -> int:
141 def __init__(self, value: int,
142 shape: Optional[ShapeArgument] = None) -> None:
145 def shape(self) -> ShapeResult:
152 def Mux(sel: ValueOrLiteral,
153 val1: ValueOrLiteral,
154 val0: ValueOrLiteral) -> Value:
160 *args: Union[ValueOrLiteral,
161 Iterable[ValueOrLiteral]]) -> None:
164 def shape(self) -> ShapeResult:
170 value: ValueOrLiteral,
174 def shape(self) -> ShapeResult:
187 shape: Optional[ShapeArgument] = None,
188 name: Optional[str] = None,
190 reset_less: bool = False,
191 min: Optional[int] = None, max: Optional[int] = None,
192 attrs: Optional[dict] = None,
193 decoder: Any = None) -> None:
198 other: ValueOrLiteral,
199 name: Optional[str] = None) -> 'Signal':
202 def shape(self) -> ShapeResult:
206 class ClockSignal(Value):
207 def __init__(self, domain: str = "sync") -> None:
210 def shape(self) -> ShapeResult:
214 class ResetSignal(Value):
216 domain: str = "sync",
217 allow_reset_less: bool = False) -> None:
220 def shape(self) -> ShapeResult:
224 StatementOrStatementList = Union[Iterable['Statement'], 'Statement']
227 class _StatementList(list):
233 def wrap(obj: StatementOrStatementList) -> _StatementList:
237 class Assign(Statement):
238 def __init__(self, lhs: ValueOrLiteral, rhs: ValueOrLiteral) -> None:
242 class Property(Statement):
243 def __init__(self, test: ValueOrLiteral) -> None:
247 class Assert(Property):
251 class Assume(Property):
255 class Switch(Statement):
257 test: ValueOrLiteral,
258 cases: Mapping[Union[bool, int, str],
259 StatementOrStatementList]) -> None:
263 class Delay(Statement):
264 def __init__(self, interval: Optional[float]) -> None:
268 class Tick(Statement):
269 def __init__(self, domain: Any = "sync"):
273 class Passive(Property):