diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-09-30 10:24:53 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-09-30 10:24:53 -0700 |
commit | b614f2bc5d9fc421565824b1ceb9a3384f26f35f (patch) | |
tree | 243c47baa4c6ce4273a5743d79f3c0dbc78789e5 | |
parent | c70758e3b49beb016a3d9db7b609c499d55de48b (diff) | |
parent | 7eaa78060c34489c7e56193c725641303d520f31 (diff) |
Merge branch 'incoming'
95 files changed, 11177 insertions, 63 deletions
@@ -26,7 +26,7 @@ a license to everyone to use it as detailed in LICENSE.) * Jon Bardin <diclophis@gmail.com> * Jukka Jylänki <jujjyl@gmail.com> * Aleksander Guryanov <caiiiycuk@gmail.com> -* Chad Austin <chad@chadaustin.me> +* Chad Austin <chad@chadaustin.me> (copyright owned by IMVU) * nandhp <nandhp@gmail.com> * YeZhongWen <linghuye2.0@gmail.com> * Xingxing Pan <forandom@gmail.com> @@ -37,3 +37,4 @@ a license to everyone to use it as detailed in LICENSE.) * Benjamin Stover <benjamin.stover@gmail.com> * Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> * Janus Troelsen <janus.troelsen@stud.tu-darmstadt.de> +* Lars Schneider <lars.schneider@autodesk.com> (copyright owned by Autodesk, Inc.)
\ No newline at end of file @@ -268,6 +268,27 @@ Options that are modified or new in %s include: will not minify the code (closure does that) + --split <size> Splits the resulting javascript file into pieces + to ease debugging. This option only works if + Javascript is generated (target -o <name>.js). + Files with function declarations must be loaded + before main file upon execution. + + Without "-g" option: + Creates files with function declarations up + to the given size with the suffix + "_functions.partxxx.js" and a main file with + the suffix ".js". + + With "-g" option: + Recreates the directory structure of the C + source files and stores function declarations + in their respective C files with the suffix + ".js". If such a file exceeds the given size, + files with the suffix ".partxxx.js" are created. + The main file resides in the base directory and + has the suffix ".js". + --ignore-dynamic-linking Normally emcc will treat dynamic linking like static linking, by linking in the code from the dynamic library. This fails if the same @@ -471,6 +492,7 @@ try: pre_js = '' post_js = '' minify_whitespace = None + split_js_file = None preload_files = [] embed_files = [] compression = None @@ -527,6 +549,11 @@ try: minify_whitespace = int(newargs[i+1]) newargs[i] = '' newargs[i+1] = '' + elif newargs[i].startswith('--split'): + check_bad_eq(newargs[i]) + split_js_file = int(newargs[i+1]) + newargs[i] = '' + newargs[i+1] = '' elif newargs[i].startswith('--embed-file'): check_bad_eq(newargs[i]) embed_files.append(newargs[i+1]) @@ -601,6 +628,9 @@ try: newargs[i+1] = '' newargs = [ arg for arg in newargs if arg is not '' ] + if split_js_file: + settings_changes.append("PRINT_SPLIT_FILE_MARKER=1") + # Find input files input_files = [] @@ -1071,8 +1101,12 @@ try: html.close() else: - # copy final JS to output - shutil.move(final, target) + if split_js_file: + from tools.split import split_javascript_file + split_javascript_file(final, unsuffixed(target), split_js_file) + else: + # copy final JS to output + shutil.move(final, target) finally: if not TEMP_DIR: diff --git a/src/compiler.js b/src/compiler.js index 89da32d5..2863afda 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -31,15 +31,30 @@ if (ENVIRONMENT_IS_NODE) { var nodeFS = require('fs'); var nodePath = require('path'); - read = function(filename) { - filename = nodePath['normalize'](filename); - var ret = nodeFS['readFileSync'](filename).toString(); - // The path is absolute if the normalized version is the same as the resolved. - if (!ret && filename != nodePath['resolve'](filename)) { - filename = path.join(__dirname, '..', 'src', filename); - ret = nodeFS['readFileSync'](filename).toString(); + if (!nodeFS.existsSync) { + nodeFS.existsSync = function(path) { + try { + return !!nodeFS.readFileSync(path); + } catch(e) { + return false; + } + } + } + + function find(filename) { + var prefixes = [__dirname, process.cwd()]; + for (var i = 0; i < prefixes.length; ++i) { + var combined = nodePath.join(prefixes[i], filename); + if (nodeFS.existsSync(combined)) { + return combined; + } } - return ret; + return filename; + } + + read = function(filename) { + var absolute = find(filename); + return nodeFS['readFileSync'](absolute).toString(); }; load = function(f) { diff --git a/src/jsifier.js b/src/jsifier.js index 01ecd7d3..8021f8a1 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -32,7 +32,7 @@ function JSify(data, functionsOnly, givenFunctions) { // else. This lets us not hold any strings in memory, we simply print // things out as they are ready. - var shellFile = BUILD_AS_SHARED_LIB ? 'shell_sharedlib.js' : 'shell.js'; + var shellFile = SHELL_FILE ? SHELL_FILE : (BUILD_AS_SHARED_LIB ? 'shell_sharedlib.js' : 'shell.js'); var shellParts = read(shellFile).split('{{BODY}}'); print(shellParts[0]); var preFile = BUILD_AS_SHARED_LIB ? 'preamble_sharedlib.js' : 'preamble.js'; @@ -522,6 +522,11 @@ function JSify(data, functionsOnly, givenFunctions) { func.JS += ' */\n'; } + if (PRINT_SPLIT_FILE_MARKER) { + func.JS += '\n//FUNCTION_BEGIN_MARKER\n' + var associatedSourceFile = "NO_SOURCE"; + } + func.JS += 'function ' + func.ident + '(' + paramIdents.join(', ') + ') {\n'; if (PROFILE) { @@ -572,6 +577,13 @@ function JSify(data, functionsOnly, givenFunctions) { if (EXECUTION_TIMEOUT > 0) { ret += indent + 'if (Date.now() - START_TIME >= ' + (EXECUTION_TIMEOUT*1000) + ') throw "Timed out!" + (new Error().stack);\n'; } + + if (PRINT_SPLIT_FILE_MARKER && Debugging.on && Debugging.getAssociatedSourceFile(line.lineNum)) { + // Overwrite the associated source file for every line. The last line should contain the source file associated to + // the return value/address of outer most block (the marked function). + associatedSourceFile = Debugging.getAssociatedSourceFile(line.lineNum); + } + // for special labels we care about (for phi), mark that we visited them return ret + label.lines.map(function(line) { return line.JS + (Debugging.on ? Debugging.getComment(line.lineNum) : '') }) .join('\n') @@ -653,6 +665,11 @@ function JSify(data, functionsOnly, givenFunctions) { func.JS += ' return' + (func.returnType !== 'void' ? ' null' : '') + ';\n'; } func.JS += '}\n'; + + if (PRINT_SPLIT_FILE_MARKER) { + func.JS += '\n//FUNCTION_END_MARKER_OF_SOURCE_FILE_' + associatedSourceFile + '\n'; + } + if (func.ident in EXPORTED_FUNCTIONS) { func.JS += 'Module["' + func.ident + '"] = ' + func.ident + ';'; } diff --git a/src/library.js b/src/library.js index 1c150bc9..938a3c92 100644 --- a/src/library.js +++ b/src/library.js @@ -4850,6 +4850,7 @@ LibraryManager.library = { // RTTI hacks for exception handling, defining type_infos for common types. // The values are dummies. We simply use the addresses of these statically // allocated variables as unique identifiers. + _ZTIb: [0], // bool _ZTIi: [0], // int _ZTIj: [0], // unsigned int _ZTIl: [0], // long @@ -4863,7 +4864,7 @@ LibraryManager.library = { _ZTIa: [0], // signed char _ZTIh: [0], // unsigned char _ZTIs: [0], // short - _ZTIt: [0], // signed short + _ZTIt: [0], // unsigned short _ZTIv: [0], // void _ZTIPv: [0], // void* @@ -6314,6 +6315,122 @@ LibraryManager.library = { ntohl: 'htonl', ntohs: 'htons', + inet_pton__deps: ['__setErrNo', '$ERRNO_CODES'], + inet_pton: function(af, src, dst) { + // int af, const char *src, void *dst + if ((af ^ {{{ cDefine("AF_INET") }}}) !== 0) { ___setErrNo(ERRNO_CODES.EAFNOSUPPORT); return -1; } + var b = Pointer_stringify(src).split("."); + if (b.length !== 4) return 0; + var ret = Number(b[0]) | (Number(b[1]) << 8) | (Number(b[2]) << 16) | (Number(b[3]) << 24); + if (isNaN(ret)) return 0; + setValue(dst, ret, 'i32'); + return 1; + }, + + _inet_ntop_raw: function(addr) { + return (addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff) + }, + + inet_ntop__deps: ['_inet_ntop_raw'], + inet_ntop: function(af, src, dst, size) { + var addr = getValue(src, 'i32'); + var str = __inet_ntop_raw(addr); + writeStringToMemory(str.substr(0, size), dst, true); + return dst; + }, + + // ========================================================================== + // sockets + // ================================================ |