Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/migen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 737af2e4973a
Choose a base ref
...
head repository: m-labs/migen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0575c749e35a
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 21, 2016

  1. Copy the full SHA
    1ce3504 View commit details
  2. fhdl/visit: determinism

    sbourdeauducq committed Mar 21, 2016
    Copy the full SHA
    0575c74 View commit details
Showing with 18 additions and 7 deletions.
  1. +8 −3 migen/fhdl/structure.py
  2. +10 −4 migen/fhdl/visit.py
11 changes: 8 additions & 3 deletions migen/fhdl/structure.py
Original file line number Diff line number Diff line change
@@ -542,16 +542,21 @@ def makedefault(self, key=None):
Parameters
----------
key : int or None
key : int, Constant or None
Key to use as default case if no other key matches.
By default, the largest key is the default key.
"""
if key is None:
for choice in self.cases.keys():
if key is None or choice.value > key.value:
if (key is None
or (isinstance(choice, str) and choice == "default")
or choice.value > key.value):
key = choice
self.cases["default"] = self.cases[key]
if not isinstance(key, str) or key != "default":
key = wrap(key)
stmts = self.cases[key]
del self.cases[key]
self.cases["default"] = stmts
return self


14 changes: 10 additions & 4 deletions migen/fhdl/visit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from copy import copy
from operator import itemgetter

from migen.fhdl.structure import *
from migen.fhdl.structure import (_Operator, _Slice, _Assign, _ArrayProxy,
@@ -77,7 +78,8 @@ def visit_If(self, node):

def visit_Case(self, node):
self.visit(node.test)
for v, statements in node.cases.items():
for v, statements in sorted(node.cases.items(),
key=lambda x: str(x[0])):
self.visit(statements)

def visit_Fragment(self, node):
@@ -89,7 +91,7 @@ def visit_statements(self, node):
self.visit(statement)

def visit_clock_domains(self, node):
for clockname, statements in node.items():
for clockname, statements in sorted(node.items(), key=itemgetter(0)):
self.visit(statements)

def visit_ArrayProxy(self, node):
@@ -177,7 +179,9 @@ def visit_If(self, node):
return r

def visit_Case(self, node):
cases = dict((v, self.visit(statements)) for v, statements in node.cases.items())
cases = {v: self.visit(statements)
for v, statements in sorted(node.cases.items(),
key=lambda x: str(x[0]))}
r = Case(self.visit(node.test), cases)
return r

@@ -192,7 +196,9 @@ def visit_statements(self, node):
return [self.visit(statement) for statement in node]

def visit_clock_domains(self, node):
return dict((clockname, self.visit(statements)) for clockname, statements in node.items())
return {clockname: self.visit(statements)
for clockname, statements in sorted(node.items(),
key=itemgetter(0))}

def visit_ArrayProxy(self, node):
return _ArrayProxy([self.visit(choice) for choice in node.choices],