use a separate memory initialization file
This commit is contained in:
Родитель
f8c930551e
Коммит
3245705765
26
emcc
26
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'
|
||||
|
|
|
@ -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 ===
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче