Changeset 3960


Ignore:
Timestamp:
Aug 5, 2014, 12:38:42 PM (5 years ago)
Author:
cameron
Message:

Eliminating some common subexpressions

Location:
proto/charsetcompiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/CC_compiler.py

    r3959 r3960  
    2020        predeclared = [self.bit_var(i) for i in range(0, self.mEncoding.bits)]
    2121        for sym in predeclared: self.common_expression_map[sym] = sym
     22
     23    def add_symbol_to_map(self, sym):
     24        self.common_expression_map[sym] = sym
     25
     26    def add_common_expressions(self, enclosing_cgo):
     27        for sym in enclosing_cgo.common_expression_map.keys():
     28            self.common_expression_map[sym] = enclosing_cgo.common_expression_map[sym]
    2229
    2330    def bit_var(self, n):
     
    231238            if isinstance(expr, TrueLiteral): return '-1'
    232239            elif isinstance(expr, FalseLiteral): return '0'
    233             elif isinstance(expr, Var): return expr.varname
     240            elif isinstance(expr, Var):
     241               # This is a hack.
     242               self.common_expression_map[expr.varname] = expr.varname
     243               return expr.varname
    234244            elif isinstance(expr, Not):
    235245               e = self.expr_string_to_variable(self.expr2py(expr.operand))
  • proto/charsetcompiler/unicode_category_compiler.py

    r3959 r3960  
    196196     utf8_range_compiler(cgo, lo, hi, range_var)
    197197     inner_cgo = CC_compiler(UTF8(), range_var + '_tmp%i', False, '')
     198     inner_cgo.add_common_expressions(cgo)
    198199     generateCharClassDefsInIfHierarchy(inner_cgo, (lo, hi), ifRangeList, charClassMap)
    199200     cgo.add_if_stmt(Var(range_var), inner_cgo.generated_code)
     
    207208   for k in charClassMap.keys():
    208209     subcc1 = rangeIntersect(charClassMap[k], lo, hi)
    209      CC_var = "CC_%s_%x_%x" % (k, lo, hi)
    210210     # Divide by UTF-8 length
    211211     for byte_range in [(0, 0x7F), (0x80, 0x7FF), (0x800, 0xFFFF), (0x10000, 0x10FFFF)]:
    212         subcc2 = rangeIntersect(charClassMap[k], byte_range[0], byte_range[1])
    213         ulen = utf8_length(byte_range[0])
     212        (lo1, hi1) = byte_range
     213        subcc2 = rangeIntersect(subcc1, lo1, hi1)
     214        ulen = utf8_length(lo1)
    214215        for subrange in subcc2:
    215            matched_sequence_compiler(cgo, subrange[0], subrange[1], 1, ulen, CC_var)
    216      cgo.add_assignment("struct_%s.cc" % k, cgo.expr2py(make_or(Var("struct_%s.cc" % k), Var(CC_var))))
     216           (lo2, hi2) = subrange
     217           CC_var = "CC_%s_%x_%x" % (k, lo2, hi2)
     218           matched_sequence_compiler(cgo, lo2, hi2, 1, ulen, CC_var)
     219           cgo.add_assignment("struct_%s.cc" % k, cgo.expr2py(make_or(Var("struct_%s.cc" % k), Var(CC_var))))
    217220
    218221def rangeIntersect(ccList, lo, hi):
     
    227230
    228231defaultIfRangeList = [(0,0x7FF), (0, 0x7F), (0x80, 0x3FF), (0x400,0x7FF), (0x800, 0xFFFF), (0x10000, 0x10FFFF)]
     232
     233#defaultIfRangeList = [(0x80,0x10FFFF), (0x80,0x7FF), (0x800,0xFFFF), (0x10000, 0x10FFFF)]
    229234
    230235
Note: See TracChangeset for help on using the changeset viewer.