add more type annotations
[nmigen-type-annotations.git] / nmigen / hdl / ast.pyi
1 from abc import ABCMeta, abstractmethod
2 from typing import Union, Tuple, Any, Iterable, Optional, Mapping
3 from collections.abc import MutableSequence
4
5 __all__ = [
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"
11 ]
12
13 ValueOrLiteral = Union[int, bool, 'Value']
14 ShapeResult = Tuple[int, bool]
15
16
17 class Value(metaclass=ABCMeta):
18 @staticmethod
19 def wrap(obj: Any) -> 'Value':
20 ...
21
22 def __invert__(self) -> 'Value':
23 ...
24
25 def __neg__(self) -> 'Value':
26 ...
27
28 def __add__(self, other: ValueOrLiteral) -> 'Value':
29 ...
30
31 def __radd__(self, other: ValueOrLiteral) -> 'Value':
32 ...
33
34 def __sub__(self, other: ValueOrLiteral) -> 'Value':
35 ...
36
37 def __rsub__(self, other: ValueOrLiteral) -> 'Value':
38 ...
39
40 def __mul__(self, other: ValueOrLiteral) -> 'Value':
41 ...
42
43 def __rmul__(self, other: ValueOrLiteral) -> 'Value':
44 ...
45
46 def __mod__(self, other: ValueOrLiteral) -> 'Value':
47 ...
48
49 def __rmod__(self, other: ValueOrLiteral) -> 'Value':
50 ...
51
52 def __div__(self, other: ValueOrLiteral) -> 'Value':
53 ...
54
55 def __rdiv__(self, other: ValueOrLiteral) -> 'Value':
56 ...
57
58 def __lshift__(self, other: ValueOrLiteral) -> 'Value':
59 ...
60
61 def __rlshift__(self, other: ValueOrLiteral) -> 'Value':
62 ...
63
64 def __rshift__(self, other: ValueOrLiteral) -> 'Value':
65 ...
66
67 def __rrshift__(self, other: ValueOrLiteral) -> 'Value':
68 ...
69
70 def __and__(self, other: ValueOrLiteral) -> 'Value':
71 ...
72
73 def __rand__(self, other: ValueOrLiteral) -> 'Value':
74 ...
75
76 def __xor__(self, other: ValueOrLiteral) -> 'Value':
77 ...
78
79 def __rxor__(self, other: ValueOrLiteral) -> 'Value':
80 ...
81
82 def __or__(self, other: ValueOrLiteral) -> 'Value':
83 ...
84
85 def __ror__(self, other: ValueOrLiteral) -> 'Value':
86 ...
87
88 def __eq__(self, other: Any) -> Any:
89 ...
90
91 def __ne__(self, other: Any) -> Any:
92 ...
93
94 def __lt__(self, other: ValueOrLiteral) -> 'Value':
95 ...
96
97 def __le__(self, other: ValueOrLiteral) -> 'Value':
98 ...
99
100 def __gt__(self, other: ValueOrLiteral) -> 'Value':
101 ...
102
103 def __ge__(self, other: ValueOrLiteral) -> 'Value':
104 ...
105
106 def __len__(self) -> int:
107 ...
108
109 def __getitem__(self, key: Union[slice, int, str]) -> 'Value':
110 ...
111
112 def bool(self) -> 'Value':
113 ...
114
115 def implies(premise: ValueOrLiteral,
116 conclusion: ValueOrLiteral) -> 'Value':
117 ...
118
119 def part(self, offset: ValueOrLiteral, width: int) -> 'Value':
120 ...
121
122 def eq(self, value: ValueOrLiteral) -> 'Assign':
123 ...
124
125 @abstractmethod
126 def shape(self) -> ShapeResult:
127 ...
128
129
130 ShapeArgument = Union[int, Tuple[int, bool]]
131
132
133 class Const(Value):
134 nbits: int
135 signed: bool
136
137 @staticmethod
138 def normalize(value: int, shape: Tuple[int, bool]) -> int:
139 ...
140
141 def __init__(self, value: int,
142 shape: Optional[ShapeArgument] = None) -> None:
143 ...
144
145 def shape(self) -> ShapeResult:
146 ...
147
148
149 C = Const
150
151
152 def Mux(sel: ValueOrLiteral,
153 val1: ValueOrLiteral,
154 val0: ValueOrLiteral) -> Value:
155 ...
156
157
158 class Cat(Value):
159 def __init__(self,
160 *args: Union[ValueOrLiteral,
161 Iterable[ValueOrLiteral]]) -> None:
162 ...
163
164 def shape(self) -> ShapeResult:
165 ...
166
167
168 class Repl(Value):
169 def __init__(self,
170 value: ValueOrLiteral,
171 count: int) -> None:
172 ...
173
174 def shape(self) -> ShapeResult:
175 ...
176
177
178 class Signal(Value):
179 nbits: int
180 signed: bool
181 name: str
182 reset: int
183 reset_less: bool
184 attrs: dict
185
186 def __init__(self,
187 shape: Optional[ShapeArgument] = None,
188 name: Optional[str] = None,
189 reset: int = 0,
190 reset_less: bool = False,
191 min: Optional[int] = None, max: Optional[int] = None,
192 attrs: Optional[dict] = None,
193 decoder: Any = None) -> None:
194 ...
195
196 @classmethod
197 def like(cls,
198 other: ValueOrLiteral,
199 name: Optional[str] = None) -> 'Signal':
200 ...
201
202 def shape(self) -> ShapeResult:
203 ...
204
205
206 class ClockSignal(Value):
207 def __init__(self, domain: str = "sync") -> None:
208 ...
209
210 def shape(self) -> ShapeResult:
211 ...
212
213
214 class ResetSignal(Value):
215 def __init__(self,
216 domain: str = "sync",
217 allow_reset_less: bool = False) -> None:
218 ...
219
220 def shape(self) -> ShapeResult:
221 ...
222
223
224 StatementOrStatementList = Union[Iterable['Statement'], 'Statement']
225
226
227 class _StatementList(list):
228 pass
229
230
231 class Statement:
232 @staticmethod
233 def wrap(obj: StatementOrStatementList) -> _StatementList:
234 ...
235
236
237 class Assign(Statement):
238 def __init__(self, lhs: ValueOrLiteral, rhs: ValueOrLiteral) -> None:
239 ...
240
241
242 class Property(Statement):
243 def __init__(self, test: ValueOrLiteral) -> None:
244 ...
245
246
247 class Assert(Property):
248 pass
249
250
251 class Assume(Property):
252 pass
253
254
255 class Switch(Statement):
256 def __init__(self,
257 test: ValueOrLiteral,
258 cases: Mapping[Union[bool, int, str],
259 StatementOrStatementList]) -> None:
260 ...
261
262
263 class Delay(Statement):
264 def __init__(self, interval: Optional[float]) -> None:
265 ...
266
267
268 class Tick(Statement):
269 def __init__(self, domain: Any = "sync"):
270 ...
271
272
273 class Passive(Property):
274 pass