Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 static void WriteShort(this ITextColorWriter output, InstructionVM instr)
 {
     output.Write(BoxedTextColor.Number, instr.Index.ToString());
     output.WriteSpace();
     output.Write(BoxedTextColor.Punctuation, "(");
     output.Write(BoxedTextColor.Number, string.Format("{0:X4}", instr.Offset));
     output.Write(BoxedTextColor.Punctuation, ")");
 }
Exemplo n.º 4
0
 static void WriteShort(this ISyntaxHighlightOutput output, InstructionVM instr)
 {
     output.Write(instr.Index.ToString(), TextTokenKind.Number);
     output.WriteSpace();
     output.Write("(", TextTokenKind.Operator);
     output.Write(string.Format("{0:X4}", instr.Offset), TextTokenKind.Number);
     output.Write(")", TextTokenKind.Operator);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 static void WriteShort(this ITextColorWriter output, InstructionVM instr)
 {
     output.Write(BoxedTextColor.Number, instr.Index.ToString());
     output.WriteSpace();
     output.Write(BoxedTextColor.Punctuation, "(");
     output.Write(BoxedTextColor.Label, instr.Offset.ToString("X4"));
     output.Write(BoxedTextColor.Punctuation, ")");
 }
Exemplo n.º 7
0
 static void WriteLong(this ITextColorWriter output, InstructionVM instr)
 {
     output.WriteShort(instr);
     output.WriteSpace();
     output.Write(BoxedTextColor.OpCode, instr.Code.ToOpCode().Name);
     output.WriteSpace();
     Write(output, instr.InstructionOperandVM);
 }
Exemplo n.º 8
0
        public InstructionVM Import(ModuleDef ownerModule)
        {
            var instr = new InstructionVM();

            instr.Code = Code;
            instr.InstructionOperandVM.ImportFrom(ownerModule, InstructionOperandVM);
            instr.Offset = offset;
            return(instr);
        }
Exemplo n.º 9
0
 static InstructionVM RemoveNullInstance(InstructionVM vm)
 {
     Debug.Assert(vm != null);
     if (vm == null || vm == InstructionVM.Null)
     {
         return(null);
     }
     return(vm);
 }
Exemplo n.º 10
0
		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;
		}
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
        public object Clone()
        {
            var inst = new InstructionVM(ownerModule);

            inst.Code = this.Code;
            inst.InstructionOperandVM.InitializeFrom(this.InstructionOperandVM);
            inst.SequencePoint = this.SequencePoint;

            return(inst);
        }
Exemplo n.º 13
0
        public IIndexedItem Clone()
        {
            var instr = new InstructionVM();

            instr.Code = Code;
            instr.InstructionOperandVM.InitializeFrom(InstructionOperandVM);
            instr.SequencePoint = SequencePoint;
            instr.Offset        = offset;

            return(instr);
        }
Exemplo n.º 14
0
        public static object ToOperandVM(Dictionary <object, object> ops, object operand)
        {
            if (operand is IList <Instruction> targets)
            {
                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));
        }
Exemplo n.º 15
0
        public void ImportFrom(ModuleDef ownerModule, InstructionOperandVM other)
        {
            this.InstructionOperandType = other.InstructionOperandType;

            switch (other.InstructionOperandType)
            {
            case MethodBody.InstructionOperandType.None:    break;

            case MethodBody.InstructionOperandType.SByte:   SByte.StringValue = other.SByte.StringValue; break;

            case MethodBody.InstructionOperandType.Byte:    Byte.StringValue = other.Byte.StringValue; break;

            case MethodBody.InstructionOperandType.Int32:   Int32.StringValue = other.Int32.StringValue; break;

            case MethodBody.InstructionOperandType.Int64:   Int64.StringValue = other.Int64.StringValue; break;

            case MethodBody.InstructionOperandType.Single:  Single.StringValue = other.Single.StringValue; break;

            case MethodBody.InstructionOperandType.Double:  Double.StringValue = other.Double.StringValue; break;

            case MethodBody.InstructionOperandType.String:  String.StringValue = other.String.StringValue; break;

            case MethodBody.InstructionOperandType.Field:   Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.Method:  Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.Token:   Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.Type:    Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.MethodSig: Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.BranchTarget: OperandListItem = InstructionVM.Null; break;

            case MethodBody.InstructionOperandType.SwitchTargets: Other = new InstructionVM[0]; break;

            case MethodBody.InstructionOperandType.Local:   OperandListItem = LocalVM.Null; break;

            case MethodBody.InstructionOperandType.Parameter: OperandListItem = BodyUtils.NullParameter; break;

            default: throw new InvalidOperationException();
            }
        }
Exemplo n.º 16
0
 public SwitchInstructionVM(InstructionVM instr) => InstructionVM = instr;
Exemplo n.º 17
0
		public void ImportFrom(ModuleDef ownerModule, InstructionOperandVM other) {
			this.InstructionOperandType = other.InstructionOperandType;

			switch (other.InstructionOperandType) {
			case MethodBody.InstructionOperandType.None:	break;
			case MethodBody.InstructionOperandType.SByte:	SByte.StringValue = other.SByte.StringValue; break;
			case MethodBody.InstructionOperandType.Byte:	Byte.StringValue = other.Byte.StringValue; break;
			case MethodBody.InstructionOperandType.Int32:	Int32.StringValue = other.Int32.StringValue; break;
			case MethodBody.InstructionOperandType.Int64:	Int64.StringValue = other.Int64.StringValue; break;
			case MethodBody.InstructionOperandType.Single:	Single.StringValue = other.Single.StringValue; break;
			case MethodBody.InstructionOperandType.Double:	Double.StringValue = other.Double.StringValue; break;
			case MethodBody.InstructionOperandType.String:	String.StringValue = other.String.StringValue; break;
			case MethodBody.InstructionOperandType.Field:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.Method:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.Token:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.Type:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.MethodSig: Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.BranchTarget: OperandListItem = InstructionVM.Null; break;
			case MethodBody.InstructionOperandType.SwitchTargets: Other = new InstructionVM[0]; break;
			case MethodBody.InstructionOperandType.Local:	OperandListItem = LocalVM.Null; break;
			case MethodBody.InstructionOperandType.Parameter: OperandListItem = BodyUtils.NullParameter; break;
			default: throw new InvalidOperationException();
			}
		}
Exemplo n.º 18
0
		public SwitchInstructionVM(InstructionVM instr) {
			this.instr = instr;
		}
Exemplo n.º 19
0
 static InstructionVM RemoveNullInstance(InstructionVM vm)
 {
     Debug.Assert(vm != null);
     if (vm == null || vm == InstructionVM.Null)
         return null;
     return vm;
 }
Exemplo n.º 20
0
		public IIndexedItem Clone() {
			var instr = new InstructionVM();

			instr.Code = Code;
			instr.InstructionOperandVM.InitializeFrom(InstructionOperandVM);
			instr.SequencePoint = SequencePoint;
			instr.Offset = offset;

			return instr;
		}
Exemplo n.º 21
0
		public SwitchInstructionVM(InstructionVM instr) {
			InstructionVM = instr;
		}
Exemplo n.º 22
0
		public InstructionVM Import(ModuleDef ownerModule) {
			var instr = new InstructionVM();
			instr.Code = Code;
			instr.InstructionOperandVM.ImportFrom(ownerModule, InstructionOperandVM);
			instr.Offset = offset;
			return instr;
		}
Exemplo n.º 23
0
 public SwitchInstructionVM(InstructionVM instr)
 {
     this.instr = instr;
 }
Exemplo n.º 24
0
		public object Clone() {
			var inst = new InstructionVM(ownerModule);

			inst.Code = this.Code;
			inst.InstructionOperandVM.InitializeFrom(this.InstructionOperandVM);
			inst.SequencePoint = this.SequencePoint;

			return inst;
		}