diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/analyzer.js | 16 | ||||
-rw-r--r-- | src/intertyper.js | 11 | ||||
-rw-r--r-- | src/library.js | 12 | ||||
-rw-r--r-- | src/library_browser.js | 1 | ||||
-rw-r--r-- | src/library_fs.js | 22 | ||||
-rw-r--r-- | src/library_gl.js | 46 | ||||
-rw-r--r-- | src/library_memfs.js | 66 | ||||
-rw-r--r-- | src/library_sdl.js | 7 | ||||
-rw-r--r-- | src/postamble.js | 1 | ||||
-rw-r--r-- | src/settings.js | 5 | ||||
-rw-r--r-- | src/shell.js | 7 |
11 files changed, 140 insertions, 54 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 931ce421..2a7d64f5 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -953,9 +953,23 @@ function analyzer(data, sidePass) { if (type[0] == '{' || type[0] == '<') { type = nonPointing; var packed = type[0] == '<'; + var internal = type; + if (packed) { + if (internal[internal.length-1] != '>') { + warnOnce('ignoring type ' + internal); + return; // function pointer or such + } + internal = internal.substr(1, internal.length-2); + } + assert(internal[0] == '{', internal); + if (internal[internal.length-1] != '}') { + warnOnce('ignoring type ' + internal); + return; // function pointer or such + } + internal = internal.substr(2, internal.length-4); Types.types[type] = { name_: type, - fields: splitTokenList(tokenize(type.substr(2 + packed, type.length - 4 - 2*packed)).tokens).map(function(segment) { + fields: splitTokenList(tokenize(internal).tokens).map(function(segment) { return segment[0].text; }), packed: packed, diff --git a/src/intertyper.js b/src/intertyper.js index 3fc840c4..31e97bd0 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -365,8 +365,17 @@ function intertyper(data, sidePass, baseLineNums) { } if (tokensLength >= 3 && (token0Text == 'call' || token1Text == 'call')) return 'Call'; - if (token0Text == 'target') + if (token0Text == 'target') { + if (token1Text == 'triple') { + var triple = item.tokens[3].text; + triple = triple.substr(1, triple.length-2); + var expected = TARGET_LE32 ? 'le32-unknown-nacl' : 'i386-pc-linux-gnu'; + if (triple !== expected) { + warn('using an unexpected LLVM triple: ' + [triple, ' !== ', expected] + ' (are you using emcc for everything and not clang?)'); + } + } return '/dev/null'; + } if (token0Text == ';') return '/dev/null'; if (tokensLength >= 3 && token0Text == 'invoke') diff --git a/src/library.js b/src/library.js index 815badc1..9e78db13 100644 --- a/src/library.js +++ b/src/library.js @@ -100,7 +100,7 @@ LibraryManager.library = { } var entries; try { - entries = FS.readdir(stream); + entries = FS.readdir(stream.path); } catch (e) { return FS.handleFSError(e); } @@ -478,8 +478,6 @@ LibraryManager.library = { open: function(path, oflag, varargs) { // int open(const char *path, int oflag, ...); // http://pubs.opengroup.org/onlinepubs/009695399/functions/open.html - // NOTE: This implementation tries to mimic glibc rather than strictly - // following the POSIX standard. var mode = {{{ makeGetValue('varargs', 0, 'i32') }}}; path = Pointer_stringify(path); try { @@ -7237,7 +7235,7 @@ LibraryManager.library = { socket__deps: ['$FS', '$Sockets'], socket: function(family, type, protocol) { var INCOMING_QUEUE_LENGTH = 64; - var stream = FS.createStream({ + var info = FS.createStream({ addr: null, port: null, inQueue: new CircularBuffer(INCOMING_QUEUE_LENGTH), @@ -7246,7 +7244,7 @@ LibraryManager.library = { socket: true, stream_ops: {} }); - assert(stream.fd < 64); // select() assumes socket fd values are in 0..63 + assert(info.fd < 64); // select() assumes socket fd values are in 0..63 var stream = type == {{{ cDefine('SOCK_STREAM') }}}; if (protocol) { assert(stream == (protocol == {{{ cDefine('IPPROTO_TCP') }}})); // if stream, must be tcp @@ -7359,8 +7357,7 @@ LibraryManager.library = { } }; }; - - return stream.fd; + return info.fd; }, mkport__deps: ['$Sockets'], @@ -7454,6 +7451,7 @@ LibraryManager.library = { buffer.set(data, info.header.byteLength); connection.send('unreliable', buffer.buffer); + return ret; }, recvmsg__deps: ['$FS', '$Sockets', 'bind', '__setErrNo', '$ERRNO_CODES', 'htons'], diff --git a/src/library_browser.js b/src/library_browser.js index f65791e4..511e158e 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -6,6 +6,7 @@ mergeInto(LibraryManager.library, { $Browser__deps: ['$PATH'], $Browser__postset: 'Module["requestFullScreen"] = function(lockPointer, resizeCanvas) { Browser.requestFullScreen(lockPointer, resizeCanvas) };\n' + // exports 'Module["requestAnimationFrame"] = function(func) { Browser.requestAnimationFrame(func) };\n' + + 'Module["setCanvasSize"] = function(width, height, noUpdates) { Browser.setCanvasSize(width, height, noUpdates) };\n' + 'Module["pauseMainLoop"] = function() { Browser.mainLoop.pause() };\n' + 'Module["resumeMainLoop"] = function() { Browser.mainLoop.resume() };\n' + 'Module["getUserMedia"] = function() { Browser.getUserMedia() }', diff --git a/src/library_fs.js b/src/library_fs.js index f18e4809..51341a3e 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -56,7 +56,7 @@ mergeInto(LibraryManager.library, { for (var i = 0; i < name.length; i++) { hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0; } - return (parentid + hash) % FS.name_table.length; + return ((parentid + hash) >>> 0) % FS.name_table.length; }, hashAddNode: function(node) { var hash = FS.hashName(node.parent.id, node.name); @@ -735,6 +735,9 @@ mergeInto(LibraryManager.library, { }); // use a custom read function stream_ops.read = function(stream, buffer, offset, length, position) { + if (!FS.forceLoadFile(node)) { + throw new FS.ErrnoError(ERRNO_CODES.EIO); + } var contents = stream.node.contents; var size = Math.min(contents.length - position, length); if (contents.slice) { // normal array @@ -1040,7 +1043,7 @@ mergeInto(LibraryManager.library, { FS.hashRemoveNode(old_node); // do the underlying fs rename try { - old_node.node_ops.rename(old_node, new_dir, new_name); + old_dir.node_ops.rename(old_node, new_dir, new_name); } catch (e) { throw e; } finally { @@ -1067,6 +1070,14 @@ mergeInto(LibraryManager.library, { parent.node_ops.rmdir(parent, name); FS.destroyNode(node); }, + readdir: function(path) { + var lookup = FS.lookupPath(path, { follow: true }); + var node = lookup.node; + if (!node.node_ops.readdir) { + throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR); + } + return node.node_ops.readdir(node); + }, unlink: function(path) { var lookup = FS.lookupPath(path, { parent: true }); var parent = lookup.node; @@ -1207,6 +1218,7 @@ mergeInto(LibraryManager.library, { open: function(path, flags, mode, fd_start, fd_end) { path = PATH.normalize(path); flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags; + mode = typeof mode === 'undefined' ? 0666 : mode; if ((flags & {{{ cDefine('O_CREAT') }}})) { mode = (mode & {{{ cDefine('S_IALLUGO') }}}) | {{{ cDefine('S_IFREG') }}}; } else { @@ -1285,12 +1297,6 @@ mergeInto(LibraryManager.library, { } return stream.stream_ops.llseek(stream, offset, whence); }, - readdir: function(stream) { - if (!stream.stream_ops.readdir) { - throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR); - } - return stream.stream_ops.readdir(stream); - }, read: function(stream, buffer, offset, length, position) { if (length < 0 || position < 0) { throw new FS.ErrnoError(ERRNO_CODES.EINVAL); diff --git a/src/library_gl.js b/src/library_gl.js index 8c724245..89a13bbe 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -1285,7 +1285,7 @@ var LibraryGL = { return Module.ctx.isFramebuffer(fb); }, -#if DISABLE_GL_EMULATION == 0 +#if LEGACY_GL_EMULATION // GL emulation: provides misc. functionality not present in OpenGL ES 2.0 or WebGL @@ -1323,7 +1323,7 @@ var LibraryGL = { GLEmulation.fogColor = new Float32Array(4); // Add some emulation workarounds - Module.printErr('WARNING: using emscripten GL emulation. This is a collection of limited workarounds, do not expect it to work. (If you do not want this, build with -s DISABLE_GL_EMULATION=1)'); + Module.printErr('WARNING: using emscripten GL emulation. This is a collection of limited workarounds, do not expect it to work.'); #if GL_UNSAFE_OPTS == 0 Module.printErr('WARNING: using emscripten GL emulation unsafe opts. If weirdness happens, try -s GL_UNSAFE_OPTS=0'); #endif @@ -1618,17 +1618,15 @@ var LibraryGL = { var glCompileShader = _glCompileShader; _glCompileShader = function(shader) { Module.ctx.compileShader(GL.shaders[shader]); +#if GL_DEBUG if (!Module.ctx.getShaderParameter(GL.shaders[shader], Module.ctx.COMPILE_STATUS)) { Module.printErr('Failed to compile shader: ' + Module.ctx.getShaderInfoLog(GL.shaders[shader])); Module.printErr('Info: ' + JSON.stringify(GL.shaderInfos[shader])); -#if GL_DEBUG Module.printErr('Original source: ' + GL.shaderOriginalSources[shader]); Module.printErr('Source: ' + GL.shaderSources[shader]); throw 'Shader compilation halt'; -#else - Module.printErr('Enable GL_DEBUG to see shader source'); -#endif } +#endif }; GL.programShaders = {}; @@ -4202,7 +4200,31 @@ var LibraryGL = { glBindVertexArrayOES: 'glBindVertexArray', glFramebufferTexture2DOES: 'glFramebufferTexture2D', -#endif // DISABLE_GL_EMULATION == 0 +#else // LEGACY_GL_EMULATION + + // Warn if code tries to use various emulation stuff, when emulation is disabled + glVertexPointer__deps: [function() { + error('Legacy GL function (glVertexPointer) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'); + }], + glVertexPointer: function(){}, + glGenVertexArrays__deps: [function() { + error('Legacy GL function (glGenVertexArrays) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'); + }], + glGenVertexArrays: function(){}, + glMatrixMode__deps: [function() { + error('Legacy GL function (glMatrixMode) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'); + }], + glMatrixMode: function(){}, + glBegin__deps: [function() { + error('Legacy GL function (glBegin) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'); + }], + glBegin: function(){}, + glLoadIdentity__deps: [function() { + error('Legacy GL function (glLoadIdentity) called. You need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'); + }], + glLoadIdentity: function(){}, + +#endif // LEGACY_GL_EMULATION // GLU @@ -4438,7 +4460,7 @@ var LibraryGL = { autoAddDeps(LibraryGL, '$GL'); -if (!DISABLE_GL_EMULATION) { +if (LEGACY_GL_EMULATION) { // Emulation requires everything else, potentially LibraryGL.$GLEmulation__deps = LibraryGL.$GLEmulation__deps.slice(0); // the __deps object is shared var glFuncs = []; @@ -4455,11 +4477,11 @@ if (!DISABLE_GL_EMULATION) { } }); - if (FORCE_GL_EMULATION) { - LibraryGL.glDrawElements__deps = LibraryGL.glDrawElements__deps.concat('$GLEmulation'); - LibraryGL.glDrawArrays__deps = LibraryGL.glDrawArrays__deps.concat('$GLEmulation'); - } + LibraryGL.glDrawElements__deps = LibraryGL.glDrawElements__deps.concat('$GLEmulation'); + LibraryGL.glDrawArrays__deps = LibraryGL.glDrawArrays__deps.concat('$GLEmulation'); } mergeInto(LibraryManager.library, LibraryGL); +assert(!(FULL_ES2 && LEGACY_GL_EMULATION), 'cannot emulate both ES2 and legacy GL'); + diff --git a/src/library_memfs.js b/src/library_memfs.js index a044e0c6..0fa6cdfb 100644 --- a/src/library_memfs.js +++ b/src/library_memfs.js @@ -10,16 +10,48 @@ mergeInto(LibraryManager.library, { throw new FS.ErrnoError(ERRNO_CODES.EPERM); } var node = FS.createNode(parent, name, mode, dev); - node.node_ops = MEMFS.node_ops; if (FS.isDir(node.mode)) { - node.stream_ops = MEMFS.stream_ops; + node.node_ops = { + getattr: MEMFS.node_ops.getattr, + setattr: MEMFS.node_ops.setattr, + lookup: MEMFS.node_ops.lookup, + mknod: MEMFS.node_ops.mknod, + mknod: MEMFS.node_ops.mknod, + rename: MEMFS.node_ops.rename, + unlink: MEMFS.node_ops.unlink, + rmdir: MEMFS.node_ops.rmdir, + readdir: MEMFS.node_ops.readdir, + symlink: MEMFS.node_ops.symlink + }; + node.stream_ops = { + llseek: MEMFS.stream_ops.llseek + }; node.contents = {}; } else if (FS.isFile(node.mode)) { - node.stream_ops = MEMFS.stream_ops; + node.node_ops = { + getattr: MEMFS.node_ops.getattr, + setattr: MEMFS.node_ops.setattr + }; + node.stream_ops = { + llseek: MEMFS.stream_ops.llseek, + read: MEMFS.stream_ops.read, + write: MEMFS.stream_ops.write, + allocate: MEMFS.stream_ops.allocate, + mmap: MEMFS.stream_ops.mmap + }; node.contents = []; } else if (FS.isLink(node.mode)) { - node.stream_ops = MEMFS.stream_ops; + node.node_ops = { + getattr: MEMFS.node_ops.getattr, + setattr: MEMFS.node_ops.setattr, + readlink: MEMFS.node_ops.readlink + }; + node.stream_ops = {}; } else if (FS.isChrdev(node.mode)) { + node.node_ops = { + getattr: MEMFS.node_ops.getattr, + setattr: MEMFS.node_ops.setattr + }; node.stream_ops = FS.chrdev_stream_ops; } node.timestamp = Date.now(); @@ -106,6 +138,16 @@ mergeInto(LibraryManager.library, { } delete parent.contents[name]; }, + readdir: function(node) { + var entries = ['.', '..'] + for (var key in node.contents) { + if (!node.contents.hasOwnProperty(key)) { + continue; + } + entries.push(key); + } + return entries; + }, symlink: function(parent, newname, oldpath) { var node = MEMFS.create_node(parent, newname, 0777 | {{{ cDefine('S_IFLNK') }}}, 0); node.link = oldpath; @@ -119,19 +161,6 @@ mergeInto(LibraryManager.library, { }, }, stream_ops: { - open: function(stream) { - if (FS.isDir(stream.node.mode)) { - // cache off the directory entries when open'd - var entries = ['.', '..'] - for (var key in stream.node.contents) { - if (!stream.node.contents.hasOwnProperty(key)) { - continue; - } - entries.push(key); - } - stream.entries = entries; - } - }, read: function(stream, buffer, offset, length, position) { var contents = stream.node.contents; var size = Math.min(contents.length - position, length); @@ -172,9 +201,6 @@ mergeInto(LibraryManager.library, { stream.position = position; return position; }, - readdir: function(stream) { - return stream.entries; - }, allocate: function(stream, offset, length) { var contents = stream.node.contents; var limit = offset + length; diff --git a/src/library_sdl.js b/src/library_sdl.js index 92cfc7e5..6cc337e8 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -258,7 +258,7 @@ var LibrarySDL = { makeSurface: function(width, height, flags, usePageCanvas, source, rmask, gmask, bmask, amask) { flags = flags || 0; - var surf = _malloc(14*Runtime.QUANTUM_SIZE); // SDL_Surface has 14 fields of quantum size + var surf = _malloc(15*Runtime.QUANTUM_SIZE); // SDL_Surface has 15 fields of quantum size var buffer = _malloc(width*height*4); // TODO: only allocate when locked the first time var pixelFormat = _malloc(18*Runtime.QUANTUM_SIZE); flags |= 1; // SDL_HWSURFACE - this tells SDL_MUSTLOCK that this needs to be locked @@ -755,6 +755,11 @@ var LibrarySDL = { return depth; // all modes are ok. }, + SDL_AudioDriverName__deps: ['SDL_VideoDriverName'], + SDL_AudioDriverName: function(buf, max_size) { + return _SDL_VideoDriverName(buf, max_size); + }, + SDL_VideoDriverName: function(buf, max_size) { if (SDL.startTime === null) { return 0; //return NULL diff --git a/src/postamble.js b/src/postamble.js index c4ca3aae..08c3a9d8 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -127,6 +127,7 @@ Module['exit'] = Module.exit = exit; function abort(text) { if (text) { Module.print(text); + Module.printErr(text); } ABORT = true; diff --git a/src/settings.js b/src/settings.js index 3ecac040..8757f7b9 100644 --- a/src/settings.js +++ b/src/settings.js @@ -191,9 +191,8 @@ var GL_TESTING = 0; // When enabled, sets preserveDrawingBuffer in the context, var GL_MAX_TEMP_BUFFER_SIZE = 2097152; // How large GL emulation temp buffers are var GL_UNSAFE_OPTS = 1; // Enables some potentially-unsafe optimizations in GL emulation code var FULL_ES2 = 0; // Forces support for all GLES2 features, not just the WebGL-friendly subset. -var FORCE_GL_EMULATION = 0; // Forces inclusion of full GL emulation code. -var DISABLE_GL_EMULATION = 0; // Disable inclusion of full GL emulation code. Useful when you don't want emulation - // but do need INCLUDE_FULL_LIBRARY or MAIN_MODULE. +var LEGACY_GL_EMULATION = 0; // Includes code to emulate various desktop GL features. Incomplete but useful + // in some cases, see https://github.com/kripken/emscripten/wiki/OpenGL-support var STB_IMAGE = 0; // Enables building of stb-image, a tiny public-domain library for decoding images, allowing // decoding of images without using the browser's built-in decoders. The benefit is that this diff --git a/src/shell.js b/src/shell.js index bac4eaa3..f91aa96a 100644 --- a/src/shell.js +++ b/src/shell.js @@ -74,7 +74,12 @@ else if (ENVIRONMENT_IS_SHELL) { Module['print'] = print; if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm - Module['read'] = read; + if (typeof read != 'undefined') { + Module['read'] = read; + } else { + Module['read'] = function() { throw 'no read() available (jsc?)' }; + } + Module['readBinary'] = function(f) { return read(f, 'binary'); }; |