diff --git a/src/compiler.ts b/src/compiler.ts index 67e9bd71..c7017519 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -39,10 +39,10 @@ import { getBlockChild, getBlockName, needsExplicitUnreachable, - getGetLocalIndex, + getLocalGetIndex, FeatureFlags, - isTeeLocal, - getSetLocalIndex + isLocalTee, + getLocalSetIndex } from "./module"; import { @@ -2181,8 +2181,8 @@ export class Compiler extends DiagnosticEmitter { if (!this.skippedAutoreleases.has(expr)) { if (returnType.isManaged) { if (getExpressionId(expr) == ExpressionId.LocalGet) { - if (flow.isAnyLocalFlag(getGetLocalIndex(expr), LocalFlags.ANY_RETAINED)) { - flow.unsetLocalFlag(getGetLocalIndex(expr), LocalFlags.ANY_RETAINED); + if (flow.isAnyLocalFlag(getLocalGetIndex(expr), LocalFlags.ANY_RETAINED)) { + flow.unsetLocalFlag(getLocalGetIndex(expr), LocalFlags.ANY_RETAINED); this.skippedAutoreleases.add(expr); } } @@ -6243,9 +6243,9 @@ export class Compiler extends DiagnosticEmitter { let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS); let thisType = assert(instance.signature.thisType); if (canAlias && getExpressionId(thisArg) == ExpressionId.LocalGet) { - flow.addScopedAlias(CommonSymbols.this_, thisType, getGetLocalIndex(thisArg)); + flow.addScopedAlias(CommonSymbols.this_, thisType, getLocalGetIndex(thisArg)); let baseInstance = (classInstance).base; - if (baseInstance) flow.addScopedAlias(CommonSymbols.super_, baseInstance.type, getGetLocalIndex(thisArg)); + if (baseInstance) flow.addScopedAlias(CommonSymbols.super_, baseInstance.type, getLocalGetIndex(thisArg)); } else { let thisLocal = flow.addScopedLocal(CommonSymbols.this_, thisType); // No need to retain `this` as it can't be reassigned and thus can't become prematurely released @@ -6265,7 +6265,7 @@ export class Compiler extends DiagnosticEmitter { let paramExpr = args[i]; let paramType = parameterTypes[i]; if (canAlias && getExpressionId(paramExpr) == ExpressionId.LocalGet) { - flow.addScopedAlias(signature.getParameterName(i), paramType, getGetLocalIndex(paramExpr)); + flow.addScopedAlias(signature.getParameterName(i), paramType, getLocalGetIndex(paramExpr)); } else { let argumentLocal = flow.addScopedLocal(signature.getParameterName(i), paramType); // Normal function wouldn't know about wrap/nonnull states, but inlining does: @@ -6297,7 +6297,7 @@ export class Compiler extends DiagnosticEmitter { ContextualFlags.IMPLICIT ); if (canAlias && getExpressionId(initExpr) == ExpressionId.LocalGet) { - flow.addScopedAlias(signature.getParameterName(i), initType, getGetLocalIndex(initExpr)); + flow.addScopedAlias(signature.getParameterName(i), initType, getLocalGetIndex(initExpr)); } else { let argumentLocal = flow.addScopedLocal(signature.getParameterName(i), initType); if (!flow.canOverflow(initExpr, initType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.WRAPPED); @@ -6585,8 +6585,8 @@ export class Compiler extends DiagnosticEmitter { // make it optimize away. switch (getExpressionId(expr)) { case ExpressionId.LocalSet: { // local.tee(__retain(expr)) - if (isTeeLocal(expr)) { - let index = getSetLocalIndex(expr); + if (isLocalTee(expr)) { + let index = getLocalSetIndex(expr); if (flow.isAnyLocalFlag(index, LocalFlags.ANY_RETAINED)) { // Assumes that the expression actually belongs to the flow and that // top-level autoreleases are never undone. While that's true, it's diff --git a/src/decompiler.ts b/src/decompiler.ts index 3a49f3de..774c8fb8 100644 --- a/src/decompiler.ts +++ b/src/decompiler.ts @@ -30,9 +30,9 @@ import { getLoopBody, getBreakName, getBreakCondition, - getGetLocalIndex, - getSetLocalIndex, - getSetLocalValue, + getLocalGetIndex, + getLocalSetIndex, + getLocalSetValue, getLoadOffset, getLoadPtr, getStoreOffset, @@ -175,14 +175,14 @@ export class Decompiler { } case ExpressionId.LocalGet: { this.push("$"); - this.push(getGetLocalIndex(expr).toString(10)); + this.push(getLocalGetIndex(expr).toString(10)); return; } case ExpressionId.LocalSet: { this.push("$"); - this.push(getSetLocalIndex(expr).toString(10)); + this.push(getLocalSetIndex(expr).toString(10)); this.push(" = "); - this.decompileExpression(getSetLocalValue(expr)); + this.decompileExpression(getLocalSetValue(expr)); return; } case ExpressionId.GlobalGet: diff --git a/src/flow.ts b/src/flow.ts index 87cccfe2..2c541637 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -23,10 +23,10 @@ import { ExpressionRef, getExpressionId, - getGetLocalIndex, - isTeeLocal, - getSetLocalValue, - getGetGlobalName, + getLocalGetIndex, + isLocalTee, + getLocalSetValue, + getGlobalGetName, getBinaryOp, BinaryOp, getBinaryLeft, @@ -48,7 +48,7 @@ import { getSelectThen, getSelectElse, getCallTarget, - getSetLocalIndex, + getLocalSetIndex, getIfCondition, getConstValueI64High, getUnaryValue, @@ -612,12 +612,12 @@ export class Flow { // has already been handled by the nullable type check above. switch (getExpressionId(expr)) { case ExpressionId.LocalSet: { - if (!isTeeLocal(expr)) break; - let local = this.parentFunction.localsByIndex[getSetLocalIndex(expr)]; + if (!isLocalTee(expr)) break; + let local = this.parentFunction.localsByIndex[getLocalSetIndex(expr)]; return !local.type.is(TypeFlags.NULLABLE) || this.isLocalFlag(local.index, LocalFlags.NONNULL, false); } case ExpressionId.LocalGet: { - let local = this.parentFunction.localsByIndex[getGetLocalIndex(expr)]; + let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)]; return !local.type.is(TypeFlags.NULLABLE) || this.isLocalFlag(local.index, LocalFlags.NONNULL, false); } } @@ -629,14 +629,14 @@ export class Flow { // A: `expr` is true-ish -> Q: how did that happen? switch (getExpressionId(expr)) { case ExpressionId.LocalSet: { - if (!isTeeLocal(expr)) break; - let local = this.parentFunction.localsByIndex[getSetLocalIndex(expr)]; + if (!isLocalTee(expr)) break; + let local = this.parentFunction.localsByIndex[getLocalSetIndex(expr)]; this.setLocalFlag(local.index, LocalFlags.NONNULL); - this.inheritNonnullIfTrue(getSetLocalValue(expr)); // must have been true-ish as well + this.inheritNonnullIfTrue(getLocalSetValue(expr)); // must have been true-ish as well break; } case ExpressionId.LocalGet: { - let local = this.parentFunction.localsByIndex[getGetLocalIndex(expr)]; + let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)]; this.setLocalFlag(local.index, LocalFlags.NONNULL); break; } @@ -824,21 +824,21 @@ export class Flow { // overflows if the local isn't wrapped or the conversion does case ExpressionId.LocalGet: { - let local = this.parentFunction.localsByIndex[getGetLocalIndex(expr)]; + let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)]; return !this.isLocalFlag(local.index, LocalFlags.WRAPPED, true) || canConversionOverflow(local.type, type); } // overflows if the value does case ExpressionId.LocalSet: { // tee - assert(isTeeLocal(expr)); - return this.canOverflow(getSetLocalValue(expr), type); + assert(isLocalTee(expr)); + return this.canOverflow(getLocalSetValue(expr), type); } // overflows if the conversion does (globals are wrapped on set) case ExpressionId.GlobalGet: { // TODO: this is inefficient because it has to read a string - let global = assert(this.parentFunction.program.elementsByName.get(assert(getGetGlobalName(expr)))); + let global = assert(this.parentFunction.program.elementsByName.get(assert(getGlobalGetName(expr)))); assert(global.kind == ElementKind.GLOBAL); return canConversionOverflow(assert((global).type), type); } @@ -1080,12 +1080,12 @@ function canConversionOverflow(fromType: Type, toType: Type): bool { function findUsedLocals(expr: ExpressionRef, used: Set): void { switch (getExpressionId(expr)) { case ExpressionId.LocalGet: { - used.add(getGetLocalIndex(expr)); + used.add(getLocalGetIndex(expr)); break; } case ExpressionId.LocalSet: { - used.add(getSetLocalIndex(expr)); - break; + used.add(getLocalSetIndex(expr)); + // fall-through for value } default: traverse(expr, used, findUsedLocals); } diff --git a/src/module.ts b/src/module.ts index 8366b12f..d8396671 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1329,23 +1329,23 @@ export function getConstValueF64(expr: ExpressionRef): f32 { return _BinaryenConstGetValueF64(expr); } -export function getGetLocalIndex(expr: ExpressionRef): Index { +export function getLocalGetIndex(expr: ExpressionRef): Index { return _BinaryenLocalGetGetIndex(expr); } -export function getSetLocalIndex(expr: ExpressionRef): Index { +export function getLocalSetIndex(expr: ExpressionRef): Index { return _BinaryenLocalSetGetIndex(expr); } -export function getSetLocalValue(expr: ExpressionRef): ExpressionRef { +export function getLocalSetValue(expr: ExpressionRef): ExpressionRef { return _BinaryenLocalSetGetValue(expr); } -export function isTeeLocal(expr: ExpressionRef): bool { +export function isLocalTee(expr: ExpressionRef): bool { return _BinaryenLocalSetIsTee(expr); } -export function getGetGlobalName(expr: ExpressionRef): string | null { +export function getGlobalGetName(expr: ExpressionRef): string | null { return readString(_BinaryenGlobalGetGetName(expr)); }