Lichen

Changeset

652:03ca7bd1abc0
2017-03-03 Paul Boddie raw files shortlog changelog graph Simplified the constant consolidation process by using the constant values mapping directly to generate the optimised mappings.
optimiser.py (file)
     1.1 --- a/optimiser.py	Fri Mar 03 13:44:32 2017 +0100
     1.2 +++ b/optimiser.py	Fri Mar 03 21:35:02 2017 +0100
     1.3 @@ -982,31 +982,28 @@
     1.4  
     1.5          self.constants = {}
     1.6  
     1.7 -        for path, constants in self.importer.all_constants.items():
     1.8 -
     1.9 -            # Record constants and obtain a number for them.
    1.10 -            # Each constant is actually (value, value_type, encoding).
    1.11 -
    1.12 -            for constant, n in constants.items():
    1.13 -                d = digest(constant)
    1.14 -                self.constants[constant] = d
    1.15 -
    1.16 -                # Make sure the digests are really distinct for different
    1.17 -                # constants.
    1.18 -
    1.19 -                if self.digests.has_key(d):
    1.20 -                    if self.digests[d] != constant:
    1.21 -                        raise OptimiseError, "Digest %s used for distinct constants %r and %r." % (
    1.22 -                                             d, self.digests[d], constant)
    1.23 -                else:
    1.24 -                    self.digests[d] = constant
    1.25 -
    1.26          # Establish a mapping from local constant identifiers to consolidated
    1.27          # constant identifiers.
    1.28  
    1.29          self.constant_numbers = {}
    1.30  
    1.31          for name, constant in self.importer.all_constant_values.items():
    1.32 +
    1.33 +            # Each constant is actually (value, value_type, encoding).
    1.34 +
    1.35 +            d = digest(constant)
    1.36 +            self.constants[constant] = d
    1.37 +
    1.38 +            # Make sure the digests are really distinct for different
    1.39 +            # constants.
    1.40 +
    1.41 +            if self.digests.has_key(d):
    1.42 +                if self.digests[d] != constant:
    1.43 +                    raise OptimiseError, "Digest %s used for distinct constants %r and %r." % (
    1.44 +                                         d, self.digests[d], constant)
    1.45 +            else:
    1.46 +                self.digests[d] = constant
    1.47 +
    1.48              self.constant_numbers[name] = self.constants[constant]
    1.49  
    1.50  def combine_rows(a, b):