Browse Source

Add BlockType

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
d87a9bf149
  1. 12
      ICSharpCode.Decompiler/IL/Instructions/Block.cs
  2. 6
      ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

12
ICSharpCode.Decompiler/IL/Instructions/Block.cs

@ -52,6 +52,7 @@ namespace ICSharpCode.Decompiler.IL @@ -52,6 +52,7 @@ namespace ICSharpCode.Decompiler.IL
public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true);
public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction");
public readonly BlockType Type;
public readonly InstructionCollection<ILInstruction> Instructions;
ILInstruction finalInstruction;
@ -89,15 +90,16 @@ namespace ICSharpCode.Decompiler.IL @@ -89,15 +90,16 @@ namespace ICSharpCode.Decompiler.IL
finalInstruction.ChildIndex = Instructions.Count;
}
public Block() : base(OpCode.Block)
public Block(BlockType type = BlockType.ControlFlow) : base(OpCode.Block)
{
this.Type = type;
this.Instructions = new InstructionCollection<ILInstruction>(this, 0);
this.FinalInstruction = new Nop();
}
public override ILInstruction Clone()
{
Block clone = new Block();
Block clone = new Block(Type);
clone.ILRange = this.ILRange;
clone.Instructions.AddRange(this.Instructions.Select(inst => inst.Clone()));
clone.FinalInstruction = this.FinalInstruction.Clone();
@ -195,4 +197,10 @@ namespace ICSharpCode.Decompiler.IL @@ -195,4 +197,10 @@ namespace ICSharpCode.Decompiler.IL
}
}
}
public enum BlockType {
ControlFlow,
ArrayInitializer,
CompoundOperator
}
}

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

@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
ILVariable finalStore;
int instructionsToRemove;
if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out finalStore, out values, out instructionsToRemove)) {
var block = new Block();
var block = new Block(BlockType.ArrayInitializer);
var tempStore = function.RegisterVariable(VariableKind.StackSlot, v.Type);
block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
block.Instructions.AddRange(values.SelectWithIndex(
@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true;
}
if (HandleJaggedArrayInitializer(body, pos + 1, v, arrayLength[0], out finalStore, out values, out instructionsToRemove)) {
var block = new Block();
var block = new Block(BlockType.ArrayInitializer);
var tempStore = function.RegisterVariable(VariableKind.StackSlot, v.Type);
block.Instructions.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
block.Instructions.AddRange(values.SelectWithIndex((i, value) => StElem(new LdLoc(tempStore), new[] { new LdcI4(i) }, value, elementType)));
@ -277,7 +277,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -277,7 +277,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block BlockFromInitializer(ILVariable v, IType elementType, int[] arrayLength, ILInstruction[] values)
{
var block = new Block();
var block = new Block(BlockType.ArrayInitializer);
block.Instructions.Add(new StLoc(v, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
int step = arrayLength.Length + 1;
for (int i = 0; i < values.Length / step; i++) {

Loading…
Cancel
Save