~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tools/shared.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-02-05 18:46:19 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140205184619-bmxq31rw0cd3ar4u
Tags: 1.10.0~20140205~ef1e460-1
* New snapshot release
* Also install cmake / emscripten files. Thanks to Daniele Di Proietto
  for the patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
345
345
# we re-check sanity when the settings are changed)
346
346
# We also re-check sanity and clear the cache when the version changes
347
347
 
348
 
EMSCRIPTEN_VERSION = '1.9.0'
 
348
EMSCRIPTEN_VERSION = '1.10.0'
349
349
 
350
350
def generate_sanity():
351
351
  return EMSCRIPTEN_VERSION + '|' + get_llvm_target() + '|' + LLVM_ROOT + '|' + get_clang_version()
809
809
        self.attrs['DISABLE_EXCEPTION_CATCHING'] = 1
810
810
        self.attrs['RELOOP'] = 1
811
811
        self.attrs['ALIASING_FUNCTION_POINTERS'] = 1
812
 
      if opt_level >= 3:
813
 
        # Aside from these, -O3 also runs closure compiler and llvm lto
814
 
        self.attrs['FORCE_ALIGNED_MEMORY'] = 1
815
 
        self.attrs['DOUBLE_MODE'] = 0
816
 
        self.attrs['PRECISE_I64_MATH'] = 0
817
 
        if noisy: logging.warning('Applying some potentially unsafe optimizations! (Use -O2 if this fails.)')
818
812
 
819
813
    def __getattr__(self, attr):
820
814
      if attr in self.attrs:
1568
1562
chunkify = cache.chunkify
1569
1563
 
1570
1564
class JS:
1571
 
  memory_initializer_pattern = '/\* memory initializer \*/ allocate\(([\d,\.concat\(\)\[\]\\n ]+)"i8", ALLOC_NONE, ([\dRuntime\.GLOBAL_BASEH+]+)\)'
 
1565
  memory_initializer_pattern = '/\* memory initializer \*/ allocate\(\[([\d, ]+)\], "i8", ALLOC_NONE, ([\d+Runtime\.GLOBAL_BASEH]+)\);'
1572
1566
  no_memory_initializer_pattern = '/\* no memory initializer \*/'
1573
1567
 
1574
1568
  memory_staticbump_pattern = 'STATICTOP = STATIC_BASE \+ (\d+);'
1652
1646
    while x % by != 0: x += 1
1653
1647
    return x
1654
1648
 
 
1649
  INITIALIZER_CHUNK_SIZE = 10240
 
1650
 
 
1651
  @staticmethod
 
1652
  def collect_initializers(src):
 
1653
    ret = []
 
1654
    max_offset = -1
 
1655
    for init in re.finditer(JS.memory_initializer_pattern, src):
 
1656
      contents = init.group(1).split(',')
 
1657
      offset = sum([int(x) if x[0] != 'R' else 0 for x in init.group(2).split('+')])
 
1658
      ret.append((offset, contents))
 
1659
      assert offset > max_offset
 
1660
      max_offset = offset
 
1661
    return ret
 
1662
 
 
1663
  @staticmethod
 
1664
  def split_initializer(contents):
 
1665
    # given a memory initializer (see memory_initializer_pattern), split it up into multiple initializers to avoid long runs of zeros or a single overly-large allocator
 
1666
    ret = []
 
1667
    l = len(contents)
 
1668
    maxx = JS.INITIALIZER_CHUNK_SIZE
 
1669
    i = 0
 
1670
    start = 0
 
1671
    while 1:
 
1672
      if i - start >= maxx or (i > start and i == l):
 
1673
        #print >> sys.stderr, 'new', start, i-start
 
1674
        ret.append((start, contents[start:i]))
 
1675
        start = i
 
1676
      if i == l: break
 
1677
      if contents[i] != '0':
 
1678
        i += 1
 
1679
      else:
 
1680
        # look for a sequence of zeros
 
1681
        j = i + 1
 
1682
        while j < l and contents[j] == '0': j += 1
 
1683
        if j-i > maxx/10 or j-start >= maxx:
 
1684
          #print >> sys.stderr, 'skip', start, i-start, j-start
 
1685
          ret.append((start, contents[start:i])) # skip over the zeros starting at i and ending at j
 
1686
          start = j
 
1687
        i = j
 
1688
    return ret
 
1689
 
 
1690
  @staticmethod
 
1691
  def replace_initializers(src, inits):
 
1692
    class State:
 
1693
      first = True
 
1694
    def rep(m):
 
1695
      if not State.first: return ''
 
1696
      # write out all the new initializers in place of the first old one
 
1697
      State.first = False
 
1698
      def gen_init(init):
 
1699
        offset, contents = init
 
1700
        return '/* memory initializer */ allocate([%s], "i8", ALLOC_NONE, Runtime.GLOBAL_BASE%s);' % (
 
1701
          ','.join(contents),
 
1702
          '' if offset == 0 else ('+%d' % offset)
 
1703
        )
 
1704
      return '\n'.join(map(gen_init, inits))
 
1705
    return re.sub(JS.memory_initializer_pattern, rep, src)
 
1706
 
 
1707
  @staticmethod
 
1708
  def optimize_initializer(src):
 
1709
    inits = JS.collect_initializers(src)
 
1710
    if len(inits) == 0: return None
 
1711
    assert len(inits) == 1
 
1712
    init = inits[0]
 
1713
    offset, contents = init
 
1714
    assert offset == 0 # offset 0, singleton
 
1715
    if len(contents) <= JS.INITIALIZER_CHUNK_SIZE: return None
 
1716
    return JS.replace_initializers(src, JS.split_initializer(contents))
 
1717
 
1655
1718
# Compression of code and data for smaller downloads
1656
1719
class Compression:
1657
1720
  on = False