Skip to content

Commit 98f6c4d

Browse files
author
Chad Austin
committed
remove jcache global variable in emscripten.py
1 parent cdbb73f commit 98f6c4d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

emscripten.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def path_from_root(*pathelems):
2323
configuration = shared.Configuration(environ=os.environ)
2424
temp_files = shared.make_temp_files()
2525

26-
jcache = False
27-
2826
def scan(ll, settings):
2927
# blockaddress(@main, %23)
3028
blockaddrs = []
@@ -51,7 +49,9 @@ def process_funcs((i, funcs, meta, settings_file, compiler, forwarded_file, libr
5149
shared.try_delete(funcs_file)
5250
return out
5351

54-
def emscript(configuration, infile, settings, outfile, libraries=[], compiler_engine=None):
52+
def emscript(configuration, infile, settings, outfile, libraries=[],
53+
compiler_engine=None,
54+
jcache=None):
5555
"""Runs the emscripten LLVM-to-JS compiler. We parallelize as much as possible
5656
5757
Args:
@@ -72,7 +72,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[], compiler_en
7272

7373
configuration.debug_log('emscript: ll=>js')
7474

75-
if jcache: shared.JCache.ensure()
75+
if jcache: jcache.ensure()
7676

7777
# Pre-scan ll and alter settings as necessary
7878
if DEBUG: t = time.time()
@@ -141,13 +141,13 @@ def save_settings():
141141
out = None
142142
if jcache:
143143
keys = [pre_input, settings_text, ','.join(libraries)]
144-
shortkey = shared.JCache.get_shortkey(keys)
144+
shortkey = jcache.get_shortkey(keys)
145145
if DEBUG_CACHE: print >>sys.stderr, 'shortkey', shortkey
146146

147-
out = shared.JCache.get(shortkey, keys)
147+
out = jcache.get(shortkey, keys)
148148

149149
if DEBUG_CACHE and not out:
150-
dfpath = os.path.join(shared.TEMP_DIR, "ems_" + shortkey)
150+
dfpath = os.path.join(configuration.TEMP_DIR, "ems_" + shortkey)
151151
dfp = open(dfpath, 'w')
152152
dfp.write(pre_input);
153153
dfp.write("\n\n========================== settings_text\n\n");
@@ -163,7 +163,7 @@ def save_settings():
163163
out = shared.run_js(compiler, compiler_engine, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, cwd=path_from_root('src'))
164164
if jcache:
165165
if DEBUG: print >> sys.stderr, ' saving pre to jcache'
166-
shared.JCache.set(shortkey, keys, out)
166+
jcache.set(shortkey, keys, out)
167167
pre, forwarded_data = out.split('//FORWARDED_DATA:')
168168
forwarded_file = temp_files.get('.json').name
169169
open(forwarded_file, 'w').write(forwarded_data)
@@ -195,8 +195,8 @@ def save_settings():
195195
cached_outputs = []
196196
def load_from_cache(chunk):
197197
keys = [settings_text, forwarded_data, chunk]
198-
shortkey = shared.JCache.get_shortkey(keys) # TODO: share shortkeys with later code
199-
out = shared.JCache.get(shortkey, keys) # this is relatively expensive (pickling?)
198+
shortkey = jcache.get_shortkey(keys) # TODO: share shortkeys with later code
199+
out = jcache.get(shortkey, keys) # this is relatively expensive (pickling?)
200200
if out:
201201
cached_outputs.append(out)
202202
return False
@@ -236,8 +236,8 @@ def load_from_cache(chunk):
236236
for i in range(len(chunks)):
237237
chunk = chunks[i]
238238
keys = [settings_text, forwarded_data, chunk]
239-
shortkey = shared.JCache.get_shortkey(keys)
240-
shared.JCache.set(shortkey, keys, outputs[i])
239+
shortkey = jcache.get_shortkey(keys)
240+
jcache.set(shortkey, keys, outputs[i])
241241
if out and DEBUG and len(chunks) > 0: print >> sys.stderr, ' saving %d funcchunks to jcache' % len(chunks)
242242

243243
if jcache: outputs += cached_outputs # TODO: preserve order
@@ -497,7 +497,7 @@ def fix(m):
497497
outfile.close()
498498

499499

500-
def main(args, compiler_engine=None):
500+
def main(args, compiler_engine=None, jcache=None):
501501
# Prepare settings for serialization to JSON.
502502
settings = {}
503503
for setting in args.settings:
@@ -573,7 +573,9 @@ def lookup(value):
573573
# Compile the assembly to Javascript.
574574
if settings.get('RELOOP'): shared.Building.ensure_relooper()
575575

576-
emscript(configuration, args.infile, settings, args.outfile, libraries, compiler_engine=compiler_engine)
576+
emscript(configuration, args.infile, settings, args.outfile, libraries,
577+
compiler_engine=compiler_engine,
578+
jcache=jcache)
577579

578580
def _main(environ):
579581
parser = optparse.OptionParser(
@@ -630,12 +632,10 @@ def _main(environ):
630632
shared.RELOOPER = os.path.abspath(keywords.relooper)
631633
keywords.settings.append("RELOOPER=" + json.dumps(shared.RELOOPER))
632634

633-
global jcache
634-
jcache = keywords.jcache
635-
636635
temp_files.run_and_clean(lambda: main(
637636
keywords,
638-
compiler_engine=os.path.abspath(keywords.compiler)))
637+
compiler_engine=os.path.abspath(keywords.compiler),
638+
jcache=shared.JCache if keywords.jcache else None))
639639

640640
if __name__ == '__main__':
641641
_main(environ=os.environ)

0 commit comments

Comments
 (0)