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 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 Add(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var i2 = (int)vCLRExecContext.StackPop(); var i1 = (int)vCLRExecContext.StackPop(); vCLRExecContext.StackPush(i1 + i2); }
/// <summary> /// Loads the address of the local variable at a specific index onto the evaluation stack, short form. /// </summary> private void Ldloca_S(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var gc = GCHandle.Alloc(vCLRExecContext.MethodLocals[(byte)instruction.Operand], GCHandleType.Pinned); var ptr = gc.AddrOfPinnedObject(); vCLRExecContext.StackPush(ptr); }
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 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> /// 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); }
/// <summary> /// Pushes the value of a static field onto the evaluation stack. /// </summary> private void Ldsfld(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var fieldInfo = (FieldInfo)instruction.Operand; var o1 = fieldInfo.GetValue(null); vCLRExecContext.StackPush(o1); }
/// <summary> /// Pushes the address of a static field onto the evaluation stack. /// </summary> private void Ldsflda(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var fieldInfo = (FieldInfo)instruction.Operand; var o1 = fieldInfo.FieldHandle.Value; vCLRExecContext.StackPush(o1); }
/// <summary> /// Pushes an unmanaged pointer (type native int) to the native code implementing a specific method onto the evaluation stack. /// </summary> private void Ldftn(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var methodInfo = (MethodInfo)instruction.Operand; var ptr = methodInfo.MethodHandle.GetFunctionPointer(); vCLRExecContext.StackPush(ptr); }
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); } } }
private void Ldarg_0(ILInstruction instruction, VCLRExecContext vCLRExecContext, VCLRExecContext callerContext) { if (callerContext != null && callerContext.HasObjectInstance) { vCLRExecContext.ObjectInstance = callerContext.ObjectInstance; } //get 'this' instance context if not already done if (!vCLRExecContext.HasObjectInstance) { vCLRExecContext.ObjectInstance = Activator.CreateInstance(vCLRExecContext.MethodIL.MethodInfo.DeclaringType); } vCLRExecContext.StackPush(vCLRExecContext.ObjectInstance); }
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); } }
private void Ldc_I4(ILInstruction instruction, VCLRExecContext vCLRExecContext) { vCLRExecContext.StackPush((int)instruction.Operand); }
private void Ldc_I4_0(ILInstruction instruction, VCLRExecContext vCLRExecContext) { vCLRExecContext.StackPush(0); }
private void Ldc_I4_S(ILInstruction instruction, VCLRExecContext vCLRExecContext) { int i1 = Convert.ToInt32(instruction.Operand); vCLRExecContext.StackPush(i1); }
/// <summary> /// Pushes a null reference (type O) onto the evaluation stack. /// </summary> private void Ldnull(ILInstruction instruction, VCLRExecContext vCLRExecContext) { vCLRExecContext.StackPush(null); }
private void Ldlen(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var array = (Array)vCLRExecContext.StackPop(); vCLRExecContext.StackPush(array.Length); }
private void Dup(ILInstruction instruction, VCLRExecContext vCLRExecContext) { var cpy = vCLRExecContext.EvaluationStack.Peek(); vCLRExecContext.StackPush(cpy); }
private void Ldarg_3(ILInstruction instruction, VCLRExecContext vCLRExecContext, VCLRExecContext callerContext) { var o1 = vCLRExecContext.Arguments[2]; vCLRExecContext.StackPush(o1); }