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

@ -421,6 +421,7 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setTarget(compilerOptions, 0);
assemblyscript.setNoAssert(compilerOptions, args.noAssert);
assemblyscript.setImportMemory(compilerOptions, args.importMemory);
assemblyscript.setSharedMemory(compilerOptions, args.sharedMemory);
assemblyscript.setImportTable(compilerOptions, args.importTable);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);

View File

@ -101,6 +101,11 @@
"type": "b",
"default": false
},
"sharedMemory": {
"description": "Declare memory as shared by settings the max shared memory.",
"type": "i",
"default": 0
},
"memoryBase": {
"description": "Sets the start offset of compiler-generated static memory.",
"type": "i",

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;

View File

@ -97,6 +97,11 @@ export function setImportMemory(options: Options, importMemory: bool): void {
options.importMemory = importMemory;
}
/** Sets the `sharedMemory` option. */
export function setSharedMemory(options: Options, sharedMemory: i32): void {
options.sharedMemory = sharedMemory;
}
/** Sets the `importTable` option. */
export function setImportTable(options: Options, importTable: bool): void {
options.importTable = importTable;