generic_platform: support name remapping
This commit is contained in:
parent
9ecfdeccec
commit
32dcfc6d02
|
@ -34,7 +34,7 @@ def _lookup(description, name, number):
|
||||||
return resource
|
return resource
|
||||||
raise ConstraintError("Resource not found")
|
raise ConstraintError("Resource not found")
|
||||||
|
|
||||||
def _resource_type(resource):
|
def _resource_type(resource, name_map):
|
||||||
t = None
|
t = None
|
||||||
for element in resource[2:]:
|
for element in resource[2:]:
|
||||||
if isinstance(element, Pins):
|
if isinstance(element, Pins):
|
||||||
|
@ -49,7 +49,7 @@ def _resource_type(resource):
|
||||||
if isinstance(c, Pins):
|
if isinstance(c, Pins):
|
||||||
assert(n_bits is None)
|
assert(n_bits is None)
|
||||||
n_bits = len(c.identifiers)
|
n_bits = len(c.identifiers)
|
||||||
t.append((element.name, n_bits))
|
t.append((name_map(element.name), n_bits))
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def _match(description, requests):
|
def _match(description, requests):
|
||||||
|
@ -61,14 +61,14 @@ def _match(description, requests):
|
||||||
if request[1] is not None:
|
if request[1] is not None:
|
||||||
resource = _lookup(available, request[0], request[1])
|
resource = _lookup(available, request[0], request[1])
|
||||||
available.remove(resource)
|
available.remove(resource)
|
||||||
matched.append((resource, request[2]))
|
matched.append((resource, request[2], request[3]))
|
||||||
|
|
||||||
# 2. Match requests for no specific number
|
# 2. Match requests for no specific number
|
||||||
for request in requests:
|
for request in requests:
|
||||||
if request[1] is None:
|
if request[1] is None:
|
||||||
resource = _lookup(available, request[0], request[1])
|
resource = _lookup(available, request[0], request[1])
|
||||||
available.remove(resource)
|
available.remove(resource)
|
||||||
matched.append((resource, request[2]))
|
matched.append((resource, request[2], request[3]))
|
||||||
|
|
||||||
return matched
|
return matched
|
||||||
|
|
||||||
|
@ -89,27 +89,27 @@ class ConstraintManager:
|
||||||
self.requests = []
|
self.requests = []
|
||||||
self.platform_commands = []
|
self.platform_commands = []
|
||||||
|
|
||||||
def request(self, name, number=None, obj=None):
|
def request(self, name, number=None, obj=None, name_map=lambda s: s):
|
||||||
r = _lookup(self.description, name, number)
|
r = _lookup(self.description, name, number)
|
||||||
t = _resource_type(r)
|
t = _resource_type(r, name_map)
|
||||||
|
|
||||||
# If obj is None, then create it.
|
# If obj is None, then create it.
|
||||||
# If it already exists, do some sanity checking.
|
# If it already exists, do some sanity checking.
|
||||||
if obj is None:
|
if obj is None:
|
||||||
if isinstance(t, int):
|
if isinstance(t, int):
|
||||||
obj = Signal(t, name_override=r[0])
|
obj = Signal(t, name_override=name_map(r[0]))
|
||||||
else:
|
else:
|
||||||
obj = Record(t)
|
obj = Record(t)
|
||||||
else:
|
else:
|
||||||
if isinstance(t, int):
|
if isinstance(t, int):
|
||||||
assert(isinstance(obj, Signal) and obj.nbits == t)
|
assert(isinstance(obj, Signal) and obj.nbits == t)
|
||||||
else:
|
else:
|
||||||
for e in t:
|
for name, nbits in t:
|
||||||
sig = getattr(obj, e[0])
|
sig = getattr(obj, name)
|
||||||
assert(isinstance(sig, Signal) and sig.nbits == e[1])
|
assert(isinstance(sig, Signal) and sig.nbits == nbits)
|
||||||
|
|
||||||
# Register the request
|
# Register the request
|
||||||
self.requests.append((name, number, obj))
|
self.requests.append((name, number, obj, name_map))
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -123,8 +123,7 @@ class ConstraintManager:
|
||||||
if isinstance(obj, Signal):
|
if isinstance(obj, Signal):
|
||||||
s.add(obj)
|
s.add(obj)
|
||||||
else:
|
else:
|
||||||
for k in obj.__dict__:
|
for p in obj.__dict__.values():
|
||||||
p = getattr(obj, k)
|
|
||||||
if isinstance(p, Signal):
|
if isinstance(p, Signal):
|
||||||
s.add(p)
|
s.add(p)
|
||||||
return s
|
return s
|
||||||
|
@ -132,7 +131,7 @@ class ConstraintManager:
|
||||||
def get_sig_constraints(self):
|
def get_sig_constraints(self):
|
||||||
r = []
|
r = []
|
||||||
matched = _match(self.description, self.requests)
|
matched = _match(self.description, self.requests)
|
||||||
for resource, obj in matched:
|
for resource, obj, name_map in matched:
|
||||||
name = resource[0]
|
name = resource[0]
|
||||||
number = resource[1]
|
number = resource[1]
|
||||||
has_subsignals = False
|
has_subsignals = False
|
||||||
|
@ -145,7 +144,7 @@ class ConstraintManager:
|
||||||
if has_subsignals:
|
if has_subsignals:
|
||||||
for element in resource[2:]:
|
for element in resource[2:]:
|
||||||
if isinstance(element, Subsignal):
|
if isinstance(element, Subsignal):
|
||||||
sig = getattr(obj, element.name)
|
sig = getattr(obj, name_map(element.name))
|
||||||
pins, others = _separate_pins(top_constraints + element.constraints)
|
pins, others = _separate_pins(top_constraints + element.constraints)
|
||||||
r.append((sig, pins, others, (name, number, element.name)))
|
r.append((sig, pins, others, (name, number, element.name)))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue