Esempio n. 1
0
 public ILInstruction(OpCode opcode, object argument, Type argumentType, ILInstructionType instructionType = ILInstructionType.OpCode)
 {
     OpCode          = opcode;
     Argument        = argument;
     ArgumentType    = argumentType;
     InstructionType = instructionType;
 }
Esempio n. 2
0
        /// <summary>
        /// Disassembles a call to the given method.
        /// </summary>
        /// <param name="type">The instruction type.</param>
        /// <param name="methodToken">The token of the method to be disassembled.</param>
        private void DisassembleCall(ILInstructionType type, int methodToken)
        {
            var method     = ResolveMethod(methodToken);
            var popCount   = method.GetParameters().Length;
            var methodInfo = method as MethodInfo;
            int pushCount  = 0;

            if (methodInfo != null)
            {
                popCount += method.GetParameterOffset();
                if (methodInfo.ReturnType != typeof(void))
                {
                    pushCount = 1;
                }
            }
            else if (method is ConstructorInfo)
            {
                if (type == ILInstructionType.Newobj)
                {
                    // We have to push the new object
                    pushCount += 1;
                }
                else
                {
                    Debug.Assert(type == ILInstructionType.Call, "Invalid constructor call");
                    popCount += 1;
                }
            }
            AppendInstruction(type, (ushort)popCount, (ushort)pushCount, method);
        }
Esempio n. 3
0
 public ILInstruction(
     int offset,
     ILInstructionType type,
     ILInstructionFlagsContext flagsContext,
     ushort popCount,
     ushort pushCount,
     object argument)
     : this(offset, type, flagsContext, popCount, pushCount, argument, null)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Appends an instruction to the current instruction list.
 /// </summary>
 /// <param name="type">The instruction type.</param>
 /// <param name="popCount">
 /// The number of elements to pop from the stack.
 /// </param>
 /// <param name="pushCount">
 /// The number of elements to push onto the stack.
 /// </param>
 /// <param name="argument">The argument of the instruction.</param>
 private void AppendInstruction(
     ILInstructionType type,
     ushort popCount,
     ushort pushCount,
     object argument = null) =>
 AppendInstructionWithFlags(
     type,
     popCount,
     pushCount,
     ILInstructionFlags.None,
     argument);
Esempio n. 5
0
 /// <summary>
 /// Appends an instruction to the current instruction list.
 /// </summary>
 /// <param name="type">The instruction type.</param>
 /// <param name="popCount">The number of elements to pop from the stack.</param>
 /// <param name="pushCount">The number of elements to push onto the stack.</param>
 /// <param name="additionalFlags">Additional instruction flags.</param>
 /// <param name="argument">The argument of the instruction.</param>
 private void AppendInstructionWithFlags(
     ILInstructionType type,
     ushort popCount,
     ushort pushCount,
     ILInstructionFlags additionalFlags,
     object argument = null)
 {
     // Merge with current flags
     instructions.Add(new ILInstruction(
                          instructionOffset,
                          type,
                          new ILInstructionFlagsContext(additionalFlags | flags, flagsArgument),
                          popCount,
                          pushCount,
                          argument,
                          CurrentSequencePoint));
 }
Esempio n. 6
0
 public ILInstruction(
     int offset,
     ILInstructionType type,
     ILInstructionFlagsContext flagsContext,
     ushort popCount,
     ushort pushCount,
     object argument,
     Location location)
 {
     Offset          = offset;
     InstructionType = type;
     FlagsContext    = flagsContext;
     PopCount        = popCount;
     PushCount       = pushCount;
     Argument        = argument;
     Location        = location ?? Location.Unknown;
 }
Esempio n. 7
0
 public ILInstruction(
     int offset,
     ILInstructionType type,
     ILInstructionFlagsContext flagsContext,
     ushort popCount,
     ushort pushCount,
     object argument,
     SequencePoint sequencePoint)
 {
     Offset          = offset;
     InstructionType = type;
     FlagsContext    = flagsContext;
     PopCount        = popCount;
     PushCount       = pushCount;
     Argument        = argument;
     SequencePoint   = sequencePoint;
 }
Esempio n. 8
0
 public ILInstruction(
     int offset,
     ILInstructionType type,
     ILInstructionFlagsContext flagsContext,
     ushort popCount,
     ushort pushCount,
     object argument)
     : this(
         offset,
         type,
         flagsContext,
         popCount,
         pushCount,
         argument,
         SequencePoint.Invalid)
 {
 }
Esempio n. 9
0
        /// <summary>
        /// Disassembles a call to the given method.
        /// </summary>
        /// <param name="type">The instruction type.</param>
        /// <param name="methodToken">The token of the method to be disassembled.</param>
        private void DisassembleCall(ILInstructionType type, int methodToken)
        {
            var method     = ResolveMethod(methodToken);
            var popCount   = method.GetParameters().Length;
            var methodInfo = method as MethodInfo;
            int pushCount  = 0;

            if (methodInfo != null)
            {
                popCount += method.GetParameterOffset();
                if (methodInfo.ReturnType != typeof(void))
                {
                    pushCount = 1;
                }
            }
            else if (method is ConstructorInfo)
            {
                pushCount = 1;
            }
            AppendInstruction(type, (ushort)popCount, (ushort)pushCount, method);
        }
Esempio n. 10
0
		public ILInstruction(int nextInstructionPosition, ILInstructionType type, params string[] args) {
			this.Type = type;
			this.Arguments = args;
			this.NextInstructionPosition = nextInstructionPosition;
		}
Esempio n. 11
0
 protected LinkedListNode<ILInstruction> Instructions_Add(ILInstructionType type, params string[] args)
 {
     return this._Instructions.AddLast(new ILInstruction(this.Position, type, args));
 }