diff options
92 files changed, 11124 insertions, 36 deletions
@@ -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/jsifier.js b/src/jsifier.js index 92b39b7d..8021f8a1 100644 --- a/src/jsifier.js +++ b/src/jsifier.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 3531db97..938a3c92 100644 --- a/src/library.js +++ b/src/library.js @@ -6315,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 + // ========================================================================== + + $Sockets__deps: ['__setErrNo', '$ERRNO_CODES'], + $Sockets: { + BUFFER_SIZE: 10*1024, + nextFd: 1, + fds: {}, + sockaddr_in_layout: Runtime.generateStructInfo([ + ['i16', 'sin_family'], + ['i16', 'sin_port'], + ['i32', 'sin_addr'], + ['i64', 'sin_zero'], + ]), + }, + + socket__deps: ['$Sockets'], + socket: function(family, type, protocol) { + var fd = Sockets.nextFd++; + Sockets.fds[fd] = { + connected: false + }; + return fd; + }, + + connect__deps: ['$Sockets', '_inet_ntop_raw', 'ntohs'], + connect: function(fd, addr, addrlen) { + var info = Sockets.fds[fd]; + if (!info) return -1; + info.connected = true; + info.addr = getValue(addr + Sockets.sockaddr_in_layout.sin_addr, 'i32'); + info.port = _ntohs(getValue(addr + Sockets.sockaddr_in_layout.sin_port, 'i16')); + info.host = __inet_ntop_raw(info.addr); + info.socket = new WebSocket('ws://' + info.host + ':' + info.port, ['arraybuffer']); + info.socket.binaryType = 'arraybuffer'; + info.buffer = new Uint8Array(Sockets.BUFFER_SIZE); + info.bufferWrite = info.bufferRead = 0; + info.socket.onmessage = function (event) { + var data = event.data; + if (typeof data == 'string') { + var binaryString = window.atob(data); + var len = binaryString.length; + for (var i = 0; i < len; i++) { + info.buffer[info.bufferWrite++] = binaryString.charCodeAt(i); + if (info.bufferWrite == Sockets.BUFFER_SIZE) info.bufferWrite = 0; + if (info.bufferWrite == info.bufferRead) throw 'socket buffer overflow'; + } + } else { + console.log('binary!'); |