static InstructionPushPopInfo?GetInstructionPops(InstructionVM instr) { var code = instr.Code; if (code == Code.Pop || code == Code.Nop) { return(null); } int pushes, pops; instr.CalculateStackUsage(out pushes, out pops); if (pops < 0) { return(null); } if (pushes == 1 && (code == Code.Call || code == Code.Callvirt || code == Code.Calli)) { return(new InstructionPushPopInfo(pops, GetMethodSig(instr.InstructionOperandVM.Other).GetRetType())); } if (pushes == 1 && code == Code.Newobj) { var ctor = instr.InstructionOperandVM.Other as IMethod; return(new InstructionPushPopInfo(pops, ctor == null ? null : ctor.DeclaringType.ToTypeSig())); } if (pushes != 0) { return(null); } return(new InstructionPushPopInfo(pops)); }
static void WriteLong(this ITextOutput output, InstructionVM instr) { output.WriteShort(instr); output.WriteSpace(); output.Write(instr.Code.ToOpCode().Name, TextTokenType.OpCode); output.WriteSpace(); Write(output, instr.InstructionOperandVM); }
static void WriteShort(this ITextOutput output, InstructionVM instr) { output.Write(instr.Index.ToString(), TextTokenType.Number); output.WriteSpace(); output.Write('(', TextTokenType.Operator); output.Write(string.Format("{0:X4}", instr.Offset), TextTokenType.Number); output.Write(')', TextTokenType.Operator); }
static InstructionVM RemoveNullInstance(InstructionVM vm) { Debug.Assert(vm != null); if (vm == null || vm == InstructionVM.Null) { return(null); } return(vm); }
public object Clone() { var inst = new InstructionVM(ownerModule); inst.Code = this.Code; inst.InstructionOperandVM.InitializeFrom(this.InstructionOperandVM); inst.SequencePoint = this.SequencePoint; return(inst); }
public ExceptionHandlerOptions(Dictionary<object, object> ops, ExceptionHandler eh) { this.TryStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryStart); this.TryEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryEnd); this.FilterStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.FilterStart); this.HandlerStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerStart); this.HandlerEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerEnd); this.CatchType = eh.CatchType; this.HandlerType = eh.HandlerType; }
public ExceptionHandlerOptions(Dictionary <object, object> ops, ExceptionHandler eh) { this.TryStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryStart); this.TryEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryEnd); this.FilterStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.FilterStart); this.HandlerStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerStart); this.HandlerEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerEnd); this.CatchType = eh.CatchType; this.HandlerType = eh.HandlerType; }
public static object ToOperandVM(Dictionary <object, object> ops, object operand) { var targets = operand as IList <Instruction>; if (targets != null) { var newTargets = new InstructionVM[targets.Count]; for (int i = 0; i < newTargets.Length; i++) { newTargets[i] = (InstructionVM)TryGetVM(ops, (object)targets[i] ?? InstructionVM.Null); } return(newTargets); } return(TryGetVM(ops, operand)); }
bool RemoveInstructionAndAddPopsCanExecute(InstructionVM[] instrs) { return instrs.Any(a => GetInstructionPops(a) != null); }
void RemoveInstructionAndAddPops(InstructionVM[] instrs) { foreach (var instr in instrs) { var info = GetInstructionPops(instr); if (info == null) continue; var popCount = info.Value.PopCount; var origCode = instr.Code; if (origCode == Code.Callvirt && instr.Index >= 1 && instructionsListVM[instr.Index - 1].Code == Code.Constrained) instructionsListVM[instr.Index - 1].Code = Code.Nop; int index = instr.Index + 1; if (popCount == 0) instr.Code = Code.Nop; else { instr.Code = Code.Pop; while (--popCount > 0) InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Pop)); } if (info.Value.Pushes) AddPushDefaultValue(0, ref index, info.Value.PushType); } }
bool InvertBranchCanExecute(InstructionVM[] instrs) { return instrs.Any(a => InvertBcc(a.Code) != null); }
void InvertBranch(InstructionVM[] instrs) { foreach (var instr in instrs) { var code = InvertBcc(instr.Code); if (code != null) instr.Code = code.Value; } }
bool ConvertBranchToUnconditionalBranchCanExecute(InstructionVM[] instrs) { return instrs.Any(a => GetBccPopCount(a.Code) > 0); }
public object Clone() { var inst = new InstructionVM(ownerModule); inst.Code = this.Code; inst.InstructionOperandVM.InitializeFrom(this.InstructionOperandVM); inst.SequencePoint = this.SequencePoint; return inst; }
void ReplaceInstructionWithNop(InstructionVM[] instrs) { var old1 = InstructionsListVM.DisableAutoUpdateProps; var old2 = DisableHasError(); try { InstructionsListVM.DisableAutoUpdateProps = true; foreach (var instr in instrs) instr.Code = Code.Nop; } finally { RestoreHasError(old2); InstructionsListVM.DisableAutoUpdateProps = old1; } InstructionsUpdateIndexes(0); }
bool ReplaceInstructionWithNopCanExecute(InstructionVM[] instrs) { return instrs.Any(a => a.Code != Code.Nop); }
static InstructionPushPopInfo? GetInstructionPops(InstructionVM instr) { var code = instr.Code; if (code == Code.Pop || code == Code.Nop) return null; int pushes, pops; instr.CalculateStackUsage(out pushes, out pops); if (pops < 0) return null; if (pushes == 1 && (code == Code.Call || code == Code.Callvirt || code == Code.Calli)) return new InstructionPushPopInfo(pops, GetMethodSig(instr.InstructionOperandVM.Other).GetRetType()); if (pushes == 1 && code == Code.Newobj) { var ctor = instr.InstructionOperandVM.Other as IMethod; return new InstructionPushPopInfo(pops, ctor == null ? null : ctor.DeclaringType.ToTypeSig()); } if (pushes != 0) return null; return new InstructionPushPopInfo(pops); }
static InstructionVM RemoveNullInstance(InstructionVM vm) { Debug.Assert(vm != null); if (vm == null || vm == InstructionVM.Null) return null; return vm; }
void ConvertBranchToUnconditionalBranch(InstructionVM[] instrs) { foreach (var instr in instrs) { var popCount = GetBccPopCount(instr.Code); if (popCount <= 0) continue; var targetOperand = instr.InstructionOperandVM.Value; instr.Code = Code.Pop; int index = instr.Index + 1; while (--popCount > 0) InstructionsListVM.Insert(index++, CreateInstructionVM(Code.Pop)); var brInstr = CreateInstructionVM(Code.Br); brInstr.InstructionOperandVM.OperandListItem = targetOperand ?? InstructionVM.Null; InstructionsListVM.Insert(index++, brInstr); } }