hdl.ast: Add AnyConst and AnySeq value types.

This commit is contained in:
William D. Jones 2019-01-15 15:13:47 -05:00 committed by whitequark
parent 1880686e2e
commit 6fdbc3d885
2 changed files with 28 additions and 2 deletions

View file

@ -1,4 +1,4 @@
from .hdl.ast import Value, Const, C, Mux, Cat, Repl, Array, Signal, ClockSignal, ResetSignal, Assert, Assume
from .hdl.ast import Value, Const, C, AnyConst, AnySeq, Mux, Cat, Repl, Array, Signal, ClockSignal, ResetSignal, Assert, Assume
from .hdl.dsl import Module
from .hdl.cd import ClockDomain
from .hdl.ir import Fragment, Instance

View file

@ -9,7 +9,7 @@ from ..tools import *
__all__ = [
"Value", "Const", "C", "Operator", "Mux", "Part", "Slice", "Cat", "Repl",
"Value", "Const", "C", "AnyConst", "AnySeq", "Operator", "Mux", "Part", "Slice", "Cat", "Repl",
"Array", "ArrayProxy",
"Signal", "ClockSignal", "ResetSignal",
"Statement", "Assign", "Assert", "Assume", "Switch", "Delay", "Tick",
@ -254,6 +254,32 @@ class Const(Value):
C = Const # shorthand
class AnyValue(Value):
def __init__(self, shape):
super().__init__(src_loc_at=0)
if isinstance(shape, int):
shape = shape, False
self.nbits, self.signed = shape
if not isinstance(self.nbits, int) or self.nbits < 0:
raise TypeError("Width must be a non-negative integer, not '{!r}'", self.nbits)
def shape(self):
return self.nbits, self.signed
def _rhs_signals(self):
return ValueSet()
class AnyConst(AnyValue):
def __repr__(self):
return "(anyconst {}'{})".format(self.nbits, "s" if self.signed else "")
class AnySeq(AnyValue):
def __repr__(self):
return "(anyseq {}'{})".format(self.nbits, "s" if self.signed else "")
class Operator(Value):
def __init__(self, op, operands, src_loc_at=0):
super().__init__(src_loc_at=1 + src_loc_at)