public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0); FieldInfo theField = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveField(metadataToken); switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Ldsfld: { Types.TypeInfo theTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theField.FieldType); int size = theTypeInfo.SizeOnStackInBytes; bool isFloat = Utilities.IsFloat(theField.FieldType); conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = isFloat, sizeOnStackInBytes = (size == 8 ? 8 : 4), isGCManaged = theTypeInfo.IsGCManaged, isValue = theTypeInfo.IsValueType }); } break; case OpCodes.Ldsflda: conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false, isValue = false }); break; } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop(); StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop(); if (itemA.sizeOnStackInBytes == 4 && itemB.sizeOnStackInBytes == 4) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false }); } else if (itemA.sizeOnStackInBytes == 8 && itemB.sizeOnStackInBytes == 8) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false }); } else { throw new NotSupportedException("Unsupported number of bytes for compare equal to!"); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { MethodBase constructorMethod = theOp.MethodToCall; Type objectType = constructorMethod.DeclaringType; if (typeof(Delegate).IsAssignableFrom(objectType)) { StackItem funcPtrItem = conversionState.CurrentStackFrame.Stack.Pop();; conversionState.CurrentStackFrame.Stack.Pop(); conversionState.CurrentStackFrame.Stack.Push(funcPtrItem); return; } Types.MethodInfo constructorMethodInfo = conversionState.TheILLibrary.GetMethodInfo(constructorMethod); ParameterInfo[] allParams = constructorMethod.GetParameters(); foreach (ParameterInfo aParam in allParams) { conversionState.CurrentStackFrame.Stack.Pop(); } conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isNewGCObject = true, isGCManaged = true }); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop(); StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop(); if (itemA.sizeOnStackInBytes == 4 && itemB.sizeOnStackInBytes == 4) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } else if (itemA.sizeOnStackInBytes == 8 && itemB.sizeOnStackInBytes == 8) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 8, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { bool loadAddr = (ILOp.OpCodes)theOp.opCode.Value == OpCodes.Ldloca || (ILOp.OpCodes)theOp.opCode.Value == OpCodes.Ldloca_S; UInt16 localIndex = 0; switch ((ILOp.OpCodes)theOp.opCode.Value) { case OpCodes.Ldloc: case OpCodes.Ldloca: localIndex = (UInt16)Utilities.ReadInt16(theOp.ValueBytes, 0); break; case OpCodes.Ldloc_0: localIndex = 0; break; case OpCodes.Ldloc_1: localIndex = 1; break; case OpCodes.Ldloc_2: localIndex = 2; break; case OpCodes.Ldloc_3: localIndex = 3; break; case OpCodes.Ldloc_S: case OpCodes.Ldloca_S: localIndex = (UInt16)theOp.ValueBytes[0]; break; } Types.VariableInfo theLoc = conversionState.Input.TheMethodInfo.LocalInfos.ElementAt(localIndex); if (loadAddr) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false, isValue = false }); } else { int pushedLocalSizeVal = theLoc.TheTypeInfo.SizeOnStackInBytes; conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = Utilities.IsFloat(theLoc.UnderlyingType), sizeOnStackInBytes = pushedLocalSizeVal, isGCManaged = theLoc.TheTypeInfo.IsGCManaged, isValue = theLoc.TheTypeInfo.IsValueType }); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0); FieldInfo theField = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveField(metadataToken); bool valueisFloat = Utilities.IsFloat(theField.FieldType); Types.TypeInfo fieldTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theField.FieldType); int stackSize = fieldTypeInfo.SizeOnStackInBytes; StackItem objPointer = conversionState.CurrentStackFrame.Stack.Pop(); if ((OpCodes)theOp.opCode.Value == OpCodes.Ldflda) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false }); } else { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = valueisFloat, sizeOnStackInBytes = stackSize, isGCManaged = fieldTypeInfo.IsGCManaged }); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { MethodBase methodToCall = theOp.MethodToCall; Types.MethodInfo methodToCallInfo = conversionState.TheILLibrary.GetMethodInfo(methodToCall); if (methodToCall is MethodInfo) { Type retType = ((MethodInfo)methodToCall).ReturnType; Types.TypeInfo retTypeInfo = conversionState.TheILLibrary.GetTypeInfo(retType); StackItem returnItem = new StackItem() { isFloat = Utilities.IsFloat(retType), sizeOnStackInBytes = retTypeInfo.SizeOnStackInBytes, isGCManaged = retTypeInfo.IsGCManaged, isValue = retTypeInfo.IsValueType }; int bytesToAdd = 0; List <Type> allParams = ((MethodInfo)methodToCall).GetParameters().Select(x => x.ParameterType).ToList(); if (!methodToCall.IsStatic) { allParams.Insert(0, methodToCall.DeclaringType); } foreach (Type aParam in allParams) { conversionState.CurrentStackFrame.Stack.Pop(); bytesToAdd += conversionState.TheILLibrary.GetTypeInfo(aParam).SizeOnStackInBytes; } if (bytesToAdd > 0) { if (returnItem.sizeOnStackInBytes != 0) { conversionState.CurrentStackFrame.Stack.Push(returnItem); } } else if (returnItem.sizeOnStackInBytes != 0) { conversionState.CurrentStackFrame.Stack.Push(returnItem); } } else if (methodToCall is ConstructorInfo) { ConstructorInfo aConstructor = (ConstructorInfo)methodToCall; if (aConstructor.IsStatic) { //Static constructors do not have parameters or return values } else { ParameterInfo[] allParams = methodToCall.GetParameters(); foreach (ParameterInfo aParam in allParams) { conversionState.CurrentStackFrame.Stack.Pop(); } } } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false }); }
public override void Preprocess(ILPreprocessState preprocessState, ILOp theOp) { for (int i = 0; i < theOp.ValueBytes.Length / 4; i++) { int branchOffset = theOp.NextOffset + Utilities.ReadInt32(theOp.ValueBytes, i * 4); ILOp opToGoTo = preprocessState.Input.At(branchOffset); opToGoTo.LabelRequired = true; } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { Type retType = (conversionState.Input.TheMethodInfo.IsConstructor ? typeof(void) : ((MethodInfo)conversionState.Input.TheMethodInfo.UnderlyingInfo).ReturnType); Types.TypeInfo retTypeInfo = conversionState.TheILLibrary.GetTypeInfo(retType); if (retTypeInfo.SizeOnStackInBytes != 0) { conversionState.CurrentStackFrame.Stack.Pop(); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0); Type theType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken); Types.TypeInfo theTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theType); int size = theTypeInfo.SizeOnStackInBytes; conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = size, isGCManaged = false }); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { try { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false }); } catch { throw new NotSupportedException("The metadata token specifies a fieldref or methodref which isn't supported yet!"); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { //Pop in reverse order to push StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop(); StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop(); if (itemA.sizeOnStackInBytes == 4 && itemB.sizeOnStackInBytes == 4) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false }); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop(); conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = itemA.isFloat, sizeOnStackInBytes = itemA.sizeOnStackInBytes, isGCManaged = itemA.isGCManaged }); conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = itemA.isFloat, sizeOnStackInBytes = itemA.sizeOnStackInBytes, isGCManaged = itemA.isGCManaged }); }
public override void Preprocess(ILPreprocessState preprocessState, ILOp theOp) { Types.MethodInfo methodInfo = preprocessState.TheILLibrary.GetMethodInfo(theOp.MethodToCall); if (theOp.LoadAtILOpAfterOp != null) { ILBlock anILBlock = preprocessState.TheILLibrary.GetILBlock(methodInfo); int index = anILBlock.ILOps.IndexOf(theOp.LoadAtILOpAfterOp); index++; anILBlock.ILOps[index].LabelRequired = true; } else if (theOp.LoadAtILOffset != int.MaxValue) { int offset = theOp.LoadAtILOffset; ILOp theLoadedOp = preprocessState.TheILLibrary.GetILBlock(methodInfo).At(offset); theLoadedOp.LabelRequired = true; } }
private static void rotateStackItems(ILPreprocessState state, int items, int distance) { if (distance >= items) { throw new IndexOutOfRangeException("IlPreprocessor.rotateStackItems: distance >= items invalid!"); } List <StackItem> poppedItems = new List <StackItem>(); for (int i = 0; i < items; i++) { poppedItems.Add(state.CurrentStackFrame.Stack.Pop()); } for (int i = distance; i > -1; i--) { state.CurrentStackFrame.Stack.Push(poppedItems[i]); } for (int i = items - 1; i > distance; i--) { state.CurrentStackFrame.Stack.Push(poppedItems[i]); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { StackItem addressItem = conversionState.CurrentStackFrame.Stack.Pop(); int bytesToLoad = 0; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Ldind_U1: case OpCodes.Ldind_I1: bytesToLoad = 1; break; case OpCodes.Ldind_U2: case OpCodes.Ldind_I2: bytesToLoad = 2; break; case OpCodes.Ldind_U4: case OpCodes.Ldind_I4: case OpCodes.Ldind_I: bytesToLoad = 4; break; case OpCodes.Ldind_I8: bytesToLoad = 8; break; case OpCodes.Ldind_Ref: bytesToLoad = Options.AddressSizeInBytes; break; } conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = bytesToLoad == 8 ? 8 : 4, isFloat = false, isGCManaged = false, isValue = (OpCodes)theOp.opCode.Value != OpCodes.Ldind_Ref }); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { StackItem itemToConvert = conversionState.CurrentStackFrame.Stack.Pop(); int numBytesToConvertTo = 0; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Conv_U: numBytesToConvertTo = 4; break; case OpCodes.Conv_U1: numBytesToConvertTo = 1; break; case OpCodes.Conv_U2: numBytesToConvertTo = 2; break; case OpCodes.Conv_U4: numBytesToConvertTo = 4; break; case OpCodes.Conv_U8: numBytesToConvertTo = 8; break; } bool pushEDX = numBytesToConvertTo == 8; conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = (pushEDX ? 8 : 4), isFloat = false, isGCManaged = false, isValue = true }); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { Int16 index = 0; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Ldarg: index = Utilities.ReadInt16(theOp.ValueBytes, 0); break; case OpCodes.Ldarg_0: index = 0; break; case OpCodes.Ldarg_1: index = 1; break; case OpCodes.Ldarg_2: index = 2; break; case OpCodes.Ldarg_3: index = 3; break; case OpCodes.Ldarg_S: index = (Int16)theOp.ValueBytes[0]; break; case OpCodes.Ldarga: index = Utilities.ReadInt16(theOp.ValueBytes, 0); break; case OpCodes.Ldarga_S: index = (Int16)theOp.ValueBytes[0]; break; } List <Type> allParams = conversionState.Input.TheMethodInfo.UnderlyingInfo.GetParameters().Select(x => x.ParameterType).ToList(); if (!conversionState.Input.TheMethodInfo.IsStatic) { allParams.Insert(0, conversionState.Input.TheMethodInfo.UnderlyingInfo.DeclaringType); } if ((OpCodes)theOp.opCode.Value == OpCodes.Ldarga || (OpCodes)theOp.opCode.Value == OpCodes.Ldarga_S) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = 4, isFloat = false, isGCManaged = false, isValue = false }); } else { Types.TypeInfo paramTypeInfo = conversionState.TheILLibrary.GetTypeInfo(allParams[index]); int bytesForArg = paramTypeInfo.SizeOnStackInBytes; conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = bytesForArg, isFloat = false, isGCManaged = paramTypeInfo.IsGCManaged, isValue = paramTypeInfo.IsValueType }); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { conversionState.CurrentStackFrame.Stack.Pop(); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { //Weirdly this is not a true/false returning op - it actually returns a null or object ref. }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { Type elementType = null; bool pushValue = true; int sizeToPush = 4; bool isFloat = false; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Ldelem: { int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0); elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken); } break; case OpCodes.Ldelema: { int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0); elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken); pushValue = false; } break; case OpCodes.Ldelem_R4: case OpCodes.Ldelem_R8: throw new NotSupportedException("Ldelem op variant not supported yet!"); case OpCodes.Ldelem_I1: sizeToPush = 1; elementType = typeof(sbyte); break; case OpCodes.Ldelem_I2: sizeToPush = 2; elementType = typeof(Int16); break; case OpCodes.Ldelem_U1: sizeToPush = 1; elementType = typeof(byte); break; case OpCodes.Ldelem_U2: sizeToPush = 2; elementType = typeof(UInt16); break; case OpCodes.Ldelem_Ref: elementType = null; break; case OpCodes.Ldelem_U4: elementType = typeof(UInt32); break; case OpCodes.Ldelem_I4: elementType = typeof(Int32); break; case OpCodes.Ldelem_I8: sizeToPush = 8; elementType = typeof(Int64); break; } // 5.2. Pop index and array ref from our stack conversionState.CurrentStackFrame.Stack.Pop(); conversionState.CurrentStackFrame.Stack.Pop(); // 5.3. Push element onto our stack conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = sizeToPush > 4 ? 8 : 4, isFloat = isFloat, isNewGCObject = false, isGCManaged = pushValue ? (elementType == null || conversionState.TheILLibrary.GetTypeInfo(elementType).IsGCManaged) : false }); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { MethodBase methodToCall = theOp.MethodToCall; Types.MethodInfo methodToCallInfo = conversionState.TheILLibrary.GetMethodInfo(methodToCall); if (methodToCall is MethodInfo) { if (typeof(Delegate).IsAssignableFrom(((MethodInfo)methodToCall).DeclaringType)) { List <Type> allParams = ((MethodInfo)methodToCall).GetParameters().Select(x => x.ParameterType).ToList(); Type retType = ((MethodInfo)methodToCall).ReturnType; Types.TypeInfo retTypeInfo = conversionState.TheILLibrary.GetTypeInfo(retType); StackItem returnItem = new StackItem() { isFloat = Utilities.IsFloat(retType), sizeOnStackInBytes = retTypeInfo.SizeOnStackInBytes, isGCManaged = retTypeInfo.IsGCManaged, isValue = retTypeInfo.IsValueType }; int bytesToAdd = 4; foreach (Type aParam in allParams) { conversionState.CurrentStackFrame.Stack.Pop(); bytesToAdd += conversionState.TheILLibrary.GetTypeInfo(aParam).SizeOnStackInBytes; } if (returnItem.sizeOnStackInBytes != 0) { conversionState.CurrentStackFrame.Stack.Push(returnItem); } } else { string methodIDValueWanted = methodToCallInfo.IDValue.ToString(); int currOpPosition = conversionState.PositionOf(theOp); Types.TypeInfo declaringTypeInfo = conversionState.TheILLibrary.GetTypeInfo(methodToCall.DeclaringType); Type retType = ((MethodInfo)methodToCall).ReturnType; Types.TypeInfo retTypeInfo = conversionState.TheILLibrary.GetTypeInfo(retType); StackItem returnItem = new StackItem() { isFloat = Utilities.IsFloat(retType), sizeOnStackInBytes = retTypeInfo.SizeOnStackInBytes, isGCManaged = retTypeInfo.IsGCManaged, isValue = retTypeInfo.IsValueType }; int bytesToAdd = 0; List <Type> allParams = ((MethodInfo)methodToCall).GetParameters().Select(x => x.ParameterType).ToList(); if (!methodToCall.IsStatic) { allParams.Insert(0, methodToCall.DeclaringType); } foreach (Type aParam in allParams) { conversionState.CurrentStackFrame.Stack.Pop(); bytesToAdd += conversionState.TheILLibrary.GetTypeInfo(aParam).SizeOnStackInBytes; } if (bytesToAdd > 0) { if (returnItem.sizeOnStackInBytes != 0) { conversionState.CurrentStackFrame.Stack.Push(returnItem); } } else if (returnItem.sizeOnStackInBytes != 0) { conversionState.CurrentStackFrame.Stack.Push(returnItem); } } } }
public override void Preprocess(ILPreprocessState preprocessState, ILOp theOp) { //This will store the offset from the current next op's position //to the IL op to jump to. int ILOffset = 0; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Br: //Load the IL offset as signed Int 32 from the value bytes. ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Br_S: //Load the IL offset as signed Int 8 from the value bytes. ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Brtrue: //See above. ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Brtrue_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Brfalse: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Brfalse_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Beq: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Beq_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Bne_Un: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Bne_Un_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Bge: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Bge_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Bge_Un: //See above : This is unsigned variant ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Bge_Un_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Ble: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Ble_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Ble_Un: //See above : This is unsigned variant ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Ble_Un_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Blt: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Blt_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Blt_Un: //See above : This is unsigned variant ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Blt_Un_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Bgt: //See above ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Bgt_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; case OpCodes.Bgt_Un: //See above : This is unsigned variant ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0); break; case OpCodes.Bgt_Un_S: //See above ILOffset = (int)(sbyte)theOp.ValueBytes[0]; break; } if (ILOffset != 0) { //Get the IL number of the next op int startILNum = theOp.NextOffset; //Add the offset to get the IL op num to jump to int ILNumToGoTo = startILNum + ILOffset; //Find the IL op to jump to ILOp opToGoTo = preprocessState.Input.At(ILNumToGoTo); //Mark it as requiring a label opToGoTo.LabelRequired = true; } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { bool isFloat = false; int numBytes = 0; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Ldc_I4: numBytes = 4; break; case OpCodes.Ldc_I4_0: numBytes = 4; break; case OpCodes.Ldc_I4_1: numBytes = 4; break; case OpCodes.Ldc_I4_2: numBytes = 4; break; case OpCodes.Ldc_I4_3: numBytes = 4; break; case OpCodes.Ldc_I4_4: numBytes = 4; break; case OpCodes.Ldc_I4_5: numBytes = 4; break; case OpCodes.Ldc_I4_6: numBytes = 4; break; case OpCodes.Ldc_I4_7: numBytes = 4; break; case OpCodes.Ldc_I4_8: numBytes = 4; break; case OpCodes.Ldc_I4_M1: numBytes = 4; break; case OpCodes.Ldc_I4_S: numBytes = 4; break; case OpCodes.Ldc_I8: numBytes = 8; break; case OpCodes.Ldc_R4: numBytes = 4; isFloat = true; break; case OpCodes.Ldc_R8: numBytes = 8; isFloat = true; break; } conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = numBytes, isFloat = isFloat, isGCManaged = false }); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { ASMOps.JmpOp jumpOp = ASMOps.JmpOp.Jump; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Br: case OpCodes.Br_S: break; case OpCodes.Brtrue: jumpOp = ASMOps.JmpOp.JumpNotZero; break; case OpCodes.Brtrue_S: jumpOp = ASMOps.JmpOp.JumpNotZero; break; case OpCodes.Brfalse: jumpOp = ASMOps.JmpOp.JumpZero; break; case OpCodes.Brfalse_S: jumpOp = ASMOps.JmpOp.JumpZero; break; case OpCodes.Beq: jumpOp = ASMOps.JmpOp.JumpEqual; break; case OpCodes.Beq_S: jumpOp = ASMOps.JmpOp.JumpEqual; break; case OpCodes.Bne_Un: jumpOp = ASMOps.JmpOp.JumpNotEqual; break; case OpCodes.Bne_Un_S: jumpOp = ASMOps.JmpOp.JumpNotEqual; break; case OpCodes.Bge: jumpOp = ASMOps.JmpOp.JumpGreaterThanEqual; break; case OpCodes.Bge_S: jumpOp = ASMOps.JmpOp.JumpGreaterThanEqual; break; case OpCodes.Bge_Un: jumpOp = ASMOps.JmpOp.JumpGreaterThanEqual; break; case OpCodes.Bge_Un_S: jumpOp = ASMOps.JmpOp.JumpGreaterThanEqual; break; case OpCodes.Ble: jumpOp = ASMOps.JmpOp.JumpLessThanEqual; break; case OpCodes.Ble_S: jumpOp = ASMOps.JmpOp.JumpLessThanEqual; break; case OpCodes.Ble_Un: jumpOp = ASMOps.JmpOp.JumpLessThanEqual; break; case OpCodes.Ble_Un_S: jumpOp = ASMOps.JmpOp.JumpLessThanEqual; break; case OpCodes.Blt: jumpOp = ASMOps.JmpOp.JumpLessThan; break; case OpCodes.Blt_S: jumpOp = ASMOps.JmpOp.JumpLessThan; break; case OpCodes.Blt_Un: jumpOp = ASMOps.JmpOp.JumpLessThan; break; case OpCodes.Blt_Un_S: jumpOp = ASMOps.JmpOp.JumpLessThan; break; case OpCodes.Bgt: jumpOp = ASMOps.JmpOp.JumpGreaterThan; break; case OpCodes.Bgt_S: jumpOp = ASMOps.JmpOp.JumpGreaterThan; break; case OpCodes.Bgt_Un: jumpOp = ASMOps.JmpOp.JumpGreaterThan; break; case OpCodes.Bgt_Un_S: jumpOp = ASMOps.JmpOp.JumpGreaterThan; break; } if (jumpOp == ASMOps.JmpOp.JumpZero || jumpOp == ASMOps.JmpOp.JumpNotZero) { //Pop from our stack the test item to use in the condition StackItem testItem = conversionState.CurrentStackFrame.Stack.Pop(); } else if (jumpOp == ASMOps.JmpOp.JumpEqual || jumpOp == ASMOps.JmpOp.JumpNotEqual || jumpOp == ASMOps.JmpOp.JumpGreaterThanEqual || jumpOp == ASMOps.JmpOp.JumpLessThanEqual || jumpOp == ASMOps.JmpOp.JumpLessThan || jumpOp == ASMOps.JmpOp.JumpGreaterThan) { //Pop from our stack the test items to use in the condition StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop(); StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop(); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { rotateStackItems(conversionState, theOp.StackSwitch_Items, 1); }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { Int16 index = 0; switch ((OpCodes)theOp.opCode.Value) { case OpCodes.Ldarg: index = Utilities.ReadInt16(theOp.ValueBytes, 0); break; case OpCodes.Ldarg_0: index = 0; break; case OpCodes.Ldarg_1: index = 1; break; case OpCodes.Ldarg_2: index = 2; break; case OpCodes.Ldarg_3: index = 3; break; case OpCodes.Ldarg_S: index = (Int16)theOp.ValueBytes[0]; break; case OpCodes.Ldarga: index = Utilities.ReadInt16(theOp.ValueBytes, 0); break; case OpCodes.Ldarga_S: index = (Int16)theOp.ValueBytes[0]; break; } if ((OpCodes)theOp.opCode.Value == OpCodes.Ldarga || (OpCodes)theOp.opCode.Value == OpCodes.Ldarga_S) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = 4, isFloat = false, isGCManaged = false, isValue = false }); } else { Types.VariableInfo argInfo = conversionState.Input.TheMethodInfo.ArgumentInfos[index]; Types.TypeInfo paramTypeInfo = argInfo.TheTypeInfo; int bytesForArg = paramTypeInfo.SizeOnStackInBytes; conversionState.CurrentStackFrame.Stack.Push(new StackItem() { sizeOnStackInBytes = bytesForArg, isFloat = false, isGCManaged = paramTypeInfo.IsGCManaged, isValue = paramTypeInfo.IsValueType }); } }
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp) { //Pop in reverse order to push StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop(); StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop(); if (itemA.sizeOnStackInBytes == 4 && itemB.sizeOnStackInBytes == 4) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 4, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } else if ((itemA.sizeOnStackInBytes == 8 && itemB.sizeOnStackInBytes == 4)) { if ((OpCodes)theOp.opCode.Value == OpCodes.Shr_Un) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 8, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } else { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 8, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } } else if (itemA.sizeOnStackInBytes == 8 && itemB.sizeOnStackInBytes == 8) { if ((OpCodes)theOp.opCode.Value == OpCodes.Shr_Un) { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 8, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } else { conversionState.CurrentStackFrame.Stack.Push(new StackItem() { isFloat = false, sizeOnStackInBytes = 8, isGCManaged = false, isValue = itemA.isValue && itemB.isValue }); } } }