aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--src/analyzer.js2
-rw-r--r--src/intertyper.js10
-rw-r--r--src/jsifier.js22
-rw-r--r--src/library.js24
-rw-r--r--src/library_egl.js8
-rw-r--r--src/library_fs.js172
-rw-r--r--src/library_gl.js50
-rw-r--r--src/library_idbfs.js2
-rw-r--r--src/library_memfs.js100
-rw-r--r--src/library_nodefs.js12
-rw-r--r--src/library_path.js22
-rw-r--r--src/parseTools.js69
-rw-r--r--src/preamble.js10
-rw-r--r--src/runtime.js4
-rw-r--r--src/shell.html5
-rw-r--r--system/include/compat/ctype.h17
-rw-r--r--system/include/compat/wchar.h23
-rw-r--r--system/include/compat/wctype.h23
-rw-r--r--system/include/emscripten/vector.h10
-rw-r--r--tests/aniso.c3
-rw-r--r--tests/cases/caall.ll2
-rw-r--r--tests/test_core.py136
-rw-r--r--tests/test_other.py44
-rw-r--r--tools/file_packager.py39
-rw-r--r--tools/js_optimizer.py8
26 files changed, 544 insertions, 274 deletions
diff --git a/AUTHORS b/AUTHORS
index 5ad3f98d..18124a6c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -104,4 +104,5 @@ a license to everyone to use it as detailed in LICENSE.)
* Daniel Aquino <mr.danielaquino@gmail.com>
* Remi Papillie <remi.papillie@gmail.com>
* Fraser Adams <fraser.adams@blueyonder.co.uk>
+* Michael Tirado <icetooth333@gmail.com>
diff --git a/src/analyzer.js b/src/analyzer.js
index 2b74a83f..253c5505 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -418,7 +418,7 @@ function analyzer(data, sidePass) {
toAdd.push({
intertype: 'value',
assignTo: element.ident,
- type: element.bits,
+ type: 'i' + element.bits,
ident: 'tempRet' + (j - 1)
});
assert(j<10); // TODO: dynamically create more than 10 tempRet-s
diff --git a/src/intertyper.js b/src/intertyper.js
index d3640889..fceeb38d 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -682,7 +682,7 @@ function intertyper(lines, sidePass, baseLineNums) {
}
if (item.assignTo) item.ident = 'return ' + item.ident;
item.ident = '(function(' + params + ') { ' + item.ident + ' })(' + args + ');';
- return { forward: null, ret: item, item: item };
+ return { ret: item, item: item };
}
if (item.ident.substr(-2) == '()') {
// See comment in isStructType()
@@ -705,13 +705,12 @@ function intertyper(lines, sidePass, baseLineNums) {
if (item.indent == 2) {
// standalone call - not in assign
item.standalone = true;
- return { forward: null, ret: item, item: item };
+ return { ret: item, item: item };
}
- return { forward: item, ret: null, item: item };
+ return { ret: null, item: item };
}
function callHandler(item) {
var result = makeCall.call(this, item, 'call');
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
return result.ret;
}
function invokeHandler(item) {
@@ -721,10 +720,9 @@ function intertyper(lines, sidePass, baseLineNums) {
finalResults.push({
intertype: 'branch',
label: result.item.toLabel,
- lineNum: (result.forward ? item.parentLineNum : item.lineNum) + 0.5
+ lineNum: item.lineNum + 0.5
});
}
- if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
return result.ret;
}
function atomicHandler(item) {
diff --git a/src/jsifier.js b/src/jsifier.js
index b36e11ed..adcb38ee 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -948,11 +948,12 @@ function JSify(data, functionsOnly, givenFunctions) {
}
if (item.valueType[item.valueType.length-1] === '>') {
// vector store TODO: move to makeSetValue?
- var base = getVectorBaseType(item.valueType);
- return '(' + makeSetValue(item.ident, 0, value + '.x', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 4, value + '.y', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 8, value + '.z', base, 0, 0, item.align) + ',' +
- makeSetValue(item.ident, 12, value + '.w', base, 0, 0, item.align) + ')';
+ var native = getVectorNativeType(item.valueType);
+ var base = getSIMDName(native);
+ return '(' + makeSetValue(item.ident, 0, value + '.x', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 4, value + '.y', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 8, value + '.z', native, 0, 0, item.align) + ',' +
+ makeSetValue(item.ident, 12, value + '.w', native, 0, 0, item.align) + ');';
}
switch (impl) {
case VAR_NATIVIZED:
@@ -1323,11 +1324,12 @@ function JSify(data, functionsOnly, givenFunctions) {
var value = finalizeLLVMParameter(item.pointer);
if (item.valueType[item.valueType.length-1] === '>') {
// vector load
- var base = getVectorBaseType(item.valueType);
- return base + '32x4(' + makeGetValue(value, 0, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 4, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 8, base, 0, item.unsigned, 0, item.align) + ',' +
- makeGetValue(value, 12, base, 0, item.unsigned, 0, item.align) + ')';
+ var native = getVectorNativeType(item.valueType);
+ var base = getSIMDName(native);
+ return base + '32x4(' + makeGetValue(value, 0, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 4, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 8, native, 0, item.unsigned, 0, item.align) + ',' +
+ makeGetValue(value, 12, native, 0, item.unsigned, 0, item.align) + ');';
}
var impl = item.ident ? getVarImpl(item.funcData, item.ident) : VAR_EMULATED;
switch (impl) {
diff --git a/src/library.js b/src/library.js
index 875d8bab..e3cdc7c3 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1579,12 +1579,12 @@ LibraryManager.library = {
// stdio.h
// ==========================================================================
- _isFloat: function(text) {
- return !!(/^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?$/.exec(text));
+ _getFloat: function(text) {
+ return /^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?/.exec(text);
},
// TODO: Document.
- _scanString__deps: ['_isFloat'],
+ _scanString__deps: ['_getFloat'],
_scanString: function(format, get, unget, varargs) {
if (!__scanString.whiteSpace) {
__scanString.whiteSpace = {};
@@ -1743,15 +1743,13 @@ LibraryManager.library = {
// Read characters according to the format. floats are trickier, they may be in an unfloat state in the middle, then be a valid float later
if (type == 'f' || type == 'e' || type == 'g' ||
type == 'F' || type == 'E' || type == 'G') {
- var last = 0;
next = get();
- while (next > 0) {
+ while (next > 0 && (!(next in __scanString.whiteSpace))) {
buffer.push(String.fromCharCode(next));
- if (__isFloat(buffer.join(''))) {
- last = buffer.length;
- }
next = get();
}
+ var m = __getFloat(buffer.join(''));
+ var last = m ? m[0].length : 0;
for (var i = 0; i < buffer.length - last + 1; i++) {
unget();
}
@@ -8580,7 +8578,7 @@ LibraryManager.library = {
},
emscripten_run_script_string: function(ptr) {
- var s = eval(Pointer_stringify(ptr));
+ var s = eval(Pointer_stringify(ptr)) + '';
var me = _emscripten_run_script_string;
if (!me.bufferSize || me.bufferSize < s.length+1) {
if (me.bufferSize) _free(me.buffer);
@@ -8623,6 +8621,14 @@ LibraryManager.library = {
},
//============================
+ // emscripten vector ops
+ //============================
+
+ emscripten_float32x4_signmask__inline: function(x) {
+ return x + '.signMask()';
+ },
+
+ //============================
// i64 math
//============================
diff --git a/src/library_egl.js b/src/library_egl.js
index 69902785..cc702fec 100644
--- a/src/library_egl.js
+++ b/src/library_egl.js
@@ -421,10 +421,10 @@ var LibraryEGL = {
if (EGL.stringCache[name]) return EGL.stringCache[name];
var ret;
switch(name) {
- case 0x3053 /* EGL_VENDOR */: ret = allocate(intArrayFromString("Emscripten"), 'i8', ALLOC_NORMAL);
- case 0x3054 /* EGL_VERSION */: ret = allocate(intArrayFromString("1.4 Emscripten EGL"), 'i8', ALLOC_NORMAL);
- case 0x3055 /* EGL_EXTENSIONS */: ret = allocate(intArrayFromString(""), 'i8', ALLOC_NORMAL); // Currently not supporting any EGL extensions.
- case 0x308D /* EGL_CLIENT_APIS */: ret = allocate(intArrayFromString("OpenGL_ES"), 'i8', ALLOC_NORMAL);
+ case 0x3053 /* EGL_VENDOR */: ret = allocate(intArrayFromString("Emscripten"), 'i8', ALLOC_NORMAL); break;
+ case 0x3054 /* EGL_VERSION */: ret = allocate(intArrayFromString("1.4 Emscripten EGL"), 'i8', ALLOC_NORMAL); break;
+ case 0x3055 /* EGL_EXTENSIONS */: ret = allocate(intArrayFromString(""), 'i8', ALLOC_NORMAL); break; // Currently not supporting any EGL extensions.
+ case 0x308D /* EGL_CLIENT_APIS */: ret = allocate(intArrayFromString("OpenGL_ES"), 'i8', ALLOC_NORMAL); break;
default:
EGL.setErrorCode(0x300C /* EGL_BAD_PARAMETER */);
return 0;
diff --git a/src/library_fs.js b/src/library_fs.js
index bd1522a8..aece2664 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -28,6 +28,7 @@ mergeInto(LibraryManager.library, {
ignorePermissions: true,
ErrnoError: null, // set during init
+ genericErrors: {},
handleFSError: function(e) {
if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + stackTrace();
@@ -62,7 +63,7 @@ mergeInto(LibraryManager.library, {
}
current = FS.lookupNode(current, parts[i]);
- current_path = PATH.join(current_path, parts[i]);
+ current_path = PATH.join2(current_path, parts[i]);
// jump to the mount's root node if this is a mountpoint
if (FS.isMountpoint(current)) {
@@ -94,9 +95,11 @@ mergeInto(LibraryManager.library, {
var path;
while (true) {
if (FS.isRoot(node)) {
- return path ? PATH.join(node.mount.mountpoint, path) : node.mount.mountpoint;
+ var mount = node.mount.mountpoint;
+ if (!path) return mount;
+ return mount[mount.length-1] !== '/' ? mount + '/' + path : mount + path;
}
- path = path ? PATH.join(node.name, path) : node.name;
+ path = path ? node.name + '/' + path : node.name;
node = node.parent;
}
},
@@ -158,44 +161,50 @@ mergeInto(LibraryManager.library, {
return FS.lookup(parent, name);
},
createNode: function(parent, name, mode, rdev) {
- var node = {
- id: FS.nextInode++,
- name: name,
- mode: mode,
- node_ops: {},
- stream_ops: {},
- rdev: rdev,
- parent: null,
- mount: null
- };
- if (!parent) {
- parent = node; // root node sets parent to itself
- }
- node.parent = parent;
- node.mount = parent.mount;
- // compatibility
- var readMode = {{{ cDefine('S_IRUGO') }}} | {{{ cDefine('S_IXUGO') }}};
- var writeMode = {{{ cDefine('S_IWUGO') }}};
- // NOTE we must use Object.defineProperties instead of individual calls to
- // Object.defineProperty in order to make closure compiler happy
- Object.defineProperties(node, {
- read: {
- get: function() { return (node.mode & readMode) === readMode; },
- set: function(val) { val ? node.mode |= readMode : node.mode &= ~readMode; }
- },
- write: {
- get: function() { return (node.mode & writeMode) === writeMode; },
- set: function(val) { val ? node.mode |= writeMode : node.mode &= ~writeMode; }
- },
- isFolder: {
- get: function() { return FS.isDir(node.mode); },
- },
- isDevice: {
- get: function() { return FS.isChrdev(node.mode); },
- },
- });
- FS.hashAddNode(node);
- return node;
+ if (!FS.FSNode) {
+ FS.FSNode = function(parent, name, mode, rdev) {
+ this.id = FS.nextInode++;
+ this.name = name;
+ this.mode = mode;
+ this.node_ops = {};
+ this.stream_ops = {};
+ this.rdev = rdev;
+ this.parent = null;
+ this.mount = null;
+ if (!parent) {
+ parent = this; // root node sets parent to itself
+ }
+ this.parent = parent;
+ this.mount = parent.mount;
+ FS.hashAddNode(this);
+ };
+
+ // compatibility
+ var readMode = {{{ cDefine('S_IRUGO') }}} | {{{ cDefine('S_IXUGO') }}};
+ var writeMode = {{{ cDefine('S_IWUGO') }}};
+
+ FS.FSNode.prototype = {};
+
+ // NOTE we must use Object.defineProperties instead of individual calls to
+ // Object.defineProperty in order to make closure compiler happy
+ Object.defineProperties(FS.FSNode.prototype, {
+ read: {
+ get: function() { return (this.mode & readMode) === readMode; },
+ set: function(val) { val ? this.mode |= readMode : this.mode &= ~readMode; }
+ },
+ write: {
+ get: function() { return (this.mode & writeMode) === writeMode; },
+ set: function(val) { val ? this.mode |= writeMode : this.mode &= ~writeMode; }
+ },
+ isFolder: {
+ get: function() { return FS.isDir(this.mode); },
+ },
+ isDevice: {
+ get: function() { return FS.isChrdev(this.mode); },
+ },
+ });
+ }
+ return new FS.FSNode(parent, name, mode, rdev);
},
destroyNode: function(node) {
FS.hashRemoveNode(node);
@@ -351,24 +360,28 @@ mergeInto(LibraryManager.library, {
// object isn't directly passed in. not possible until
// SOCKFS is completed.
createStream: function(stream, fd_start, fd_end) {
+ if (!FS.FSStream) {
+ FS.FSStream = {};
+ // compatibility
+ Object.defineProperties(FS.FSStream, {
+ object: {
+ get: function() { return this.node; },
+ set: function(val) { this.node = val; }
+ },
+ isRead: {
+ get: function() { return (this.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_WRONLY') }}}; }
+ },
+ isWrite: {
+ get: function() { return (this.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_RDONLY') }}}; }
+ },
+ isAppend: {
+ get: function() { return (this.flags & {{{ cDefine('O_APPEND') }}}); }
+ }
+ });
+ }
+ stream.prototype = FS.FSStream;
var fd = FS.nextfd(fd_start, fd_end);
stream.fd = fd;
- // compatibility
- Object.defineProperties(stream, {
- object: {
- get: function() { return stream.node; },
- set: function(val) { stream.node = val; }
- },
- isRead: {
- get: function() { return (stream.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_WRONLY') }}}; }
- },
- isWrite: {
- get: function() { return (stream.flags & {{{ cDefine('O_ACCMODE') }}}) !== {{{ cDefine('O_RDONLY') }}}; }
- },
- isAppend: {
- get: function() { return (stream.flags & {{{ cDefine('O_APPEND') }}}); }
- }
- });
FS.streams[fd] = stream;
return stream;
},
@@ -771,7 +784,6 @@ 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') }}})) {
@@ -780,13 +792,18 @@ mergeInto(LibraryManager.library, {
mode = 0;
}
var node;
- try {
- var lookup = FS.lookupPath(path, {
- follow: !(flags & {{{ cDefine('O_NOFOLLOW') }}})
- });
- node = lookup.node;
- } catch (e) {
- // ignore
+ if (typeof path === 'object') {
+ node = path;
+ } else {
+ path = PATH.normalize(path);
+ try {
+ var lookup = FS.lookupPath(path, {
+ follow: !(flags & {{{ cDefine('O_NOFOLLOW') }}})
+ });
+ node = lookup.node;
+ } catch (e) {
+ // ignore
+ }
}
// perhaps we need to create the node
if ((flags & {{{ cDefine('O_CREAT') }}})) {
@@ -1079,6 +1096,11 @@ mergeInto(LibraryManager.library, {
};
FS.ErrnoError.prototype = new Error();
FS.ErrnoError.prototype.constructor = FS.ErrnoError;
+ // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
+ [ERRNO_CODES.ENOENT].forEach(function(code) {
+ FS.genericErrors[code] = new FS.ErrnoError(code);
+ FS.genericErrors[code].stack = '<generic error, no stack>';
+ });
},
staticInit: function() {
FS.ensureErrnoError();
@@ -1173,7 +1195,7 @@ mergeInto(LibraryManager.library, {
return ret;
},
createFolder: function(parent, name, canRead, canWrite) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(canRead, canWrite);
return FS.mkdir(path, mode);
},
@@ -1183,7 +1205,7 @@ mergeInto(LibraryManager.library, {
while (parts.length) {
var part = parts.pop();
if (!part) continue;
- var current = PATH.join(parent, part);
+ var current = PATH.join2(parent, part);
try {
FS.mkdir(current);
} catch (e) {
@@ -1194,12 +1216,12 @@ mergeInto(LibraryManager.library, {
return current;
},
createFile: function(parent, name, properties, canRead, canWrite) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(canRead, canWrite);
return FS.create(path, mode);
},
createDataFile: function(parent, name, data, canRead, canWrite, canOwn) {
- var path = name ? PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
+ var path = name ? PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
var mode = FS.getMode(canRead, canWrite);
var node = FS.create(path, mode);
if (data) {
@@ -1209,16 +1231,16 @@ mergeInto(LibraryManager.library, {
data = arr;
}
// make sure we can write to the file
- FS.chmod(path, mode | {{{ cDefine('S_IWUGO') }}});
- var stream = FS.open(path, 'w');
+ FS.chmod(node, mode | {{{ cDefine('S_IWUGO') }}});
+ var stream = FS.open(node, 'w');
FS.write(stream, data, 0, data.length, 0, canOwn);
FS.close(stream);
- FS.chmod(path, mode);
+ FS.chmod(node, mode);
}
return node;
},
createDevice: function(parent, name, input, output) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
var mode = FS.getMode(!!input, !!output);
if (!FS.createDevice.major) FS.createDevice.major = 64;
var dev = FS.makedev(FS.createDevice.major++, 0);
@@ -1272,7 +1294,7 @@ mergeInto(LibraryManager.library, {
return FS.mkdev(path, mode, dev);
},
createLink: function(parent, name, target, canRead, canWrite) {
- var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
+ var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
return FS.symlink(target, path);
},
// Makes sure a file's contents are loaded. Returns whether the file has
@@ -1462,7 +1484,7 @@ mergeInto(LibraryManager.library, {
Browser.init();
// TODO we should allow people to just pass in a complete filename instead
// of parent and name being that we just join them anyways
- var fullname = name ? PATH.resolve(PATH.join(parent, name)) : parent;
+ var fullname = name ? PATH.resolve(PATH.join2(parent, name)) : parent;
function processData(byteArray) {
function finish(byteArray) {
if (!dontCreateFile) {
diff --git a/src/library_gl.js b/src/library_gl.js
index cfdd800d..6f145e91 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -242,7 +242,9 @@ var LibraryGL = {
sizePerPixel = 2;
break;
case 0x1406 /* GL_FLOAT */:
+#if ASSERTIONS
assert(GL.floatExt, 'Must have OES_texture_float to use float textures');
+#endif
switch (format) {
case 0x1907 /* GL_RGB */:
sizePerPixel = 3*4;
@@ -506,6 +508,7 @@ var LibraryGL = {
case 0x1F01 /* GL_RENDERER */:
case 0x1F02 /* GL_VERSION */:
ret = allocate(intArrayFromString(Module.ctx.getParameter(name_)), 'i8', ALLOC_NORMAL);
+ break;
case 0x1F03 /* GL_EXTENSIONS */:
var exts = Module.ctx.getSupportedExtensions();
var gl_exts = [];
@@ -514,8 +517,10 @@ var LibraryGL = {
gl_exts.push("GL_" + exts[i]);
}
ret = allocate(intArrayFromString(gl_exts.join(' ')), 'i8', ALLOC_NORMAL);
+ break;
case 0x8B8C /* GL_SHADING_LANGUAGE_VERSION */:
ret = allocate(intArrayFromString('OpenGL ES GLSL 1.00 (WebGL)'), 'i8', ALLOC_NORMAL);
+ break;
default:
throw 'Failure: Invalid glGetString value: ' + name_;
}
@@ -686,7 +691,9 @@ var LibraryGL = {
glCompressedTexImage2D__sig: 'viiiiiiii',
glCompressedTexImage2D: function(target, level, internalFormat, width, height, border, imageSize, data) {
+#if ASSERTIONS
assert(GL.compressionExt);
+#endif
if (data) {
data = {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}};
} else {
@@ -697,7 +704,9 @@ var LibraryGL = {
glCompressedTexSubImage2D__sig: 'viiiiiiiii',
glCompressedTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, imageSize, data) {
+#if ASSERTIONS
assert(GL.compressionExt);
+#endif
if (data) {
data = {{{ makeHEAPView('U8', 'data', 'data+imageSize') }}};
} else {
@@ -731,7 +740,9 @@ var LibraryGL = {
glReadPixels__sig: 'viiiiiii',
glReadPixels: function(x, y, width, height, format, type, pixels) {
+#if ASSERTIONS
assert(type == 0x1401 /* GL_UNSIGNED_BYTE */);
+#endif
var sizePerPixel;
switch (format) {
case 0x1907 /* GL_RGB */:
@@ -1363,7 +1374,9 @@ var LibraryGL = {
{{{ makeSetValue('count', '0', 'len', 'i32') }}};
for (var i = 0; i < len; ++i) {
var id = GL.shaders.indexOf(result[i]);
+#if ASSERTIONS
assert(id !== -1, 'shader not bound to local id');
+#endif
{{{ makeSetValue('shaders', 'i*4', 'id', 'i32') }}};
}
},
@@ -1800,13 +1813,16 @@ var LibraryGL = {
var glGetString = _glGetString;
_glGetString = function(name_) {
+ if (GL.stringCache[name_]) return GL.stringCache[name_];
switch(name_) {
case 0x1F03 /* GL_EXTENSIONS */: // Add various extensions that we can support
- return allocate(intArrayFromString(Module.ctx.getSupportedExtensions().join(' ') +
+ var ret = allocate(intArrayFromString(Module.ctx.getSupportedExtensions().join(' ') +
' GL_EXT_texture_env_combine GL_ARB_texture_env_crossbar GL_ATI_texture_env_combine3 GL_NV_texture_env_combine4 GL_EXT_texture_env_dot3 GL_ARB_multitexture GL_ARB_vertex_buffer_object GL_EXT_framebuffer_object GL_ARB_vertex_program GL_ARB_fragment_program GL_ARB_shading_language_100 GL_ARB_shader_objects GL_ARB_vertex_shader GL_ARB_fragment_shader GL_ARB_texture_cube_map GL_EXT_draw_range_elements' +
(GL.compressionExt ? ' GL_ARB_texture_compression GL_EXT_texture_compression_s3tc' : '') +
(GL.anisotropicExt ? ' GL_EXT_texture_filter_anisotropic' : '')
), 'i8', ALLOC_NORMAL);
+ GL.stringCache[name_] = ret;
+ return ret;
}
return glGetString(name_);
};
@@ -2019,7 +2035,9 @@ var LibraryGL = {
glBindBuffer(target, buffer);
if (target == Module.ctx.ARRAY_BUFFER) {
if (GLEmulation.currentVao) {
+#if ASSERTIONS
assert(GLEmulation.currentVao.arrayBuffer == buffer || GLEmulation.currentVao.arrayBuffer == 0 || buffer == 0, 'TODO: support for multiple array buffers in vao');
+#endif
GLEmulation.currentVao.arrayBuffer = buffer;
}
} else if (target == Module.ctx.ELEMENT_ARRAY_BUFFER) {
@@ -2159,7 +2177,9 @@ var LibraryGL = {
glBindProgram__sig: 'vii',
glBindProgram: function(type, id) {
+#if ASSERTIONS
assert(id == 0);
+#endif
},
glGetPointerv: function(name, p) {
@@ -2838,9 +2858,9 @@ var LibraryGL = {
} else if (gl) {
maxTexUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
}
-
+#if ASSERTIONS
assert(maxTexUnits > 0);
-
+#endif
s_texUnits = [];
for (var i = 0; i < maxTexUnits; i++) {
s_texUnits.push(new CTexUnit());
@@ -2899,9 +2919,10 @@ var LibraryGL = {
},
getTexUnitType: function(texUnitID) {
+#if ASSERTIONS
assert(texUnitID >= 0 &&
texUnitID < s_texUnits.length);
-
+#endif
return s_texUnits[texUnitID].getTexType();
},
@@ -3204,9 +3225,11 @@ var LibraryGL = {
if (!GL.immediate.enabledClientAttributes[texAttribName])
continue;
+#if ASSERTIONS
if (!useCurrProgram) {
assert(GL.immediate.TexEnvJIT.getTexUnitType(i) != 0, "GL_TEXTURE" + i + " coords are supplied, but that texture unit is disabled in the fixed-function pipeline.");
}
+#endif
textureSizes[i] = GL.immediate.clientAttributes[texAttribName].size;
textureTypes[i] = GL.immediate.clientAttributes[texAttribName].type;
@@ -3423,7 +3446,9 @@ var LibraryGL = {
if (!GL.currArrayBuffer) {
var start = GL.immediate.firstVertex*GL.immediate.stride;
var end = GL.immediate.lastVertex*GL.immediate.stride;
+#if ASSERTIONS
assert(end <= GL.MAX_TEMP_BUFFER_SIZE, 'too much vertex data');
+#endif
arrayBuffer = GL.tempVertexBuffers[GL.tempBufferIndexLookup[end]];
// TODO: consider using the last buffer we bound, if it was larger. downside is larger buffer, but we might avoid rebinding and preparing
} else {
@@ -3592,10 +3617,10 @@ var LibraryGL = {
Module.ctx.drawElements(mode, count, type, indices);
return;
}
+#if ASSERTIONS
if (!GL.currElementArrayBuffer) {
assert(type == Module.ctx.UNSIGNED_SHORT); // We can only emulate buffers of this kind, for now
}
-#if ASSERTIONS
console.log("DrawElements doesn't actually prepareClientAttributes properly.");
#endif
GL.immediate.prepareClientAttributes(count, false);
@@ -3803,13 +3828,17 @@ var LibraryGL = {
if (!attribute) break;
attribute.offset = attribute.pointer - start;
if (attribute.offset > bytes) { // ensure we start where we should
+#if ASSERTIONS
assert((attribute.offset - bytes)%4 == 0); // XXX assuming 4-alignment
+#endif
bytes += attribute.offset - bytes;
}
bytes += attribute.size * GL.byteSizeByType[attribute.type - GL.byteSizeByTypeRoot];
if (bytes % 4 != 0) bytes += 4 - (bytes % 4); // XXX assuming 4-alignment
}
+#if ASSERTIONS
assert(beginEnd || bytes <= stride); // if not begin-end, explicit stride should make sense with total byte size
+#endif
if (bytes < stride) { // ensure the size is that of the stride
bytes = stride;
}
@@ -3836,18 +3865,21 @@ var LibraryGL = {
// Generate index data in a format suitable for GLES 2.0/WebGL
var numVertexes = 4 * this.vertexCounter / GL.immediate.stride;
+#if ASSERTIONS
assert(numVertexes % 1 == 0, "`numVertexes` must be an integer.");
-
+#endif
var emulatedElementArrayBuffer = false;
var numIndexes = 0;
if (numProvidedIndexes) {
numIndexes = numProvidedIndexes;
if (!GL.currArrayBuffer && GL.immediate.firstVertex > GL.immediate.lastVertex) {
// Figure out the first and last vertex from the index data
+#if ASSERTIONS
assert(!GL.currElementArrayBuffer); // If we are going to upload array buffer data, we need to find which range to
// upload based on the indices. If they are in a buffer on the GPU, that is very
// inconvenient! So if you do not have an array buffer, you should also not have
// an element array buffer. But best is to use both buffers!
+#endif
for (var i = 0; i < numProvidedIndexes; i++) {
var currIndex = {{{ makeGetValue('ptr', 'i*2', 'i16', null, 1) }}};
GL.immediate.firstVertex = Math.min(GL.immediate.firstVertex, currIndex);
@@ -3856,7 +3888,9 @@ var LibraryGL = {
}
if (!GL.currElementArrayBuffer) {
// If no element array buffer is bound, then indices is a literal pointer to clientside data
+#if ASSERTIONS
assert(numProvidedIndexes << 1 <= GL.MAX_TEMP_BUFFER_SIZE, 'too many immediate mode indexes (a)');
+#endif
var indexBuffer = GL.tempIndexBuffers[GL.tempBufferIndexLookup[numProvidedIndexes << 1]];
Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, indexBuffer);
Module.ctx.bufferSubData(Module.ctx.ELEMENT_ARRAY_BUFFER, 0, {{{ makeHEAPView('U16', 'ptr', 'ptr + (numProvidedIndexes << 1)') }}});
@@ -3868,11 +3902,15 @@ var LibraryGL = {
// GL.immediate.firstVertex is the first vertex we want. Quad indexes are in the pattern
// 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at index firstVertex * 1.5 to see it.
// Then since indexes are 2 bytes each, that means 3
+#if ASSERTIONS
assert(GL.immediate.firstVertex % 4 == 0);
+#endif
ptr = GL.immediate.firstVertex*3;
var numQuads = numVertexes / 4;
numIndexes = numQuads * 6; // 0 1 2, 0 2 3 pattern
+#if ASSERTIONS
assert(ptr + (numIndexes << 1) <= GL.MAX_TEMP_BUFFER_SIZE, 'too many immediate mode indexes (b)');
+#endif
Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, GL.tempQuadIndexBuffer);
emulatedElementArrayBuffer = true;
}
diff --git a/src/library_idbfs.js b/src/library_idbfs.js
index 9031bad8..ab55673f 100644
--- a/src/library_idbfs.js
+++ b/src/library_idbfs.js
@@ -130,7 +130,7 @@ mergeInto(LibraryManager.library, {
};
var toAbsolute = function(root) {
return function(p) {
- return PATH.join(root, p);
+ return PATH.join2(root, p);
}
};
diff --git a/src/library_memfs.js b/src/library_memfs.js
index 94fd767e..9f528108 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -1,6 +1,8 @@
mergeInto(LibraryManager.library, {
$MEMFS__deps: ['$FS'],
$MEMFS: {
+ ops_table: null,
+
// content modes
CONTENT_OWNING: 1, // contains a subarray into the heap, and we own it, without copying (note: someone else needs to free() it, if that is necessary)
CONTENT_FLEXIBLE: 2, // has been modified or never set to anything, and is a flexible js array that can grow/shrink
@@ -13,51 +15,71 @@ mergeInto(LibraryManager.library, {
// no supported
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
}
+ if (!MEMFS.ops_table) {
+ MEMFS.ops_table = {
+ dir: {
+ node: {
+ 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
+ },
+ stream: {
+ llseek: MEMFS.stream_ops.llseek
+ }
+ },
+ file: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr
+ },
+ stream: {
+ 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
+ }
+ },
+ link: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr,
+ readlink: MEMFS.node_ops.readlink
+ },
+ stream: {}
+ },
+ chrdev: {
+ node: {
+ getattr: MEMFS.node_ops.getattr,
+ setattr: MEMFS.node_ops.setattr
+ },
+ stream: FS.chrdev_stream_ops
+ },
+ };
+ }
var node = FS.createNode(parent, name, mode, dev);
if (FS.isDir(node.mode)) {
- 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.node_ops = MEMFS.ops_table.dir.node;
+ node.stream_ops = MEMFS.ops_table.dir.stream;
node.contents = {};
} else if (FS.isFile(node.mode)) {
- 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.node_ops = MEMFS.ops_table.file.node;
+ node.stream_ops = MEMFS.ops_table.file.stream;
node.contents = [];
node.contentMode = MEMFS.CONTENT_FLEXIBLE;
} else if (FS.isLink(node.mode)) {
- node.node_ops = {
- getattr: MEMFS.node_ops.getattr,
- setattr: MEMFS.node_ops.setattr,
- readlink: MEMFS.node_ops.readlink
- };
- node.stream_ops = {};
+ node.node_ops = MEMFS.ops_table.link.node;
+ node.stream_ops = MEMFS.ops_table.link.stream;
} 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.node_ops = MEMFS.ops_table.chrdev.node;
+ node.stream_ops = MEMFS.ops_table.chrdev.stream;
}
node.timestamp = Date.now();
// add the new node to the parent
@@ -117,7 +139,7 @@ mergeInto(LibraryManager.library, {
}
},
lookup: function(parent, name) {
- throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
+ throw FS.genericErrors[ERRNO_CODES.ENOENT];
},
mknod: function(parent, name, mode, dev) {
return MEMFS.createNode(parent, name, mode, dev);
@@ -200,7 +222,9 @@ mergeInto(LibraryManager.library, {
#if USE_TYPED_ARRAYS == 2
if (length && contents.length === 0 && position === 0 && buffer.subarray) {
// just replace it with the new data
+#if ASSERTIONS
assert(buffer.length);
+#endif
if (canOwn && buffer.buffer === HEAP8.buffer && offset === 0) {
node.contents = buffer; // this is a subarray of the heap, and we can own it
node.contentMode = MEMFS.CONTENT_OWNING;
diff --git a/src/library_nodefs.js b/src/library_nodefs.js
index 2be54076..7686f3f2 100644
--- a/src/library_nodefs.js
+++ b/src/library_nodefs.js
@@ -134,7 +134,7 @@ mergeInto(LibraryManager.library, {
}
},
lookup: function (parent, name) {
- var path = PATH.join(NODEFS.realPath(parent), name);
+ var path = PATH.join2(NODEFS.realPath(parent), name);
var mode = NODEFS.getMode(path);
return NODEFS.createNode(parent, name, mode);
},
@@ -156,7 +156,7 @@ mergeInto(LibraryManager.library, {
},
rename: function (oldNode, newDir, newName) {
var oldPath = NODEFS.realPath(oldNode);
- var newPath = PATH.join(NODEFS.realPath(newDir), newName);
+ var newPath = PATH.join2(NODEFS.realPath(newDir), newName);
try {
fs.renameSync(oldPath, newPath);
} catch (e) {
@@ -165,7 +165,7 @@ mergeInto(LibraryManager.library, {
}
},
unlink: function(parent, name) {
- var path = PATH.join(NODEFS.realPath(parent), name);
+ var path = PATH.join2(NODEFS.realPath(parent), name);
try {
fs.unlinkSync(path);
} catch (e) {
@@ -174,7 +174,7 @@ mergeInto(LibraryManager.library, {
}
},
rmdir: function(parent, name) {
- var path = PATH.join(NODEFS.realPath(parent), name);
+ var path = PATH.join2(NODEFS.realPath(parent), name);
try {
fs.rmdirSync(path);
} catch (e) {
@@ -192,7 +192,7 @@ mergeInto(LibraryManager.library, {
}
},
symlink: function(parent, newName, oldPath) {
- var newPath = PATH.join(NODEFS.realPath(parent), newName);
+ var newPath = PATH.join2(NODEFS.realPath(parent), newName);
try {
fs.symlinkSync(oldPath, newPath);
} catch (e) {
@@ -283,4 +283,4 @@ mergeInto(LibraryManager.library, {
}
}
}
-}); \ No newline at end of file
+});
diff --git a/src/library_path.js b/src/library_path.js
index 09808acd..f00a7586 100644
--- a/src/library_path.js
+++ b/src/library_path.js
@@ -59,26 +59,22 @@ mergeInto(LibraryManager.library, {
}
return root + dir;
},
- basename: function(path, ext) {
+ basename: function(path) {
// EMSCRIPTEN return '/'' for '/', not an empty string
if (path === '/') return '/';
- var f = PATH.splitPath(path)[2];
- if (ext && f.substr(-1 * ext.length) === ext) {
- f = f.substr(0, f.length - ext.length);
- }
- return f;
+ var lastSlash = path.lastIndexOf('/');
+ if (lastSlash === -1) return path;
+ return path.substr(lastSlash+1);
},
extname: function(path) {
return PATH.splitPath(path)[3];
},
join: function() {
var paths = Array.prototype.slice.call(arguments, 0);
- return PATH.normalize(paths.filter(function(p, index) {
- if (typeof p !== 'string') {
- throw new TypeError('Arguments to path.join must be strings');
- }
- return p;
- }).join('/'));
+ return PATH.normalize(paths.join('/'));
+ },
+ join2: function(l, r) {
+ return PATH.normalize(l + '/' + r);
},
resolve: function() {
var resolvedPath = '',
@@ -134,4 +130,4 @@ mergeInto(LibraryManager.library, {
return outputParts.join('/');
}
}
-}); \ No newline at end of file
+});
diff --git a/src/parseTools.js b/src/parseTools.js
index dae386f1..238b6bd5 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -215,8 +215,22 @@ function isIdenticallyImplemented(type1, type2) {
}
function isIllegalType(type) {
- var bits = getBits(type);
- return bits > 0 && (bits >= 64 || !isPowerOfTwo(bits));
+ switch (type) {
+ case 'i1':
+ case 'i8':
+ case 'i16':
+ case 'i32':
+ case 'float':
+ case 'double':
+ case 'rawJS':
+ case '<2 x float>':
+ case '<4 x float>':
+ case '<2 x i32>':
+ case '<4 x i32>':
+ case 'void': return false;
+ }
+ if (!type || type[type.length-1] === '*') return false;
+ return true;
}
function isVoidType(type) {
@@ -287,6 +301,9 @@ 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) {
+ // handle things like void (i32)* (i32, void (i32)*)*
+ var closeStar = type.indexOf(')*');
+ if (closeStar > 0 && closeStar < type.length-2) lastOpen = closeStar+3;
return type.substr(0, lastOpen-1);
}
return type;
@@ -328,28 +345,29 @@ function getVectorSize(type) {
return parseInt(type.substring(1, type.indexOf(' ')));
}
-function getVectorBaseType(type) {
+function getVectorNativeType(type) {
Types.usesSIMD = true;
switch (type) {
case '<2 x float>':
case '<4 x float>': return 'float';
case '<2 x i32>':
- case '<4 x i32>': return 'uint';
+ case '<4 x i32>': return 'i32';
default: throw 'unknown vector type ' + type;
}
}
-function getVectorNativeType(type) {
- Types.usesSIMD = true;
+function getSIMDName(type) {
switch (type) {
- case '<2 x float>':
- case '<4 x float>': return 'float';
- case '<2 x i32>':
- case '<4 x i32>': return 'i32';
- default: throw 'unknown vector type ' + type;
+ case 'i32': return 'uint';
+ case 'float': return 'float';
+ default: throw 'getSIMDName ' + type;
}
}
+function getVectorBaseType(type) {
+ return getSIMDName(getVectorNativeType(type));
+}
+
function addIdent(token) {
token.ident = token.text;
return token;
@@ -465,26 +483,13 @@ function parseParamTokens(params) {
Types.needAnalysis[ret[ret.length-1].type] = 0;
anonymousIndex ++;
}
- } else if (segment[1].text in PARSABLE_LLVM_FUNCTIONS) {
- ret.push(parseLLVMFunctionCall(segment));
- } else if (segment[1].text === 'blockaddress') {
- ret.push(parseBlockAddress(segment));
- } else if (segment[1].type && segment[1].type == '{') {
- ret.push(parseLLVMSegment(segment));
} else {
if (segment[2] && segment[2].text == 'to') { // part of bitcast params
segment = segment.slice(0, 2);
}
- while (segment.length > 2) {
- segment[0].text += segment[1].text;
- segment.splice(1, 1); // TODO: merge tokens nicely
- }
- ret.push({
- intertype: 'value',
- type: segment[0].text,
- ident: toNiceIdent(parseNumerical(segment[1].text, segment[0].text))
- });
- Types.needAnalysis[removeAllPointing(ret[ret.length-1].type)] = 0;
+ var parsed = parseLLVMSegment(segment);
+ if (parsed.intertype === 'value' && !isIllegalType(parsed.type)) parsed.ident = parseNumerical(parsed.ident, parsed.type);
+ ret.push(parsed);
}
ret[ret.length-1].byVal = byVal;
}
@@ -1009,11 +1014,9 @@ function getOldLabel(label) {
}
function calcAllocatedSize(type) {
- if (pointingLevels(type) == 0 && isStructType(type)) {
- return Types.types[type].flatSize; // makeEmptyStruct(item.allocatedType).length;
- } else {
- return Runtime.getNativeTypeSize(type); // We can really get away with '1', though, at least on the stack...
- }
+ var ret = Runtime.getNativeTypeSize(type);
+ if (ret) return ret;
+ return Types.types[type].flatSize; // known type
}
// Generates the type signature for a structure, for each byte, the type that is there.
@@ -1809,7 +1812,7 @@ function makeGetSlabs(ptr, type, allowMultiple, unsigned) {
switch(type) {
case 'i1': case 'i8': return [unsigned ? 'HEAPU8' : 'HEAP8']; break;
case 'i16': return [unsigned ? 'HEAPU16' : 'HEAP16']; break;
- case '<4 x i32>': case 'uint':
+ case '<4 x i32>':
case 'i32': case 'i64': return [unsigned ? 'HEAPU32' : 'HEAP32']; break;
case 'double': {
if (TARGET_LE32) return ['HEAPF64']; // in le32, we do have the ability to assume 64-bit alignment
diff --git a/src/preamble.js b/src/preamble.js
index ee273f6a..9e72e7b8 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -1107,19 +1107,21 @@ var Math_min = Math.min;
// it happens right before run - run will be postponed until
// the dependencies are met.
var runDependencies = 0;
-var runDependencyTracking = {};
var runDependencyWatcher = null;
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
+#if ASSERTIONS
+var runDependencyTracking = {};
+#endif
function addRunDependency(id) {
runDependencies++;
if (Module['monitorRunDependencies']) {
Module['monitorRunDependencies'](runDependencies);
}
+#if ASSERTIONS
if (id) {
assert(!runDependencyTracking[id]);
runDependencyTracking[id] = 1;
-#if ASSERTIONS
if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
// Check for missing dependencies every few seconds
runDependencyWatcher = setInterval(function() {
@@ -1136,10 +1138,10 @@ function addRunDependency(id) {
}
}, 10000);
}
-#endif
} else {
Module.printErr('warning: run dependency added without ID');
}
+#endif
}
Module['addRunDependency'] = addRunDependency;
function removeRunDependency(id) {
@@ -1147,12 +1149,14 @@ function removeRunDependency(id) {
if (Module['monitorRunDependencies']) {
Module['monitorRunDependencies'](runDependencies);
}
+#if ASSERTIONS
if (id) {
assert(runDependencyTracking[id]);
delete runDependencyTracking[id];
} else {
Module.printErr('warning: run dependency removed without ID');
}
+#endif
if (runDependencies == 0) {
if (runDependencyWatcher !== null) {
clearInterval(runDependencyWatcher);
diff --git a/src/runtime.js b/src/runtime.js
index 5d5cb43b..ca2304da 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -145,7 +145,7 @@ var Runtime = {
//! @param type The type, by name.
getNativeTypeSize: function(type) {
#if QUANTUM_SIZE == 1
- return 1;
+ return 1;
#else
switch (type) {
case 'i1': case 'i8': return 1;
@@ -161,6 +161,8 @@ var Runtime = {
var bits = parseInt(type.substr(1));
assert(bits % 8 === 0);
return bits/8;
+ } else {
+ return 0;
}
}
}
diff --git a/src/shell.html b/src/shell.html
index a33735d9..53a4fffb 100644
--- a/src/shell.html
+++ b/src/shell.html
@@ -63,8 +63,11 @@
},
canvas: document.getElementById('canvas'),
setStatus: function(text) {
- if (Module.setStatus.interval) clearInterval(Module.setStatus.interval);
+ if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
+ if (text === Module.setStatus.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
+ var now = Date.now();
+ if (m && now - Date.now() < 30) return; // if this is a progress update, skip it if too soon
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
if (m) {
diff --git a/system/include/compat/ctype.h b/system/include/compat/ctype.h
index 891006d9..3f504946 100644
--- a/system/include/compat/ctype.h
+++ b/system/include/compat/ctype.h
@@ -14,4 +14,21 @@
#include_next <ctype.h>
+/* We undef these until libcxx is fixed. Without this,
+ some things can fail to compile correctly, like
+ Boost. Issue #1716. */
+
+#undef isalpha
+#undef isblank
+#undef iscntrl
+#undef isdigit
+#undef isgraph
+#undef islower
+#undef isprint
+#undef ispunct
+#undef isspace
+#undef isupper
+#undef isxdigit
+#undef isctype
+
#endif /* _COMPAT_CTYPE_H_ */
diff --git a/system/include/compat/wchar.h b/system/include/compat/wchar.h
new file mode 100644
index 00000000..42f0bcee
--- /dev/null
+++ b/system/include/compat/wchar.h
@@ -0,0 +1,23 @@
+#ifndef _COMPAT_WCHAR_H_
+#define _COMPAT_WCHAR_H_
+
+#include_next <wchar.h>
+
+/* We undef these until libcxx is fixed. Without this,
+ some things can fail to compile correctly, like
+ Boost. Issue #1716. */
+
+#undef iswalpha
+#undef iswblank
+#undef iswcntrl
+#undef iswdigit
+#undef iswgraph
+#undef iswlower
+#undef iswprint
+#undef iswpunct
+#undef iswspace
+#undef iswupper
+#undef iswxdigit
+#undef iswctype
+
+#endif /* _COMPAT_WCHAR_H_ */
diff --git a/system/include/compat/wctype.h b/system/include/compat/wctype.h
new file mode 100644
index 00000000..0eeaab8b
--- /dev/null
+++ b/system/include/compat/wctype.h
@@ -0,0 +1,23 @@
+#ifndef _COMPAT_WCTYPE_H_
+#define _COMPAT_WCTYPE_H_
+
+#include_next <wctype.h>
+
+/* We undef these until libcxx is fixed. Without this,
+ some things can fail to compile correctly, like
+ Boost. Issue #1716. */
+
+#undef iswalpha
+#undef iswblank
+#undef iswcntrl
+#undef iswdigit
+#undef iswgraph
+#undef iswlower
+#undef iswprint
+#undef iswpunct
+#undef iswspace
+#undef iswupper
+#undef iswxdigit
+#undef iswctype
+
+#endif /* _COMPAT_WCTYPE_H_ */
diff --git a/system/include/emscripten/vector.h b/system/include/emscripten/vector.h
index ea148f0d..938f2369 100644
--- a/system/include/emscripten/vector.h
+++ b/system/include/emscripten/vector.h
@@ -4,3 +4,13 @@
typedef float float32x4 __attribute__((__vector_size__(16)));
typedef unsigned int uint32x4 __attribute__((__vector_size__(16)));
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+unsigned int emscripten_float32x4_signmask(float32x4 x);
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/tests/aniso.c b/tests/aniso.c
index e8d7bd3f..f1674cad 100644
--- a/tests/aniso.c
+++ b/tests/aniso.c
@@ -66,6 +66,9 @@ int main(int argc, char *argv[])
const char *exts = (const char *)glGetString(GL_EXTENSIONS);
assert(hasext(exts, "GL_EXT_texture_filter_anisotropic"));
+ const char *vendor = (const char *)glGetString(GL_VENDOR);
+ printf("vendor: %s\n", vendor);
+
GLint aniso;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso);
printf("Max anisotropy: %d (using that)\n", aniso);
diff --git a/tests/cases/caall.ll b/tests/cases/caall.ll
index 313116e6..5b8f7f29 100644
--- a/tests/cases/caall.ll
+++ b/tests/cases/caall.ll
@@ -18,7 +18,7 @@ entry:
define (i32*)** @_ZNSt3__13mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPFvP6ObjectENS_4lessIS6_EENS4_INS_4pairIKS6_SA_EEEEEixERSE_(i32 %x) {
entry:
%ret = inttoptr i32 0 to (i32*)**
- ret %ret
+ ret (i32*)** %ret
}
; [#uses=1]
diff --git a/tests/test_core.py b/tests/test_core.py
index dd5b1e39..6857d803 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2949,6 +2949,23 @@ Exiting setjmp function, level: 0, prev_jmp: -1
'''
self.do_run(src, '3.14159')
+ def test_iswdigit(self):
+ if self.emcc_args is None: return self.skip('no libcxx inclusion without emcc')
+
+ src = '''
+ #include <stdio.h>
+ #include <cctype>
+ #include <cwctype>
+
+ int main() {
+ using namespace std;
+ printf("%d ", isdigit('0'));
+ printf("%d ", iswdigit(L'0'));
+ return 0;
+ }
+ '''
+ self.do_run(src, '1 1')
+
def test_polymorph(self):
if self.emcc_args is None: return self.skip('requires emcc')
src = '''
@@ -7268,6 +7285,18 @@ date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3
'''
self.do_run(src, '4779 4779')
+ def test_sscanf_float(self):
+ src = r'''
+ #include "stdio.h"
+
+ int main(){
+ float f1, f2, f3, f4, f5, f6, f7, f8, f9;
+ sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9);
+ printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9);
+ }
+ '''
+ self.do_run(src, '\n0.512000, 0.250000, 5.129000, -9.980000, 1.120000, 54320.000000, 54320.000000, 0.087500, 0.087500\n')
+
def test_langinfo(self):
src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read()
expected = open(path_from_root('tests', 'langinfo', 'output.txt'), 'r').read()
@@ -8631,6 +8660,113 @@ void*:16
main = main[:main.find('\n}')]
assert main.count('\n') == 7, 'must not emit too many postSets: %d' % main.count('\n')
+ def test_simd(self):
+ if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
+ if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
+ src = r'''
+#include <stdio.h>
+
+#include <emscripten/vector.h>
+
+static inline float32x4 __attribute__((always_inline))
+_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+{
+ return (float32x4){ __W, __X, __Y, __Z };
+}
+
+int main(int argc, char **argv) {
+ float data[8];
+ for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc);
+ {
+ float32x4 *a = (float32x4*)&data[0];
+ float32x4 *b = (float32x4*)&data[4];
+ float32x4 c, d;
+ c = *a;
+ d = *b;
+ printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = c+d;
+ printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ d = c*d;
+ printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ }
+ {
+ uint32x4 *a = (uint32x4*)&data[0];
+ uint32x4 *b = (uint32x4*)&data[4];
+ uint32x4 c, d, e, f;
+ c = *a;
+ d = *b;
+ printf("4uints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
+ e = c+d;
+ f = c-d;
+ printf("5uints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ }
+ {
+ float32x4 c, d, e, f;
+ c = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ d = _mm_set_ps(10.0, 14.0, -12, -2.0);
+ printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ //printf("7calcs: %d\n", emscripten_float32x4_signmask(c));
+ }
+
+ return 0;
+}
+ '''
+
+ self.do_run(src, '''1floats! 6, 12, 20, 30 42, 56, 72, 90
+2floats! 48, 68, 92, 120 42, 56, 72, 90
+3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
+4uints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
+5uints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
+6floats! -9, 0, 4, 9 -2, -12, 14, 10
+''')
+
+ def test_simd2(self):
+ if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
+
+ self.do_run(r'''
+ #include <stdio.h>
+
+ typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+ static inline __m128 __attribute__((always_inline))
+ _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+ {
+ return (__m128){ __W, __X, __Y, __Z };
+ }
+
+ static inline void __attribute__((always_inline))
+ _mm_store_ps(float *__P, __m128 __A)
+ {
+ *(__m128 *)__P = __A;
+ }
+
+ static inline __m128 __attribute__((always_inline))
+ _mm_add_ps(__m128 __A, __m128 __B)
+ {
+ return __A + __B;
+ }
+
+ using namespace std;
+
+ int main(int argc, char ** argv) {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0);
+ __m128 v3 = _mm_add_ps(v1, v2);
+ _mm_store_ps(ar, v3);
+
+ for (int i = 0; i < 4; i++) {
+ printf("%f\n", ar[i]);
+ }
+
+ return 0;
+ }
+ ''', '''-8.000000
+2.500000
+7.000000
+16.000000
+''')
+
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this
diff --git a/tests/test_other.py b/tests/test_other.py
index e251da5d..86e0eadf 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2015,47 +2015,3 @@ a(int [32], char [5]*)
Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate()
self.assertContained('Unrolled Single Precision', run_js('a.out.js'))
- def test_simd2(self):
- self.clear()
- open('src.cpp', 'w').write(r'''
-#include <stdio.h>
-
-#include <emscripten/vector.h>
-
-int main(int argc, char **argv) {
- float data[8];
- for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc);
- {
- float32x4 *a = (float32x4*)&data[0];
- float32x4 *b = (float32x4*)&data[4];
- float32x4 c, d;
- c = *a;
- d = *b;
- printf("floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- c = c+d;
- printf("floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- d = c*d;
- printf("floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- }
- {
- uint32x4 *a = (uint32x4*)&data[0];
- uint32x4 *b = (uint32x4*)&data[4];
- uint32x4 c, d, e, f;
- c = *a;
- d = *b;
- printf("uints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
- e = c+d;
- f = c-d;
- printf("uints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
- }
- return 0;
-}
- ''')
- Popen([PYTHON, EMCC, 'src.cpp', '-O2']).communicate()
- self.assertContained('''floats! 6, 12, 20, 30 42, 56, 72, 90
-floats! 48, 68, 92, 120 42, 56, 72, 90
-floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
-uints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
-uints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
-''', run_js('a.out.js'))
-
diff --git a/tools/file_packager.py b/tools/file_packager.py
index a2349a57..1d0ec447 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -134,6 +134,11 @@ if (not force) and len(data_files) == 0:
ret = '''
var Module;
if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
+if (!Module.expectedDataFileDownloads) {
+ Module.expectedDataFileDownloads = 0;
+ Module.finishedDataFileDownloads = 0;
+}
+Module.expectedDataFileDownloads++;
(function() {
'''
@@ -338,18 +343,9 @@ if has_preloaded:
send: function() {},
onload: function() {
var byteArray = this.byteArray.subarray(this.start, this.end);
- if (this.crunched) {
- var ddsHeader = byteArray.subarray(0, 128);
- var that = this;
- requestDecrunch(this.name, byteArray.subarray(128), function(ddsData) {
- byteArray = new Uint8Array(ddsHeader.length + ddsData.length);
- byteArray.set(ddsHeader, 0);
- byteArray.set(ddsData, 128);
- that.finish(byteArray);
- });
- } else {
+%s
this.finish(byteArray);
- }
+%s
},
finish: function(byteArray) {
var that = this;
@@ -365,7 +361,20 @@ if has_preloaded:
this.requests[this.name] = null;
},
};
- '''
+ ''' % ('' if not crunch else '''
+ if (this.crunched) {
+ var ddsHeader = byteArray.subarray(0, 128);
+ var that = this;
+ requestDecrunch(this.name, byteArray.subarray(128), function(ddsData) {
+ byteArray = new Uint8Array(ddsHeader.length + ddsData.length);
+ byteArray.set(ddsHeader, 0);
+ byteArray.set(ddsData, 128);
+ that.finish(byteArray);
+ });
+ } else {
+''', '' if not crunch else '''
+ }
+''')
counter = 0
for file_ in data_files:
@@ -427,12 +436,6 @@ if has_preloaded:
package_uuid = uuid.uuid4();
remote_package_name = os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target)
code += r'''
- if (!Module.expectedDataFileDownloads) {
- Module.expectedDataFileDownloads = 0;
- Module.finishedDataFileDownloads = 0;
- }
- Module.expectedDataFileDownloads++;
-
var PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
var PACKAGE_NAME = '%s';
var REMOTE_PACKAGE_NAME = '%s';
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index d6f8921c..dcc9cd5f 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -29,13 +29,13 @@ class Minifier:
during registerize perform minification of locals.
'''
- def __init__(self, js, js_engine):
+ def __init__(self, js, js_engine, MAX_NAMES):
self.js = js
self.js_engine = js_engine
+ MAX_NAMES = min(MAX_NAMES, 120000)
# Create list of valid short names
- MAX_NAMES = 80000
INVALID_2 = set(['do', 'if', 'in'])
INVALID_3 = set(['for', 'new', 'try', 'var', 'env', 'let'])
@@ -56,7 +56,6 @@ class Minifier:
if len(self.names) >= MAX_NAMES: break
curr = a + b + c
if curr not in INVALID_3: self.names.append(curr)
- #print >> sys.stderr, self.names
def minify_shell(self, shell, minify_whitespace, source_map=False):
#print >> sys.stderr, "MINIFY SHELL 1111111111", shell, "\n222222222222222"
@@ -187,7 +186,8 @@ EMSCRIPTEN_FUNCS();
''' + js[end_funcs + len(end_funcs_marker):end_asm + len(end_asm_marker)]
js = js[start_funcs + len(start_funcs_marker):end_funcs]
- minifier = Minifier(js, js_engine)
+ # we assume there is a maximum of one new name per line
+ minifier = Minifier(js, js_engine, js.count('\n') + asm_shell.count('\n'))
asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes, source_map).split('EMSCRIPTEN_FUNCS();');
asm_shell_post = asm_shell_post.replace('});', '})');
pre += asm_shell_pre + '\n' + start_funcs_marker