Lichen

Changeset

620:67f2da40bb32
2017-02-26 Paul Boddie raw files shortlog changelog graph Added constant identifier digest collision testing.
errors.py (file) optimiser.py (file)
     1.1 --- a/errors.py	Sun Feb 26 00:11:12 2017 +0100
     1.2 +++ b/errors.py	Sun Feb 26 14:29:36 2017 +0100
     1.3 @@ -4,7 +4,7 @@
     1.4  Error classes.
     1.5  
     1.6  Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
     1.7 -              2014, 2016 Paul Boddie <paul@boddie.org.uk>
     1.8 +              2014, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     1.9  
    1.10  This program is free software; you can redistribute it and/or modify it under
    1.11  the terms of the GNU General Public License as published by the Free Software
    1.12 @@ -85,6 +85,13 @@
    1.13      def __str__(self):
    1.14          return "Error in deduction: %s" % self.message
    1.15  
    1.16 +class OptimiseError(ProgramError):
    1.17 +
    1.18 +    "An error during optimisation."
    1.19 +
    1.20 +    def __str__(self):
    1.21 +        return "Error in optimisation: %s" % self.message
    1.22 +
    1.23  class TranslateError(NodeProcessingError):
    1.24  
    1.25      "An error during the module translation process."
     2.1 --- a/optimiser.py	Sun Feb 26 00:11:12 2017 +0100
     2.2 +++ b/optimiser.py	Sun Feb 26 14:29:36 2017 +0100
     2.3 @@ -22,6 +22,7 @@
     2.4  from common import add_counter_item, get_attrname_from_location, init_item, \
     2.5                     sorted_output
     2.6  from encoders import digest, encode_access_location, encode_instruction, get_kinds
     2.7 +from errors import OptimiseError
     2.8  from os.path import exists, join
     2.9  from os import makedirs
    2.10  from referencing import Reference
    2.11 @@ -73,6 +74,7 @@
    2.12  
    2.13          self.constants = []
    2.14          self.constant_numbers = {}
    2.15 +        self.digests = {}
    2.16  
    2.17          # Optimiser activities.
    2.18  
    2.19 @@ -742,7 +744,21 @@
    2.20              # Each constant is actually (value, value_type, encoding).
    2.21  
    2.22              for constant, n in constants.items():
    2.23 -                self.constants[constant] = digest(constant)
    2.24 +                d = digest(constant)
    2.25 +                self.constants[constant] = d
    2.26 +
    2.27 +                # Make sure the digests are really distinct for different
    2.28 +                # constants.
    2.29 +
    2.30 +                if self.digests.has_key(d):
    2.31 +                    if self.digests[d] != constant:
    2.32 +                        raise OptimiseError, "Digest %s used for distinct constants %r and %r." % (
    2.33 +                                             d, self.digests[d], constant)
    2.34 +                else:
    2.35 +                    self.digests[d] = constant
    2.36 +
    2.37 +        # Establish a mapping from local constant identifiers to consolidated
    2.38 +        # constant identifiers.
    2.39  
    2.40          self.constant_numbers = {}
    2.41