update heap resizing code to latest proposal
This commit is contained in:
Родитель
1c12291bcb
Коммит
b5ae09fd87
|
@ -449,6 +449,7 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
|
|||
asm_setup = ''
|
||||
maths = ['Math.' + func for func in ['floor', 'abs', 'sqrt', 'pow', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'exp', 'log', 'ceil', 'imul']]
|
||||
fundamentals = ['Math', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
|
||||
if settings['ALLOW_MEMORY_GROWTH']: fundamentals.append('byteLength')
|
||||
math_envs = ['Math.min'] # TODO: move min to maths
|
||||
asm_setup += '\n'.join(['var %s = %s;' % (f.replace('.', '_'), f) for f in math_envs])
|
||||
|
||||
|
@ -567,6 +568,9 @@ function asmPrintFloat(x, y) {
|
|||
// EMSCRIPTEN_START_ASM
|
||||
var asm = (function(global, env, buffer) {
|
||||
%s
|
||||
%s
|
||||
''' % (asm_setup, "'use asm';" if not forwarded_json['Types']['hasInlineJS'] and not settings['SIDE_MODULE'] and settings['ASM_JS'] == 1 else "'almost asm';",
|
||||
'''
|
||||
var HEAP8 = new global.Int8Array(buffer);
|
||||
var HEAP16 = new global.Int16Array(buffer);
|
||||
var HEAP32 = new global.Int32Array(buffer);
|
||||
|
@ -575,7 +579,25 @@ var asm = (function(global, env, buffer) {
|
|||
var HEAPU32 = new global.Uint32Array(buffer);
|
||||
var HEAPF32 = new global.Float32Array(buffer);
|
||||
var HEAPF64 = new global.Float64Array(buffer);
|
||||
''' % (asm_setup, "'use asm';" if not forwarded_json['Types']['hasInlineJS'] and not settings['SIDE_MODULE'] and settings['ASM_JS'] == 1 else "'almost asm';") + '\n' + asm_global_vars + '''
|
||||
''' if not settings['ALLOW_MEMORY_GROWTH'] else '''
|
||||
var Int8View = global.Int8Array;
|
||||
var Int16View = global.Int16Array;
|
||||
var Int32View = global.Int32Array;
|
||||
var Uint8View = global.Uint8Array;
|
||||
var Uint16View = global.Uint16Array;
|
||||
var Uint32View = global.Uint32Array;
|
||||
var Float32View = global.Float32Array;
|
||||
var Float64View = global.Float64Array;
|
||||
var HEAP8 = new Int8View(buffer);
|
||||
var HEAP16 = new Int16View(buffer);
|
||||
var HEAP32 = new Int32View(buffer);
|
||||
var HEAPU8 = new Uint8View(buffer);
|
||||
var HEAPU16 = new Uint16View(buffer);
|
||||
var HEAPU32 = new Uint32View(buffer);
|
||||
var HEAPF32 = new Float32View(buffer);
|
||||
var HEAPF64 = new Float64View(buffer);
|
||||
var byteLength = global.byteLength;
|
||||
''') + '\n' + asm_global_vars + '''
|
||||
var __THREW__ = 0;
|
||||
var threwValue = 0;
|
||||
var setjmpId = 0;
|
||||
|
@ -1015,6 +1037,7 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
|
|||
asm_setup = ''
|
||||
maths = ['Math.' + func for func in ['floor', 'abs', 'sqrt', 'pow', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'exp', 'log', 'ceil', 'imul']]
|
||||
fundamentals = ['Math', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
|
||||
if settings['ALLOW_MEMORY_GROWTH']: fundamentals.append('byteLength')
|
||||
math_envs = ['Math.min'] # TODO: move min to maths
|
||||
asm_setup += '\n'.join(['var %s = %s;' % (f.replace('.', '_'), f) for f in math_envs])
|
||||
|
||||
|
@ -1189,6 +1212,8 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
|
|||
// EMSCRIPTEN_START_ASM
|
||||
var asm = (function(global, env, buffer) {
|
||||
%s
|
||||
%s
|
||||
''' % (asm_setup, "'use asm';" if not metadata.get('hasInlineJS') and not settings['SIDE_MODULE'] and settings['ASM_JS'] == 1 else "'almost asm';", '''
|
||||
var HEAP8 = new global%s(buffer);
|
||||
var HEAP16 = new global%s(buffer);
|
||||
var HEAP32 = new global%s(buffer);
|
||||
|
@ -1197,15 +1222,39 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
|
|||
var HEAPU32 = new global%s(buffer);
|
||||
var HEAPF32 = new global%s(buffer);
|
||||
var HEAPF64 = new global%s(buffer);
|
||||
''' % (asm_setup, "'use asm';" if not metadata.get('hasInlineJS') and not settings['SIDE_MODULE'] and settings['ASM_JS'] == 1 else "'almost asm';",
|
||||
access_quote('Int8Array'),
|
||||
access_quote('Int16Array'),
|
||||
access_quote('Int32Array'),
|
||||
access_quote('Uint8Array'),
|
||||
access_quote('Uint16Array'),
|
||||
access_quote('Uint32Array'),
|
||||
access_quote('Float32Array'),
|
||||
access_quote('Float64Array')) + '\n' + asm_global_vars + '''
|
||||
''' % (access_quote('Int8Array'),
|
||||
access_quote('Int16Array'),
|
||||
access_quote('Int32Array'),
|
||||
access_quote('Uint8Array'),
|
||||
access_quote('Uint16Array'),
|
||||
access_quote('Uint32Array'),
|
||||
access_quote('Float32Array'),
|
||||
access_quote('Float64Array')) if not settings['ALLOW_MEMORY_GROWTH'] else '''
|
||||
var Int8View = global%s;
|
||||
var Int16View = global%s;
|
||||
var Int32View = global%s;
|
||||
var Uint8View = global%s;
|
||||
var Uint16View = global%s;
|
||||
var Uint32View = global%s;
|
||||
var Float32View = global%s;
|
||||
var Float64View = global%s;
|
||||
var HEAP8 = new Int8View(buffer);
|
||||
var HEAP16 = new Int16View(buffer);
|
||||
var HEAP32 = new Int32View(buffer);
|
||||
var HEAPU8 = new Uint8View(buffer);
|
||||
var HEAPU16 = new Uint16View(buffer);
|
||||
var HEAPU32 = new Uint32View(buffer);
|
||||
var HEAPF32 = new Float32View(buffer);
|
||||
var HEAPF64 = new Float64View(buffer);
|
||||
var byteLength = global.byteLength;
|
||||
''' % (access_quote('Int8Array'),
|
||||
access_quote('Int16Array'),
|
||||
access_quote('Int32Array'),
|
||||
access_quote('Uint8Array'),
|
||||
access_quote('Uint16Array'),
|
||||
access_quote('Uint32Array'),
|
||||
access_quote('Float32Array'),
|
||||
access_quote('Float64Array'))) + '\n' + asm_global_vars + '''
|
||||
var __THREW__ = 0;
|
||||
var threwValue = 0;
|
||||
var setjmpId = 0;
|
||||
|
|
|
@ -8770,23 +8770,18 @@ LibraryManager.library = {
|
|||
#if ALLOW_MEMORY_GROWTH
|
||||
emscripten_replace_memory__asm: true, // this is used inside the asm module
|
||||
emscripten_replace_memory__sig: 'viiiiiiii', // bogus
|
||||
emscripten_replace_memory: function(_HEAP8, _HEAP16, _HEAP32, _HEAPU8, _HEAPU16, _HEAPU32, _HEAPF32, _HEAPF64) {
|
||||
_HEAP8 = _HEAP8; // fake asm coercions
|
||||
_HEAP16 = _HEAP16;
|
||||
_HEAP32 = _HEAP32;
|
||||
_HEAPU8 = _HEAPU8;
|
||||
_HEAPU16 = _HEAPU16;
|
||||
_HEAPU32 = _HEAPU32;
|
||||
_HEAPF32 = _HEAPF32;
|
||||
_HEAPF64 = _HEAPF64;
|
||||
HEAP8 = _HEAP8; // replace the memory views
|
||||
HEAP16 = _HEAP16;
|
||||
HEAP32 = _HEAP32;
|
||||
HEAPU8 = _HEAPU8;
|
||||
HEAPU16 = _HEAPU16;
|
||||
HEAPU32 = _HEAPU32;
|
||||
HEAPF32 = _HEAPF32;
|
||||
HEAPF64 = _HEAPF64;
|
||||
emscripten_replace_memory: function(newBuffer) {
|
||||
if ((byteLength(newBuffer) & 0xffff) || byteLength(newBuffer) < 0xffff) return false;
|
||||
HEAP8 = new Int8View(newBuffer);
|
||||
HEAP16 = new Int16View(newBuffer);
|
||||
HEAP32 = new Int32View(newBuffer);
|
||||
HEAPU8 = new Uint8View(newBuffer);
|
||||
HEAPU16 = new Uint16View(newBuffer);
|
||||
HEAPU32 = new Uint32View(newBuffer);
|
||||
HEAPF32 = new Float32View(newBuffer);
|
||||
HEAPF64 = new Float64View(newBuffer);
|
||||
buffer = newBuffer;
|
||||
return true;
|
||||
},
|
||||
// this function is inside the asm block, but prevents validation as asm.js
|
||||
// the codebase still benefits from being in the general asm.js shape,
|
||||
|
|
|
@ -1013,12 +1013,22 @@ function enlargeMemory() {
|
|||
abort('cannot enlarge memory arrays in non-ta2 modes');
|
||||
#endif
|
||||
#if ASM_JS
|
||||
_emscripten_replace_memory(HEAP8, HEAP16, HEAP32, HEAPU8, HEAPU16, HEAPU32, HEAPF32, HEAPF64);
|
||||
var success = _emscripten_replace_memory(buffer);
|
||||
assert(success);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ALLOW_MEMORY_GROWTH
|
||||
var byteLength;
|
||||
try {
|
||||
byteLength = Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get);
|
||||
} catch(e) { // can fail on older node/v8
|
||||
byteLength = function(buffer) { return buffer.byteLength; };
|
||||
}
|
||||
#endif
|
||||
|
||||
var TOTAL_STACK = Module['TOTAL_STACK'] || {{{ TOTAL_STACK }}};
|
||||
var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || {{{ TOTAL_MEMORY }}};
|
||||
var FAST_MEMORY = Module['FAST_MEMORY'] || {{{ FAST_MEMORY }}};
|
||||
|
|
|
@ -1840,8 +1840,8 @@ function makeAsmCoercion(node, type) {
|
|||
case ASM_INT: return ['binary', '|', node, ['num', 0]];
|
||||
case ASM_DOUBLE: return ['unary-prefix', '+', node];
|
||||
case ASM_FLOAT: return ['call', ['name', 'Math_fround'], [node]];
|
||||
case ASM_NONE: return node; // non-validating code, emit nothing
|
||||
default: throw 'whaa?';
|
||||
case ASM_NONE:
|
||||
default: return node; // non-validating code, emit nothing XXX this is dangerous, we should only allow this when we know we are not validating
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2372,6 +2372,13 @@ function registerizeHarder(ast) {
|
|||
|
||||
traverseGeneratedFunctions(ast, function(fun) {
|
||||
|
||||
// Do not try to process non-validating methods, like the heap replacer
|
||||
var abort = false;
|
||||
traverse(fun, function(node, type) {
|
||||
if (type === 'new') abort = true;
|
||||
});
|
||||
if (abort) return;
|
||||
|
||||
var asmData = normalizeAsm(fun);
|
||||
|
||||
var localVars = asmData.vars;
|
||||
|
|
Загрузка…
Ссылка в новой задаче