Browse Source

Use ILVariable as ldloca operand.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
8b342ea469
  1. 12
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 9
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
  3. 2
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

12
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -608,17 +608,9 @@ namespace Decompiler
AstBuilder.ConvertType(((FieldReference)operand).DeclaringType) AstBuilder.ConvertType(((FieldReference)operand).DeclaringType)
.Member(((FieldReference)operand).Name).WithAnnotation(operand)); .Member(((FieldReference)operand).Name).WithAnnotation(operand));
case Code.Ldloc: case Code.Ldloc:
if (operand is ILVariable) { return new Ast.IdentifierExpression(((ILVariable)operand).Name);
return new Ast.IdentifierExpression(((ILVariable)operand).Name);
} else {
return new Ast.IdentifierExpression(((VariableDefinition)operand).Name);
}
case Code.Ldloca: case Code.Ldloca:
if (operand is ILVariable) { return MakeRef(new Ast.IdentifierExpression(((ILVariable)operand).Name));
return MakeRef(new Ast.IdentifierExpression(((ILVariable)operand).Name));
} else {
return MakeRef(new Ast.IdentifierExpression(((VariableDefinition)operand).Name));
}
case Code.Ldnull: return new Ast.NullReferenceExpression(); case Code.Ldnull: return new Ast.NullReferenceExpression();
case Code.Ldobj: throw new NotImplementedException(); case Code.Ldobj: throw new NotImplementedException();
case Code.Ldstr: return new Ast.PrimitiveExpression(operand); case Code.Ldstr: return new Ast.PrimitiveExpression(operand);

9
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -262,11 +262,16 @@ namespace Decompiler
int index = ((VariableDefinition)byteCode.Operand).Index; int index = ((VariableDefinition)byteCode.Operand).Index;
byteCode.Operand = Variables[index]; byteCode.Operand = Variables[index];
numReads[index]++; numReads[index]++;
} } else if (byteCode.Code == ILCode.Stloc) {
if (byteCode.Code == ILCode.Stloc) {
int index = ((VariableDefinition)byteCode.Operand).Index; int index = ((VariableDefinition)byteCode.Operand).Index;
byteCode.Operand = Variables[index]; byteCode.Operand = Variables[index];
numWrites[index]++; numWrites[index]++;
} else if (byteCode.Code == ILCode.Ldloca) {
int index = ((VariableDefinition)byteCode.Operand).Index;
byteCode.Operand = Variables[index];
// ldloca leads to an unknown numbers of reads/writes, so ensure we don't inline the variable
numReads[index] += 2;
numWrites[index] += 2;
} }
} }

2
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -85,7 +85,7 @@ namespace Decompiler
case Code.Ldarg: case Code.Ldarg:
return ((ParameterReference)expr.Operand).ParameterType; return ((ParameterReference)expr.Operand).ParameterType;
case Code.Ldloca: case Code.Ldloca:
return new ByReferenceType(((VariableDefinition)expr.Operand).VariableType); return new ByReferenceType(((ILVariable)expr.Operand).Type);
case Code.Ldarga: case Code.Ldarga:
return new ByReferenceType(((ParameterReference)expr.Operand).ParameterType); return new ByReferenceType(((ParameterReference)expr.Operand).ParameterType);
#endregion #endregion

Loading…
Cancel
Save