@@ -23,8 +23,6 @@ def path_from_root(*pathelems):
23
23
configuration = shared .Configuration (environ = os .environ )
24
24
temp_files = shared .make_temp_files ()
25
25
26
- jcache = False
27
-
28
26
def scan (ll , settings ):
29
27
# blockaddress(@main, %23)
30
28
blockaddrs = []
@@ -51,7 +49,9 @@ def process_funcs((i, funcs, meta, settings_file, compiler, forwarded_file, libr
51
49
shared .try_delete (funcs_file )
52
50
return out
53
51
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 ):
55
55
"""Runs the emscripten LLVM-to-JS compiler. We parallelize as much as possible
56
56
57
57
Args:
@@ -72,7 +72,7 @@ def emscript(configuration, infile, settings, outfile, libraries=[], compiler_en
72
72
73
73
configuration .debug_log ('emscript: ll=>js' )
74
74
75
- if jcache : shared . JCache .ensure ()
75
+ if jcache : jcache .ensure ()
76
76
77
77
# Pre-scan ll and alter settings as necessary
78
78
if DEBUG : t = time .time ()
@@ -141,13 +141,13 @@ def save_settings():
141
141
out = None
142
142
if jcache :
143
143
keys = [pre_input , settings_text , ',' .join (libraries )]
144
- shortkey = shared . JCache .get_shortkey (keys )
144
+ shortkey = jcache .get_shortkey (keys )
145
145
if DEBUG_CACHE : print >> sys .stderr , 'shortkey' , shortkey
146
146
147
- out = shared . JCache .get (shortkey , keys )
147
+ out = jcache .get (shortkey , keys )
148
148
149
149
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 )
151
151
dfp = open (dfpath , 'w' )
152
152
dfp .write (pre_input );
153
153
dfp .write ("\n \n ========================== settings_text\n \n " );
@@ -163,7 +163,7 @@ def save_settings():
163
163
out = shared .run_js (compiler , compiler_engine , [settings_file , pre_file , 'pre' ] + libraries , stdout = subprocess .PIPE , cwd = path_from_root ('src' ))
164
164
if jcache :
165
165
if DEBUG : print >> sys .stderr , ' saving pre to jcache'
166
- shared . JCache .set (shortkey , keys , out )
166
+ jcache .set (shortkey , keys , out )
167
167
pre , forwarded_data = out .split ('//FORWARDED_DATA:' )
168
168
forwarded_file = temp_files .get ('.json' ).name
169
169
open (forwarded_file , 'w' ).write (forwarded_data )
@@ -195,8 +195,8 @@ def save_settings():
195
195
cached_outputs = []
196
196
def load_from_cache (chunk ):
197
197
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?)
200
200
if out :
201
201
cached_outputs .append (out )
202
202
return False
@@ -236,8 +236,8 @@ def load_from_cache(chunk):
236
236
for i in range (len (chunks )):
237
237
chunk = chunks [i ]
238
238
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 ])
241
241
if out and DEBUG and len (chunks ) > 0 : print >> sys .stderr , ' saving %d funcchunks to jcache' % len (chunks )
242
242
243
243
if jcache : outputs += cached_outputs # TODO: preserve order
@@ -497,7 +497,7 @@ def fix(m):
497
497
outfile .close ()
498
498
499
499
500
- def main (args , compiler_engine = None ):
500
+ def main (args , compiler_engine = None , jcache = None ):
501
501
# Prepare settings for serialization to JSON.
502
502
settings = {}
503
503
for setting in args .settings :
@@ -573,7 +573,9 @@ def lookup(value):
573
573
# Compile the assembly to Javascript.
574
574
if settings .get ('RELOOP' ): shared .Building .ensure_relooper ()
575
575
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 )
577
579
578
580
def _main (environ ):
579
581
parser = optparse .OptionParser (
@@ -630,12 +632,10 @@ def _main(environ):
630
632
shared .RELOOPER = os .path .abspath (keywords .relooper )
631
633
keywords .settings .append ("RELOOPER=" + json .dumps (shared .RELOOPER ))
632
634
633
- global jcache
634
- jcache = keywords .jcache
635
-
636
635
temp_files .run_and_clean (lambda : main (
637
636
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 ))
639
639
640
640
if __name__ == '__main__' :
641
641
_main (environ = os .environ )
0 commit comments