1.1 --- a/optimiser.py Sun Feb 26 00:11:12 2017 +0100
1.2 +++ b/optimiser.py Sun Feb 26 14:29:36 2017 +0100
1.3 @@ -22,6 +22,7 @@
1.4 from common import add_counter_item, get_attrname_from_location, init_item, \
1.5 sorted_output
1.6 from encoders import digest, encode_access_location, encode_instruction, get_kinds
1.7 +from errors import OptimiseError
1.8 from os.path import exists, join
1.9 from os import makedirs
1.10 from referencing import Reference
1.11 @@ -73,6 +74,7 @@
1.12
1.13 self.constants = []
1.14 self.constant_numbers = {}
1.15 + self.digests = {}
1.16
1.17 # Optimiser activities.
1.18
1.19 @@ -742,7 +744,21 @@
1.20 # Each constant is actually (value, value_type, encoding).
1.21
1.22 for constant, n in constants.items():
1.23 - self.constants[constant] = digest(constant)
1.24 + d = digest(constant)
1.25 + self.constants[constant] = d
1.26 +
1.27 + # Make sure the digests are really distinct for different
1.28 + # constants.
1.29 +
1.30 + if self.digests.has_key(d):
1.31 + if self.digests[d] != constant:
1.32 + raise OptimiseError, "Digest %s used for distinct constants %r and %r." % (
1.33 + d, self.digests[d], constant)
1.34 + else:
1.35 + self.digests[d] = constant
1.36 +
1.37 + # Establish a mapping from local constant identifiers to consolidated
1.38 + # constant identifiers.
1.39
1.40 self.constant_numbers = {}
1.41