aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc26
-rw-r--r--src/preamble.js18
2 files changed, 44 insertions, 0 deletions
diff --git a/emcc b/emcc
index bc76b01d..a3b78815 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 = 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,21 @@ try:
src = re.sub(r'\n+[ \n]*\n+', '\n', src)
open(final, 'w').write(src)
+ if memory_init_file:
+ memfile = target + '.mem'
+ def repl(m):
+ open(memfile, 'wb').write(''.join(map(lambda x: chr(int(x or '0')), m.groups(0)[0].split(','))))
+ if DEBUG:
+ # Copy into temp dir as well, so can be run there too
+ shutil.copyfile(memfile, os.path.join(shared.EMSCRIPTEN_TEMP_DIR, os.path.basename(memfile)))
+ return 'Module["preRun"].push(function() { loadMemoryInitializer("%s") })' % os.path.basename(memfile)
+ src = re.sub('/\* memory initializer \*/ allocate\(\[([\d,]+)\], "i8", ALLOC_NONE, TOTAL_STACK\)', repl, src, count=1)
+ open(final + '.mem.js', 'w').write(src)
+ final += '.mem.js'
+ if DEBUG:
+ save_intermediate('meminit')
+ print >> sys.stderr, 'emcc: wrote memory initialization to %s' % memfile
+
# If we were asked to also generate HTML, do that
if final_suffix == 'html':
if DEBUG: print >> sys.stderr, 'emcc: generating HTML'
diff --git a/src/preamble.js b/src/preamble.js
index f85cf4f3..392de7dc 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -882,5 +882,23 @@ if (!Module.preRun) Module.preRun = [];
Module.preRun.push(function() { addRunDependency('pgo') });
#endif
+function loadMemoryInitializer(filename) {
+ function applyData(data) {
+ HEAPU8.set(data, TOTAL_STACK);
+ }
+
+ if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) {
+ // synchronous
+ applyData(Module['readBinary'](filename));
+ } else {
+ // asynchronous
+ Browser.asyncLoad(filename, function(data) {
+ applyData(data);
+ }, function(data) {
+ throw 'could not load memory initializer ' + filename;
+ });
+ }
+}
+
// === Body ===