private void Add(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var i2 = (int)vCLRExecContext.StackPop(); var i1 = (int)vCLRExecContext.StackPop(); vCLRExecContext.StackPush(i1 + i2); }
private void Stelem_Ref(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var value = vCLRExecContext.StackPop(); var index = (int)vCLRExecContext.StackPop(); var array = (Array)vCLRExecContext.StackPop(); array.SetValue(value, index); }
/// <summary> /// Loads the element containing an object reference at a specified array index onto the top of the evaluation stack as type O (object reference). /// </summary> private void Ldelem_Ref(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var index = (int)vCLRExecContext.StackPop(); var array = (Array)vCLRExecContext.StackPop(); var value = array.GetValue(index); vCLRExecContext.StackPush(value); }
private void Stfld(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var targetField = (FieldInfo)instruction.Operand; var targetValue = vCLRExecContext.StackPop(); var targetInstance = vCLRExecContext.StackPop(); targetField.SetValue(targetInstance, targetValue); }
private object Blt(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var i2 = (int)vCLRExecContext.StackPop(); var i1 = (int)vCLRExecContext.StackPop(); if (i1 < i2) { return((int)instruction.Operand); } return(null); }
/// <summary> /// Transfers control to a target instruction (short form) when two unsigned integer values or unordered float values are not equal. /// </summary> private object Bne_Un_S(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var o2 = vCLRExecContext.StackPop(); var o1 = vCLRExecContext.StackPop(); if (o1 != o2) { return((int)instruction.Operand); } return(null); }
private object Blt_S(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Transfers control to a target instruction (short form) if the first value is less than the second value. var i2 = (int)vCLRExecContext.StackPop(); var i1 = (int)vCLRExecContext.StackPop(); if (i1 < i2) { return((int)instruction.Operand); } return(null); }
private void Ceq(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Compares two values. If they are equal, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack. var o2 = vCLRExecContext.StackPop(); var o1 = vCLRExecContext.StackPop(); if (o1.Equals(o2)) { vCLRExecContext.StackPush(1); } else { vCLRExecContext.StackPush(0); } }
private void Clt(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Compares two values. If the first value is less than the second, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack. var i2 = (int)vCLRExecContext.StackPop(); var i1 = (int)vCLRExecContext.StackPop(); if (i1 < i2) { vCLRExecContext.StackPush(1); } else { vCLRExecContext.StackPush(0); } }
private void Conv_I4(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Description: Converts the value on top of the evaluation stack to int32. var value = vCLRExecContext.StackPop(); var i1 = Convert.ToInt32(value); vCLRExecContext.StackPush(i1); }
/// <summary> /// Replaces the value of a static field with a value from the evaluation stack. /// </summary> private void Stsfld(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var fieldInfo = (FieldInfo)instruction.Operand; var o1 = vCLRExecContext.StackPop(); fieldInfo.SetValue(vCLRExecContext, o1); }
private void Newarr(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Description: Pushes an object reference to a new zero-based, one-dimensional array whose elements are of a specific type onto the evaluation stack. var length = (int)vCLRExecContext.StackPop(); var arrInst = Array.CreateInstance((Type)instruction.Operand, length); vCLRExecContext.StackPush(arrInst); }
private void Box(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Converts a value type to an object reference (type O). var o1 = vCLRExecContext.StackPop(); o1 = Convert.ChangeType(o1, instruction.Operand as Type); vCLRExecContext.StackPush((object)o1); }
/// <summary> /// Finds the value of a field in the object whose reference is currently on the evaluation stack. /// </summary> private void Ldfld(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var o1 = vCLRExecContext.StackPop(); var fieldInfo = (FieldInfo)instruction.Operand; var value = fieldInfo.GetValue(o1); vCLRExecContext.StackPush(value); }
private void Ret(ILInstruction instruction, VCLRExecContext vCLRExecContext, VCLRExecContext callerContext) { if (vCLRExecContext.EvaluationStack.Count > 0) { if (callerContext != null) { var retVal = vCLRExecContext.StackPop(); callerContext.StackPush(retVal); } } }
/// <summary> /// Transfers control to a target instruction if value is false, a null reference, or zero. /// </summary> private object Brfalse_S(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var o1 = vCLRExecContext.StackPop(); if (o1 != null) { if (isNumericType(o1)) { var i1 = Convert.ToInt32(o1); if (i1 == 0) { return((int)instruction.Operand); } } else { return((int)instruction.Operand); } } return(null); }
private object Brtrue(ILInstruction instruction, VCLRExecContext vCLRExecContext) { //Transfers control to a target instruction (short form) if value is true, not null, or non-zero. var o1 = vCLRExecContext.StackPop(); if (o1 != null) { if (o1 is bool && ((bool)o1)) //bool && true { return((int)instruction.Operand); } if (isNumericType(o1)) { var i1 = Convert.ToInt32(o1); if (i1 != 0) { return((int)instruction.Operand); } } } return(null); }
private void Newobj(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var targetCtor = (ConstructorInfo)instruction.Operand; var ctorParameters = targetCtor.GetParameters(); object[] invocationParameters = null; if (ctorParameters.Length > 0) { invocationParameters = new object[ctorParameters.Length]; for (int i = ctorParameters.Length - 1; i >= 0; i--) { var targetType = ctorParameters[i]; var o1 = vCLRExecContext.StackPop(); if (targetType.ParameterType == typeof(Boolean)) { invocationParameters[i] = Convert.ToBoolean(o1); } else { invocationParameters[i] = o1; } } } var ctorInstance = targetCtor.Invoke(invocationParameters); if (ctorInstance != null) { vCLRExecContext.StackPush(ctorInstance); } }
/// <summary> /// Invokes a method using reflection, passing all parameters from the stack (if any) /// </summary> /// <param name="instruction">The instruction being executed</param> /// <param name="vCLRExecContext">The context of the executed method</param> private void Call(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var ownerMethod = vCLRExecContext.MethodIL.MethodInfo; var methodInfo = instruction.Operand as MethodInfo; var methodParameters = methodInfo.GetParameters(); object[] invocationParameters = null; //The object on which to invoke the method or constructor. If a method is static, this argument is ignored. object invocationTargetInstance = null; if (Scope == vCLRScope.Class) { //check if the target method resides in the same class as the entry method if (ownerMethod.DeclaringType == methodInfo.DeclaringType) { //go deeper if (methodParameters.Length > 0) { invocationParameters = new object[methodParameters.Length]; for (int i = methodParameters.Length - 1; i >= 0; i--) { invocationParameters[i] = vCLRExecContext.StackPop(); //Convert.ChangeType(vCLRExecContext.StackPop(), methodParameters[i].ParameterType); } vCLRExecContext.Arguments = invocationParameters; } if (!methodInfo.IsStatic) { //get invocation instance target invocationTargetInstance = vCLRExecContext.StackPop(); } ExecuteILMethod(methodInfo.GetInstructions(), vCLRExecContext); return; } } object methodReturnValue; if (methodParameters.Length > 0) { invocationParameters = new object[methodParameters.Length]; for (int i = methodParameters.Length - 1; i >= 0; i--) { invocationParameters[i] = vCLRExecContext.StackPop(); //Convert.ChangeType(vCLRExecContext.StackPop(), methodParameters[i].ParameterType); } } if (!methodInfo.IsStatic) { //get invocation instance target invocationTargetInstance = vCLRExecContext.StackPop(); } if (invocationParameters != null) { methodReturnValue = methodInfo.Invoke(invocationTargetInstance, invocationParameters); } else { methodReturnValue = methodInfo.Invoke(invocationTargetInstance, null); } if (methodReturnValue != null) { vCLRExecContext.StackPush(methodReturnValue); } }
/// <summary> /// Pushes a typed reference to an instance of a specific type onto the evaluation stack. /// </summary> private void Mkrefany(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var targetType = (Type)instruction.Operand; var ptr = (IntPtr)vCLRExecContext.StackPop(); }
private void Ldlen(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var array = (Array)vCLRExecContext.StackPop(); vCLRExecContext.StackPush(array.Length); }
private void Throw(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var ex = (Exception)vCLRExecContext.StackPop(); throw (ex); }
private void Pop(ILInstruction instruction, VCLRExecContext vCLRExecContext) { vCLRExecContext.StackPop(); }