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
public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true); public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true);
public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction"); public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction");
public readonly BlockType Type;
public readonly InstructionCollection<ILInstruction> Instructions; public readonly InstructionCollection<ILInstruction> Instructions;
ILInstruction finalInstruction; ILInstruction finalInstruction;
@ -89,15 +90,16 @@ namespace ICSharpCode.Decompiler.IL
finalInstruction.ChildIndex = Instructions.Count; 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.Instructions = new InstructionCollection<ILInstruction>(this, 0);
this.FinalInstruction = new Nop(); this.FinalInstruction = new Nop();
} }
public override ILInstruction Clone() public override ILInstruction Clone()
{ {
Block clone = new Block(); Block clone = new Block(Type);
clone.ILRange = this.ILRange; clone.ILRange = this.ILRange;
clone.Instructions.AddRange(this.Instructions.Select(inst => inst.Clone())); clone.Instructions.AddRange(this.Instructions.Select(inst => inst.Clone()));
clone.FinalInstruction = this.FinalInstruction.Clone(); clone.FinalInstruction = this.FinalInstruction.Clone();
@ -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
ILVariable finalStore; ILVariable finalStore;
int instructionsToRemove; int instructionsToRemove;
if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out finalStore, out values, out 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); 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.Add(new StLoc(tempStore, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
block.Instructions.AddRange(values.SelectWithIndex( block.Instructions.AddRange(values.SelectWithIndex(
@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true; return true;
} }
if (HandleJaggedArrayInitializer(body, pos + 1, v, arrayLength[0], out finalStore, out values, out instructionsToRemove)) { 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); 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.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))); 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
Block BlockFromInitializer(ILVariable v, IType elementType, int[] arrayLength, ILInstruction[] values) 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()))); block.Instructions.Add(new StLoc(v, new NewArr(elementType, arrayLength.Select(l => new LdcI4(l)).ToArray())));
int step = arrayLength.Length + 1; int step = arrayLength.Length + 1;
for (int i = 0; i < values.Length / step; i++) { for (int i = 0; i < values.Length / step; i++) {

Loading…
Cancel
Save