本文整理汇总了C#中Drivers.Compiler.IL.ILConversionState.PositionOf方法的典型用法代码示例。如果您正苦于以下问题:C# ILConversionState.PositionOf方法的具体用法?C# ILConversionState.PositionOf怎么用?C# ILConversionState.PositionOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drivers.Compiler.IL.ILConversionState
的用法示例。
在下文中一共展示了ILConversionState.PositionOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
if (theOp.IsDebugOp)
{
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "Debug", IsDebugOp = true });
conversionState.Append(new ASMOps.Nop());
//conversionState.Append(new ASMOps.Int() { IntNum = "3" });
}
else
{
conversionState.Append(new ASMOps.Nop());
}
}
示例2: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if field to load is a floating value or the field to load
/// is not of size 4 or 8 bytes.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
conversionState.CurrentStackFrame.Stack.Pop();
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
int lengthOffset = conversionState.TheILLibrary.GetFieldInfo(arrayTypeInfo, "length").OffsetInBytes;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
// 1. Check array reference is not null
// 1.1. Move array ref into eax
// 1.2. Compare eax (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 2. Load array length
// 1.1. Move array ref into eax
GlobalMethods.InsertPageFaultDetection(conversionState, "ESP", 0, (OpCodes)theOp.opCode.Value);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP]", Dest = "EAX" });
// 1.2. Compare eax (array ref) to 0
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "0" });
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotZero, DestILPosition = currOpPosition, Extension = "ContinueExecution1" });
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "ContinueExecution1" });
//2. Load array length
// - Pop array ref
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "ECX" });
// - Load length from array ref
GlobalMethods.InsertPageFaultDetection(conversionState, "ECX", lengthOffset, (OpCodes)theOp.opCode.Value);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ECX+" + lengthOffset.ToString() + "]", Dest = "EAX" });
// - Push array length
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false
});
}
示例3: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if field to load is a floating value or the field to load
/// is not of size 4 or 8 bytes.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
conversionState.CurrentStackFrame.Stack.Pop();
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
int lengthOffset = conversionState.TheILLibrary.GetFieldInfo(arrayTypeInfo, "length").OffsetInBytes;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
// 1. Check array reference is not null
// 1.1. Move array ref into $t0
// 1.2. Compare $t0 (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 2. Load array length
// 1.1. Move array ref into eax
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0($sp)", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
// 1.2. Compare eax (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Branch() { Src1 = "$t0", Src2 = "0", BranchType = ASMOps.BranchOp.BranchNotZero, DestILPosition = currOpPosition, Extension = "ContinueExecution1", UnsignedTest = false });
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "ContinueExecution1" });
//2. Load array length
// - Pop array ref
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t2" });
// - Load length from array ref
//conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = lengthOffset.ToString() + "($t2)", Dest = "$t0" });
GlobalMethods.LoadData(conversionState, theOp, "$t2", "$t0", lengthOffset, 4);
// - Push array length
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false,
isValue = true
});
}
示例4: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
int currOpPosition = conversionState.PositionOf(theOp);
// Test if the object provided inherits from the specified class
// 1. Pop object ref
// 1.1. Test if object ref is null:
// 1.1.1 True: Push null and continue
// 1.1.2 False: Go to 2
// 2. Load object type
// 3. Test if object type == provided type:
// 3.1 True: Push object ref and continue
// 3.2 False:
// 3.2.1. Move to base type
// 3.2.2. Test if base type null:
// 3.2.2.1 True: Push null and continue
// 3.2.2.2 False: Jump back to (3)
// 1. Pop object ref
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
// 1.1. Test if object ref is null:
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "0" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "False1" });
// 1.1.1 True: Push null and continue
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.Jump, DestILPosition = currOpPosition, Extension = "End" });
// 1.1.2 False: Go to 2
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "False1" });
// 2. Load object type
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[EAX]", Dest = "EBX" });
// 3. Test if object type == provided type:
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
Type theType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
Types.TypeInfo theTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theType);
string TestTypeId = theTypeInfo.ID;
conversionState.AddExternalLabel(TestTypeId);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = TestTypeId, Dest = "ECX" });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "Label3" });
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EBX", Arg2 = "ECX" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "False2" });
// 3.1 True: Push object ref and continue
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.Jump, DestILPosition = currOpPosition, Extension = "End" });
// 3.2 False:
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "False2" });
// 3.2.1. Move to base type
int baseTypeOffset = conversionState.GetTypeFieldOffset("TheBaseType");
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[EBX+"+baseTypeOffset+"]", Dest = "EBX" });
// 3.2.2. Test if base type null:
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EBX", Arg2 = "0" });
// 3.2.2.2 False: Jump back to (3)
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "Label3" });
// 3.2.2.1 True: Push null and continue
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "End" });
}
示例5: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
StackItem itemToConvert = conversionState.CurrentStackFrame.Stack.Pop();
int numBytesToConvertTo = 0;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Conv_I:
numBytesToConvertTo = 4;
break;
case OpCodes.Conv_I1:
numBytesToConvertTo = 1;
break;
case OpCodes.Conv_I2:
numBytesToConvertTo = 2;
break;
case OpCodes.Conv_I4:
numBytesToConvertTo = 4;
break;
case OpCodes.Conv_I8:
numBytesToConvertTo = 8;
break;
}
int bytesPopped = 0;
bool pushEDX = false;
switch(numBytesToConvertTo)
{
case 1:
//Convert to Int8 (byte)
//Sign extend to dword
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.ImmediateToReg });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Byte, Dest = "$t0", SignExtend = true });
bytesPopped = 1;
break;
case 2:
//Convert to Int16 (word)
//Sign extend to dword
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.ImmediateToReg });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Halfword, Dest = "$t0", SignExtend = true });
bytesPopped = 2;
break;
case 4:
//Convert to Int32 (dword)
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
bytesPopped = 4;
break;
case 8:
//Convert to Int64
if (itemToConvert.sizeOnStackInBytes == 8)
{
//Result stored in EAX:EDX
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t3" });
bytesPopped = 8;
}
else
{
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
conversionState.Append(new ASMOps.Mov() { Src = "$t0", Dest = "$t3", MoveType = ASMOps.Mov.MoveTypes.RegToReg, Size = ASMOps.OperandSize.Word });
conversionState.Append(new ASMOps.And() { Src1 = "$t3", Src2 = "0x80000000", Dest = "$t3" });
conversionState.Append(new ASMOps.Branch() { Src1 = "$t3", BranchType = ASMOps.BranchOp.BranchZero, DestILPosition = currOpPosition, Extension = "Positive" });
conversionState.Append(new ASMOps.Mov() { Src = "0xFFFFFFFF", Dest = "$t3", Size = ASMOps.OperandSize.Word, MoveType = ASMOps.Mov.MoveTypes.ImmediateToReg });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "Positive" });
bytesPopped = 4;
}
pushEDX = true;
break;
}
int bytesDiff = itemToConvert.sizeOnStackInBytes - bytesPopped;
if (bytesDiff > 0)
{
conversionState.Append(new ASMOps.Add() { Src1 = "$sp", Src2 = bytesDiff.ToString(), Dest = "$sp" });
}
if (pushEDX)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t3" });
}
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
sizeOnStackInBytes = (pushEDX ? 8 : 4),
isFloat = false,
isGCManaged = false
});
}
示例6: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if constant is a floating point number.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
Type elementType = null;
//bool pushValue = true;
int sizeToPop = 4;
bool isFloat = false;
int currOpPosition = conversionState.PositionOf(theOp);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowIndexOutOfRangeExceptionMethodInfo().ID);
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Stelem:
{
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the element type
elementType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
}
break;
case OpCodes.Stelem_R4:
case OpCodes.Stelem_R8:
//TODO - Add more StElem op variants support
throw new NotSupportedException("Stelem op variant not supported yet!");
case OpCodes.Stelem_I1:
sizeToPop = 1;
elementType = typeof(sbyte);
break;
case OpCodes.Stelem_I2:
sizeToPop = 2;
elementType = typeof(Int16);
break;
case OpCodes.Stelem_Ref:
elementType = null;
break;
case OpCodes.Stelem_I4:
elementType = typeof(Int32);
break;
case OpCodes.Stelem_I8:
sizeToPop = 8;
elementType = typeof(Int64);
break;
}
if (isFloat)
{
//TODO - Support floats
throw new NotSupportedException("StElem for floats not supported yet!");
}
//Get element from array and push the value onto the stack
// (or for LdElemA push the address of the value)
//This involves:
// 1. Check array reference is not null
// - If it is, throw NullReferenceException
// 2. Check array element type is correct
// - If not, throw ArrayTypeMismatchException
// 3. Check index to get is > -1 and < array length
// - If not, throw IndexOutOfRangeException
// 4. Calculate address of element
// 5. Pop the value from the stack into the element
//Stack setup upon entering this op: (top-most downwards)
// 0. Value to store (word or 2 words)
// 1. Index of element to get as Int32 (word)
// 2. Array object reference as address (word)
Types.TypeInfo arrayTypeInfo = conversionState.GetArrayTypeInfo();
// 1. Check array reference is not null
// 1.1. Move array ref into $t0
// 1.2. Compare $t0 (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
// 1.4. Otherwise, call Exceptions.ThrowNullReferenceException
// 1.1. Move array ref into $t0
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = (sizeToPop == 8 ? 12 : 8).ToString() + "($sp)", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
// 1.2. Compare $t0 (array ref) to 0
// 1.3. If not zero, jump to continue execution further down
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchNotZero, Src1 = "$t0", DestILPosition = currOpPosition, Extension = "Continue1" });
// 1.4. Otherwise, call Exceptions.Throw1NullReferenceException
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
//.........这里部分代码省略.........
示例7: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
int currOpPosition = conversionState.PositionOf(theOp);
// Test if the object provided inherits from the specified class
// 1. Pop object ref
// 1.1. Test if object ref is null:
// 1.1.1 True: Push null and continue
// 1.1.2 False: Go to 2
// 2. Load object type
// 3. Test if object type == provided type:
// 3.1 True: Push object ref and continue
// 3.2 False:
// 3.2.1. Move to base type
// 3.2.2. Test if base type null:
// 3.2.2.1 True: Push null and continue
// 3.2.2.2 False: Jump back to (3)
// 1. Pop object ref
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
// 1.1. Test if object ref is null:
conversionState.Append(new ASMOps.Branch() { Src1 = "$t0", Src2 = "0", BranchType = ASMOps.BranchOp.BranchNotEqual, DestILPosition = currOpPosition, Extension = "False1", UnsignedTest = true });
// 1.1.1 True: Push null and continue
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.Branch, DestILPosition = currOpPosition, Extension = "End" });
// 1.1.2 False: Go to 2
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "False1" });
// 2. Load object type
//conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0($t0)", Dest = "$t1", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
GlobalMethods.LoadData(conversionState, theOp, "$t0", "$t1", 0, 4);
// 3. Test if object type == provided type:
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
Type theType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
Types.TypeInfo theTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theType);
string TestTypeId = theTypeInfo.ID;
conversionState.AddExternalLabel(TestTypeId);
conversionState.Append(new ASMOps.La() { Label = TestTypeId, Dest = "$t2" });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "Label3" });
conversionState.Append(new ASMOps.Branch() { Src1 = "$t1", Src2 = "$t2", BranchType = ASMOps.BranchOp.BranchNotEqual, DestILPosition = currOpPosition, Extension = "False2", UnsignedTest = true });
// 3.1 True: Push object ref and continue
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.Branch, DestILPosition = currOpPosition, Extension = "End" });
// 3.2 False:
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "False2" });
// 3.2.1. Move to base type
int baseTypeOffset = conversionState.GetTypeFieldOffset("TheBaseType");
//conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = baseTypeOffset + "($t1)", Dest = "$t1" });
GlobalMethods.LoadData(conversionState, theOp, "$t1", "$t1", baseTypeOffset, 4);
// 3.2.2. Test if base type null:
// 3.2.2.2 False: Jump back to (3)
conversionState.Append(new ASMOps.Branch() { Src1 = "$t1", Src2 = "0", BranchType = ASMOps.BranchOp.BranchNotEqual, DestILPosition = currOpPosition, Extension = "Label3", UnsignedTest = true });
// 3.2.2.1 True: Push null and continue
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "End" });
}
示例8: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if divide operands are floating point numbers or if attempting to divide 64-bit numbers.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Thrown if either operand is < 4 bytes long.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
StackItem testItem = conversionState.CurrentStackFrame.Stack.Pop();
if (testItem.isFloat)
{
//TODO - Support floats
throw new NotSupportedException("Switch for floats no supported!");
}
else if (testItem.sizeOnStackInBytes != 4)
{
//TODO - Support other sizes
throw new NotSupportedException("Switch for non-int32s not supported!");
}
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
for (int i = 0; i < theOp.ValueBytes.Length / 4; i++)
{
int branchOffset = theOp.NextOffset + Utilities.ReadInt32(theOp.ValueBytes, i * 4);
ILOp opToGoTo = conversionState.Input.At(branchOffset);
int branchPos = conversionState.PositionOf(opToGoTo);
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = i.ToString() });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpEqual, DestILPosition = branchPos });
}
}
示例9: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if either or both values to shift left are floating point values or
/// if the values are 8 bytes in size.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Thrown if either or both values to multiply are not 4 or 8 bytes
/// in size or if the values are of different size.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Pop in reverse order to push
StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop();
StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop();
int currOpPosition = conversionState.PositionOf(theOp);
if (itemB.sizeOnStackInBytes < 4 ||
itemA.sizeOnStackInBytes < 4)
{
throw new InvalidOperationException("Invalid stack operand sizes!");
}
else if (itemB.isFloat || itemA.isFloat)
{
//SUPPORT - floats
throw new NotSupportedException("Shift right on floats is unsupported!");
}
else
{
bool SignedShift = (OpCodes)theOp.opCode.Value != OpCodes.Shr_Un;
if (itemA.sizeOnStackInBytes == 4 &&
itemB.sizeOnStackInBytes == 4)
{
//Pop item B
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "ECX" });
//Pop item A
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
conversionState.Append(new ASMOps.Shr() { Src = "CL", Dest = "EAX", Signed = SignedShift });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false
});
}
else if ((itemA.sizeOnStackInBytes == 4 &&
itemB.sizeOnStackInBytes == 8))
{
throw new InvalidOperationException("Invalid stack operand sizes! 4,8 not supported.");
}
else if ((itemA.sizeOnStackInBytes == 8 &&
itemB.sizeOnStackInBytes == 4))
{
if (!SignedShift)
{
//Pop item B
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "ECX" });
//Pop item A (8 bytes)
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EDX" });
//Check shift size
conversionState.Append(new ASMOps.Cmp() { Arg1 = "ECX", Arg2 = "32" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpGreaterThanEqual, DestILPosition = currOpPosition, Extension = "ShiftMoreThan32", UnsignedTest = true });
//Shr (< 32)
conversionState.Append(new ASMOps.Shr() { Src = "EDX", Dest = "EAX", Count = "CL" });
conversionState.Append(new ASMOps.Shr() { Src = "CL", Dest = "EDX" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.Jump, DestILPosition = currOpPosition, Extension = "End" });
//Shr (>= 32)
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "ShiftMoreThan32" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "EDX", Dest = "EAX" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "0", Dest = "EDX" });
conversionState.Append(new ASMOps.Sub() { Src = "32", Dest = "ECX" });
conversionState.Append(new ASMOps.Shr() { Src = "CL", Dest = "EAX" });
//Push result
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "End" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EDX" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 8,
isGCManaged = false
});
}
else
{
//Pop item B
//.........这里部分代码省略.........
示例10: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if the value to store is floating point.
/// </exception>
/// <exception cref="System.NotImplementedException">
/// Thrown if the op is 'StIndRef'.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Pop value
//Pop address
//Mov [address], value
StackItem valueItem = conversionState.CurrentStackFrame.Stack.Pop();
StackItem addressItem = conversionState.CurrentStackFrame.Stack.Pop();
int bytesToStore = 0;
bool isFloat = false;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Stind_I:
bytesToStore = 4;
break;
case OpCodes.Stind_I1:
bytesToStore = 1;
break;
case OpCodes.Stind_I2:
bytesToStore = 2;
break;
case OpCodes.Stind_I4:
bytesToStore = 4;
break;
case OpCodes.Stind_I8:
bytesToStore = 8;
break;
case OpCodes.Stind_R4:
bytesToStore = 4;
isFloat = true;
break;
case OpCodes.Stind_R8:
bytesToStore = 8;
isFloat = true;
break;
case OpCodes.Stind_Ref:
bytesToStore = 4;
break;
}
if (isFloat)
{
//SUPPORT - floats
throw new NotSupportedException("Floats not supported yet!");
}
int currOpPosition = conversionState.PositionOf(theOp);
if (bytesToStore == 8)
{
//Pop value low bits
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
//Pop value high bits
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t3" });
//Pop address
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t1" });
// Alignment tests
conversionState.Append(new ASMOps.And() { Src1 = "$t1", Src2 = "3", Dest = "$t5" });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchEqual, Src1 = "$t5", Src2 = "1", DestILPosition = currOpPosition, Extension = "ByteAligned" });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchEqual, Src1 = "$t5", Src2 = "2", DestILPosition = currOpPosition, Extension = "HalfwordAligned" });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchEqual, Src1 = "$t5", Src2 = "3", DestILPosition = currOpPosition, Extension = "ByteAligned" });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.Branch, DestILPosition = currOpPosition, Extension = "WordAligned" });
//Mov [address], value
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "ByteAligned" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t0", Dest = "0($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Srl() { Src = "$t0", Dest = "$t0", Bits = 8 });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t0", Dest = "1($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Srl() { Src = "$t0", Dest = "$t0", Bits = 8 });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t0", Dest = "2($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Srl() { Src = "$t0", Dest = "$t0", Bits = 8 });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t0", Dest = "3($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t3", Dest = "4($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Srl() { Src = "$t3", Dest = "$t3", Bits = 8 });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t3", Dest = "5($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Srl() { Src = "$t3", Dest = "$t3", Bits = 8 });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t3", Dest = "6($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Srl() { Src = "$t3", Dest = "$t3", Bits = 8 });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "$t3", Dest = "7($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.Branch, DestILPosition = currOpPosition, Extension = "End" });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "HalfwordAligned" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Halfword, Src = "$t0", Dest = "0($t1)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
//.........这里部分代码省略.........
示例11: ScanNonpluggedILBlock
/// <summary>
/// Scans the specified non-plugged IL block.
/// </summary>
/// <param name="TheLibrary">The library currently being compiled.</param>
/// <param name="theMethodInfo">The method which generated the IL block.</param>
/// <param name="theILBlock">The IL block to scan.</param>
/// <returns>CompileResult.OK.</returns>
private static CompileResult ScanNonpluggedILBlock(ILLibrary TheLibrary, Types.MethodInfo theMethodInfo, ILBlock theILBlock)
{
CompileResult result = CompileResult.OK;
ASM.ASMBlock TheASMBlock = new ASM.ASMBlock()
{
OriginMethodInfo = theMethodInfo,
Priority = theMethodInfo.Priority
};
ILConversionState convState = new ILConversionState()
{
TheILLibrary = TheLibrary,
CurrentStackFrame = new StackFrame(),
Input = theILBlock,
Result = TheASMBlock
};
foreach (ILOp anOp in theILBlock.ILOps)
{
try
{
string commentText = TheASMBlock.GenerateILOpLabel(convState.PositionOf(anOp), "") + " -- " + anOp.opCode.ToString() + " -- Offset: " + anOp.Offset.ToString("X2");
ASM.ASMOp newCommentOp = TargetArchitecture.CreateASMOp(ASM.OpCodes.Comment, commentText);
TheASMBlock.ASMOps.Add(newCommentOp);
int currCount = TheASMBlock.ASMOps.Count;
if (anOp is ILOps.MethodStart)
{
TargetArchitecture.MethodStartOp.Convert(convState, anOp);
}
else if (anOp is ILOps.MethodEnd)
{
TargetArchitecture.MethodEndOp.Convert(convState, anOp);
}
else if (anOp is ILOps.StackSwitch)
{
TargetArchitecture.StackSwitchOp.Convert(convState, anOp);
}
else
{
ILOp ConverterOp = TargetArchitecture.TargetILOps[(ILOp.OpCodes)anOp.opCode.Value];
ConverterOp.Convert(convState, anOp);
}
if (anOp.LabelRequired)
{
if (currCount < TheASMBlock.ASMOps.Count)
{
TheASMBlock.ASMOps[currCount].ILLabelPosition = convState.PositionOf(anOp);
TheASMBlock.ASMOps[currCount].RequiresILLabel = true;
}
}
}
catch (KeyNotFoundException)
{
result = CompileResult.PartialFailure;
Logger.LogError(Errors.ILCompiler_ScanILOpFailure_ErrorCode, theMethodInfo.ToString(), anOp.Offset,
string.Format(Errors.ErrorMessages[Errors.ILCompiler_ScanILOpFailure_ErrorCode], Enum.GetName(typeof(ILOp.OpCodes), anOp.opCode.Value), "Conversion for IL op not found."));
}
catch (InvalidOperationException ex)
{
result = CompileResult.PartialFailure;
Logger.LogError(Errors.ILCompiler_ScanILOpFailure_ErrorCode, theMethodInfo.ToString(), anOp.Offset,
string.Format(Errors.ErrorMessages[Errors.ILCompiler_ScanILOpFailure_ErrorCode], Enum.GetName(typeof(ILOp.OpCodes), anOp.opCode.Value), ex.Message));
}
catch (NotSupportedException ex)
{
result = CompileResult.PartialFailure;
Logger.LogError(Errors.ILCompiler_ScanILOpFailure_ErrorCode, theMethodInfo.ToString(), anOp.Offset,
string.Format(Errors.ErrorMessages[Errors.ILCompiler_ScanILOpFailure_ErrorCode], Enum.GetName(typeof(ILOp.OpCodes), anOp.opCode.Value), "An IL op reported something as not supported : " + ex.Message));
}
catch (Exception ex)
{
result = CompileResult.Fail;
Logger.LogError(Errors.ILCompiler_ScanILOpFailure_ErrorCode, theMethodInfo.ToString(), anOp.Offset,
string.Format(Errors.ErrorMessages[Errors.ILCompiler_ScanILOpFailure_ErrorCode], Enum.GetName(typeof(ILOp.OpCodes), anOp.opCode.Value), ex.Message));
}
}
TheLibrary.TheASMLibrary.ASMBlocks.Add(TheASMBlock);
return result;
}
示例12: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if compare operands are floating point numbers or if either value is < 4 bytes in length or
/// operands are not of the same size.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Pop in reverse order to push
StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop();
StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop();
int currOpPosition = conversionState.PositionOf(theOp);
if (itemB.isFloat || itemA.isFloat)
{
//SUPPORT - floats
throw new NotSupportedException("Compare floats is unsupported!");
}
else if(itemA.sizeOnStackInBytes == 4 && itemB.sizeOnStackInBytes == 4)
{
//Pop item B
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EBX" });
//Pop item A
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
//Compare A to B
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "EBX" });
//If A != B, jump to Else (not-true case)
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "Else" });
//Otherwise, A = B, so push true (true=1)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "1" });
//And then jump to the end of this IL op.
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.Jump, DestILPosition = currOpPosition, Extension = "End" });
//Insert the Else label.
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "Else" });
//Else case - Push false (false=0)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
//Push the result onto our stack
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false,
isValue = true
});
}
else if (itemA.sizeOnStackInBytes == 8 && itemB.sizeOnStackInBytes == 8)
{
//Pop item B
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EBX" });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "ECX" });
//Pop item A
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EDX" });
//If A high bytes = B high bytes : Check, if A low bytes = B low bytes : True
//Else : False
//Compare high bytes
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EDX", Arg2 = "ECX" });
//A high bytes != B high bytes? Jump to else case.
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "Else" });
//Otherwise, A high bytes = B high bytes
//So compare low bytes
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "EBX" });
//A low bytes != B low bytes? Jump to else case.
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "Else" });
//Otherwise A = B.
//Insert True case label
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "True" });
//True case - Push true (true=1)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "1" });
//And then jump to the end of this IL op.
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.Jump, DestILPosition = currOpPosition, Extension = "End" });
//Insert Else case label
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "Else" });
//Else case - Push false (false=0)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
//Push the result onto our stack
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
// Yes, this is supposed to be 4 - the value that just got pushed was a
// true / false integer
sizeOnStackInBytes = 4,
isGCManaged = false,
isValue = true
});
}
else
{
throw new NotSupportedException("Unsupported number of bytes for compare equal to!");
}
//.........这里部分代码省略.........
示例13: Convert
//.........这里部分代码省略.........
conversionState.Append(new ASMOps.Add() { Src = bytesToAdd.ToString(), Dest = "ESP" });
//If necessary, push the return value onto the stack.
if (returnItem.sizeOnStackInBytes != 0)
{
//SUPPORT - floats (with above)
//The return value was stored in eax
//So push it back onto the stack
if (returnItem.sizeOnStackInBytes == 4)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
}
else if (returnItem.sizeOnStackInBytes == 8)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EDX" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
}
}
}
else
{
//Normal callvirt
// - Get object ref from loaded args
// - Check object ref not null
// - Get type table entry from object ref
// - Get method table from type table entry
// - Scan method table for the method we want
// - If found, load method address
// - Else, check for parent type method table
// - If no parent type method table, throw exception
// - Else, scan parent type method table
string methodIDValueWanted = methodToCallInfo.IDValue.ToString();
int currOpPosition = conversionState.PositionOf(theOp);
Types.TypeInfo declaringTypeInfo = conversionState.TheILLibrary.GetTypeInfo(methodToCall.DeclaringType);
//DB_Type declaringDBType = DebugDatabase.GetType(conversionState.GetTypeID(methodToCall.DeclaringType));
//Get object ref
int bytesForAllParams = ((MethodInfo)methodToCall).GetParameters().Select(x => conversionState.TheILLibrary.GetTypeInfo(x.ParameterType).SizeOnStackInBytes).Sum();
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP+" + bytesForAllParams + "]", Dest = "EAX" });
//Check object ref
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = "0" });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotZero, DestILPosition = currOpPosition, Extension = "NotNull" });
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "NotNull" });
//Get type ref
int typeOffset = conversionState.TheILLibrary.GetFieldInfo(declaringTypeInfo, "_Type").OffsetInBytes;
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[EAX+" + typeOffset.ToString() + "]", Dest = "EAX" });
//Get method table ref
int methodTablePtrOffset = conversionState.GetTypeFieldOffset("MethodTablePtr");
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[EAX+" + methodTablePtrOffset.ToString() + "]", Dest = "EAX" });
//Loop through entries
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "LoopMethodTable" });
//Load ID Val for current entry
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[EAX]", Dest = "EBX" });
//Compare to wanted ID value
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EBX", Arg2 = methodIDValueWanted });
//If equal, load method address into EAX
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpNotEqual, DestILPosition = currOpPosition, Extension = "NotEqual" });
示例14: Convert
//.........这里部分代码省略.........
case OpCodes.Bgt_Un:
//See above : This is unsigned variant
ILOffset = Utilities.ReadInt32(theOp.ValueBytes, 0);
UnsignedTest = true;
//See above
jumpOp = ASMOps.JmpOp.JumpGreaterThan;
isNegativeTest = true;
break;
case OpCodes.Bgt_Un_S:
//See above
ILOffset = (sbyte)theOp.ValueBytes[0];
UnsignedTest = true;
//See above
jumpOp = ASMOps.JmpOp.JumpGreaterThan;
isNegativeTest = true;
break;
}
if (ILOffset == 0)
{
//Err..why bother jumping at all if the offset is 0?
conversionState.Append(new ASMOps.Comment("No jump insert - pointless 0 distance jump"));
}
else
{
//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 = conversionState.Input.At(ILNumToGoTo);
int opToGoToPosition = conversionState.PositionOf(opToGoTo);
int currOpPosition = conversionState.PositionOf(theOp);
//If the jump op is not a straightforward jump i.e. has one or more conditions
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();
if (testItem.isFloat)
{
//SUPPORT - floats
throw new NotSupportedException("Branch test based on float not supported!");
}
//If the test item is Int64 or UInt64 TODO: or Struct
else if (testItem.sizeOnStackInBytes == 8)
{
//Compare first 32 bits (low bits)
//Then (if necessary) compare second 32 bits (high bits)
//Pop the low bits
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
//Compare the low bits to the test value
conversionState.Append(new ASMOps.Cmp() { Arg2 = testVal, Arg1 = "EAX" });
//Pre-emptively pop the high bits
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
//If we are testing for not equal to zero:
if (jumpOp == ASMOps.JmpOp.JumpNotZero)
{
//If the low bits are not zero, do the jump
conversionState.Append(new ASMOps.Jmp() { JumpType = jumpOp, DestILPosition = opToGoToPosition });
//Otherwise, test if the high bits are not 0
示例15: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
MethodBase constructorMethod = theOp.MethodToCall;
Type objectType = constructorMethod.DeclaringType;
//New obj must:
// - Ignore for creation of Delegates
// - Allocate memory on the heap for the object
// - If no memory is left, throw a panic attack because we're out of memory...
// - Call the specified constructor
if (typeof(Delegate).IsAssignableFrom(objectType))
{
conversionState.Append(new ASMOps.Comment("Ignore newobj calls for Delegates"));
//Still need to:
// - Remove the "object" param but preserve the "function pointer"
StackItem funcPtrItem = conversionState.CurrentStackFrame.Stack.Pop(); ;
conversionState.CurrentStackFrame.Stack.Pop();
conversionState.CurrentStackFrame.Stack.Push(funcPtrItem);
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "0($sp)", Dest = "$t0", MoveType = ASMOps.Mov.MoveTypes.SrcMemoryToDestReg });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "$t0", Dest = "4($sp)", MoveType = ASMOps.Mov.MoveTypes.SrcRegToDestMemory });
conversionState.Append(new ASMOps.Add() { Src1 = "$sp", Src2 = "4", Dest = "$sp" });
return;
}
Types.MethodInfo constructorMethodInfo = conversionState.TheILLibrary.GetMethodInfo(constructorMethod);
conversionState.AddExternalLabel(conversionState.GetNewObjMethodInfo().ID);
conversionState.AddExternalLabel(conversionState.GetThrowNullReferenceExceptionMethodInfo().ID);
conversionState.AddExternalLabel(constructorMethodInfo.ID);
int currOpPosition = conversionState.PositionOf(theOp);
//Attempt to allocate memory on the heap for the new object
//This involves:
// - Pushing the type reference onto the stack
// - Calling GC NewObj method
// - Check the pointer == 0, if so, out of memory
//Push type reference
string typeIdStr = conversionState.TheILLibrary.GetTypeInfo(objectType).ID;
conversionState.AddExternalLabel(typeIdStr);
conversionState.Append(new ASMOps.La() { Dest = "$t4", Label = typeIdStr });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t4" });
//Push a word for return value (i.e. new object pointer)
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
//Get the GC.NewObj method ID (i.e. ASM label)
string methodLabel = conversionState.GetNewObjMethodInfo().ID;
//Call GC.NewObj
conversionState.Append(new ASMOps.Call() { Target = methodLabel });
//Pop the return value (i.e. new object pointer)
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
//Remove arg 0 from stack
conversionState.Append(new ASMOps.Add() { Src1 = "$sp", Src2 = "4", Dest = "$sp" });
//Check if pointer == 0?
//If it isn't 0, not out of memory so continue execution
conversionState.Append(new ASMOps.Branch() { BranchType = ASMOps.BranchOp.BranchNotZero, Src1 = "$t0", DestILPosition = currOpPosition, Extension = "NotNullMem" });
//If we are out of memory, we have a massive problem
//Because it means we don't have space to create a new exception object
//So ultimately we just have to throw a kernel panic
//Throw a panic attack... ( :/ ) by calling kernel Halt(uint lastAddress)
//result.AppendLine("call GetEIP");
//result.AppendLine("push dword esp");
//result.AppendLine("push dword ebp");
//result.AppendLine("pushad");
//result.AppendLine("mov dword eax, 0xDEADBEEF");
//result.AppendLine("mov dword ebx, 0x1");
//result.AppendLine("mov dword ecx, 1");
//result.AppendLine("mov dword [staticfield_System_Boolean_Kernel_FOS_System_GC_Enabled], 1");
//result.AppendLine("mov dword [staticfield_System_Boolean_Kernel_FOS_System_Heap_PreventAllocation], 0");
//result.AppendLine("jmp method_System_Void_RETEND_Kernel_PreReqs_DECLEND_PageFaultDetection_NAMEEND___Fail");
conversionState.Append(new ASMOps.Call() { Target = "GetEIP" });
conversionState.AddExternalLabel("GetEIP");
conversionState.Append(new ASMOps.Call() { Target = conversionState.GetThrowNullReferenceExceptionMethodInfo().ID });
//Insert the not null label
conversionState.Append(new ASMOps.Label() { ILPosition = currOpPosition, Extension = "NotNullMem" });
//Call the specified constructor
//This involves:
// - Push empty dword onto stack
// - Move all args down by one dword
// - Move object reference into dword as first arg
// - Call constructor
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
int sizeOfArgs = 0;
ParameterInfo[] allParams = constructorMethod.GetParameters();
foreach (ParameterInfo aParam in allParams)
{
sizeOfArgs += conversionState.TheILLibrary.GetTypeInfo(aParam.ParameterType).SizeOnStackInBytes;
conversionState.CurrentStackFrame.Stack.Pop();
}
//.........这里部分代码省略.........