__hash__ = None
+@final
class Const(Value):
"""A constant, literal integer value.
return ValueSet()
+@final
class AnyConst(AnyValue):
def __repr__(self):
return "(anyconst {}'{})".format(self.nbits, "s" if self.signed else "")
+@final
class AnySeq(AnyValue):
def __repr__(self):
return "(anyseq {}'{})".format(self.nbits, "s" if self.signed else "")
+@final
class Operator(Value):
def __init__(self, op, operands, src_loc_at=0):
super().__init__(src_loc_at=1 + src_loc_at)
return Operator("m", [sel, val1, val0], src_loc_at=1)
+@final
class Slice(Value):
def __init__(self, value, start, end):
if not isinstance(start, int):
return "(slice {} {}:{})".format(repr(self.value), self.start, self.end)
+@final
class Part(Value):
def __init__(self, value, offset, width):
if not isinstance(width, int) or width < 0:
return "(part {} {} {})".format(repr(self.value), repr(self.offset), self.width)
+@final
class Cat(Value):
"""Concatenate values.
return "(cat {})".format(" ".join(map(repr, self.parts)))
+@final
class Repl(Value):
"""Replicate a value
return "(repl {!r} {})".format(self.value, self.count)
+@final
class Signal(Value, DUID):
"""A varying integer value.
return "(sig {})".format(self.name)
+@final
class ClockSignal(Value):
"""Clock signal for a clock domain.
return "(clk {})".format(self.domain)
+@final
class ResetSignal(Value):
"""Reset signal for a clock domain.
", ".join(map(repr, self._inner)))
+@final
class ArrayProxy(Value):
def __init__(self, elems, index):
super().__init__(src_loc_at=1)
return "(proxy (array [{}]) {!r})".format(", ".join(map(repr, self.elems)), self.index)
+@final
class Sample(Value):
"""Value from the past.
raise TypeError("Object '{!r}' is not an nMigen statement".format(obj))
+@final
class Assign(Statement):
def __init__(self, lhs, rhs):
self.lhs = Value.wrap(lhs)
return "({} {!r})".format(self._kind, self.test)
+@final
class Assert(Property):
_kind = "assert"
+@final
class Assume(Property):
_kind = "assume"
+# @final
class Switch(Statement):
def __init__(self, test, cases):
self.test = Value.wrap(test)
return "(switch {!r} {})".format(self.test, " ".join(cases))
+@final
class Delay(Statement):
def __init__(self, interval=None):
self.interval = None if interval is None else float(interval)
return "(delay {:.3}us)".format(self.interval * 1e6)
+@final
class Tick(Statement):
def __init__(self, domain="sync"):
self.domain = str(domain)
return "(tick {})".format(self.domain)
+@final
class Passive(Statement):
def _rhs_signals(self):
return ValueSet()
from contextlib import contextmanager
-__all__ = ["flatten", "union", "log2_int", "bits_for", "memoize", "deprecated"]
+__all__ = ["flatten", "union", "log2_int", "bits_for", "memoize", "final", "deprecated"]
def flatten(i):
return g
+def final(cls):
+ def init_subclass():
+ raise TypeError("Subclassing {}.{} is not supported"
+ .format(cls.__module__, cls.__name__))
+ cls.__init_subclass__ = init_subclass
+ return cls
+
+
def deprecated(message, stacklevel=2):
def decorator(f):
@functools.wraps(f)