aboutsummaryrefslogtreecommitdiff
path: root/emcc
diff options
context:
space:
mode:
Diffstat (limited to 'emcc')
-rwxr-xr-xemcc37
1 files changed, 37 insertions, 0 deletions
diff --git a/emcc b/emcc
index bc76b01d..1d285cbb 100755
--- a/emcc
+++ b/emcc
@@ -470,6 +470,11 @@ Options that are modified or new in %s include:
libraries, and after any link-time optimizations
(if any).
+ --memory-init-file <on> If on, we generate a separate memory initialization
+ file. This is more efficient than storing the
+ memory initialization data embedded inside
+ JavaScript as text. (default is on)
+
The target file, if specified (-o <target>), defines what will
be generated:
@@ -716,6 +721,7 @@ try:
bind = False
jcache = False
save_bc = False
+ memory_init_file = False # XXX TODO True
if use_cxx:
default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
@@ -849,6 +855,11 @@ try:
save_bc = newargs[i+1]
newargs[i] = ''
newargs[i+1] = ''
+ elif newargs[i] == '--memory-init-file':
+ check_bad_eq(newargs[i])
+ memory_init_file = int(newargs[i+1])
+ newargs[i] = ''
+ newargs[i+1] = ''
elif newargs[i].startswith(('-I/', '-L/')):
if not absolute_warning_shown:
print >> sys.stderr, 'emcc: warning: -I or -L of an absolute path encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)' # Of course an absolute path to a non-system-specific library or header is fine, and you can ignore this warning. The danger are system headers that are e.g. x86 specific and nonportable. The emscripten bundled headers are modified to be portable, local system ones are generally not
@@ -1429,6 +1440,32 @@ try:
src = re.sub(r'\n+[ \n]*\n+', '\n', src)
open(final, 'w').write(src)
+ if memory_init_file:
+ memfile = target + '.mem'
+ seen_memory_init = False
+ def repl(m):
+ seen_memory_init = True
+ # handle chunking of the memory initializer
+ s = re.sub('[\[\]\n\(\)\. ]', '', m.groups(0)[0])
+ s = s.replace('concat', ',')
+ if s[-1] == ',': s = s[:-1]
+ open(memfile, 'wb').write(''.join(map(lambda x: chr(int(x or '0')), s.split(','))))
+ if DEBUG:
+ # Copy into temp dir as well, so can be run there too
+ temp_memfile = os.path.join(shared.EMSCRIPTEN_TEMP_DIR, os.path.basename(memfile))
+ if os.path.abspath(memfile) != os.path.abspath(memfile):
+ shutil.copyfile(memfile, temp_memfile)
+ return 'loadMemoryInitializer("%s");' % os.path.basename(memfile)
+ src = re.sub('/\* memory initializer \*/ allocate\(([\d,\.concat\(\)\[\]\\n ]+)"i8", ALLOC_NONE, TOTAL_STACK\)', repl, src, count=1)
+ open(final + '.mem.js', 'w').write(src)
+ final += '.mem.js'
+ if DEBUG:
+ if seen_memory_init:
+ save_intermediate('meminit')
+ print >> sys.stderr, 'emcc: wrote memory initialization to %s' % memfile
+ else:
+ print >> sys.stderr, 'emcc: did not see memory initialization'
+
# If we were asked to also generate HTML, do that
if final_suffix == 'html':
if DEBUG: print >> sys.stderr, 'emcc: generating HTML'