fix emscript funcs caching and add testing

This commit is contained in:
Alon Zakai 2012-11-21 14:53:45 +01:00
Родитель cd80d52b85
Коммит cbfcb2e9f1
2 изменённых файлов: 17 добавлений и 16 удалений

Просмотреть файл

@ -175,22 +175,22 @@ def emscript(infile, settings, outfile, libraries=[]):
if jcache:
# load chunks from cache where we can # TODO: ignore small chunks
cached_funcs = []
cached_outputs = []
def load_from_cache(chunk):
keys = [settings_text, forwarded_data, chunk]
shortkey = shared.JCache.get_shortkey(keys) # TODO: share shortkeys with later code
out = shared.JCache.get(shortkey, keys)
if out:
cached_funcs.append(out)
cached_outputs.append(out)
return False
return True
chunks = filter(load_from_cache, chunks)
if len(cached_funcs) > 0:
if out and DEBUG: print >> sys.stderr, ' loading %d funcchunks from jcache' % len(cached_funcs)
cached_funcs_js = ''.join(cached_funcs)
cached_funcs = None
if len(cached_outputs) > 0:
if out and DEBUG: print >> sys.stderr, ' loading %d funcchunks from jcache' % len(cached_outputs)
else:
cached_funcs_js = ''
cached_outputs = []
# TODO: minimize size of forwarded data from funcs to what we actually need
if cores == 1 and total_ll_size < MAX_CHUNK_SIZE: assert len(chunks) == 1, 'no point in splitting up without multiple cores'
@ -216,9 +216,8 @@ def emscript(infile, settings, outfile, libraries=[]):
shared.JCache.set(shortkey, keys, outputs[i])
if out and DEBUG and len(chunks) > 0: print >> sys.stderr, ' saving %d funcchunks to jcache' % len(chunks)
if jcache: outputs += cached_outputs # TODO: preserve order
funcs_js = ''.join([output[0] for output in outputs])
if jcache:
funcs_js += cached_funcs_js # TODO insert them in the original order
for func_js, curr_forwarded_data in outputs:
# merge forwarded data

Просмотреть файл

@ -10461,7 +10461,9 @@ fi
assert not os.path.exists(JCache.get_cachename('emscript_files'))
src = None
srcs = {}
used_jcache = False
for args, input_file, expect_save, expect_load in [
([], 'hello_world_loop.cpp', False, False),
(['--jcache'], 'hello_world_loop.cpp', True, False),
@ -10473,7 +10475,7 @@ fi
([], 'hello_world.cpp', False, False),
(['--jcache'], 'hello_world_loop.cpp', False, True), # go back to old file, experience caching
]:
print args, input_file, expect_save, expect_load
print >> sys.stderr, args, input_file, expect_save, expect_load
self.clear()
out, err = Popen(['python', EMCC, path_from_root('tests', input_file)] + args, stdout=PIPE, stderr=PIPE).communicate()
assert (PRE_SAVE_MSG in err) == expect_save, err
@ -10481,12 +10483,12 @@ fi
assert (FUNC_CHUNKS_SAVE_MSG in err) == expect_save, err
assert (FUNC_CHUNKS_LOAD_MSG in err) == expect_load, err
curr = open('a.out.js').read()
if src is None:
src = None
if input_file not in srcs:
srcs[input_file] = curr
else:
assert src == curr, 'caching must not affect codegen'
assert os.path.exists(JCache.get_cachename('emscript_files'))
assert curr == srcs[input_file], err
used_jcache = used_jcache or ('--jcache' in args)
assert used_jcache == os.path.exists(JCache.get_cachename('emscript_files'))
finally:
del os.environ['EMCC_DEBUG']