aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js25
-rw-r--r--src/jsifier.js21
-rw-r--r--src/library.js23
-rw-r--r--src/library_gl.js29
-rw-r--r--src/library_openal.js2
-rw-r--r--src/parseTools.js3
-rw-r--r--src/relooper/Relooper.cpp3
-rw-r--r--src/settings.js14
8 files changed, 71 insertions, 49 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index b1991c3f..6ed55414 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -9,7 +9,6 @@ var VAR_NATIVIZED = 'nativized';
var VAR_EMULATED = 'emulated';
var ENTRY_IDENT = toNiceIdent('%0');
-var ENTRY_IDENT_IDS = set(0, 1); // XXX
function recomputeLines(func) {
func.lines = func.labels.map(function(label) { return label.lines }).reduce(concatenator, []);
@@ -1326,14 +1325,14 @@ function analyzer(data, sidePass) {
func.labelsDict = {};
func.labelIds = {};
func.labelIdsInverse = {};
- func.labelIds[toNiceIdent('%0')] = 0;
+ func.labelIds[toNiceIdent('%0')] = 1;
func.labelIdsInverse[0] = toNiceIdent('%0');
- func.labelIds[toNiceIdent('%1')] = 1;
- func.labelIdsInverse[1] = toNiceIdent('%1');
func.labelIdCounter = 2;
func.labels.forEach(function(label) {
- func.labelIds[label.ident] = func.labelIdCounter++;
- func.labelIdsInverse[func.labelIdCounter-1] = label.ident;
+ if (!(label.ident in func.labelIds)) {
+ func.labelIds[label.ident] = func.labelIdCounter++;
+ func.labelIdsInverse[func.labelIdCounter-1] = label.ident;
+ }
});
// Minify label ids to numeric ids.
@@ -1368,16 +1367,12 @@ function analyzer(data, sidePass) {
}
});
- // The entry might not have an explicit label, and there is no consistent naming convention for it - it can be %0 or %1
- // So we need to handle that in a special way here.
function getActualLabelId(labelId) {
if (func.labelsDict[labelId]) return labelId;
- if (labelId in ENTRY_IDENT_IDS) {
- labelId = func.labelIds[ENTRY_IDENT];
- assert(func.labelsDict[labelId]);
- return labelId;
- }
- return null;
+ // If not present, it must be a surprisingly-named entry (or undefined behavior, in which case, still ok to use the entry)
+ labelId = func.labelIds[ENTRY_IDENT];
+ assert(func.labelsDict[labelId]);
+ return labelId;
}
// Basic longjmp support, see library.js setjmp/longjmp
@@ -1573,7 +1568,7 @@ function analyzer(data, sidePass) {
}
item.functions.forEach(function(func) {
dprint('relooping', "// relooping function: " + func.ident);
- func.block = makeBlock(func.labels, [toNiceIdent(func.labels[0].ident)], func.labelsDict, func.forceEmulated);
+ func.block = makeBlock(func.labels, [func.labels[0].ident], func.labelsDict, func.forceEmulated);
});
return finish();
diff --git a/src/jsifier.js b/src/jsifier.js
index c55072b4..69d9842a 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -441,7 +441,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
// In asm, we need to know about library functions. If there is a target, though, then no
// need to consider this a library function - we will call directly to it anyhow
- if (ASM_JS && !redirectedIdent && (typeof target == 'function' || /Math\..+/.exec(snippet))) {
+ if (ASM_JS && !redirectedIdent && (typeof target == 'function' || /Math\.\w+/.exec(snippet))) {
Functions.libraryFunctions[ident] = 1;
}
} else if (typeof snippet === 'object') {
@@ -1322,9 +1322,10 @@ function JSify(data, functionsOnly, givenFunctions) {
ident = Variables.resolveAliasToIdent(ident);
var shortident = ident.slice(1);
- var callIdent = LibraryManager.getRootIdent(shortident);
+ var simpleIdent = shortident;
+ var callIdent = LibraryManager.getRootIdent(simpleIdent);
if (callIdent) {
- shortident = callIdent; // ident may not be in library, if all there is is ident__inline, but in this case it is
+ simpleIdent = callIdent; // ident may not be in library, if all there is is ident__inline, but in this case it is
if (callIdent.indexOf('.') < 0) {
callIdent = '_' + callIdent; // Not Math.*, so add the normal prefix
}
@@ -1339,7 +1340,7 @@ function JSify(data, functionsOnly, givenFunctions) {
var varargsTypes = [];
var varargsByVals = {};
var ignoreFunctionIndexizing = [];
- var useJSArgs = (shortident + '__jsargs') in LibraryManager.library;
+ var useJSArgs = (simpleIdent + '__jsargs') in LibraryManager.library;
var hasVarArgs = isVarArgsFunctionType(type);
var normalArgs = (hasVarArgs && !useJSArgs) ? countNormalArgs(type) : -1;
var byPointer = getVarData(funcData, ident);
@@ -1367,7 +1368,7 @@ function JSify(data, functionsOnly, givenFunctions) {
args = args.map(function(arg, i) { return indexizeFunctions(arg, argsTypes[i]) });
if (ASM_JS) {
- if (shortident in Functions.libraryFunctions) {
+ if (shortident in Functions.libraryFunctions || simpleIdent in Functions.libraryFunctions) {
args = args.map(function(arg, i) { return asmCoercion(arg, argsTypes[i]) });
} else {
args = args.map(function(arg, i) { return asmEnsureFloat(arg, argsTypes[i]) });
@@ -1411,8 +1412,8 @@ function JSify(data, functionsOnly, givenFunctions) {
var argsText = args.join(', ');
// Inline if either we inline whenever we can (and we can), or if there is no noninlined version
- var inline = LibraryManager.library[shortident + '__inline'];
- var nonInlined = shortident in LibraryManager.library;
+ var inline = LibraryManager.library[simpleIdent + '__inline'];
+ var nonInlined = simpleIdent in LibraryManager.library;
if (inline && (INLINE_LIBRARY_FUNCS || !nonInlined)) {
return inline.apply(null, args); // Warning: inlining does not prevent recalculation of the arguments. They should be simple identifiers
}
@@ -1420,7 +1421,7 @@ function JSify(data, functionsOnly, givenFunctions) {
if (ASM_JS) {
// remove unneeded arguments, which the asm sig can show us. this lets us alias memset with llvm.memset, we just
// drop the final 2 args so things validate properly in asm
- var libsig = LibraryManager.library[shortident + '__sig'];
+ var libsig = LibraryManager.library[simpleIdent + '__sig'];
if (libsig) {
assert(!hasVarArgs);
while (libsig.length - 1 < args.length) {
@@ -1454,9 +1455,9 @@ function JSify(data, functionsOnly, givenFunctions) {
}
var ret = callIdent + '(' + args.join(', ') + ')';
- if (ASM_JS) { // TODO: do only when needed (library functions and Math.*?) XXX && shortident in Functions.libraryFunctions) {
+ if (ASM_JS) { // TODO: do only when needed (library functions and Math.*?) XXX && simpleIdent in Functions.libraryFunctions) {
ret = asmCoercion(ret, returnType);
- if (shortident == 'abort' && funcData.returnType != 'void') {
+ if (simpleIdent == 'abort' && funcData.returnType != 'void') {
ret += '; return 0'; // special case: abort() can happen without return, breaking the return type of asm functions. ensure a return
}
}
diff --git a/src/library.js b/src/library.js
index f8ea67ba..b63ac955 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5082,6 +5082,10 @@ LibraryManager.library = {
_ZSt18uncaught_exceptionv: function() { // std::uncaught_exception()
return !!__ZSt18uncaught_exceptionv.uncaught_exception;
},
+ __cxa_uncaught_exception__deps: ['_Zst18uncaught_exceptionv'],
+ __cxa_uncaught_exception: function() {
+ return !!__ZSt18uncaught_exceptionv.uncaught_exception;
+ },
__cxa_call_unexpected: function(exception) {
Module.printErr('Unexpected exception thrown, this is not properly supported - aborting');
@@ -7293,11 +7297,17 @@ LibraryManager.library = {
// exceptfds not supported
// timeout is always 0 - fully async
assert(!exceptfds);
+
+ var errorCondition = 0;
function canRead(info) {
// make sure hasData exists.
// we do create it when the socket is connected,
// but other implementations may create it lazily
+ if ((info.socket.readyState == WebSocket.CLOSING || info.socket.readyState == WebSocket.CLOSED) && info.inQueue.length == 0) {
+ errorCondition = -1;
+ return false;
+ }
return info.hasData && info.hasData();
}
@@ -7305,6 +7315,10 @@ LibraryManager.library = {
// make sure socket exists.
// we do create it when the socket is connected,
// but other implementations may create it lazily
+ if ((info.socket.readyState == WebSocket.CLOSING || info.socket.readyState == WebSocket.CLOSED)) {
+ errorCondition = -1;
+ return false;
+ }
return info.socket && (info.socket.readyState == info.socket.OPEN);
}
@@ -7336,8 +7350,13 @@ LibraryManager.library = {
return bitsSet;
}
- return checkfds(nfds, readfds, canRead)
- + checkfds(nfds, writefds, canWrite);
+ var totalHandles = checkfds(nfds, readfds, canRead) + checkfds(nfds, writefds, canWrite);
+ if (errorCondition) {
+ ___setErrNo(ERRNO_CODES.EBADF);
+ return -1;
+ } else {
+ return totalHandles;
+ }
},
// pty.h
diff --git a/src/library_gl.js b/src/library_gl.js
index 297a36cf..0912b5da 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1222,6 +1222,9 @@ var LibraryGL = {
// 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 GL_UNSAFE_OPTS == 0
+ Module.printErr('WARNING: using emscripten GL emulation unsafe opts. If weirdness happens, try -s GL_UNSAFE_OPTS=0');
+#endif
// XXX some of the capabilities we don't support may lead to incorrect rendering, if we do not emulate them in shaders
var validCapabilities = {
@@ -1798,6 +1801,7 @@ var LibraryGL = {
lastRenderer: null, // used to avoid cleaning up and re-preparing the same renderer
lastArrayBuffer: null, // used in conjunction with lastRenderer
lastProgram: null, // ""
+ lastStride: -1, // ""
// The following data structures are used for OpenGL Immediate Mode matrix routines.
matrix: {},
@@ -1874,8 +1878,6 @@ var LibraryGL = {
var typeIndex = attribute.type - GL.byteSizeByTypeRoot; // ensure it starts at 0 to keep the cache items dense
temp = cacheItem[typeIndex];
cacheItem = temp ? temp : (cacheItem[typeIndex] = GL.immediate.rendererCacheItemTemplate.slice());
- temp = cacheItem[attribute.stride];
- cacheItem = temp ? temp : (cacheItem[attribute.stride] = GL.immediate.rendererCacheItemTemplate.slice());
}
var fogParam;
if (GLEmulation.fogEnabled) {
@@ -1910,30 +1912,25 @@ var LibraryGL = {
createRenderer: function(renderer) {
var useCurrProgram = !!GL.currProgram;
- var hasTextures = false, textureSizes = [], textureTypes = [], textureOffsets = [];
+ var hasTextures = false, textureSizes = [], textureTypes = [];
for (var i = 0; i < GL.immediate.NUM_TEXTURES; i++) {
if (GL.immediate.enabledClientAttributes[GL.immediate.TEXTURE0 + i]) {
textureSizes[i] = GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].size;
textureTypes[i] = GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].type;
- textureOffsets[i] = GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].offset;
hasTextures = true;
}
}
- var stride = GL.immediate.stride;
var positionSize = GL.immediate.clientAttributes[GL.immediate.VERTEX].size;
var positionType = GL.immediate.clientAttributes[GL.immediate.VERTEX].type;
- var positionOffset = GL.immediate.clientAttributes[GL.immediate.VERTEX].offset;
- var colorSize = 0, colorType, colorOffset;
+ var colorSize = 0, colorType;
if (GL.immediate.enabledClientAttributes[GL.immediate.COLOR]) {
colorSize = GL.immediate.clientAttributes[GL.immediate.COLOR].size;
colorType = GL.immediate.clientAttributes[GL.immediate.COLOR].type;
- colorOffset = GL.immediate.clientAttributes[GL.immediate.COLOR].offset;
}
- var normalSize = 0, normalType, normalOffset;
+ var normalSize = 0, normalType;
if (GL.immediate.enabledClientAttributes[GL.immediate.NORMAL]) {
normalSize = GL.immediate.clientAttributes[GL.immediate.NORMAL].size;
normalType = GL.immediate.clientAttributes[GL.immediate.NORMAL].type;
- normalOffset = GL.immediate.clientAttributes[GL.immediate.NORMAL].offset;
}
var ret = {
init: function() {
@@ -2075,6 +2072,7 @@ var LibraryGL = {
var canSkip = this == lastRenderer &&
arrayBuffer == GL.immediate.lastArrayBuffer &&
(GL.currProgram || this.program) == GL.immediate.lastProgram &&
+ GL.immediate.stride == GL.immediate.lastStride &&
!GL.immediate.matricesModified;
if (!canSkip && lastRenderer) lastRenderer.cleanup();
#endif
@@ -2095,6 +2093,7 @@ var LibraryGL = {
GL.immediate.lastRenderer = this;
GL.immediate.lastArrayBuffer = arrayBuffer;
GL.immediate.lastProgram = GL.currProgram || this.program;
+ GL.immediate.lastStride == GL.immediate.stride;
GL.immediate.matricesModified = false;
#endif
@@ -2106,13 +2105,13 @@ var LibraryGL = {
if (this.projectionLocation) Module.ctx.uniformMatrix4fv(this.projectionLocation, false, GL.immediate.matrix['p']);
Module.ctx.vertexAttribPointer(this.positionLocation, positionSize, positionType, false,
- stride, positionOffset);
+ GL.immediate.stride, GL.immediate.clientAttributes[GL.immediate.VERTEX].offset);
Module.ctx.enableVertexAttribArray(this.positionLocation);
if (this.hasTextures) {
for (var i = 0; i < textureSizes.length; i++) {
if (textureSizes[i] && this.texCoordLocations[i] >= 0) {
Module.ctx.vertexAttribPointer(this.texCoordLocations[i], textureSizes[i], textureTypes[i], false,
- stride, textureOffsets[i]);
+ GL.immediate.stride, GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].offset);
Module.ctx.enableVertexAttribArray(this.texCoordLocations[i]);
}
}
@@ -2124,7 +2123,7 @@ var LibraryGL = {
}
if (this.hasColorAttrib) {
Module.ctx.vertexAttribPointer(this.colorLocation, colorSize, colorType, true,
- stride, colorOffset);
+ GL.immediate.stride, GL.immediate.clientAttributes[GL.immediate.COLOR].offset);
Module.ctx.enableVertexAttribArray(this.colorLocation);
Module.ctx.uniform1i(this.hasColorAttribLocation, 1);
} else if (this.hasColorUniform) {
@@ -2133,7 +2132,7 @@ var LibraryGL = {
}
if (this.hasNormal) {
Module.ctx.vertexAttribPointer(this.normalLocation, normalSize, normalType, true,
- stride, normalOffset);
+ GL.immediate.stride, GL.immediate.clientAttributes[GL.immediate.NORMAL].offset);
Module.ctx.enableVertexAttribArray(this.normalLocation);
}
if (!useCurrProgram) { // otherwise, the user program will set the sampler2D binding and uniform itself
@@ -2282,7 +2281,7 @@ var LibraryGL = {
if (GL.immediate.enabledClientAttributes[i]) attributes.push(GL.immediate.clientAttributes[i]);
}
attributes.sort(function(x, y) { return !x ? (!y ? 0 : 1) : (!y ? -1 : (x.pointer - y.pointer)) });
- start = attributes[0].pointer;
+ start = GL.currArrayBuffer ? 0 : attributes[0].pointer;
for (var i = 0; i < attributes.length; i++) {
var attribute = attributes[i];
if (!attribute) break;
diff --git a/src/library_openal.js b/src/library_openal.js
index df1d15db..0b6e9b2f 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -103,6 +103,8 @@ var LibraryOpenAL = {
var gain = AL.currentContext.ctx.createGain();
var panner = AL.currentContext.ctx.createPanner();
panner.panningModel = "equalpower";
+ panner.distanceModel = "linear";
+ panner.rolloffFactor = 0.3;
gain.connect(panner);
panner.connect(AL.currentContext.ctx.destination);
AL.currentContext.src.push({
diff --git a/src/parseTools.js b/src/parseTools.js
index d0d3e89f..6818e442 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -65,7 +65,7 @@ function pointingLevels(type) {
var ret = 0;
var len1 = type.length - 1;
while (type[len1-ret] && type[len1-ret] === '*') {
- ret ++;
+ ret++;
}
return ret;
}
@@ -234,6 +234,7 @@ function isFunctionType(type, out) {
}
function getReturnType(type) {
+ if (pointingLevels(type) > 1) return '*'; // the type of a call can be either the return value, or the entire function. ** or more means it is a return value
var lastOpen = type.lastIndexOf('(');
if (lastOpen > 0) {
return type.substr(0, lastOpen-1);
diff --git a/src/relooper/Relooper.cpp b/src/relooper/Relooper.cpp
index ae393de3..61daed79 100644
--- a/src/relooper/Relooper.cpp
+++ b/src/relooper/Relooper.cpp
@@ -499,8 +499,7 @@ void Relooper::Calculate(Block *Entry) {
Block *Curr = *iter;
for (BlockBranchMap::iterator iter = Curr->BranchesOut.begin(); iter != Curr->BranchesOut.end(); iter++) {
Block *Possible = iter->first;
- if (InnerBlocks.find(Possible) == InnerBlocks.end() &&
- NextEntries.find(Possible) == NextEntries.find(Possible)) {
+ if (InnerBlocks.find(Possible) == InnerBlocks.end()) {
NextEntries.insert(Possible);
}
}
diff --git a/src/settings.js b/src/settings.js
index 9ed87bd6..6b054443 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -335,10 +335,16 @@ var PGO = 0; // Enables profile-guided optimization in the form of runtime check
// which functions are actually called. Emits a list during shutdown that you
// can pass to DEAD_FUNCTIONS (you can also emit the list manually by
// calling PGOMonitor.dump());
-var DEAD_FUNCTIONS = []; // A list of functions that no code will be emitted for, and
- // a runtime abort will happen if they are called. If
- // such a function is an unresolved reference, that is not
- // considered an error.
+var DEAD_FUNCTIONS = []; // Functions on this list are not converted to JS, and calls to
+ // them are turned into abort()s. This is potentially useful for
+ // (1) reducing code size, if you know some function will never
+ // be called (see PGO), and also (2) ASM.js requires all declared
+ // functions to have a corresponding implementation (even if the
+ // function is never called) and will emit an error during linking if no
+ // implementation can be found; with this option, asm.js validation will
+ // succeed for that function and calls to it.
+ // If a dead function is actually called, you will get a runtime
+ // error.
// TODO: options to lazily load such functions
var UNRESOLVED_AS_DEAD = 0; // Handle all unresolved functions as if they were in the
// list of dead functions. This is a quick way to turn