This commit is contained in:
dcode 2019-05-24 12:16:14 +02:00
parent 792b366769
commit c41c57e6d6
6 changed files with 1294 additions and 1285 deletions

View File

@ -19,7 +19,7 @@ function rtrace(onerror) {
onfree: function(block) { onfree: function(block) {
++rtrace.freeCount; ++rtrace.freeCount;
if (!blocks.has(block)) { if (!blocks.has(block)) {
onerror(Error("invalid free: " + block)); onerror(Error("orphaned free: " + block));
} else { } else {
blocks.delete(block); blocks.delete(block);
} }
@ -28,7 +28,7 @@ function rtrace(onerror) {
onincrement: function(block) { onincrement: function(block) {
++rtrace.incrementCount; ++rtrace.incrementCount;
if (!blocks.has(block)) { if (!blocks.has(block)) {
onerror(Error("invalid increment: " + block)); onerror(Error("orphaned increment: " + block));
} else { } else {
let rc = blocks.get(block) + 1; let rc = blocks.get(block) + 1;
blocks.set(block, rc); blocks.set(block, rc);
@ -38,7 +38,7 @@ function rtrace(onerror) {
ondecrement: function(block) { ondecrement: function(block) {
++rtrace.decrementCount; ++rtrace.decrementCount;
if (!blocks.has(block)) { if (!blocks.has(block)) {
onerror(Error("invalid decrement: " + block)); onerror(Error("orphaned decrement: " + block));
} else { } else {
let rc = blocks.get(block) - 1; let rc = blocks.get(block) - 1;
if (rc < 0) { if (rc < 0) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -296,7 +296,7 @@ export class Flow {
} }
/** Gets a free temporary local of the specified type. */ /** Gets a free temporary local of the specified type. */
getTempLocal(type: Type, wrapped: bool = false, nonNull: bool = false): Local { getTempLocal(type: Type): Local {
var parentFunction = this.parentFunction; var parentFunction = this.parentFunction;
var temps: Local[] | null; var temps: Local[] | null;
switch (type.toNativeType()) { switch (type.toNativeType()) {
@ -315,13 +315,7 @@ export class Flow {
} else { } else {
local = parentFunction.addLocal(type); local = parentFunction.addLocal(type);
} }
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) { this.unsetLocalFlag(local.index, ~0);
if (wrapped) this.setLocalFlag(local.index, LocalFlags.WRAPPED);
else this.unsetLocalFlag(local.index, LocalFlags.WRAPPED);
} else {
if (nonNull) this.setLocalFlag(local.index, LocalFlags.NONNULL);
else this.unsetLocalFlag(local.index, LocalFlags.NONNULL);
}
return local; return local;
} }
@ -371,7 +365,7 @@ export class Flow {
} }
/** Gets and immediately frees a temporary local of the specified type. */ /** Gets and immediately frees a temporary local of the specified type. */
getAndFreeTempLocal(type: Type, wrapped: bool = false, nonnull: bool = false): Local { getAndFreeTempLocal(type: Type): Local {
var parentFunction = this.parentFunction; var parentFunction = this.parentFunction;
var temps: Local[]; var temps: Local[];
switch (type.toNativeType()) { switch (type.toNativeType()) {
@ -405,18 +399,12 @@ export class Flow {
local = parentFunction.addLocal(type); local = parentFunction.addLocal(type);
temps.push(local); temps.push(local);
} }
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) { this.unsetLocalFlag(local.index, ~0);
if (wrapped) this.setLocalFlag(local.index, LocalFlags.WRAPPED);
else this.unsetLocalFlag(local.index, LocalFlags.WRAPPED);
} else {
if (nonnull) this.setLocalFlag(local.index, LocalFlags.NONNULL);
else this.unsetLocalFlag(local.index, LocalFlags.NONNULL);
}
return local; return local;
} }
/** Adds a new scoped local of the specified name. */ /** Adds a new scoped local of the specified name. */
addScopedLocal(name: string, type: Type, wrapped: bool, reportNode: Node | null = null): Local { addScopedLocal(name: string, type: Type, reportNode: Node | null = null): Local {
var scopedLocal = this.getTempLocal(type); var scopedLocal = this.getTempLocal(type);
if (!this.scopedLocals) this.scopedLocals = new Map(); if (!this.scopedLocals) this.scopedLocals = new Map();
else { else {
@ -433,10 +421,6 @@ export class Flow {
} }
scopedLocal.set(CommonFlags.SCOPED); scopedLocal.set(CommonFlags.SCOPED);
this.scopedLocals.set(name, scopedLocal); this.scopedLocals.set(name, scopedLocal);
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
if (wrapped) this.setLocalFlag(scopedLocal.index, LocalFlags.WRAPPED);
else this.unsetLocalFlag(scopedLocal.index, LocalFlags.WRAPPED);
}
return scopedLocal; return scopedLocal;
} }
@ -635,7 +619,7 @@ export class Flow {
} }
/** Checks if an expression of the specified type is known to be non-null, even if the type might be nullable. */ /** Checks if an expression of the specified type is known to be non-null, even if the type might be nullable. */
isNonnull(type: Type, expr: ExpressionRef): bool { isNonnull(expr: ExpressionRef, type: Type): bool {
if (!type.is(TypeFlags.NULLABLE)) return true; if (!type.is(TypeFlags.NULLABLE)) return true;
// below, only teeLocal/getLocal are relevant because these are the only expressions that // below, only teeLocal/getLocal are relevant because these are the only expressions that
// depend on a dynamic nullable state (flag = LocalFlags.NONNULL), while everything else // depend on a dynamic nullable state (flag = LocalFlags.NONNULL), while everything else

View File

@ -459,31 +459,31 @@ export class Module {
// constants // constants
createI32(value: i32): ExpressionRef { i32(value: i32): ExpressionRef {
var out = this.lit; var out = this.lit;
_BinaryenLiteralInt32(out, value); _BinaryenLiteralInt32(out, value);
return _BinaryenConst(this.ref, out); return _BinaryenConst(this.ref, out);
} }
createI64(valueLow: i32, valueHigh: i32 = 0): ExpressionRef { i64(valueLow: i32, valueHigh: i32 = 0): ExpressionRef {
var out = this.lit; var out = this.lit;
_BinaryenLiteralInt64(out, valueLow, valueHigh); _BinaryenLiteralInt64(out, valueLow, valueHigh);
return _BinaryenConst(this.ref, out); return _BinaryenConst(this.ref, out);
} }
createF32(value: f32): ExpressionRef { f32(value: f32): ExpressionRef {
var out = this.lit; var out = this.lit;
_BinaryenLiteralFloat32(out, value); _BinaryenLiteralFloat32(out, value);
return _BinaryenConst(this.ref, out); return _BinaryenConst(this.ref, out);
} }
createF64(value: f64): ExpressionRef { f64(value: f64): ExpressionRef {
var out = this.lit; var out = this.lit;
_BinaryenLiteralFloat64(out, value); _BinaryenLiteralFloat64(out, value);
return _BinaryenConst(this.ref, out); return _BinaryenConst(this.ref, out);
} }
createV128(bytes: Uint8Array): ExpressionRef { v128(bytes: Uint8Array): ExpressionRef {
assert(bytes.length == 16); assert(bytes.length == 16);
var out = this.lit; var out = this.lit;
for (let i = 0; i < 16; ++i) store<u8>(out + i, bytes[i]); for (let i = 0; i < 16; ++i) store<u8>(out + i, bytes[i]);
@ -493,14 +493,14 @@ export class Module {
// expressions // expressions
createUnary( unary(
op: UnaryOp, op: UnaryOp,
expr: ExpressionRef expr: ExpressionRef
): ExpressionRef { ): ExpressionRef {
return _BinaryenUnary(this.ref, op, expr); return _BinaryenUnary(this.ref, op, expr);
} }
createBinary( binary(
op: BinaryOp, op: BinaryOp,
left: ExpressionRef, left: ExpressionRef,
right: ExpressionRef right: ExpressionRef
@ -508,7 +508,7 @@ export class Module {
return _BinaryenBinary(this.ref, op, left, right); return _BinaryenBinary(this.ref, op, left, right);
} }
createHost( host(
op: HostOp, op: HostOp,
name: string | null = null, name: string | null = null,
operands: ExpressionRef[] | null = null operands: ExpressionRef[] | null = null
@ -522,21 +522,21 @@ export class Module {
} }
} }
createGetLocal( local_get(
index: i32, index: i32,
type: NativeType type: NativeType
): ExpressionRef { ): ExpressionRef {
return _BinaryenLocalGet(this.ref, index, type); return _BinaryenLocalGet(this.ref, index, type);
} }
createTeeLocal( local_tee(
index: i32, index: i32,
value: ExpressionRef value: ExpressionRef
): ExpressionRef { ): ExpressionRef {
return _BinaryenLocalTee(this.ref, index, value); return _BinaryenLocalTee(this.ref, index, value);
} }
createGetGlobal( global_get(
name: string, name: string,
type: NativeType type: NativeType
): ExpressionRef { ): ExpressionRef {
@ -544,7 +544,7 @@ export class Module {
return _BinaryenGlobalGet(this.ref, cStr, type); return _BinaryenGlobalGet(this.ref, cStr, type);
} }
createLoad( load(
bytes: Index, bytes: Index,
signed: bool, signed: bool,
ptr: ExpressionRef, ptr: ExpressionRef,
@ -555,7 +555,7 @@ export class Module {
return _BinaryenLoad(this.ref, bytes, signed ? 1 : 0, offset, align, type, ptr); return _BinaryenLoad(this.ref, bytes, signed ? 1 : 0, offset, align, type, ptr);
} }
createStore( store(
bytes: Index, bytes: Index,
ptr: ExpressionRef, ptr: ExpressionRef,
value: ExpressionRef, value: ExpressionRef,
@ -567,7 +567,7 @@ export class Module {
return _BinaryenStore(this.ref, bytes, offset, align, ptr, value, type); return _BinaryenStore(this.ref, bytes, offset, align, ptr, value, type);
} }
createAtomicLoad( atomic_load(
bytes: Index, bytes: Index,
ptr: ExpressionRef, ptr: ExpressionRef,
type: NativeType, type: NativeType,
@ -576,7 +576,7 @@ export class Module {
return _BinaryenAtomicLoad(this.ref, bytes, offset, type, ptr); return _BinaryenAtomicLoad(this.ref, bytes, offset, type, ptr);
} }
createAtomicStore( atomic_store(
bytes: Index, bytes: Index,
ptr: ExpressionRef, ptr: ExpressionRef,
value: ExpressionRef, value: ExpressionRef,
@ -586,7 +586,7 @@ export class Module {
return _BinaryenAtomicStore(this.ref, bytes, offset, ptr, value, type); return _BinaryenAtomicStore(this.ref, bytes, offset, ptr, value, type);
} }
createAtomicRMW( atomic_rmw(
op: AtomicRMWOp, op: AtomicRMWOp,
bytes: Index, bytes: Index,
offset: Index, offset: Index,
@ -597,7 +597,7 @@ export class Module {
return _BinaryenAtomicRMW(this.ref, op, bytes, offset, ptr, value, type); return _BinaryenAtomicRMW(this.ref, op, bytes, offset, ptr, value, type);
} }
createAtomicCmpxchg( atomic_cmpxchg(
bytes: Index, bytes: Index,
offset: Index, offset: Index,
ptr: ExpressionRef, ptr: ExpressionRef,
@ -608,7 +608,7 @@ export class Module {
return _BinaryenAtomicCmpxchg(this.ref, bytes, offset, ptr, expected, replacement, type); return _BinaryenAtomicCmpxchg(this.ref, bytes, offset, ptr, expected, replacement, type);
} }
createAtomicWait( atomic_wait(
ptr: ExpressionRef, ptr: ExpressionRef,
expected: ExpressionRef, expected: ExpressionRef,
timeout: ExpressionRef, timeout: ExpressionRef,
@ -617,7 +617,7 @@ export class Module {
return _BinaryenAtomicWait(this.ref, ptr, expected, timeout, expectedType); return _BinaryenAtomicWait(this.ref, ptr, expected, timeout, expectedType);
} }
createAtomicNotify( atomic_notify(
ptr: ExpressionRef, ptr: ExpressionRef,
notifyCount: ExpressionRef notifyCount: ExpressionRef
): ExpressionRef { ): ExpressionRef {
@ -626,14 +626,14 @@ export class Module {
// statements // statements
createSetLocal( local_set(
index: Index, index: Index,
value: ExpressionRef value: ExpressionRef
): ExpressionRef { ): ExpressionRef {
return _BinaryenLocalSet(this.ref, index, value); return _BinaryenLocalSet(this.ref, index, value);
} }
createSetGlobal( global_set(
name: string, name: string,
value: ExpressionRef value: ExpressionRef
): ExpressionRef { ): ExpressionRef {
@ -641,7 +641,7 @@ export class Module {
return _BinaryenGlobalSet(this.ref, cStr, value); return _BinaryenGlobalSet(this.ref, cStr, value);
} }
createBlock( block(
label: string | null, label: string | null,
children: ExpressionRef[], children: ExpressionRef[],
type: NativeType = NativeType.None type: NativeType = NativeType.None
@ -655,7 +655,7 @@ export class Module {
} }
} }
createBreak( br(
label: string | null, label: string | null,
condition: ExpressionRef = 0, condition: ExpressionRef = 0,
value: ExpressionRef = 0 value: ExpressionRef = 0
@ -664,13 +664,13 @@ export class Module {
return _BinaryenBreak(this.ref, cStr, condition, value); return _BinaryenBreak(this.ref, cStr, condition, value);
} }
createDrop( drop(
expression: ExpressionRef expression: ExpressionRef
): ExpressionRef { ): ExpressionRef {
return _BinaryenDrop(this.ref, expression); return _BinaryenDrop(this.ref, expression);
} }
createLoop( loop(
label: string | null, label: string | null,
body: ExpressionRef body: ExpressionRef
): ExpressionRef { ): ExpressionRef {
@ -678,7 +678,7 @@ export class Module {
return _BinaryenLoop(this.ref, cStr, body); return _BinaryenLoop(this.ref, cStr, body);
} }
createIf( if(
condition: ExpressionRef, condition: ExpressionRef,
ifTrue: ExpressionRef, ifTrue: ExpressionRef,
ifFalse: ExpressionRef = 0 ifFalse: ExpressionRef = 0
@ -686,17 +686,17 @@ export class Module {
return _BinaryenIf(this.ref, condition, ifTrue, ifFalse); return _BinaryenIf(this.ref, condition, ifTrue, ifFalse);
} }
createNop(): ExpressionRef { nop(): ExpressionRef {
return _BinaryenNop(this.ref); return _BinaryenNop(this.ref);
} }
createReturn( return(
expression: ExpressionRef = 0 expression: ExpressionRef = 0
): ExpressionRef { ): ExpressionRef {
return _BinaryenReturn(this.ref, expression); return _BinaryenReturn(this.ref, expression);
} }
createSelect( select(
ifTrue: ExpressionRef, ifTrue: ExpressionRef,
ifFalse: ExpressionRef, ifFalse: ExpressionRef,
condition: ExpressionRef condition: ExpressionRef
@ -704,7 +704,7 @@ export class Module {
return _BinaryenSelect(this.ref, condition, ifTrue, ifFalse); return _BinaryenSelect(this.ref, condition, ifTrue, ifFalse);
} }
createSwitch( switch(
names: string[], names: string[],
defaultName: string | null, defaultName: string | null,
condition: ExpressionRef, condition: ExpressionRef,
@ -724,7 +724,7 @@ export class Module {
} }
} }
createCall( call(
target: string, target: string,
operands: ExpressionRef[] | null, operands: ExpressionRef[] | null,
returnType: NativeType returnType: NativeType
@ -738,7 +738,7 @@ export class Module {
} }
} }
createCallIndirect( call_indirect(
index: ExpressionRef, index: ExpressionRef,
operands: ExpressionRef[] | null, operands: ExpressionRef[] | null,
typeName: string typeName: string
@ -752,13 +752,13 @@ export class Module {
} }
} }
createUnreachable(): ExpressionRef { unreachable(): ExpressionRef {
return _BinaryenUnreachable(this.ref); return _BinaryenUnreachable(this.ref);
} }
// bulk memory // bulk memory
createMemoryCopy( memory_copy(
dest: ExpressionRef, dest: ExpressionRef,
source: ExpressionRef, source: ExpressionRef,
size: ExpressionRef size: ExpressionRef
@ -766,7 +766,7 @@ export class Module {
return _BinaryenMemoryCopy(this.ref, dest, source, size); return _BinaryenMemoryCopy(this.ref, dest, source, size);
} }
createMemoryFill( memory_fill(
dest: ExpressionRef, dest: ExpressionRef,
value: ExpressionRef, value: ExpressionRef,
size: ExpressionRef size: ExpressionRef
@ -776,7 +776,7 @@ export class Module {
// simd // simd
createSIMDExtract( simd_extract(
op: SIMDExtractOp, op: SIMDExtractOp,
vec: ExpressionRef, vec: ExpressionRef,
idx: u8 idx: u8
@ -784,7 +784,7 @@ export class Module {
return _BinaryenSIMDExtract(this.ref, op, vec, idx); return _BinaryenSIMDExtract(this.ref, op, vec, idx);
} }
createSIMDReplace( simd_replace(
op: SIMDReplaceOp, op: SIMDReplaceOp,
vec: ExpressionRef, vec: ExpressionRef,
idx: u8, idx: u8,
@ -793,7 +793,7 @@ export class Module {
return _BinaryenSIMDReplace(this.ref, op, vec, idx, value); return _BinaryenSIMDReplace(this.ref, op, vec, idx, value);
} }
createSIMDShuffle( simd_shuffle(
vec1: ExpressionRef, vec1: ExpressionRef,
vec2: ExpressionRef, vec2: ExpressionRef,
mask: Uint8Array mask: Uint8Array
@ -807,7 +807,7 @@ export class Module {
} }
} }
createSIMDBitselect( simd_bitselect(
vec1: ExpressionRef, vec1: ExpressionRef,
vec2: ExpressionRef, vec2: ExpressionRef,
cond: ExpressionRef cond: ExpressionRef
@ -815,7 +815,7 @@ export class Module {
return _BinaryenSIMDBitselect(this.ref, vec1, vec2, cond); return _BinaryenSIMDBitselect(this.ref, vec1, vec2, cond);
} }
createSIMDShift( simd_shift(
op: SIMDShiftOp, op: SIMDShiftOp,
vec: ExpressionRef, vec: ExpressionRef,
shift: ExpressionRef shift: ExpressionRef
@ -994,8 +994,8 @@ export class Module {
segs[i] = allocU8Array(buffer); segs[i] = allocU8Array(buffer);
psvs[i] = 0; // no passive segments currently psvs[i] = 0; // no passive segments currently
offs[i] = target == Target.WASM64 offs[i] = target == Target.WASM64
? this.createI64(i64_low(offset), i64_high(offset)) ? this.i64(i64_low(offset), i64_high(offset))
: this.createI32(i64_low(offset)); : this.i32(i64_low(offset));
sizs[i] = buffer.length; sizs[i] = buffer.length;
} }
var cArr1 = allocI32Array(segs); var cArr1 = allocI32Array(segs);
@ -1198,19 +1198,19 @@ export class Module {
case ExpressionId.Const: { case ExpressionId.Const: {
switch (_BinaryenExpressionGetType(expr)) { switch (_BinaryenExpressionGetType(expr)) {
case NativeType.I32: { case NativeType.I32: {
return this.createI32(_BinaryenConstGetValueI32(expr)); return this.i32(_BinaryenConstGetValueI32(expr));
} }
case NativeType.I64: { case NativeType.I64: {
return this.createI64( return this.i64(
_BinaryenConstGetValueI64Low(expr), _BinaryenConstGetValueI64Low(expr),
_BinaryenConstGetValueI64High(expr) _BinaryenConstGetValueI64High(expr)
); );
} }
case NativeType.F32: { case NativeType.F32: {
return this.createF32(_BinaryenConstGetValueF32(expr)); return this.f32(_BinaryenConstGetValueF32(expr));
} }
case NativeType.F64: { case NativeType.F64: {
return this.createF64(_BinaryenConstGetValueF64(expr)); return this.f64(_BinaryenConstGetValueF64(expr));
} }
case NativeType.V128: { case NativeType.V128: {
// TODO // TODO
@ -1792,43 +1792,43 @@ export function needsExplicitUnreachable(expr: ExpressionRef): bool {
} }
/** Traverses all expression members of an expression, calling the given visitor. */ /** Traverses all expression members of an expression, calling the given visitor. */
export function traverse(expr: ExpressionRef, visit: (expr: ExpressionRef) => bool): bool { export function traverse<T>(expr: ExpressionRef, data: T, visit: (expr: ExpressionRef, data: T) => bool): bool {
switch (getExpressionId(expr)) { switch (getExpressionId(expr)) {
case ExpressionId.Block: { case ExpressionId.Block: {
for (let i = 0, n = _BinaryenBlockGetNumChildren(expr); i < n; ++i) { for (let i = 0, n = _BinaryenBlockGetNumChildren(expr); i < n; ++i) {
if (!visit(_BinaryenBlockGetChild(expr, i))) return false; if (!visit(_BinaryenBlockGetChild(expr, i), data)) return false;
} }
break; break;
} }
case ExpressionId.If: { case ExpressionId.If: {
if (!visit(_BinaryenIfGetCondition(expr))) return false; if (!visit(_BinaryenIfGetCondition(expr), data)) return false;
if (!visit(_BinaryenIfGetIfTrue(expr))) return false; if (!visit(_BinaryenIfGetIfTrue(expr), data)) return false;
let ifFalse = _BinaryenIfGetIfFalse(expr); let ifFalse = _BinaryenIfGetIfFalse(expr);
if (ifFalse) if (!visit(ifFalse)) return false; if (ifFalse) if (!visit(ifFalse, data)) return false;
break; break;
} }
case ExpressionId.Loop: { case ExpressionId.Loop: {
if (!visit(_BinaryenLoopGetBody(expr))) return false; if (!visit(_BinaryenLoopGetBody(expr), data)) return false;
break; break;
} }
case ExpressionId.Break: { case ExpressionId.Break: {
let condition = _BinaryenBreakGetCondition(expr); let condition = _BinaryenBreakGetCondition(expr);
if (condition) if (!visit(condition)) return false; if (condition) if (!visit(condition, data)) return false;
break; break;
} }
case ExpressionId.Switch: { case ExpressionId.Switch: {
if (!visit(_BinaryenSwitchGetCondition(expr))) return false; if (!visit(_BinaryenSwitchGetCondition(expr), data)) return false;
break; break;
} }
case ExpressionId.Call: { case ExpressionId.Call: {
for (let i = 0, n = _BinaryenCallGetNumOperands(expr); i < n; ++i) { for (let i = 0, n = _BinaryenCallGetNumOperands(expr); i < n; ++i) {
if (!visit(_BinaryenCallGetOperand(expr, i))) return false; if (!visit(_BinaryenCallGetOperand(expr, i), data)) return false;
} }
break; break;
} }
case ExpressionId.CallIndirect: { case ExpressionId.CallIndirect: {
for (let i = 0, n = _BinaryenCallIndirectGetNumOperands(expr); i < n; ++i) { for (let i = 0, n = _BinaryenCallIndirectGetNumOperands(expr); i < n; ++i) {
if (!visit(_BinaryenCallIndirectGetOperand(expr, i))) return false; if (!visit(_BinaryenCallIndirectGetOperand(expr, i), data)) return false;
} }
break; break;
} }
@ -1836,121 +1836,121 @@ export function traverse(expr: ExpressionRef, visit: (expr: ExpressionRef) => bo
break; break;
} }
case ExpressionId.LocalSet: { case ExpressionId.LocalSet: {
if (!visit(_BinaryenLocalSetGetValue(expr))) return false; if (!visit(_BinaryenLocalSetGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.GlobalGet: { case ExpressionId.GlobalGet: {
break; break;
} }
case ExpressionId.GlobalSet: { case ExpressionId.GlobalSet: {
if (!visit(_BinaryenGlobalSetGetValue(expr))) return false; if (!visit(_BinaryenGlobalSetGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.Load: { case ExpressionId.Load: {
if (!visit(_BinaryenLoadGetPtr(expr))) return false; if (!visit(_BinaryenLoadGetPtr(expr), data)) return false;
break; break;
} }
case ExpressionId.Store: { case ExpressionId.Store: {
if (!visit(_BinaryenStoreGetPtr(expr))) return false; if (!visit(_BinaryenStoreGetPtr(expr), data)) return false;
if (!visit(_BinaryenStoreGetValue(expr))) return false; if (!visit(_BinaryenStoreGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.AtomicRMW: { case ExpressionId.AtomicRMW: {
if (!visit(_BinaryenAtomicRMWGetPtr(expr))) return false; if (!visit(_BinaryenAtomicRMWGetPtr(expr), data)) return false;
if (!visit(_BinaryenAtomicRMWGetValue(expr))) return false; if (!visit(_BinaryenAtomicRMWGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.AtomicCmpxchg: { case ExpressionId.AtomicCmpxchg: {
if (!visit(_BinaryenAtomicCmpxchgGetPtr(expr))) return false; if (!visit(_BinaryenAtomicCmpxchgGetPtr(expr), data)) return false;
if (!visit(_BinaryenAtomicCmpxchgGetExpected(expr))) return false; if (!visit(_BinaryenAtomicCmpxchgGetExpected(expr), data)) return false;
if (!visit(_BinaryenAtomicCmpxchgGetReplacement(expr))) return false; if (!visit(_BinaryenAtomicCmpxchgGetReplacement(expr), data)) return false;
break; break;
} }
case ExpressionId.AtomicWait: { case ExpressionId.AtomicWait: {
if (!visit(_BinaryenAtomicWaitGetPtr(expr))) return false; if (!visit(_BinaryenAtomicWaitGetPtr(expr), data)) return false;
if (!visit(_BinaryenAtomicWaitGetExpected(expr))) return false; if (!visit(_BinaryenAtomicWaitGetExpected(expr), data)) return false;
if (!visit(_BinaryenAtomicWaitGetTimeout(expr))) return false; if (!visit(_BinaryenAtomicWaitGetTimeout(expr), data)) return false;
break; break;
} }
case ExpressionId.AtomicNotify: { case ExpressionId.AtomicNotify: {
if (!visit(_BinaryenAtomicNotifyGetPtr(expr))) return false; if (!visit(_BinaryenAtomicNotifyGetPtr(expr), data)) return false;
break; break;
} }
case ExpressionId.SIMDExtract: { case ExpressionId.SIMDExtract: {
if (!visit(_BinaryenSIMDExtractGetVec(expr))) return false; if (!visit(_BinaryenSIMDExtractGetVec(expr), data)) return false;
break; break;
} }
case ExpressionId.SIMDReplace: { case ExpressionId.SIMDReplace: {
if (!visit(_BinaryenSIMDReplaceGetVec(expr))) return false; if (!visit(_BinaryenSIMDReplaceGetVec(expr), data)) return false;
if (!visit(_BinaryenSIMDReplaceGetValue(expr))) return false; if (!visit(_BinaryenSIMDReplaceGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.SIMDShuffle: { case ExpressionId.SIMDShuffle: {
if (!visit(_BinaryenSIMDShuffleGetLeft(expr))) return false; if (!visit(_BinaryenSIMDShuffleGetLeft(expr), data)) return false;
if (!visit(_BinaryenSIMDShuffleGetRight(expr))) return false; if (!visit(_BinaryenSIMDShuffleGetRight(expr), data)) return false;
break; break;
} }
case ExpressionId.SIMDBitselect: { case ExpressionId.SIMDBitselect: {
if (!visit(_BinaryenSIMDBitselectGetLeft(expr))) return false; if (!visit(_BinaryenSIMDBitselectGetLeft(expr), data)) return false;
if (!visit(_BinaryenSIMDBitselectGetRight(expr))) return false; if (!visit(_BinaryenSIMDBitselectGetRight(expr), data)) return false;
if (!visit(_BinaryenSIMDBitselectGetCond(expr))) return false; if (!visit(_BinaryenSIMDBitselectGetCond(expr), data)) return false;
break; break;
} }
case ExpressionId.SIMDShift: { case ExpressionId.SIMDShift: {
if (!visit(_BinaryenSIMDShiftGetVec(expr))) return false; if (!visit(_BinaryenSIMDShiftGetVec(expr), data)) return false;
if (!visit(_BinaryenSIMDShiftGetShift(expr))) return false; if (!visit(_BinaryenSIMDShiftGetShift(expr), data)) return false;
break; break;
} }
case ExpressionId.MemoryInit: { case ExpressionId.MemoryInit: {
if (!visit(_BinaryenMemoryInitGetDest(expr))) return false; if (!visit(_BinaryenMemoryInitGetDest(expr), data)) return false;
if (!visit(_BinaryenMemoryInitGetOffset(expr))) return false; if (!visit(_BinaryenMemoryInitGetOffset(expr), data)) return false;
if (!visit(_BinaryenMemoryInitGetSize(expr))) return false; if (!visit(_BinaryenMemoryInitGetSize(expr), data)) return false;
break; break;
} }
case ExpressionId.DataDrop: { case ExpressionId.DataDrop: {
break; break;
} }
case ExpressionId.MemoryCopy: { case ExpressionId.MemoryCopy: {
if (!visit(_BinaryenMemoryCopyGetDest(expr))) return false; if (!visit(_BinaryenMemoryCopyGetDest(expr), data)) return false;
if (!visit(_BinaryenMemoryCopyGetSource(expr))) return false; if (!visit(_BinaryenMemoryCopyGetSource(expr), data)) return false;
if (!visit(_BinaryenMemoryCopyGetSize(expr))) return false; if (!visit(_BinaryenMemoryCopyGetSize(expr), data)) return false;
break; break;
} }
case ExpressionId.MemoryFill: { case ExpressionId.MemoryFill: {
if (!visit(_BinaryenMemoryFillGetDest(expr))) return false; if (!visit(_BinaryenMemoryFillGetDest(expr), data)) return false;
if (!visit(_BinaryenMemoryFillGetValue(expr))) return false; if (!visit(_BinaryenMemoryFillGetValue(expr), data)) return false;
if (!visit(_BinaryenMemoryFillGetSize(expr))) return false; if (!visit(_BinaryenMemoryFillGetSize(expr), data)) return false;
break; break;
} }
case ExpressionId.Const: { case ExpressionId.Const: {
break; break;
} }
case ExpressionId.Unary: { case ExpressionId.Unary: {
if (!visit(_BinaryenUnaryGetValue(expr))) return false; if (!visit(_BinaryenUnaryGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.Binary: { case ExpressionId.Binary: {
if (!visit(_BinaryenBinaryGetLeft(expr))) return false; if (!visit(_BinaryenBinaryGetLeft(expr), data)) return false;
if (!visit(_BinaryenBinaryGetRight(expr))) return false; if (!visit(_BinaryenBinaryGetRight(expr), data)) return false;
break; break;
} }
case ExpressionId.Select: { case ExpressionId.Select: {
if (!visit(_BinaryenSelectGetIfTrue(expr))) return false; if (!visit(_BinaryenSelectGetIfTrue(expr), data)) return false;
if (!visit(_BinaryenSelectGetIfFalse(expr))) return false; if (!visit(_BinaryenSelectGetIfFalse(expr), data)) return false;
if (!visit(_BinaryenSelectGetCondition(expr))) return false; if (!visit(_BinaryenSelectGetCondition(expr), data)) return false;
break; break;
} }
case ExpressionId.Drop: { case ExpressionId.Drop: {
if (!visit(_BinaryenDropGetValue(expr))) return false; if (!visit(_BinaryenDropGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.Return: { case ExpressionId.Return: {
if (!visit(_BinaryenReturnGetValue(expr))) return false; if (!visit(_BinaryenReturnGetValue(expr), data)) return false;
break; break;
} }
case ExpressionId.Host: { case ExpressionId.Host: {
for (let i = 0, n = _BinaryenHostGetNumOperands(expr); i < n; ++i) { for (let i = 0, n = _BinaryenHostGetNumOperands(expr); i < n; ++i) {
if (!visit(_BinaryenHostGetOperand(expr, i))) return false; if (!visit(_BinaryenHostGetOperand(expr, i), data)) return false;
} }
break; break;
} }

View File

@ -332,14 +332,14 @@ export class Type {
toNativeZero(module: Module): ExpressionRef { toNativeZero(module: Module): ExpressionRef {
switch (this.kind) { switch (this.kind) {
case TypeKind.VOID: assert(false); case TypeKind.VOID: assert(false);
default: return module.createI32(0); default: return module.i32(0);
case TypeKind.ISIZE: case TypeKind.ISIZE:
case TypeKind.USIZE: if (this.size != 64) return module.createI32(0); case TypeKind.USIZE: if (this.size != 64) return module.i32(0);
case TypeKind.I64: case TypeKind.I64:
case TypeKind.U64: return module.createI64(0); case TypeKind.U64: return module.i64(0);
case TypeKind.F32: return module.createF32(0); case TypeKind.F32: return module.f32(0);
case TypeKind.F64: return module.createF64(0); case TypeKind.F64: return module.f64(0);
case TypeKind.V128: return module.createV128(v128_zero); case TypeKind.V128: return module.v128(v128_zero);
} }
} }
@ -348,13 +348,13 @@ export class Type {
switch (this.kind) { switch (this.kind) {
case TypeKind.V128: case TypeKind.V128:
case TypeKind.VOID: assert(false); case TypeKind.VOID: assert(false);
default: return module.createI32(1); default: return module.i32(1);
case TypeKind.ISIZE: case TypeKind.ISIZE:
case TypeKind.USIZE: if (this.size != 64) return module.createI32(1); case TypeKind.USIZE: if (this.size != 64) return module.i32(1);
case TypeKind.I64: case TypeKind.I64:
case TypeKind.U64: return module.createI64(1); case TypeKind.U64: return module.i64(1);
case TypeKind.F32: return module.createF32(1); case TypeKind.F32: return module.f32(1);
case TypeKind.F64: return module.createF64(1); case TypeKind.F64: return module.f64(1);
} }
} }
@ -363,13 +363,13 @@ export class Type {
switch (this.kind) { switch (this.kind) {
case TypeKind.V128: case TypeKind.V128:
case TypeKind.VOID: assert(false); case TypeKind.VOID: assert(false);
default: return module.createI32(-1); default: return module.i32(-1);
case TypeKind.ISIZE: case TypeKind.ISIZE:
case TypeKind.USIZE: if (this.size != 64) return module.createI32(-1); case TypeKind.USIZE: if (this.size != 64) return module.i32(-1);
case TypeKind.I64: case TypeKind.I64:
case TypeKind.U64: return module.createI64(-1, -1); case TypeKind.U64: return module.i64(-1, -1);
case TypeKind.F32: return module.createF32(-1); case TypeKind.F32: return module.f32(-1);
case TypeKind.F64: return module.createF64(-1); case TypeKind.F64: return module.f64(-1);
} }
} }