consistent naming, don't miss local.set/tee value

This commit is contained in:
dcode 2019-05-25 19:25:41 +02:00
parent f9e1f65133
commit 7feb0b7077
4 changed files with 41 additions and 41 deletions

View File

@ -39,10 +39,10 @@ import {
getBlockChild, getBlockChild,
getBlockName, getBlockName,
needsExplicitUnreachable, needsExplicitUnreachable,
getGetLocalIndex, getLocalGetIndex,
FeatureFlags, FeatureFlags,
isTeeLocal, isLocalTee,
getSetLocalIndex getLocalSetIndex
} from "./module"; } from "./module";
import { import {
@ -2181,8 +2181,8 @@ export class Compiler extends DiagnosticEmitter {
if (!this.skippedAutoreleases.has(expr)) { if (!this.skippedAutoreleases.has(expr)) {
if (returnType.isManaged) { if (returnType.isManaged) {
if (getExpressionId(expr) == ExpressionId.LocalGet) { if (getExpressionId(expr) == ExpressionId.LocalGet) {
if (flow.isAnyLocalFlag(getGetLocalIndex(expr), LocalFlags.ANY_RETAINED)) { if (flow.isAnyLocalFlag(getLocalGetIndex(expr), LocalFlags.ANY_RETAINED)) {
flow.unsetLocalFlag(getGetLocalIndex(expr), LocalFlags.ANY_RETAINED); flow.unsetLocalFlag(getLocalGetIndex(expr), LocalFlags.ANY_RETAINED);
this.skippedAutoreleases.add(expr); this.skippedAutoreleases.add(expr);
} }
} }
@ -6243,9 +6243,9 @@ export class Compiler extends DiagnosticEmitter {
let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS); let classInstance = assert(instance.parent); assert(classInstance.kind == ElementKind.CLASS);
let thisType = assert(instance.signature.thisType); let thisType = assert(instance.signature.thisType);
if (canAlias && getExpressionId(thisArg) == ExpressionId.LocalGet) { if (canAlias && getExpressionId(thisArg) == ExpressionId.LocalGet) {
flow.addScopedAlias(CommonSymbols.this_, thisType, getGetLocalIndex(thisArg)); flow.addScopedAlias(CommonSymbols.this_, thisType, getLocalGetIndex(thisArg));
let baseInstance = (<Class>classInstance).base; let baseInstance = (<Class>classInstance).base;
if (baseInstance) flow.addScopedAlias(CommonSymbols.super_, baseInstance.type, getGetLocalIndex(thisArg)); if (baseInstance) flow.addScopedAlias(CommonSymbols.super_, baseInstance.type, getLocalGetIndex(thisArg));
} else { } else {
let thisLocal = flow.addScopedLocal(CommonSymbols.this_, thisType); 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 // 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 paramExpr = args[i];
let paramType = parameterTypes[i]; let paramType = parameterTypes[i];
if (canAlias && getExpressionId(paramExpr) == ExpressionId.LocalGet) { if (canAlias && getExpressionId(paramExpr) == ExpressionId.LocalGet) {
flow.addScopedAlias(signature.getParameterName(i), paramType, getGetLocalIndex(paramExpr)); flow.addScopedAlias(signature.getParameterName(i), paramType, getLocalGetIndex(paramExpr));
} else { } else {
let argumentLocal = flow.addScopedLocal(signature.getParameterName(i), paramType); let argumentLocal = flow.addScopedLocal(signature.getParameterName(i), paramType);
// Normal function wouldn't know about wrap/nonnull states, but inlining does: // Normal function wouldn't know about wrap/nonnull states, but inlining does:
@ -6297,7 +6297,7 @@ export class Compiler extends DiagnosticEmitter {
ContextualFlags.IMPLICIT ContextualFlags.IMPLICIT
); );
if (canAlias && getExpressionId(initExpr) == ExpressionId.LocalGet) { if (canAlias && getExpressionId(initExpr) == ExpressionId.LocalGet) {
flow.addScopedAlias(signature.getParameterName(i), initType, getGetLocalIndex(initExpr)); flow.addScopedAlias(signature.getParameterName(i), initType, getLocalGetIndex(initExpr));
} else { } else {
let argumentLocal = flow.addScopedLocal(signature.getParameterName(i), initType); let argumentLocal = flow.addScopedLocal(signature.getParameterName(i), initType);
if (!flow.canOverflow(initExpr, initType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.WRAPPED); if (!flow.canOverflow(initExpr, initType)) flow.setLocalFlag(argumentLocal.index, LocalFlags.WRAPPED);
@ -6585,8 +6585,8 @@ export class Compiler extends DiagnosticEmitter {
// make it optimize away. // make it optimize away.
switch (getExpressionId(expr)) { switch (getExpressionId(expr)) {
case ExpressionId.LocalSet: { // local.tee(__retain(expr)) case ExpressionId.LocalSet: { // local.tee(__retain(expr))
if (isTeeLocal(expr)) { if (isLocalTee(expr)) {
let index = getSetLocalIndex(expr); let index = getLocalSetIndex(expr);
if (flow.isAnyLocalFlag(index, LocalFlags.ANY_RETAINED)) { if (flow.isAnyLocalFlag(index, LocalFlags.ANY_RETAINED)) {
// Assumes that the expression actually belongs to the flow and that // Assumes that the expression actually belongs to the flow and that
// top-level autoreleases are never undone. While that's true, it's // top-level autoreleases are never undone. While that's true, it's

View File

@ -30,9 +30,9 @@ import {
getLoopBody, getLoopBody,
getBreakName, getBreakName,
getBreakCondition, getBreakCondition,
getGetLocalIndex, getLocalGetIndex,
getSetLocalIndex, getLocalSetIndex,
getSetLocalValue, getLocalSetValue,
getLoadOffset, getLoadOffset,
getLoadPtr, getLoadPtr,
getStoreOffset, getStoreOffset,
@ -175,14 +175,14 @@ export class Decompiler {
} }
case ExpressionId.LocalGet: { case ExpressionId.LocalGet: {
this.push("$"); this.push("$");
this.push(getGetLocalIndex(expr).toString(10)); this.push(getLocalGetIndex(expr).toString(10));
return; return;
} }
case ExpressionId.LocalSet: { case ExpressionId.LocalSet: {
this.push("$"); this.push("$");
this.push(getSetLocalIndex(expr).toString(10)); this.push(getLocalSetIndex(expr).toString(10));
this.push(" = "); this.push(" = ");
this.decompileExpression(getSetLocalValue(expr)); this.decompileExpression(getLocalSetValue(expr));
return; return;
} }
case ExpressionId.GlobalGet: case ExpressionId.GlobalGet:

View File

@ -23,10 +23,10 @@ import {
ExpressionRef, ExpressionRef,
getExpressionId, getExpressionId,
getGetLocalIndex, getLocalGetIndex,
isTeeLocal, isLocalTee,
getSetLocalValue, getLocalSetValue,
getGetGlobalName, getGlobalGetName,
getBinaryOp, getBinaryOp,
BinaryOp, BinaryOp,
getBinaryLeft, getBinaryLeft,
@ -48,7 +48,7 @@ import {
getSelectThen, getSelectThen,
getSelectElse, getSelectElse,
getCallTarget, getCallTarget,
getSetLocalIndex, getLocalSetIndex,
getIfCondition, getIfCondition,
getConstValueI64High, getConstValueI64High,
getUnaryValue, getUnaryValue,
@ -612,12 +612,12 @@ export class Flow {
// has already been handled by the nullable type check above. // has already been handled by the nullable type check above.
switch (getExpressionId(expr)) { switch (getExpressionId(expr)) {
case ExpressionId.LocalSet: { case ExpressionId.LocalSet: {
if (!isTeeLocal(expr)) break; if (!isLocalTee(expr)) break;
let local = this.parentFunction.localsByIndex[getSetLocalIndex(expr)]; let local = this.parentFunction.localsByIndex[getLocalSetIndex(expr)];
return !local.type.is(TypeFlags.NULLABLE) || this.isLocalFlag(local.index, LocalFlags.NONNULL, false); return !local.type.is(TypeFlags.NULLABLE) || this.isLocalFlag(local.index, LocalFlags.NONNULL, false);
} }
case ExpressionId.LocalGet: { 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); 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? // A: `expr` is true-ish -> Q: how did that happen?
switch (getExpressionId(expr)) { switch (getExpressionId(expr)) {
case ExpressionId.LocalSet: { case ExpressionId.LocalSet: {
if (!isTeeLocal(expr)) break; if (!isLocalTee(expr)) break;
let local = this.parentFunction.localsByIndex[getSetLocalIndex(expr)]; let local = this.parentFunction.localsByIndex[getLocalSetIndex(expr)];
this.setLocalFlag(local.index, LocalFlags.NONNULL); 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; break;
} }
case ExpressionId.LocalGet: { case ExpressionId.LocalGet: {
let local = this.parentFunction.localsByIndex[getGetLocalIndex(expr)]; let local = this.parentFunction.localsByIndex[getLocalGetIndex(expr)];
this.setLocalFlag(local.index, LocalFlags.NONNULL); this.setLocalFlag(local.index, LocalFlags.NONNULL);
break; break;
} }
@ -824,21 +824,21 @@ export class Flow {
// overflows if the local isn't wrapped or the conversion does // overflows if the local isn't wrapped or the conversion does
case ExpressionId.LocalGet: { 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) return !this.isLocalFlag(local.index, LocalFlags.WRAPPED, true)
|| canConversionOverflow(local.type, type); || canConversionOverflow(local.type, type);
} }
// overflows if the value does // overflows if the value does
case ExpressionId.LocalSet: { // tee case ExpressionId.LocalSet: { // tee
assert(isTeeLocal(expr)); assert(isLocalTee(expr));
return this.canOverflow(getSetLocalValue(expr), type); return this.canOverflow(getLocalSetValue(expr), type);
} }
// overflows if the conversion does (globals are wrapped on set) // overflows if the conversion does (globals are wrapped on set)
case ExpressionId.GlobalGet: { case ExpressionId.GlobalGet: {
// TODO: this is inefficient because it has to read a string // 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); assert(global.kind == ElementKind.GLOBAL);
return canConversionOverflow(assert((<Global>global).type), type); return canConversionOverflow(assert((<Global>global).type), type);
} }
@ -1080,12 +1080,12 @@ function canConversionOverflow(fromType: Type, toType: Type): bool {
function findUsedLocals(expr: ExpressionRef, used: Set<i32>): void { function findUsedLocals(expr: ExpressionRef, used: Set<i32>): void {
switch (getExpressionId(expr)) { switch (getExpressionId(expr)) {
case ExpressionId.LocalGet: { case ExpressionId.LocalGet: {
used.add(getGetLocalIndex(expr)); used.add(getLocalGetIndex(expr));
break; break;
} }
case ExpressionId.LocalSet: { case ExpressionId.LocalSet: {
used.add(getSetLocalIndex(expr)); used.add(getLocalSetIndex(expr));
break; // fall-through for value
} }
default: traverse(expr, used, findUsedLocals); default: traverse(expr, used, findUsedLocals);
} }

View File

@ -1329,23 +1329,23 @@ export function getConstValueF64(expr: ExpressionRef): f32 {
return _BinaryenConstGetValueF64(expr); return _BinaryenConstGetValueF64(expr);
} }
export function getGetLocalIndex(expr: ExpressionRef): Index { export function getLocalGetIndex(expr: ExpressionRef): Index {
return _BinaryenLocalGetGetIndex(expr); return _BinaryenLocalGetGetIndex(expr);
} }
export function getSetLocalIndex(expr: ExpressionRef): Index { export function getLocalSetIndex(expr: ExpressionRef): Index {
return _BinaryenLocalSetGetIndex(expr); return _BinaryenLocalSetGetIndex(expr);
} }
export function getSetLocalValue(expr: ExpressionRef): ExpressionRef { export function getLocalSetValue(expr: ExpressionRef): ExpressionRef {
return _BinaryenLocalSetGetValue(expr); return _BinaryenLocalSetGetValue(expr);
} }
export function isTeeLocal(expr: ExpressionRef): bool { export function isLocalTee(expr: ExpressionRef): bool {
return _BinaryenLocalSetIsTee(expr); return _BinaryenLocalSetIsTee(expr);
} }
export function getGetGlobalName(expr: ExpressionRef): string | null { export function getGlobalGetName(expr: ExpressionRef): string | null {
return readString(_BinaryenGlobalGetGetName(expr)); return readString(_BinaryenGlobalGetGetName(expr));
} }