Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"engineStrict": true,
"dependencies": {
"binaryen": "129.0.0-nightly.20260428",
"binaryen": "130.0.0-nightly.20260609",
"long": "^5.2.4"
},
"devDependencies": {
Expand Down
13 changes: 8 additions & 5 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ export class Compiler extends DiagnosticEmitter {
let options = this.options;
let module = this.module;

// import and/or export table if requested (default table is named '0' by Binaryen)
// import and/or export table if requested (default table is named '0' by Binaryen).
// non-imported tables are declared lazily on first indirect call, see ensureFunctionTable
if (options.importTable) {
module.addTableImport(
CommonNames.DefaultTable,
Expand Down Expand Up @@ -2152,7 +2153,11 @@ export class Compiler extends DiagnosticEmitter {
let memorySegment = instance.memorySegment;
if (!memorySegment) {

// Add to the function table
// Add to the function table, declaring it on first use so effect analysis works
if (!this.options.importTable) {
this.module.ensureFunctionTable(CommonNames.DefaultTable);
}

let functionTable = this.functionTable;
let tableBase = this.options.tableBase;
if (!tableBase) tableBase = 1; // leave first elem blank
Expand Down Expand Up @@ -7128,13 +7133,11 @@ export class Compiler extends DiagnosticEmitter {
// provided, so we must set `argumentsLength` in any case. Inject setting it
// into the index argument, which becomes executed last after any operands.
let argumentsLength = this.ensureArgumentsLength();


let functionArgWithVararg = module.block(null, [
module.global_set(argumentsLength, module.i32(numArguments)),
functionArg
], sizeTypeRef);

if (operands) this.operandsTostack(signature, operands);
let expr = module.call_indirect(
null, // TODO: handle multiple tables
Expand Down
3 changes: 3 additions & 0 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ export declare function _BinaryenUnarySetOp(expr: ExpressionRef, op: Op): void;
export declare function _BinaryenUnaryGetValue(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenUnarySetValue(expr: ExpressionRef, valueExpr: ExpressionRef): void;

export declare function _BinaryenWideIntAddSub(module: ModuleRef, op: Op, leftLowExpr: ExpressionRef, leftHighExpr: ExpressionRef, rightLowExpr: ExpressionRef, rightHighExpr: ExpressionRef): ExpressionRef;
export declare function _BinaryenWideIntMul(module: ModuleRef, op: Op, leftExpr: ExpressionRef, rightExpr: ExpressionRef): ExpressionRef;

export declare function _BinaryenBinary(module: ModuleRef, op: Op, leftExpr: ExpressionRef, rightExpr: ExpressionRef): ExpressionRef;
export declare function _BinaryenBinaryGetOp(expr: ExpressionRef): Op;
export declare function _BinaryenBinarySetOp(expr: ExpressionRef, op: Op): void;
Expand Down
3 changes: 3 additions & 0 deletions src/glue/binaryen.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ export const {
_BinaryenUnaryGetValue,
_BinaryenUnarySetValue,

_BinaryenWideIntAddSub,
_BinaryenWideIntMul,

_BinaryenBinary,
_BinaryenBinaryGetOp,
_BinaryenBinarySetOp,
Expand Down
62 changes: 53 additions & 9 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ export const enum ExpressionId {
ResumeThrow = 102 /* _BinaryenResumeThrowId */,
StackSwitch = 103 /* _BinaryenStackSwitchId */,
StructWait = 104 /* _BinaryenStructWaitId */,
StructNotify = 105 /* _BinaryenStructNotifyId */
StructNotify = 105 /* _BinaryenStructNotifyId */,
WideIntAddSub = 106 /* _BinaryenWideIntAddSubId */,
WideIntMul = 107 /* _BinaryenWideIntMulId */
}

/** Binaryen external kind constants. */
Expand Down Expand Up @@ -1057,7 +1059,7 @@ export const enum BinaryOp {
/** i16x8.relaxed_q15mulr_s */
RelaxedQ15MulrI16x8 = 215 /* _BinaryenRelaxedQ15MulrSVecI16x8 */,
/** i16x8.relaxed_dot_i8x16_i7x16_s */
RelaxedDotI8x16I7x16ToI16x8 = 216 /* _BinaryenDotI8x16I7x16SToVecI16x8 */,
RelaxedDotI8x16I7x16ToI16x8 = 216 /* _BinaryenRelaxedDotI8x16I7x16SToVecI16x8 */,

_last = RelaxedDotI8x16I7x16ToI16x8,

Expand Down Expand Up @@ -1258,15 +1260,15 @@ export const enum SIMDTernaryOp {
/** f64x2.relaxed_nmadd */
RelaxedNmaddF64x2 = 4 /* _BinaryenRelaxedNmaddVecF64x2 */,
/** i8x16.relaxed_laneselect */
RelaxedLaneselectI8x16 = 5 /* _BinaryenLaneselectI8x16 */,
RelaxedLaneselectI8x16 = 5 /* _BinaryenRelaxedLaneselectI8x16 */,
/** i16x8.relaxed_laneselect */
RelaxedLaneselectI16x8 = 6 /* _BinaryenLaneselectI16x8 */,
RelaxedLaneselectI16x8 = 6 /* _BinaryenRelaxedLaneselectI16x8 */,
/** i32x4.relaxed_laneselect */
RelaxedLaneselectI32x4 = 7 /* _BinaryenLaneselectI32x4 */,
RelaxedLaneselectI32x4 = 7 /* _BinaryenRelaxedLaneselectI32x4 */,
/** i64x2.relaxed_laneselect */
RelaxedLaneselectI64x2 = 8 /* _BinaryenLaneselectI64x2 */,
RelaxedLaneselectI64x2 = 8 /* _BinaryenRelaxedLaneselectI64x2 */,
/** i32x4.relaxed_dot_i8x16_i7x16_add_s */
RelaxedDotI8x16I7x16AddToI32x4 = 9 /* _BinaryenDotI8x16I7x16AddSToVecI32x4 */,
RelaxedDotI8x16I7x16AddToI32x4 = 9 /* _BinaryenRelaxedDotI8x16I7x16AddSToVecI32x4 */,
// FIXME: f16x8 madd/nmadd (= 10, 11) are in wasm.h but not yet exported via C API
}

Expand All @@ -1275,9 +1277,25 @@ export const enum RefAsOp {
/** ref.as_non_null */
NonNull = 0 /* _BinaryenRefAsNonNull */,
/** any.convert_extern */
ExternInternalize = 1 /* _BinaryenRefAsAnyConvertExtern */,
AnyConvertExtern = 1 /* _BinaryenRefAsAnyConvertExtern */,
/** extern.convert_any */
ExternExternalize = 2 /* _BinaryenRefAsExternConvertAny */
ExternConvertAny = 2 /* _BinaryenRefAsExternConvertAny */
}

/** Binaryen wide integer add/sub operation constants. */
export const enum WideIntAddSubOp {
/** i64.add128 */
Add = 0 /* _BinaryenAddInt128 */,
/** i64.sub128 */
Sub = 1 /* _BinaryenSubInt128 */
}

/** Binaryen wide integer multiply operation constants. */
export const enum WideIntMulOp {
/** i64.mul_wide_s */
SignedI64 = 0 /* _BinaryenMulWideSInt64 */,
/** i64.mul_wide_u */
UnsignedI64 = 1 /* _BinaryenMulWideUInt64 */
}

/** Binaryen BrOn operation constants. */
Expand Down Expand Up @@ -1511,6 +1529,24 @@ export class Module {
return binaryen._BinaryenBinary(this.ref, op, left, right);
}

wide_int_add_sub(
op: WideIntAddSubOp,
leftLow: ExpressionRef,
leftHigh: ExpressionRef,
rightLow: ExpressionRef,
rightHigh: ExpressionRef
): ExpressionRef {
return binaryen._BinaryenWideIntAddSub(this.ref, op, leftLow, leftHigh, rightLow, rightHigh);
}

wide_int_mul(
op: WideIntMulOp,
left: ExpressionRef,
right: ExpressionRef
): ExpressionRef {
return binaryen._BinaryenWideIntMul(this.ref, op, left, right);
}

memory_size(name: string = CommonNames.DefaultMemory, is64: bool = false): ExpressionRef {
let cStr = this.allocStringCached(name);
return binaryen._BinaryenMemorySize(this.ref, cStr, is64);
Expand Down Expand Up @@ -2450,6 +2486,14 @@ export class Module {
binaryen._free(cArr);
}

/** Ensures that an empty function table of the given name exists, to be sized and filled later. */
ensureFunctionTable(name: string): void {
let cStr = this.allocStringCached(name);
if (!binaryen._BinaryenGetTable(this.ref, cStr)) {
binaryen._BinaryenAddTable(this.ref, cStr, 0, Module.UNLIMITED_TABLE, TypeRef.Funcref);
}
}

/* setFunctionTable(
initial: Index,
maximum: Index,
Expand Down
9 changes: 1 addition & 8 deletions tests/compiler/assert-nonnull.release.wat
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(module
(type $0 (func (param i32) (result i32)))
(type $1 (func (result i32)))
(type $2 (func (param i32 i32 i32 i32)))
(type $1 (func (param i32 i32 i32 i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 34236))
(memory $0 1)
Expand All @@ -15,7 +14,6 @@
(data $3.1 (i32.const 1304) "\02\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
(data $4 (i32.const 1340) "|")
(data $4.1 (i32.const 1352) "\02\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y")
(table $0 1 1 funcref)
(export "memory" (memory $0))
(export "testVar" (func $export:assert-nonnull/testVar))
(export "testObj" (func $export:assert-nonnull/testObj))
Expand Down Expand Up @@ -165,7 +163,6 @@
br_if $folding-inner1
local.get $0
i32.load
call_indirect (type $1)
unreachable
end
i32.const 34256
Expand Down Expand Up @@ -283,7 +280,6 @@
br_if $folding-inner1
local.get $0
i32.load
call_indirect (type $1)
unreachable
end
i32.const 34256
Expand Down Expand Up @@ -344,7 +340,6 @@
end
local.get $0
i32.load
call_indirect (type $1)
unreachable
end
i32.const 34256
Expand Down Expand Up @@ -456,7 +451,6 @@
i32.store offset=4
local.get $0
i32.load
call_indirect (type $1)
unreachable
end
i32.const 34256
Expand Down Expand Up @@ -505,7 +499,6 @@
end
local.get $0
i32.load
call_indirect (type $1)
unreachable
end
i32.const 34256
Expand Down
20 changes: 10 additions & 10 deletions tests/compiler/features/relaxed-simd.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,42 @@
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i8x16.laneselect
i8x16.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i8x16.laneselect
i8x16.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i16x8.laneselect
i16x8.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i16x8.laneselect
i16x8.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i32x4.laneselect
i32x4.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i32x4.laneselect
i32x4.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i64x2.laneselect
i64x2.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i64x2.laneselect
i64x2.relaxed_laneselect
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
Expand Down Expand Up @@ -162,11 +162,11 @@
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i16x8.dot_i8x16_i7x16_s
i16x8.relaxed_dot_i8x16_i7x16_s
global.set $features/relaxed-simd/r
global.get $features/relaxed-simd/v
global.get $features/relaxed-simd/v
i16x8.dot_i8x16_i7x16_s
i16x8.relaxed_dot_i8x16_i7x16_s
global.set $features/relaxed-simd/r
)
(func $~start
Expand Down
5 changes: 3 additions & 2 deletions tests/compiler/ternary.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
select
)
(func $export:ternary/testVoidInclTypeMismatch (param $0 i32) (param $1 i32)
(local $2 i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
Expand All @@ -68,11 +69,11 @@
i32.store
local.get $1
i32.load
local.tee $2
call_indirect (type $0)
local.get $0
if
local.get $1
i32.load
local.get $2
call_indirect (type $0)
end
local.get $0
Expand Down
Loading