Skip to content

Commit 5b58b9a

Browse files
authored
Update Binaryen to latest (#571)
1 parent abf3de9 commit 5b58b9a

File tree

8 files changed

+29
-43
lines changed

8 files changed

+29
-43
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@protobufjs/utf8": "^1.1.0",
15-
"binaryen": "73.0.0-nightly.20190327",
15+
"binaryen": "77.0.0-nightly.20190407",
1616
"glob": "^7.1.3",
1717
"long": "^4.0.0",
1818
"opencollective-postinstall": "^2.0.0",

src/builtins.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ export namespace BuiltinSymbols {
278278
export const i64_atomic_rmw_cmpxchg = "~lib/builtins/i64.atomic.rmw.cmpxchg";
279279
export const i32_wait = "~lib/builtins/i32.wait";
280280
export const i64_wait = "~lib/builtins/i64.wait";
281-
export const i32_notify = "~lib/builtins/i32.notify";
282-
export const i64_notify = "~lib/builtins/i64.notify";
283281

284282
export const v128_splat = "~lib/builtins/v128.splat";
285283
export const v128_extract_lane = "~lib/builtins/v128.extract_lane";
@@ -1944,21 +1942,13 @@ export function compileCall(
19441942
compiler.currentType = Type.i32;
19451943
return module.createAtomicWait(arg0, arg1, arg2, type.toNativeType());
19461944
}
1947-
case BuiltinSymbols.atomic_notify: { // notify<T!>(ptr: usize, count: i32): i32;
1945+
case BuiltinSymbols.atomic_notify: { // notify(ptr: usize, count: i32): i32;
19481946
if (!compiler.options.hasFeature(Feature.THREADS)) break;
19491947
compiler.currentType = Type.i32;
19501948
if (
1951-
checkTypeRequired(typeArguments, reportNode, compiler) |
1949+
checkTypeAbsent(typeArguments, reportNode, prototype) |
19521950
checkArgsRequired(operands, 2, reportNode, compiler)
19531951
) return module.createUnreachable();
1954-
let type = typeArguments![0];
1955-
if (!type.is(TypeFlags.INTEGER) || type.size < 32) {
1956-
compiler.error(
1957-
DiagnosticCode.Operation_not_supported,
1958-
reportNode.typeArgumentsRange
1959-
);
1960-
return module.createUnreachable();
1961-
}
19621952
let arg0 = compiler.compileExpression(
19631953
operands[0],
19641954
compiler.options.usizeType,
@@ -1967,12 +1957,12 @@ export function compileCall(
19671957
);
19681958
let arg1 = compiler.compileExpression(
19691959
operands[1],
1970-
type,
1960+
Type.i32,
19711961
ConversionKind.IMPLICIT,
19721962
WrapMode.NONE
19731963
);
19741964
compiler.currentType = Type.i32;
1975-
return module.createAtomicWake(arg0, arg1);
1965+
return module.createAtomicNotify(arg0, arg1);
19761966
}
19771967

19781968
// === Control flow ===========================================================================
@@ -3792,8 +3782,6 @@ function tryDeferASM(
37923782

37933783
case BuiltinSymbols.i32_wait: return deferASM(BuiltinSymbols.atomic_wait, compiler, Type.i32, operands, Type.i32, reportNode);
37943784
case BuiltinSymbols.i64_wait: return deferASM(BuiltinSymbols.atomic_wait, compiler, Type.i64, operands, Type.i32, reportNode);
3795-
case BuiltinSymbols.i32_notify: return deferASM(BuiltinSymbols.atomic_notify, compiler, Type.i32, operands, Type.i32, reportNode);
3796-
case BuiltinSymbols.i64_notify: return deferASM(BuiltinSymbols.atomic_notify, compiler, Type.i64, operands, Type.i32, reportNode);
37973785
}
37983786
}
37993787
if (compiler.options.hasFeature(Feature.SIMD)) {

src/decompiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ export class Decompiler {
856856
case ExpressionId.AtomicCmpxchg:
857857
case ExpressionId.AtomicRMW:
858858
case ExpressionId.AtomicWait:
859-
case ExpressionId.AtomicWake:
859+
case ExpressionId.AtomicNotify:
860860
}
861861
throw new Error("not implemented");
862862
}

src/glue/binaryen.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ declare function _BinaryenUnreachableId(): BinaryenExpressionId;
5050
declare function _BinaryenAtomicCmpxchgId(): BinaryenExpressionId;
5151
declare function _BinaryenAtomicRMWId(): BinaryenExpressionId;
5252
declare function _BinaryenAtomicWaitId(): BinaryenExpressionId;
53-
declare function _BinaryenAtomicWakeId(): BinaryenExpressionId;
53+
declare function _BinaryenAtomicNotifyId(): BinaryenExpressionId;
5454
declare function _BinaryenSIMDExtractId(): BinaryenExpressionId;
5555
declare function _BinaryenSIMDReplaceId(): BinaryenExpressionId;
5656
declare function _BinaryenSIMDShuffleId(): BinaryenExpressionId;
@@ -392,7 +392,7 @@ declare function _BinaryenAtomicStore(module: BinaryenModuleRef, bytes: Binaryen
392392
declare function _BinaryenAtomicRMW(module: BinaryenModuleRef, op: BinaryenAtomicRMWOp, bytes: i32, offset: i32, ptr: BinaryenExpressionRef, value: BinaryenExpressionRef, type: BinaryenType): BinaryenExpressionRef;
393393
declare function _BinaryenAtomicCmpxchg(module: BinaryenModuleRef, bytes: i32, offset: i32, ptr: BinaryenExpressionRef, expected: BinaryenExpressionRef, replacement: BinaryenExpressionRef, type: BinaryenType): BinaryenExpressionRef;
394394
declare function _BinaryenAtomicWait(module: BinaryenModuleRef, ptr: BinaryenExpressionRef, expected: BinaryenExpressionRef, timeout: BinaryenExpressionRef, expectedType: BinaryenType): BinaryenExpressionRef;
395-
declare function _BinaryenAtomicWake(module: BinaryenModuleRef, ptr: BinaryenExpressionRef, wakeCount: BinaryenExpressionRef): BinaryenExpressionRef;
395+
declare function _BinaryenAtomicNotify(module: BinaryenModuleRef, ptr: BinaryenExpressionRef, notifyCount: BinaryenExpressionRef): BinaryenExpressionRef;
396396

397397
declare function _BinaryenSIMDExtract(module: BinaryenModuleRef, op: BinaryenSIMDOp, vec: BinaryenExpressionRef, idx: u8): BinaryenExpressionRef;
398398
declare function _BinaryenSIMDReplace(module: BinaryenModuleRef, op: BinaryenSIMDOp, vec: BinaryenExpressionRef, idx: u8, value: BinaryenExpressionRef): BinaryenExpressionRef;
@@ -506,8 +506,8 @@ declare function _BinaryenAtomicWaitGetExpected(expr: BinaryenExpressionRef): Bi
506506
declare function _BinaryenAtomicWaitGetTimeout(expr: BinaryenExpressionRef): BinaryenExpressionRef;
507507
declare function _BinaryenAtomicWaitGetExpectedType(expr: BinaryenExpressionRef): BinaryenType;
508508

509-
declare function _BinaryenAtomicWakeGetPtr(expr: BinaryenExpressionRef): BinaryenExpressionRef;
510-
declare function _BinaryenAtomicWakeGetWakeCount(expr: BinaryenExpressionRef): BinaryenExpressionRef;
509+
declare function _BinaryenAtomicNotifyGetPtr(expr: BinaryenExpressionRef): BinaryenExpressionRef;
510+
declare function _BinaryenAtomicNotifyGetNotifyCount(expr: BinaryenExpressionRef): BinaryenExpressionRef;
511511

512512
declare function _BinaryenSIMDExtractGetOp(expr: BinaryenExpressionRef): BinaryenSIMDOp;
513513
declare function _BinaryenSIMDExtractGetVec(expr: BinaryenExpressionRef): BinaryenExpressionRef;
@@ -596,7 +596,7 @@ declare function _BinaryenRemoveGlobal(module: BinaryenModuleRef, name: usize):
596596

597597
declare function _BinaryenSetFunctionTable(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, funcs: usize, numFuncs: BinaryenIndex): void;
598598

599-
declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: usize, segments: usize, segmentOffsets: usize, segmentSizes: usize, numSegments: BinaryenIndex, shared: bool): void;
599+
declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: usize, segments: usize, segmentPassive: usize, segmentOffsets: usize, segmentSizes: usize, numSegments: BinaryenIndex, shared: bool): void;
600600

601601
declare function _BinaryenSetStart(module: BinaryenModuleRef, start: BinaryenFunctionRef): void;
602602

src/module.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export enum ExpressionId {
5656
AtomicCmpxchg = _BinaryenAtomicCmpxchgId(),
5757
AtomicRMW = _BinaryenAtomicRMWId(),
5858
AtomicWait = _BinaryenAtomicWaitId(),
59-
AtomicWake = _BinaryenAtomicWakeId(),
59+
AtomicNotify = _BinaryenAtomicNotifyId(),
6060
SIMDExtract = _BinaryenSIMDExtractId(),
6161
SIMDReplace = _BinaryenSIMDReplaceId(),
6262
SIMDShuffle = _BinaryenSIMDShuffleId(),
@@ -608,11 +608,11 @@ export class Module {
608608
return _BinaryenAtomicWait(this.ref, ptr, expected, timeout, expectedType);
609609
}
610610

611-
createAtomicWake(
611+
createAtomicNotify(
612612
ptr: ExpressionRef,
613-
wakeCount: ExpressionRef
613+
notifyCount: ExpressionRef
614614
): ExpressionRef {
615-
return _BinaryenAtomicWake(this.ref, ptr, wakeCount);
615+
return _BinaryenAtomicNotify(this.ref, ptr, notifyCount);
616616
}
617617

618618
// statements
@@ -976,23 +976,27 @@ export class Module {
976976
var cStr = this.allocStringCached(exportName);
977977
var k = segments.length;
978978
var segs = new Array<usize>(k);
979+
var psvs = new Array<i8>(k);
979980
var offs = new Array<ExpressionRef>(k);
980981
var sizs = new Array<Index>(k);
981982
for (let i = 0; i < k; ++i) {
982983
let buffer = segments[i].buffer;
983984
let offset = segments[i].offset;
984985
segs[i] = allocU8Array(buffer);
986+
psvs[i] = 0; // no passive segments currently
985987
offs[i] = target == Target.WASM64
986988
? this.createI64(i64_low(offset), i64_high(offset))
987989
: this.createI32(i64_low(offset));
988990
sizs[i] = buffer.length;
989991
}
990992
var cArr1 = allocI32Array(segs);
991-
var cArr2 = allocI32Array(offs);
992-
var cArr3 = allocI32Array(sizs);
993+
var cArr2 = allocU8Array(psvs);
994+
var cArr3 = allocI32Array(offs);
995+
var cArr4 = allocI32Array(sizs);
993996
try {
994-
_BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, k, shared);
997+
_BinaryenSetMemory(this.ref, initial, maximum, cStr, cArr1, cArr2, cArr3, cArr4, k, shared);
995998
} finally {
999+
memory.free(cArr4);
9961000
memory.free(cArr3);
9971001
memory.free(cArr2);
9981002
memory.free(cArr1);

std/assembly/builtins.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export namespace atomic {
5757
@builtin export declare function xchg<T>(ptr: usize, value: T, immOffset?: usize): T;
5858
@builtin export declare function cmpxchg<T>(ptr: usize, expected: T, replacement: T, immOffset?: usize): T;
5959
@builtin export declare function wait<T>(ptr: usize, expected: T, timeout: i64): AtomicWaitResult;
60-
@builtin export declare function notify<T>(ptr: usize, count: i32): i32;
60+
@builtin export declare function notify(ptr: usize, count: i32): i32;
6161
}
6262

6363
@lazy export const enum AtomicWaitResult {
@@ -105,7 +105,6 @@ export namespace i32 {
105105
@builtin export declare function store16(offset: usize, value: i32, immOffset?: usize): void;
106106
@builtin export declare function store(offset: usize, value: i32, immOffset?: usize): void;
107107
@builtin export declare function wait(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;
108-
@builtin export declare function notify(ptr: usize, count: i32): i32;
109108

110109
export namespace rmw8 {
111110
@builtin export declare function add_u(offset: usize, value: i32, immOffset?: usize): i32;
@@ -169,7 +168,6 @@ export namespace i64 {
169168
@builtin export declare function store32(offset: usize, value: i64, immOffset?: usize): void;
170169
@builtin export declare function store(offset: usize, value: i64, immOffset?: usize): void;
171170
@builtin export declare function wait(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;
172-
@builtin export declare function notify(ptr: usize, count: i32): i32;
173171

174172
export namespace rmw8 {
175173
@builtin export declare function add_u(offset: usize, value: i64, immOffset?: usize): i64;

std/assembly/index.d.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ declare namespace atomic {
183183
export function xchg<T>(ptr: usize, value: T, immOffset?: usize): T;
184184
/** Atomically compares and exchanges an integer value in memory if the condition is met. */
185185
export function cmpxchg<T>(ptr: usize, expected: T, replacement: T, immOffset?: usize): T;
186-
/** Performs a wait operation on an integer value in memory suspending this agent if the condition is met. */
186+
/** Performs a wait operation on an address in memory suspending this agent if the integer condition is met. */
187187
export function wait<T>(ptr: usize, expected: T, timeout: i64): AtomicWaitResult;
188-
/** Performs a notify operation on an integer value in memory waking up suspended agents. */
189-
export function notify<T>(ptr: usize, count: i32): i32;
188+
/** Performs a notify operation on an address in memory waking up suspended agents. */
189+
export function notify(ptr: usize, count: i32): i32;
190190
}
191191

192192
/** Describes the result of an atomic wait operation. */
@@ -254,8 +254,6 @@ declare namespace i32 {
254254
export function store(offset: usize, value: i32, immOffset?: usize): void;
255255
/** Performs a wait operation on a 32-bit integer value in memory suspending this agent if the condition is met. */
256256
export function wait(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;
257-
/** Performs a notify operation on a 32-bit integer value in memory waking up suspended agents. */
258-
export function notify(ptr: usize, count: i32): i32;
259257
/** Atomic 32-bit integer read-modify-write operations on 8-bit values. */
260258
export namespace rmw8 {
261259
/** Atomically adds an 8-bit unsigned integer value in memory. */
@@ -358,8 +356,6 @@ declare namespace i64 {
358356
export function store(offset: usize, value: i64, immOffset?: usize): void;
359357
/** Performs a wait operation on a 64-bit integer value in memory suspending this agent if the condition is met. */
360358
export function wait(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;
361-
/** Performs a notify operation on a 64-bit integer value in memory waking up suspended agents. */
362-
export function notify(ptr: usize, count: i32): i32;
363359
/** Atomic 64-bit integer read-modify-write operations on 8-bit values. */
364360
export namespace rmw8 {
365361
/** Atomically adds an 8-bit unsigned integer value in memory. */

0 commit comments

Comments
 (0)