Browse Source

Extend TransformInlineAssignment for fields

pull/734/head
Siegfried Pammer 9 years ago
parent
commit
c4092ac91e
  1. 6
      ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs
  2. 32
      ICSharpCode.Decompiler/IL/Transforms/TransformInlineAssignment.cs

6
ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

@ -249,8 +249,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -249,8 +249,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Debug.Assert(loadInst.IsDescendantOf(next));
// decide based on the source expression being inlined
if (inlinedExpression.OpCode == OpCode.DefaultValue)
switch (inlinedExpression.OpCode) {
case OpCode.DefaultValue:
return true;
case OpCode.StObj:
return true;
}
// decide based on the target into which we are inlining
var parent = loadInst.Parent;

32
ICSharpCode.Decompiler/IL/Transforms/TransformInlineAssignment.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -36,7 +36,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
this.context = context;
foreach (var block in function.Descendants.OfType<Block>()) {
for (int i = block.Instructions.Count - 1; i >= 0; i--) {
TransformInlineAssignmentFields(block, i);
TransformInlineAssignmentStObj(block, i);
TransformInlineAssignmentLocal(block, i);
}
}
@ -64,24 +64,24 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -64,24 +64,24 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// <code>
/// stloc s(value)
/// stloc l(ldloc s)
/// stfld f(..., ldloc s)
/// stobj(..., ldloc s)
/// -->
/// stloc l(stfld f(..., value))
/// stloc l(stobj (..., value))
/// </code>
static void TransformInlineAssignmentFields(Block block, int i)
static void TransformInlineAssignmentStObj(Block block, int i)
{
// var inst = block.Instructions[i] as StLoc;
// var nextInst = block.Instructions.ElementAtOrDefault(i + 1) as StLoc;
// var fieldStore = block.Instructions.ElementAtOrDefault(i + 2) as StObj;
// if (inst == null || nextInst == null || fieldStore == null)
// return;
// if (nextInst.Variable.Kind == VariableKind.StackSlot || !nextInst.Value.MatchLdLoc(inst.Variable) || !fieldStore.Value.MatchLdLoc(inst.Variable))
// return;
// var value = inst.Value.Clone();
// var locVar = nextInst.Variable;
// block.Instructions.RemoveAt(i + 1);
// block.Instructions.RemoveAt(i + 1);
// inst.ReplaceWith(new StLoc(locVar, new StObj(fieldStore.Target, value, fieldStore.Field)));
var inst = block.Instructions[i] as StLoc;
var nextInst = block.Instructions.ElementAtOrDefault(i + 1) as StLoc;
var fieldStore = block.Instructions.ElementAtOrDefault(i + 2) as StObj;
if (inst == null || nextInst == null || fieldStore == null)
return;
if (nextInst.Variable.Kind == VariableKind.StackSlot || !nextInst.Value.MatchLdLoc(inst.Variable) || !fieldStore.Value.MatchLdLoc(inst.Variable))
return;
var value = inst.Value.Clone();
var locVar = nextInst.Variable;
block.Instructions.RemoveAt(i + 1);
block.Instructions.RemoveAt(i + 1);
inst.ReplaceWith(new StLoc(locVar, new StObj(fieldStore.Target, value, fieldStore.Type)));
}
}
}

Loading…
Cancel
Save