aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.js2
-rw-r--r--src/library.js3
-rw-r--r--src/library_gl.js237
-rw-r--r--src/library_sdl.js31
-rw-r--r--src/parseTools.js26
-rw-r--r--src/preamble.js19
-rw-r--r--src/settings.js5
7 files changed, 253 insertions, 70 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 0b43842e..14816f1e 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -185,7 +185,7 @@ if (phase == 'pre') {
print('// Note: For maximum-speed code, see "Optimizing Code" on the Emscripten wiki, https://github.com/kripken/emscripten/wiki/Optimizing-Code');
}
- if (DOUBLE_MODE || CORRECT_SIGNS || CORRECT_OVERFLOWS || CORRECT_ROUNDINGS) {
+ if (DOUBLE_MODE || CORRECT_SIGNS || CORRECT_OVERFLOWS || CORRECT_ROUNDINGS || CHECK_HEAP_ALIGN) {
print('// Note: Some Emscripten settings may limit the speed of the generated code.');
}
}
diff --git a/src/library.js b/src/library.js
index 38399632..1dcc57ad 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6701,6 +6701,9 @@ LibraryManager.library = {
pthread_mutexattr_destroy: function() {},
pthread_mutex_lock: function() {},
pthread_mutex_unlock: function() {},
+ pthread_mutex_trylock: function() {
+ return 0;
+ },
pthread_cond_init: function() {},
pthread_cond_destroy: function() {},
pthread_cond_broadcast: function() {},
diff --git a/src/library_gl.js b/src/library_gl.js
index 222e08f7..b0bf9650 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -19,6 +19,28 @@ var LibraryGL = {
uniforms: [],
shaders: [],
+#if FULL_ES2
+ clientBuffers: [],
+ enabledClientBuffers: [],
+#endif
+ currArrayBuffer: 0,
+ currElementArrayBuffer: 0,
+
+ byteSizeByTypeRoot: 0x1400, // GL_BYTE
+ byteSizeByType: [
+ 1, // GL_BYTE
+ 1, // GL_UNSIGNED_BYTE
+ 2, // GL_SHORT
+ 2, // GL_UNSIGNED_SHORT
+ 4, // GL_INT
+ 4, // GL_UNSIGNED_INT
+ 4, // GL_FLOAT
+ 2, // GL_2_BYTES
+ 3, // GL_3_BYTES
+ 4, // GL_4_BYTES
+ 8 // GL_DOUBLE
+ ],
+
uniformTable: {}, // name => uniform ID. the uID must be identical until relinking, cannot create a new uID each call to glGetUniformLocation
packAlignment: 4, // default alignment is 4 bytes
@@ -176,12 +198,48 @@ var LibraryGL = {
}
},
+#if FULL_ES2
+ calcBufLength: function(size, type, stride, count) {
+ if (stride > 0) {
+ return count * stride; // XXXvlad this is not exactly correct I don't think
+ }
+ var typeSize = GL.byteSizeByType[type - GL.byteSizeByTypeRoot];
+ return size * typeSize * count;
+ },
+
+ preDrawHandleClientVertexAttribBindings: function(count) {
+ GL.resetBufferBinding = false;
+ for (var i = 0; i < GL.maxVertexAttribs; ++i) {
+ if (!GL.enabledClientBuffers[i] || !GL.clientBuffers[i]) continue;
+
+ GL.resetBufferBinding = true;
+
+ var cb = GL.clientBuffers[i];
+
+ var buf = Module.ctx.createBuffer();
+ Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, buf);
+ Module.ctx.bufferData(Module.ctx.ARRAY_BUFFER,
+ HEAPU8.subarray(cb.ptr, cb.ptr + GL.calcBufLength(cb.size, cb.type, cb.stride, count)),
+ Module.ctx.DYNAMIC_DRAW);
+ Module.ctx.vertexAttribPointer(i, cb.size, cb.type, cb.normalized, cb.stride, 0);
+ }
+ },
+
+ postDrawHandleClientVertexAttribBindings: function() {
+ if (GL.resetBufferBinding) {
+ Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, GL.buffers[GL.currArrayBuffer]);
+ }
+ },
+#endif
+
initExtensions: function() {
if (GL.initExtensions.done) return;
GL.initExtensions.done = true;
if (!Module.useWebGL) return; // an app might link both gl and 2d backends
+ GL.maxVertexAttribs = Module.ctx.getParameter(Module.ctx.MAX_VERTEX_ATTRIBS);
+
GL.compressionExt = Module.ctx.getExtension('WEBGL_compressed_texture_s3tc') ||
Module.ctx.getExtension('MOZ_WEBGL_compressed_texture_s3tc') ||
Module.ctx.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
@@ -456,6 +514,9 @@ var LibraryGL = {
var id = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
Module.ctx.deleteBuffer(GL.buffers[id]);
GL.buffers[id] = null;
+
+ if (id == GL.currArrayBuffer) GL.currArrayBuffer = 0;
+ if (id == GL.currElementArrayBuffer) GL.currElementArrayBuffer = 0;
}
},
@@ -474,11 +535,9 @@ var LibraryGL = {
},
glIsBuffer: function(buffer) {
- var fb = GL.buffers[buffer];
- if (typeof(fb) == 'undefined') {
- return 0;
- }
- return Module.ctx.isBuffer(fb);
+ var b = GL.buffers[buffer];
+ if (!b) return 0;
+ return Module.ctx.isBuffer(b);
},
glGenRenderbuffers__sig: 'vii',
@@ -509,11 +568,9 @@ var LibraryGL = {
},
glIsRenderbuffer: function(renderbuffer) {
- var fb = GL.renderbuffers[renderbuffer];
- if (typeof(fb) == 'undefined') {
- return 0;
- }
- return Module.ctx.isRenderbuffer(fb);
+ var rb = GL.renderbuffers[renderbuffer];
+ if (!rb) return 0;
+ return Module.ctx.isRenderbuffer(rb);
},
glGetUniformfv: function(program, location, params) {
@@ -554,6 +611,11 @@ var LibraryGL = {
},
glGetVertexAttribfv: function(index, pname, params) {
+#if FULL_ES2
+ if (GL.clientBuffers[index]) {
+ Module.printErr("glGetVertexAttribfv on client-side array: not supported, bad data returned");
+ }
+#endif
var data = Module.ctx.getVertexAttrib(index, pname);
if (typeof data == 'number') {
{{{ makeSetValue('params', '0', 'data', 'float') }}};
@@ -565,6 +627,11 @@ var LibraryGL = {
},
glGetVertexAttribiv: function(index, pname, params) {
+#if FULL_ES2
+ if (GL.clientBuffers[index]) {
+ Module.printErr("glGetVertexAttribiv on client-side array: not supported, bad data returned");
+ }
+#endif
var data = Module.ctx.getVertexAttrib(index, pname);
if (typeof data == 'number' || typeof data == 'boolean') {
{{{ makeSetValue('params', '0', 'data', 'i32') }}};
@@ -576,6 +643,11 @@ var LibraryGL = {
},
glGetVertexAttribPointerv: function(index, pname, pointer) {
+#if FULL_ES2
+ if (GL.clientBuffers[index]) {
+ Module.printErr("glGetVertexAttribPointer on client-side array: not supported, bad data returned");
+ }
+#endif
{{{ makeSetValue('pointer', '0', 'Module.ctx.getVertexAttribOffset(index, pname)', 'i32') }}};
},
@@ -731,6 +803,12 @@ var LibraryGL = {
glBindBuffer__sig: 'vii',
glBindBuffer: function(target, buffer) {
+ if (target == Module.ctx.ARRAY_BUFFER) {
+ GL.currArrayBuffer = buffer;
+ } else if (target == Module.ctx.ELEMENT_ARRAY_BUFFER) {
+ GL.currElementArrayBuffer = buffer;
+ }
+
Module.ctx.bindBuffer(target, buffer ? GL.buffers[buffer] : null);
},
@@ -858,11 +936,9 @@ var LibraryGL = {
},
glIsShader: function(shader) {
- var fb = GL.shaders[shader];
- if (typeof(fb) == 'undefined') {
- return 0;
- }
- return Module.ctx.isShader(fb);
+ var s = GL.shaders[shader];
+ if (!s) return 0;
+ return Module.ctx.isShader(s);
},
glCreateProgram__sig: 'i',
@@ -975,9 +1051,7 @@ var LibraryGL = {
glIsFramebuffer__sig: 'ii',
glIsFramebuffer: function(framebuffer) {
var fb = GL.framebuffers[framebuffer];
- if (typeof(fb) == 'undefined') {
- return 0;
- }
+ if (!fb) return 0;
return Module.ctx.isFramebuffer(fb);
},
@@ -1348,27 +1422,15 @@ var LibraryGL = {
_glBindBuffer = function(target, buffer) {
glBindBuffer(target, buffer);
if (target == Module.ctx.ARRAY_BUFFER) {
- GL.currArrayBuffer = buffer;
if (GLEmulation.currentVao) {
assert(GLEmulation.currentVao.arrayBuffer == buffer || GLEmulation.currentVao.arrayBuffer == 0 || buffer == 0, 'TODO: support for multiple array buffers in vao');
GLEmulation.currentVao.arrayBuffer = buffer;
}
} else if (target == Module.ctx.ELEMENT_ARRAY_BUFFER) {
- GL.currElementArrayBuffer = buffer;
if (GLEmulation.currentVao) GLEmulation.currentVao.elementArrayBuffer = buffer;
}
};
- var glDeleteBuffers = _glDeleteBuffers;
- _glDeleteBuffers = function(n, buffers) {
- glDeleteBuffers(n, buffers);
- for (var i = 0; i < n; i++) {
- var buffer = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
- if (buffer == GL.currArrayBuffer) GL.currArrayBuffer = 0;
- if (buffer == GL.currElementArrayBuffer) GL.currElementArrayBuffer = 0;
- }
- };
-
var glGetFloatv = _glGetFloatv;
_glGetFloatv = function(pname, params) {
if (pname == 0x0BA6) { // GL_MODELVIEW_MATRIX
@@ -1621,17 +1683,6 @@ var LibraryGL = {
clientActiveTexture: 0,
clientColor: null,
- byteSizeByTypeRoot: 0x1400, // GL_BYTE
- byteSizeByType: [
- 1, // GL_BYTE
- 1, // GL_UNSIGNED_BYTE
- 2, // GL_SHORT
- 2, // GL_UNSIGNED_SHORT
- 4, // GL_INT
- 4, // GL_UNSIGNED_INT
- 4 // GL_FLOAT
- ],
-
setClientAttribute: function(name, size, type, stride, pointer) {
var attrib = this.clientAttributes[name];
attrib.name = name;
@@ -1707,7 +1758,7 @@ var LibraryGL = {
#endif
this.enabledClientAttributes[name] = true;
this.setClientAttribute(name, size, type, 0, this.rendererComponentPointer);
- this.rendererComponentPointer += size * this.byteSizeByType[type - this.byteSizeByTypeRoot];
+ this.rendererComponentPointer += size * GL.byteSizeByType[type - GL.byteSizeByTypeRoot];
} else {
this.rendererComponents[name]++;
}
@@ -1731,7 +1782,7 @@ var LibraryGL = {
cacheItem = temp ? temp : (cacheItem[attribute.name] = GL.immediate.rendererCacheItemTemplate.slice());
temp = cacheItem[attribute.size];
cacheItem = temp ? temp : (cacheItem[attribute.size] = GL.immediate.rendererCacheItemTemplate.slice());
- var typeIndex = attribute.type - GL.immediate.byteSizeByTypeRoot; // ensure it starts at 0 to keep the cache items dense
+ 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());
}
@@ -2167,7 +2218,7 @@ var LibraryGL = {
for (var i = 0; i < attributes.length; i++) {
var attribute = attributes[i];
if (!attribute) break;
- var size = attribute.size * GL.immediate.byteSizeByType[attribute.type - GL.immediate.byteSizeByTypeRoot];
+ var size = attribute.size * GL.byteSizeByType[attribute.type - GL.byteSizeByTypeRoot];
if (size % 4 != 0) size += 4 - (size % 4); // align everything
attribute.offset = bytes;
bytes += size;
@@ -2179,7 +2230,7 @@ var LibraryGL = {
for (var i = 0; i < attributes.length; i++) {
var attribute = attributes[i];
if (!attribute) break;
- var size4 = Math.floor((attribute.size * GL.immediate.byteSizeByType[attribute.type - GL.immediate.byteSizeByTypeRoot])/4);
+ var size4 = Math.floor((attribute.size * GL.byteSizeByType[attribute.type - GL.byteSizeByTypeRoot])/4);
for (var j = 0; j < count; j++) {
for (var k = 0; k < size4; k++) { // copy in chunks of 4 bytes, our alignment makes this possible
HEAP32[((start + attribute.offset + bytes*j)>>2) + k] = HEAP32[(attribute.pointer>>2) + j*size4 + k];
@@ -2197,7 +2248,7 @@ var LibraryGL = {
assert((attribute.offset - bytes)%4 == 0); // XXX assuming 4-alignment
bytes += attribute.offset - bytes;
}
- bytes += attribute.size * GL.immediate.byteSizeByType[attribute.type - GL.immediate.byteSizeByTypeRoot];
+ bytes += attribute.size * GL.byteSizeByType[attribute.type - GL.byteSizeByTypeRoot];
if (bytes % 4 != 0) bytes += 4 - (bytes % 4); // XXX assuming 4-alignment
}
assert(beginEnd || bytes <= stride); // if not begin-end, explicit stride should make sense with total byte size
@@ -2796,11 +2847,81 @@ var LibraryGL = {
glTexCoord3f: function() { throw 'glTexCoord3f: TODO' },
glGetTexLevelParameteriv: function() { throw 'glGetTexLevelParameteriv: TODO' },
- // signatures of simple pass-through functions, see later
- glActiveTexture__sig: 'vi',
+ glShadeModel: function() { Runtime.warnOnce('TODO: glShadeModel') },
+
+ glVertexAttribPointer__sig: 'viiiiii',
+ glVertexAttribPointer: function(index, size, type, normalized, stride, ptr) {
+#if FULL_ES2
+ if (!GL.currArrayBuffer) {
+ GL.clientBuffers[index] = { size: size, type: type, normalized: normalized, stride: stride, ptr: ptr };
+ return;
+ }
+
+ GL.clientBuffers[index] = null;
+#endif
+ Module.ctx.vertexAttribPointer(index, size, type, normalized, stride, ptr);
+ },
+
glEnableVertexAttribArray__sig: 'vi',
+ glEnableVertexAttribArray: function(index) {
+#if FULL_ES2
+ GL.enabledClientBuffers[index] = true;
+#endif
+ Module.ctx.enableVertexAttribArray(index);
+ },
+
glDisableVertexAttribArray__sig: 'vi',
- glVertexAttribPointer__sig: 'viiiiii',
+ glDisableVertexAttribArray: function(index) {
+#if FULL_ES2
+ GL.enabledClientBuffers[index] = false;
+#endif
+ Module.ctx.disableVertexAttribArray(index);
+ },
+
+ glDrawArrays: function(mode, first, count) {
+#if FULL_ES2
+ // bind any client-side buffers
+ GL.preDrawHandleClientVertexAttribBindings(count);
+#endif
+
+ Module.ctx.drawArrays(mode, first, count);
+
+#if FULL_ES2
+ GL.postDrawHandleClientVertexAttribBindings();
+#endif
+ },
+
+ glDrawElements: function(mode, count, type, indices) {
+#if FULL_ES2
+ var buf;
+ if (!GL.currElementArrayBuffer) {
+ buf = Module.ctx.createBuffer();
+ Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, buf);
+ Module.ctx.bufferData(Module.ctx.ELEMENT_ARRAY_BUFFER,
+ HEAPU8.subarray(indices, indices + GL.calcBufLength(1, type, 0, count)),
+ Module.ctx.DYNAMIC_DRAW);
+ // the index is now 0
+ indices = 0;
+ }
+
+ // bind any client-side buffers
+ GL.preDrawHandleClientVertexAttribBindings(count);
+#endif
+
+ Module.ctx.drawElements(mode, count, type, indices);
+
+#if FULL_ES2
+ GL.postDrawHandleClientVertexAttribBindings(count);
+
+ if (!GL.currElementArrayBuffer) {
+ Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, null);
+ Module.ctx.deleteBuffer(buf);
+ }
+#endif
+ },
+
+ // signatures of simple pass-through functions, see later
+ glActiveTexture__sig: 'vi',
glCheckFramebufferStatus__sig: 'ii',
glRenderbufferStorage__sig: 'viiii',
@@ -2822,19 +2943,18 @@ var LibraryGL = {
};
// Simple pass-through functions. Starred ones have return values. [X] ones have X in the C name but not in the JS name
-[[0, 'shadeModel getError* finish flush'],
- [1, 'clearDepth clearDepth[f] depthFunc enable disable frontFace cullFace clear enableVertexAttribArray disableVertexAttribArray lineWidth clearStencil depthMask stencilMask checkFramebufferStatus* generateMipmap activeTexture blendEquation sampleCoverage isEnabled*'],
+[[0, 'getError* finish flush'],
+ [1, 'clearDepth clearDepth[f] depthFunc enable disable frontFace cullFace clear lineWidth clearStencil depthMask stencilMask checkFramebufferStatus* generateMipmap activeTexture blendEquation sampleCoverage isEnabled*'],
[2, 'blendFunc blendEquationSeparate depthRange depthRange[f] stencilMaskSeparate hint polygonOffset'],
- [3, 'texParameteri texParameterf drawArrays vertexAttrib2f stencilFunc stencilOp'],
- [4, 'viewport clearColor scissor vertexAttrib3f colorMask drawElements renderbufferStorage blendFuncSeparate blendColor stencilFuncSeparate stencilOpSeparate'],
+ [3, 'texParameteri texParameterf vertexAttrib2f stencilFunc stencilOp'],
+ [4, 'viewport clearColor scissor vertexAttrib3f colorMask renderbufferStorage blendFuncSeparate blendColor stencilFuncSeparate stencilOpSeparate'],
[5, 'vertexAttrib4f'],
- [6, 'vertexAttribPointer'],
[8, 'copyTexImage2D copyTexSubImage2D']].forEach(function(data) {
var num = data[0];
var names = data[1];
var args = range(num).map(function(i) { return 'x' + i }).join(', ');
- var plainStub = '(function(' + args + ') { ' + (num > 0 ? 'Module.ctx.NAME(' + args + ')' : '') + ' })';
- var returnStub = '(function(' + args + ') { ' + (num > 0 ? 'return Module.ctx.NAME(' + args + ')' : '') + ' })';
+ var plainStub = '(function(' + args + ') { Module.ctx.NAME(' + args + ') })';
+ var returnStub = '(function(' + args + ') { return Module.ctx.NAME(' + args + ') })';
names.split(' ').forEach(function(name) {
var stub = plainStub;
if (name[name.length-1] == '*') {
@@ -2867,5 +2987,10 @@ LibraryGL.$GLEmulation__deps.push(function() {
for (var func in Functions.getIndex.tentative) Functions.getIndex(func);
});
+if (FORCE_GL_EMULATION) {
+ LibraryGL.glDrawElements__deps = LibraryGL.glDrawElements__deps.concat('$GLEmulation');
+ LibraryGL.glDrawArrays__deps = LibraryGL.glDrawArrays__deps.concat('$GLEmulation');
+}
+
mergeInto(LibraryManager.library, LibraryGL);
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 3b412daa..67891f63 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -44,6 +44,8 @@ var LibrarySDL = {
ctrlKey: false,
altKey: false,
+ textInput: false,
+
startTime: null,
mouseX: 0,
mouseY: 0,
@@ -173,6 +175,11 @@ var LibrarySDL = {
['i16', 'mod'],
['i32', 'unicode']
]),
+ TextInputEvent: Runtime.generateStructInfo([
+ ['i32', 'type'],
+ ['i32', 'windowID'],
+ ['b256', 'text'],
+ ]),
MouseMotionEvent: Runtime.generateStructInfo([
['i32', 'type'],
['i32', 'windowID'],
@@ -373,7 +380,7 @@ var LibrarySDL = {
}
}
// fall through
- case 'keydown': case 'keyup': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel':
+ case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel':
if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') {
var button = (event.type == 'DOMMouseScroll' ? event.detail : -event.wheelDelta) > 0 ? 4 : 3;
var event2 = {
@@ -397,6 +404,10 @@ var LibrarySDL = {
SDL.DOMButtons[event.button] = 0;
}
+ if (event.type == 'keypress' && !SDL.textInput) {
+ break;
+ }
+
SDL.events.push(event);
if (SDL.events.length >= 10000) {
Module.printErr('SDL event queue full, dropping earliest event');
@@ -476,6 +487,15 @@ var LibrarySDL = {
break;
}
+ case 'keypress': {
+ {{{ makeSetValue('ptr', 'SDL.structs.TextInputEvent.type', 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}}
+ // Not filling in windowID for now
+ var cStr = intArrayFromString(String.fromCharCode(event.charCode));
+ for (var i = 0; i < cStr.length; ++i) {
+ {{{ makeSetValue('ptr', 'SDL.structs.TextInputEvent.text + i', 'cStr[i]', 'i8') }}};
+ }
+ break;
+ }
case 'mousedown': case 'mouseup':
if (event.type == 'mousedown') {
// SDL_BUTTON(x) is defined as (1 << ((x)-1)). SDL buttons are 1-3,
@@ -618,6 +638,7 @@ var LibrarySDL = {
// Initialize this structure carefully for closure
SDL.DOMEventToSDLEvent['keydown'] = 0x300 /* SDL_KEYDOWN */;
SDL.DOMEventToSDLEvent['keyup'] = 0x301 /* SDL_KEYUP */;
+ SDL.DOMEventToSDLEvent['keypress'] = 0x303 /* SDL_TEXTINPUT */;
SDL.DOMEventToSDLEvent['mousedown'] = 0x401 /* SDL_MOUSEBUTTONDOWN */;
SDL.DOMEventToSDLEvent['mouseup'] = 0x402 /* SDL_MOUSEBUTTONUP */;
SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */;
@@ -1175,8 +1196,12 @@ var LibrarySDL = {
SDL_CondWait: function() {},
SDL_DestroyCond: function() {},
- SDL_StartTextInput: function() {}, // TODO
- SDL_StopTextInput: function() {}, // TODO
+ SDL_StartTextInput: function() {
+ SDL.textInput = true;
+ },
+ SDL_StopTextInput: function() {
+ SDL.textInput = false;
+ },
// SDL Mixer
diff --git a/src/parseTools.js b/src/parseTools.js
index 6e0d6e32..117c4987 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -984,18 +984,24 @@ function checkSafeHeap() {
function getHeapOffset(offset, type, forceAsm) {
if (USE_TYPED_ARRAYS !== 2) {
return offset;
- } else {
- if (Runtime.getNativeFieldSize(type) > 4) {
- type = 'i32'; // XXX we emulate 64-bit values as 32
- }
- var shifts = Math.log(Runtime.getNativeTypeSize(type))/Math.LN2;
- offset = '(' + offset + ')';
- if (shifts != 0) {
- return '(' + offset + '>>' + shifts + ')';
+ }
+
+ if (Runtime.getNativeFieldSize(type) > 4) {
+ type = 'i32'; // XXX we emulate 64-bit values as 32
+ }
+
+ var sz = Runtime.getNativeTypeSize(type);
+ var shifts = Math.log(sz)/Math.LN2;
+ offset = '(' + offset + ')';
+ if (shifts != 0) {
+ if (CHECK_HEAP_ALIGN) {
+ return '(CHECK_ALIGN_' + sz + '(' + offset + ')>>' + shifts + ')';
} else {
- // we need to guard against overflows here, HEAP[U]8 expects a guaranteed int
- return isJSVar(offset) ? offset : '(' + offset + '|0)';
+ return '(' + offset + '>>' + shifts + ')';
}
+ } else {
+ // we need to guard against overflows here, HEAP[U]8 expects a guaranteed int
+ return isJSVar(offset) ? offset : '(' + offset + '|0)';
}
}
diff --git a/src/preamble.js b/src/preamble.js
index 6f4b49de..71b123e7 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -150,6 +150,25 @@ function SAFE_HEAP_COPY_HISTORY(dest, src) {
//==========================================
#endif
+#if CHECK_HEAP_ALIGN
+//========================================
+// Debugging tools - alignment check
+//========================================
+function CHECK_ALIGN_8(addr) {
+ assert((addr & 7) == 0, "address must be 8-byte aligned, is " + addr + "!");
+ return addr;
+}
+function CHECK_ALIGN_4(addr) {
+ assert((addr & 3) == 0, "address must be 4-byte aligned, is " + addr + "!");
+ return addr;
+}
+function CHECK_ALIGN_2(addr) {
+ assert((addr & 1) == 0, "address must be 2-byte aligned!");
+ return addr;
+}
+#endif
+
+
#if CHECK_OVERFLOWS
//========================================
// Debugging tools - Mathop overflows
diff --git a/src/settings.js b/src/settings.js
index 308afddc..82cbebe4 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -128,6 +128,9 @@ var SAFE_HEAP = 0; // Check each write to the heap, for example, this will give
// that 3 is the option you usually want here.
var SAFE_HEAP_LOG = 0; // Log out all SAFE_HEAP operations
+var CHECK_HEAP_ALIGN = 0; // Check heap accesses for alignment, but don't do as
+ // near extensive (or slow) checks as SAFE_HEAP.
+
var SAFE_DYNCALLS = 0; // Show stack traces on missing function pointer/virtual method calls
var ASM_HEAP_LOG = 0; // Simple heap logging, like SAFE_HEAP_LOG but cheaper, and in asm.js
@@ -163,6 +166,8 @@ var GL_DEBUG = 0; // Print out all calls into WebGL. As with LIBRARY_DEBUG, you
var GL_TESTING = 0; // When enabled, sets preserveDrawingBuffer in the context, to allow tests to work (but adds overhead)
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_EXCEPTION_CATCHING = 0; // Disables generating code to actually catch exceptions. If the code you
// are compiling does not actually rely on catching exceptions (but the