1 __all__
= ["Pins", "Subsignal", "DiffPairs", "Resource"]
5 def __init__(self
, names
, dir="io"):
6 if not isinstance(names
, str):
7 raise TypeError("Names must be a whitespace-separated string, not {!r}"
9 self
.names
= names
.split()
11 if dir not in ("i", "o", "io"):
12 raise TypeError("Direction must be one of \"i\", \"o\" or \"io\", not {!r}"
17 return "(pins {} {})".format(" ".join(self
.names
), self
.dir)
21 def __init__(self
, p
, n
, dir="io"):
22 self
.p
= Pins(p
, dir=dir)
23 self
.n
= Pins(n
, dir=dir)
25 if len(self
.p
.names
) != len(self
.n
.names
):
26 raise TypeError("Positive and negative pins must have the same width, but {!r} "
28 .format(self
.p
, self
.n
))
33 return "(diffpairs {} {})".format(self
.p
, self
.n
)
37 def __init__(self
, name
, *io
, extras
=()):
41 raise TypeError("Missing I/O constraints")
43 if not isinstance(c
, (Pins
, DiffPairs
, Subsignal
)):
44 raise TypeError("I/O constraint must be one of Pins, DiffPairs or Subsignal, "
47 if isinstance(io
[0], (Pins
, DiffPairs
)) and len(io
) > 1:
48 raise TypeError("Pins and DiffPairs cannot be followed by more I/O constraints, but "
49 "{!r} is followed by {!r}"
50 .format(io
[0], io
[1]))
51 if isinstance(io
[0], Subsignal
):
53 if not isinstance(c
, Subsignal
):
54 raise TypeError("A Subsignal can only be followed by more Subsignals, but "
55 "{!r} is followed by {!r}"
60 if not isinstance(c
, str):
61 raise TypeError("Extra constraint must be a string, not {!r}".format(c
))
62 self
.extras
= list(extras
)
64 if isinstance(self
.io
[0], Subsignal
):
66 sub
.extras
+= self
.extras
69 return "(subsignal {} {} {})".format(self
.name
,
70 " ".join(map(repr, self
.io
)),
71 " ".join(self
.extras
))
74 class Resource(Subsignal
):
75 def __init__(self
, name
, number
, *io
, extras
=()):
77 super().__init
__(name
, *io
, extras
=extras
)
80 return "(resource {} {} {} {})".format(self
.name
, self
.number
,
81 " ".join(map(repr, self
.io
)),
82 " ".join(self
.extras
))