Skip to content

Commit 274c571

Browse files
authored
Update to latest Binaryen (#911)
1 parent 84a1084 commit 274c571

File tree

13 files changed

+1466
-652
lines changed

13 files changed

+1466
-652
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": "89.0.0-nightly.20190918",
15+
"binaryen": "89.0.0-nightly.20191012",
1616
"glob": "^7.1.4",
1717
"long": "^4.0.0",
1818
"opencollective-postinstall": "^2.0.0",

src/builtins.ts

Lines changed: 195 additions & 16 deletions
Large diffs are not rendered by default.

src/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ export class Compiler extends DiagnosticEmitter {
449449

450450
// set up function table
451451
var functionTable = this.functionTable;
452-
module.setFunctionTable(functionTable.length, 0xffffffff, functionTable);
452+
module.setFunctionTable(functionTable.length, 0xffffffff, functionTable, module.i32(0));
453453
module.addFunction("null", this.ensureFunctionType(null, Type.void), null, module.block(null, []));
454454

455455
// import table if requested (default table is named '0' by Binaryen)

src/glue/binaryen.d.ts

Lines changed: 198 additions & 184 deletions
Large diffs are not rendered by default.

src/module.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*//***/
55

66
import { Target } from "./common";
7-
import { Type } from "./types";
87

98
export type ModuleRef = usize;
109
export type FunctionTypeRef = usize;
@@ -79,6 +78,7 @@ export enum ExpressionId {
7978
SIMDShuffle = _BinaryenSIMDShuffleId(),
8079
SIMDTernary = _BinaryenSIMDTernaryId(),
8180
SIMDShift = _BinaryenSIMDShiftId(),
81+
SIMDLoad = _BinaryenSIMDLoadId(),
8282
MemoryInit = _BinaryenMemoryInitId(),
8383
DataDrop = _BinaryenDataDropId(),
8484
MemoryCopy = _BinaryenMemoryCopyId(),
@@ -325,6 +325,7 @@ export enum BinaryOp {
325325
AndV128 = _BinaryenAndVec128(),
326326
OrV128 = _BinaryenOrVec128(),
327327
XorV128 = _BinaryenXorVec128(),
328+
AndNotV128 = _BinaryenAndNotVec128(),
328329
AddI8x16 = _BinaryenAddVecI8x16(),
329330
AddSatI8x16 = _BinaryenAddSatSVecI8x16(),
330331
AddSatU8x16 = _BinaryenAddSatUVecI8x16(),
@@ -359,7 +360,8 @@ export enum BinaryOp {
359360
NarrowI16x8ToI8x16 = _BinaryenNarrowSVecI16x8ToVecI8x16(),
360361
NarrowU16x8ToU8x16 = _BinaryenNarrowUVecI16x8ToVecI8x16(),
361362
NarrowI32x4ToI16x8 = _BinaryenNarrowSVecI32x4ToVecI16x8(),
362-
NarrowU32x4ToU16x8 = _BinaryenNarrowUVecI32x4ToVecI16x8()
363+
NarrowU32x4ToU16x8 = _BinaryenNarrowUVecI32x4ToVecI16x8(),
364+
SwizzleV8x16 = _BinaryenSwizzleVec8x16()
363365
}
364366

365367
export enum HostOp {
@@ -419,6 +421,19 @@ export enum SIMDTernaryOp {
419421
QFMSF64x2 = _BinaryenQFMSVecF64x2()
420422
}
421423

424+
export enum SIMDLoadOp {
425+
LoadSplatV8x16 = _BinaryenLoadSplatVec8x16(),
426+
LoadSplatV16x8 = _BinaryenLoadSplatVec16x8(),
427+
LoadSplatV32x4 = _BinaryenLoadSplatVec32x4(),
428+
LoadSplatV64x2 = _BinaryenLoadSplatVec64x2(),
429+
LoadI8ToI16x8 = _BinaryenLoadExtSVec8x8ToVecI16x8(),
430+
LoadU8ToU16x8 = _BinaryenLoadExtUVec8x8ToVecI16x8(),
431+
LoadI16ToI32x4 = _BinaryenLoadExtSVec16x4ToVecI32x4(),
432+
LoadU16ToU32x4 = _BinaryenLoadExtUVec16x4ToVecI32x4(),
433+
LoadI32ToI64x2 = _BinaryenLoadExtSVec32x2ToVecI64x2(),
434+
LoadU32ToU64x2 = _BinaryenLoadExtUVec32x2ToVecI64x2()
435+
}
436+
422437
export class MemorySegment {
423438

424439
buffer: Uint8Array;
@@ -921,7 +936,7 @@ export class Module {
921936
}
922937

923938
simd_ternary(
924-
op: BinaryenSIMDOp,
939+
op: SIMDTernaryOp,
925940
a: ExpressionRef,
926941
b: ExpressionRef,
927942
c: ExpressionRef
@@ -937,6 +952,15 @@ export class Module {
937952
return _BinaryenSIMDShift(this.ref, op, vec, shift);
938953
}
939954

955+
simd_load(
956+
op: SIMDLoadOp,
957+
ptr: ExpressionRef,
958+
offset: u32,
959+
align: u32
960+
): ExpressionRef {
961+
return _BinaryenSIMDLoad(this.ref, op, offset, align, ptr);
962+
}
963+
940964
// meta
941965

942966
addGlobal(
@@ -946,7 +970,7 @@ export class Module {
946970
initializer: ExpressionRef
947971
): GlobalRef {
948972
var cStr = this.allocStringCached(name);
949-
return _BinaryenAddGlobal(this.ref, cStr, type, mutable ? 1 : 0, initializer);
973+
return _BinaryenAddGlobal(this.ref, cStr, type, mutable, initializer);
950974
}
951975

952976
removeGlobal(
@@ -1169,7 +1193,8 @@ export class Module {
11691193
setFunctionTable(
11701194
initial: Index,
11711195
maximum: Index,
1172-
funcs: string[]
1196+
funcs: string[],
1197+
offset: ExpressionRef
11731198
): void {
11741199
var numNames = funcs.length;
11751200
var names = new Array<usize>(numNames);
@@ -1178,7 +1203,7 @@ export class Module {
11781203
}
11791204
var cArr = allocI32Array(names);
11801205
try {
1181-
_BinaryenSetFunctionTable(this.ref, initial, maximum, cArr, numNames);
1206+
_BinaryenSetFunctionTable(this.ref, initial, maximum, cArr, numNames, offset);
11821207
} finally {
11831208
memory.free(cArr);
11841209
}
@@ -1188,6 +1213,16 @@ export class Module {
11881213
_BinaryenSetStart(this.ref, func);
11891214
}
11901215

1216+
addCustomSection(name: string, contents: Uint8Array): void {
1217+
var cStr = this.allocStringCached(name);
1218+
var cArr = allocU8Array(contents);
1219+
try {
1220+
_BinaryenAddCustomSection(this.ref, cStr, cArr, contents.length);
1221+
} finally {
1222+
memory.free(cArr);
1223+
}
1224+
}
1225+
11911226
getOptimizeLevel(): i32 {
11921227
return _BinaryenGetOptimizeLevel();
11931228
}
@@ -2063,6 +2098,10 @@ export function traverse<T>(expr: ExpressionRef, data: T, visit: (expr: Expressi
20632098
visit(_BinaryenSIMDShiftGetShift(expr), data);
20642099
break;
20652100
}
2101+
case ExpressionId.SIMDLoad: {
2102+
visit(_BinaryenSIMDLoadGetPtr(expr), data);
2103+
break;
2104+
}
20662105
case ExpressionId.MemoryInit: {
20672106
visit(_BinaryenMemoryInitGetDest(expr), data);
20682107
visit(_BinaryenMemoryInitGetOffset(expr), data);

0 commit comments

Comments
 (0)