Browse Source

Threat stloc as expression that returns value (the stored value)

pull/37/head
David Srbecký 15 years ago
parent
commit
77d1f62356
  1. 23
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
  2. 3
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

23
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -468,16 +468,25 @@ namespace Decompiler
// We are moving the expression evaluation past the other aguments. // We are moving the expression evaluation past the other aguments.
// It is ok to pass ldloc because the expression can not contain stloc and thus the ldcoc will still return the same value // It is ok to pass ldloc because the expression can not contain stloc and thus the ldcoc will still return the same value
if (arg.Code == ILCode.Ldloc) { if (arg.Code == ILCode.Ldloc) {
bool canInline; if (arg.Operand == currExpr.Operand) {
allowInline.TryGetValue((ILVariable)arg.Operand, out canInline); bool canInline;
if (arg.Operand == currExpr.Operand && canInline) { allowInline.TryGetValue((ILVariable)arg.Operand, out canInline);
// Assigne the ranges for optimized away instrustions somewhere // Assigne the ranges for optimized away instrustions somewhere
currExpr.Arguments[0].ILRanges.AddRange(currExpr.ILRanges); currExpr.Arguments[0].ILRanges.AddRange(currExpr.ILRanges);
currExpr.Arguments[0].ILRanges.AddRange(nextExpr.Arguments[j].ILRanges); currExpr.Arguments[0].ILRanges.AddRange(nextExpr.Arguments[j].ILRanges);
ast.RemoveAt(i);
nextExpr.Arguments[j] = currExpr.Arguments[0]; // Inline the stloc body if (canInline) {
i -= 2; // Try the same index again ast.RemoveAt(i);
break; // Found nextExpr.Arguments[j] = currExpr.Arguments[0]; // Inline the stloc body
i -= 2; // Try the same index again
break; // Found
} else {
ast.RemoveAt(i);
nextExpr.Arguments[j] = currExpr; // Inline the whole stloc
i -= 2; // Try the same index again
break; // Found
}
} }
} else { } else {
break; // Side-effects break; // Side-effects

3
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -127,9 +127,10 @@ namespace Decompiler
TypeReference t = InferTypeForExpression(expr.Arguments.Single(), ((ILVariable)expr.Operand).Type); TypeReference t = InferTypeForExpression(expr.Arguments.Single(), ((ILVariable)expr.Operand).Type);
if (v.Type == null) if (v.Type == null)
v.Type = t; v.Type = t;
return t;
} }
return null;
} }
return null;
case Code.Ldloc: case Code.Ldloc:
{ {
ILVariable v = (ILVariable)expr.Operand; ILVariable v = (ILVariable)expr.Operand;

Loading…
Cancel
Save