build.res: use ConstraintError iff a constraint invariant is violated.
In particular don't use it for type errors.
This commit is contained in:
parent
51c03ca391
commit
4310254103
|
@ -1,2 +1,3 @@
|
|||
from .dsl import Pins, DiffPairs, Subsignal, Resource, Connector
|
||||
from .res import ConstraintError
|
||||
from .plat import Platform, TemplatedPlatform
|
||||
|
|
|
@ -56,9 +56,9 @@ class ConstraintManager:
|
|||
def add_clock(self, name, number, frequency):
|
||||
resource = self.lookup(name, number)
|
||||
if isinstance(resource.io[0], Subsignal):
|
||||
raise ConstraintError("Cannot constrain frequency of resource {}#{} because it has "
|
||||
"subsignals"
|
||||
.format(resource.name, resource.number, frequency))
|
||||
raise TypeError("Cannot constrain frequency of resource {}#{} because it has "
|
||||
"subsignals"
|
||||
.format(resource.name, resource.number, frequency))
|
||||
if (resource.name, resource.number) in self.clocks:
|
||||
other = self.clocks[resource.name, resource.number]
|
||||
raise ConstraintError("Resource {}#{} is already constrained to a frequency of "
|
||||
|
@ -68,8 +68,8 @@ class ConstraintManager:
|
|||
|
||||
def lookup(self, name, number=0):
|
||||
if (name, number) not in self.resources:
|
||||
raise NameError("Resource {}#{} does not exist"
|
||||
.format(name, number))
|
||||
raise ConstraintError("Resource {}#{} does not exist"
|
||||
.format(name, number))
|
||||
return self.resources[name, number]
|
||||
|
||||
def request(self, name, number=0, *, dir=None, xdr=None):
|
||||
|
|
|
@ -192,12 +192,12 @@ class ConstraintManagerTestCase(FHDLTestCase):
|
|||
self.cm.add_connectors([Connector("pmod", 0, "1 2")])
|
||||
|
||||
def test_wrong_lookup(self):
|
||||
with self.assertRaises(NameError,
|
||||
with self.assertRaises(ConstraintError,
|
||||
msg="Resource user_led#1 does not exist"):
|
||||
r = self.cm.lookup("user_led", 1)
|
||||
|
||||
def test_wrong_frequency_subsignals(self):
|
||||
with self.assertRaises(ConstraintError,
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Cannot constrain frequency of resource i2c#0 because "
|
||||
"it has subsignals"):
|
||||
self.cm.add_clock("i2c", 0, 10e6)
|
||||
|
|
Loading…
Reference in a new issue