Add shared memory support to compiler (#494)

This commit is contained in:
Nidin Vinayakan
2019-02-21 00:22:25 +01:00
committed by Daniel Wirtz
parent 0c64f21250
commit 951b6f9f45
4 changed files with 16 additions and 2 deletions

View File

@@ -186,6 +186,8 @@ export class Options {
noAssert: bool = false;
/** If true, imports the memory provided by the embedder. */
importMemory: bool = false;
/** If greater than zero, declare memory as shared by setting max memory to sharedMemory. */
sharedMemory: i32 = 0;
/** If true, imports the function table provided by the embedder. */
importTable: bool = false;
/** If true, generates information necessary for source maps. */
@@ -400,18 +402,19 @@ export class Compiler extends DiagnosticEmitter {
}
// set up memory
var isSharedMemory = options.hasFeature(Feature.THREADS) && options.sharedMemory > 0;
module.setMemory(
this.options.memoryBase /* is specified */ || this.memorySegments.length
? i64_low(i64_shr_u(i64_align(memoryOffset, 0x10000), i64_new(16, 0)))
: 0,
Module.UNLIMITED_MEMORY,
isSharedMemory ? options.sharedMemory : Module.UNLIMITED_MEMORY,
this.memorySegments,
options.target,
"memory"
);
// import memory if requested (default memory is named '0' by Binaryen)
if (options.importMemory) module.addMemoryImport("0", "env", "memory");
if (options.importMemory) module.addMemoryImport("0", "env", "memory", isSharedMemory);
// set up function table
var functionTable = this.functionTable;