From b7c7be1fe947f140ccf47f198c1fbad8de388b29 Mon Sep 17 00:00:00 2001 From: Nidin Vinayakan Date: Fri, 25 Jan 2019 10:50:55 +0100 Subject: [PATCH] Add shared memory definitions and initial API (#435) --- NOTICE | 1 + src/glue/binaryen.d.ts | 4 ++-- src/module.ts | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/NOTICE b/NOTICE index cf9d1014..9861af34 100644 --- a/NOTICE +++ b/NOTICE @@ -11,6 +11,7 @@ under the licensing terms detailed in LICENSE: * Palmer * Linus Unnebäck * Joshua Tenner +* Nidin Vinayakan <01@01alchemist.com> Portions of this software are derived from third-party works licensed under the following terms: diff --git a/src/glue/binaryen.d.ts b/src/glue/binaryen.d.ts index 8a5cf1a1..4924bce4 100644 --- a/src/glue/binaryen.d.ts +++ b/src/glue/binaryen.d.ts @@ -552,7 +552,7 @@ declare type BinaryenImportRef = usize; declare function _BinaryenAddFunctionImport(module: BinaryenModuleRef, internalName: usize, externalModuleName: usize, externalBaseName: usize, functionType: BinaryenFunctionTypeRef): BinaryenImportRef; declare function _BinaryenAddTableImport(module: BinaryenModuleRef, internalName: usize, externalModuleName: usize, externalBaseName: usize): BinaryenImportRef; -declare function _BinaryenAddMemoryImport(module: BinaryenModuleRef, internalName: usize, externalModuleName: usize, externalBaseName: usize): BinaryenImportRef; +declare function _BinaryenAddMemoryImport(module: BinaryenModuleRef, internalName: usize, externalModuleName: usize, externalBaseName: usize, shared:bool): BinaryenImportRef; declare function _BinaryenAddGlobalImport(module: BinaryenModuleRef, internalName: usize, externalModuleName: usize, externalBaseName: usize, globalType: BinaryenType): BinaryenImportRef; declare type BinaryenExportRef = usize; @@ -570,7 +570,7 @@ declare function _BinaryenRemoveGlobal(module: BinaryenModuleRef, name: usize): declare function _BinaryenSetFunctionTable(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, funcs: usize, numFuncs: BinaryenIndex): void; -declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: usize, segments: usize, segmentOffsets: usize, segmentSizes: usize, numSegments: BinaryenIndex): void; +declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: usize, segments: usize, segmentOffsets: usize, segmentSizes: usize, numSegments: BinaryenIndex, shared: bool): void; declare function _BinaryenSetStart(module: BinaryenModuleRef, start: BinaryenFunctionRef): void; diff --git a/src/module.ts b/src/module.ts index bdff2d24..f4e223fd 100644 --- a/src/module.ts +++ b/src/module.ts @@ -905,13 +905,14 @@ export class Module { addMemoryImport( internalName: string, externalModuleName: string, - externalBaseName: string + externalBaseName: string, + shared: bool = false, ): ImportRef { var cStr1 = allocString(internalName); var cStr2 = allocString(externalModuleName); var cStr3 = allocString(externalBaseName); try { - return _BinaryenAddMemoryImport(this.ref, cStr1, cStr2, cStr3); + return _BinaryenAddMemoryImport(this.ref, cStr1, cStr2, cStr3, shared); } finally { memory.free(cStr3); memory.free(cStr2); @@ -945,7 +946,8 @@ export class Module { maximum: Index, segments: MemorySegment[], target: Target, - exportName: string | null = null + exportName: string | null = null, + shared: bool = false ): void { var cStr = allocString(exportName); var k = segments.length; @@ -965,7 +967,7 @@ export class Module { var cArr2 = allocI32Array(offs); var cArr3 = allocI32Array(sizs); try { - _BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, k); + _BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, k, shared); } finally { memory.free(cArr3); memory.free(cArr2);