diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-21 15:54:59 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-21 15:54:59 -0800 |
commit | 2f4401a79e96917f78876c3e09b8d31754a26f70 (patch) | |
tree | 8ac45e1d7b302a9f0aaa7e9b9e74aff01965a93d | |
parent | 2c8c19f60585d4e8cb78af119faba664a35e2268 (diff) | |
parent | 160cc728e0839e441897d951fa61020bc2176717 (diff) |
Merge branch 'incoming'
65 files changed, 1351 insertions, 827 deletions
@@ -42,4 +42,5 @@ a license to everyone to use it as detailed in LICENSE.) * Manuel Wellmann <manuel.wellmann@autodesk.com> (copyright owned by Autodesk, Inc.) * Xuejie Xiao <xxuejie@gmail.com> * Dominic Wong <dom@slowbunyip.org> +* Alan Kligman <alan.kligman@gmail.com> (copyright owned by Mozilla Foundation) @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' See emcc.py. This script forwards to there, noting that we want C++ and not C by default @@ -8,5 +8,5 @@ import os, subprocess, sys from tools import shared os.environ['EMMAKEN_CXX'] = '1' -exit(subprocess.call(['python', shared.EMCC] + sys.argv[1:])) +exit(subprocess.call([shared.PYTHON, shared.EMCC] + sys.argv[1:])) @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' This is a helper tool which is designed to make it possible @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' emar - ar helper script @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' emcc - compiler helper script @@ -322,11 +322,6 @@ Options that are modified or new in %s include: -v to Clang, and also enable EMCC_DEBUG to details emcc's operations - --remove-duplicates If set, will remove duplicate symbols when - linking. This can be useful because - llvm-link's behavior is not as permissive - as ld is. - --jcache Use a JavaScript cache. This is disabled by default. When enabled, emcc will store the results of compilation in a cache and check @@ -596,7 +591,6 @@ try: ignore_dynamic_linking = False shell_path = shared.path_from_root('src', 'shell.html') js_libraries = [] - remove_duplicates = False keep_debug = False bind = False jcache = False @@ -705,7 +699,7 @@ try: newargs[i] = '' newargs[i+1] = '' elif newargs[i] == '--remove-duplicates': - remove_duplicates = True + print >> sys.stderr, 'emcc: warning: --remove-duplicates is deprecated as it is no longer needed. If you cannot link without it, file a bug with a testcase' newargs[i] = '' elif newargs[i] == '--jcache': jcache = True @@ -912,7 +906,7 @@ try: # We have a specified target (-o <target>), which is not JavaScript or HTML, and # we have multiple files: Link them if DEBUG: print >> sys.stderr, 'emcc: link: ' + str(temp_files), specified_target - shared.Building.link(temp_files, specified_target, remove_duplicates=remove_duplicates) + shared.Building.link(temp_files, specified_target) exit(0) ## Continue on to create JavaScript @@ -931,9 +925,9 @@ try: # dlmalloc def create_dlmalloc(): if DEBUG: print >> sys.stderr, 'emcc: building dlmalloc for cache' - execute(shared.ENV_PREFIX + ['python', shared.EMCC, shared.path_from_root('system', 'lib', 'dlmalloc.c'), '-g', '-o', in_temp('dlmalloc.o')], stdout=stdout, stderr=stderr) + execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', 'dlmalloc.c'), '-g', '-o', in_temp('dlmalloc.o')], stdout=stdout, stderr=stderr) # we include the libc++ new stuff here, so that the common case of using just new/delete is quick to link - execute(shared.ENV_PREFIX + ['python', shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', 'new.cpp'), '-g', '-o', in_temp('new.o')], stdout=stdout, stderr=stderr) + execute([shared.PYTHON, shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', 'new.cpp'), '-g', '-o', in_temp('new.o')], stdout=stdout, stderr=stderr) shared.Building.link([in_temp('dlmalloc.o'), in_temp('new.o')], in_temp('dlmalloc_full.o')) return in_temp('dlmalloc_full.o') def fix_dlmalloc(): @@ -956,7 +950,7 @@ try: os = [] for src in ['algorithm.cpp', 'condition_variable.cpp', 'future.cpp', 'iostream.cpp', 'memory.cpp', 'random.cpp', 'stdexcept.cpp', 'system_error.cpp', 'utility.cpp', 'bind.cpp', 'debug.cpp', 'hash.cpp', 'mutex.cpp', 'string.cpp', 'thread.cpp', 'valarray.cpp', 'chrono.cpp', 'exception.cpp', 'ios.cpp', 'locale.cpp', 'regex.cpp', 'strstream.cpp', 'typeinfo.cpp']: o = in_temp(src + '.o') - execute(shared.ENV_PREFIX + ['python', shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', src), '-o', o], stdout=stdout, stderr=stderr) + execute([shared.PYTHON, shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', src), '-o', o], stdout=stdout, stderr=stderr) os.append(o) shared.Building.link(os, in_temp('libcxx.bc')) return in_temp('libcxx.bc') @@ -975,7 +969,7 @@ try: os = [] for src in ['private_typeinfo.cpp']: o = in_temp(src + '.o') - execute(shared.ENV_PREFIX + ['python', shared.EMXX, shared.path_from_root('system', 'lib', 'libcxxabi', 'src', src), '-o', o], stdout=stdout, stderr=stderr) + execute([shared.PYTHON, shared.EMXX, shared.path_from_root('system', 'lib', 'libcxxabi', 'src', src), '-o', o], stdout=stdout, stderr=stderr) os.append(o) shared.Building.link(os, in_temp('libcxxabi.bc')) return in_temp('libcxxabi.bc') @@ -1027,7 +1021,7 @@ try: (not LEAVE_INPUTS_RAW and not (suffix(temp_files[0]) in BITCODE_SUFFIXES or suffix(temp_files[0]) in DYNAMICLIB_SUFFIXES) and shared.Building.is_ar(temp_files[0])): linker_inputs = temp_files + extra_files_to_link if DEBUG: print >> sys.stderr, 'emcc: linking: ', linker_inputs - shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'), remove_duplicates=remove_duplicates) + shared.Building.link(linker_inputs, in_temp(target_basename + '.bc')) final = in_temp(target_basename + '.bc') else: if not LEAVE_INPUTS_RAW: @@ -1061,13 +1055,14 @@ try: if DEBUG: save_intermediate('opt', 'bc') # Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript) if shared.Building.can_build_standalone(): + # If we can LTO, do it before dce, since it opens up dce opportunities if llvm_lto and shared.Building.can_use_unsafe_opts(): if not shared.Building.can_inline(): link_opts.append('-disable-inlining') - link_opts.append('-std-link-opts') + # do not internalize in std-link-opts - it ignores internalize-public-api-list - and add a manual internalize + link_opts += ['-disable-internalize'] + shared.Building.get_safe_internalize() + ['-std-link-opts'] else: - # At least remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it) - link_opts += ['-internalize', '-globaldce'] - if link_opts: + # At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it) + link_opts += shared.Building.get_safe_internalize() + ['-globaldce'] if DEBUG: print >> sys.stderr, 'emcc: LLVM linktime:', link_opts shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts) if DEBUG: save_intermediate('linktime', 'bc') @@ -1081,7 +1076,7 @@ try: if AUTODEBUG: if DEBUG: print >> sys.stderr, 'emcc: autodebug' - execute(shared.ENV_PREFIX + ['python', shared.AUTODEBUGGER, final, final + '.ad.ll']) + execute([shared.PYTHON, shared.AUTODEBUGGER, final, final + '.ad.ll']) final += '.ad.ll' if DEBUG: save_intermediate('autodebug', 'll') @@ -1104,7 +1099,7 @@ try: file_args += embed_files if Compression.on: file_args += ['--compress', Compression.encoder, Compression.decoder, Compression.js_name] - code = execute(shared.ENV_PREFIX + ['python', shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE)[0] + code = execute([shared.PYTHON, shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE)[0] src = open(final).read().replace('// {{PRE_RUN_ADDITIONS}}', '// {{PRE_RUN_ADDITIONS}}\n' + code) final += '.files.js' open(final, 'w').write(src) diff --git a/emconfigure b/emconfigure index 64ca8c4f..51e57c64 100755 --- a/emconfigure +++ b/emconfigure @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' This is a helper script. It runs ./configure for you, setting @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' This is a helper script. See emcc. @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' This is a helper script. It runs make for you, setting @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' emcc - ranlib helper script diff --git a/emscripten.py b/emscripten.py index 98dcb6bb..3c636447 100755 --- a/emscripten.py +++ b/emscripten.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 ''' You should normally never use this! Use emcc instead. diff --git a/src/jsifier.js b/src/jsifier.js index 50703b90..4192cd3f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -486,6 +486,19 @@ function JSify(data, functionsOnly, givenFunctions) { } }); + // function for filtering functions for label debugging + if (LABEL_FUNCTION_FILTERS.length > 0) { + var LABEL_FUNCTION_FILTER_SET = set(LABEL_FUNCTION_FILTERS); + var functionNameFilterTest = function(ident) { + return (ident in LABEL_FUNCTION_FILTER_SET); + }; + } else { + // no filters are specified, all function names are printed + var functionNameFilterTest = function(ident) { + return true; + } + } + // function reconstructor & post-JS optimizer substrate.addActor('FunctionReconstructor', { funcs: {}, @@ -566,7 +579,7 @@ function JSify(data, functionsOnly, givenFunctions) { } }); - if (LABEL_DEBUG) func.JS += " Module.print(INDENT + ' Entering: " + func.ident + ": ' + Array.prototype.slice.call(arguments)); INDENT += ' ';\n"; + if (LABEL_DEBUG && functionNameFilterTest(func.ident)) func.JS += " Module.print(INDENT + ' Entering: " + func.ident + ": ' + Array.prototype.slice.call(arguments)); INDENT += ' ';\n"; if (true) { // TODO: optimize away when not needed if (CLOSURE_ANNOTATIONS) func.JS += '/** @type {number} */'; @@ -580,7 +593,7 @@ function JSify(data, functionsOnly, givenFunctions) { function getLabelLines(label, indent, relooping) { if (!label) return ''; var ret = ''; - if (LABEL_DEBUG >= 2) { + if ((LABEL_DEBUG >= 2) && functionNameFilterTest(func.ident)) { ret += indent + "Module.print(INDENT + '" + func.ident + ":" + label.ident + "');\n"; } if (EXECUTION_TIMEOUT > 0) { @@ -692,7 +705,7 @@ function JSify(data, functionsOnly, givenFunctions) { } func.JS += walkBlock(func.block, ' '); // Finalize function - if (LABEL_DEBUG) func.JS += " INDENT = INDENT.substr(0, INDENT.length-2);\n"; + if (LABEL_DEBUG && functionNameFilterTest(func.ident)) func.JS += " INDENT = INDENT.substr(0, INDENT.length-2);\n"; // Add an unneeded return, needed for strict mode to not throw warnings in some cases. // If we are not relooping, then switches make it unimportant to have this (and, we lack hasReturn anyhow) if (RELOOP && func.lines.length > 0 && func.labels.filter(function(label) { return label.hasReturn }).length > 0) { @@ -1025,7 +1038,7 @@ function JSify(data, functionsOnly, givenFunctions) { + 'PROFILING_NODE = __parentProfilingNode__ ' + '}\n'; } - if (LABEL_DEBUG) { + if (LABEL_DEBUG && functionNameFilterTest(item.funcData.ident)) { ret += "Module.print(INDENT + 'Exiting: " + item.funcData.ident + "');\n" + "INDENT = INDENT.substr(0, INDENT.length-2);\n"; } diff --git a/src/library.js b/src/library.js index 1bdd840d..93d54d68 100644 --- a/src/library.js +++ b/src/library.js @@ -5886,6 +5886,26 @@ LibraryManager.library = { }, // ========================================================================== + // sys/timeb.h + // ========================================================================== + + __timeb_struct_layout: Runtime.generateStructInfo([ + ['i32', 'time'], + ['i16', 'millitm'], + ['i16', 'timezone'], + ['i16', 'dstflag'] + ]), + ftime__deps: ['__timeb_struct_layout'], + ftime: function(p) { + var millis = Date.now(); + {{{ makeSetValue('p', '___timeb_struct_layout.time', 'Math.floor(millis/1000)', 'i32') }}}; + {{{ makeSetValue('p', '___timeb_struct_layout.millitm', 'millis % 1000', 'i16') }}}; + {{{ makeSetValue('p', '___timeb_struct_layout.timezone', '0', 'i16') }}}; // TODO + {{{ makeSetValue('p', '___timeb_struct_layout.dstflag', '0', 'i16') }}}; // TODO + return 0; + }, + + // ========================================================================== // sys/times.h // ========================================================================== diff --git a/src/library_gl.js b/src/library_gl.js index b4098813..0f28a6a0 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -2099,6 +2099,11 @@ var LibraryGL = { }, glColor4f: function(r, g, b, a) { + r = Math.max(Math.min(r, 1), 0); + g = Math.max(Math.min(g, 1), 0); + b = Math.max(Math.min(b, 1), 0); + a = Math.max(Math.min(a, 1), 0); + // TODO: make ub the default, not f, save a few mathops if (GL.immediate.mode) { var start = GL.immediate.vertexCounter << 2; diff --git a/src/library_sdl.js b/src/library_sdl.js index 0969f738..1cd99534 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -898,7 +898,7 @@ var LibrarySDL = { }, SDL_GetError: function() { - return allocate(intArrayFromString("SDL is cool"), 'i8'); + return allocate(intArrayFromString("unknown SDL-emscripten error"), 'i8'); }, SDL_CreateRGBSurface: function(flags, width, height, depth, rmask, gmask, bmask, amask) { @@ -1533,6 +1533,12 @@ var LibrarySDL = { SDL_GL_SwapBuffers: function() {}, + // TODO + + SDL_SetGamma: function(r, g, b) { + return -1; + }, + // Misc SDL_InitSubSystem: function(flags) { return 0 }, diff --git a/src/parseTools.js b/src/parseTools.js index 4a76a9a2..b2093da3 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1328,7 +1328,27 @@ function makePointer(slab, pos, allocator, type, ptr) { types = de[0]; } } - return 'allocate(' + slab + ', ' + JSON.stringify(types) + (allocator ? ', ' + allocator : '') + (allocator == 'ALLOC_NONE' ? ', ' + ptr : '') + ')'; + // JS engines sometimes say array initializers are too large. Work around that by chunking and calling concat to combine at runtime + var chunkSize = 10240; + function chunkify(array) { + // break very large slabs into parts + var ret = ''; + var index = 0; + while (index < array.length) { + ret = (ret ? ret + '.concat(' : '') + '[' + array.slice(index, index + chunkSize).map(JSON.stringify) + ']' + (ret ? ')' : ''); + index += chunkSize; + } + return ret; + } + if (typeof slab == 'string' && evaled && evaled.length > chunkSize) { + slab = chunkify(evaled); + } + if (typeof types != 'string' && types.length > chunkSize) { + types = chunkify(types); + } else { + types = JSON.stringify(types); + } + return 'allocate(' + slab + ', ' + types + (allocator ? ', ' + allocator : '') + (allocator == 'ALLOC_NONE' ? ', ' + ptr : '') + ')'; } function makeGetSlabs(ptr, type, allowMultiple, unsigned) { diff --git a/src/settings.js b/src/settings.js index 1d8805a8..c4d1df48 100644 --- a/src/settings.js +++ b/src/settings.js @@ -132,6 +132,12 @@ var SAFE_HEAP_LOG = 0; // Log out all SAFE_HEAP operations var LABEL_DEBUG = 0; // 1: Print out functions as we enter them // 2: Also print out each label as we enter it +var LABEL_FUNCTION_FILTERS = []; // Filters for function label debug. + // The items for this array will be used + // as filters for function names. Only the + // labels of functions that is equaled to + // one of the filters are printed out + // When the array is empty, the filter is disabled. var EXCEPTION_DEBUG = 1; // Print out exceptions in emscriptened code var LIBRARY_DEBUG = 0; // Print out when we enter a library call (library*.js). You can also unset @@ -201,9 +207,10 @@ var NAMED_GLOBALS = 1; // If 1, we use global variables for globals. Otherwise var PROFILE = 0; // Enables runtime profiling. See test_profiling for a usage example. var EXPORT_ALL = 0; // If true, we export all the symbols -var EXPORTED_FUNCTIONS = ['_main', '_malloc', '_free']; // Functions that are explicitly exported, so they are guaranteed to - // be accessible outside of the generated code even after running closure compiler. - // Note the necessary prefix of "_". +var EXPORTED_FUNCTIONS = ['_main']; // Functions that are explicitly exported. These functions are kept alive + // through LLVM dead code elimination, and also made accessible outside of + // the generated code even after running closure compiler (on "Module"). + // Note the necessary prefix of "_". var DEFAULT_LIBRARY_FUNCS_TO_INCLUDE = ['memcpy', 'memset', 'malloc', 'free', '$Browser']; // JS library functions (C functions implemented in JS) // that we include by default. If you want to make sure diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 8ce95de7..55fda986 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -445,6 +44 |