This commit is contained in:
mterwoord_cp 2009-10-20 16:26:31 +00:00
parent c9cbc44fa7
commit 2fadbd16fe
25 changed files with 261 additions and 102 deletions

View file

@ -38,6 +38,19 @@ namespace MatthijsTest
#endregion
public static void Init(){
try
{
Console.WriteLine("Try");
throw new Exception("Error message");
}
catch(Exception E)
{
Console.Write("Error: ");
Console.WriteLine(E.ToString());
}
Console.WriteLine("Klaar");
while (true)
;
var xInit = true;
if (xInit)
{

View file

@ -35,7 +35,7 @@ namespace Cosmos.IL2CPU.X86.IL
Assembler.Stack.Push( new StackContents.Item( 4, typeof( object ) ) );
Assembler.Stack.Push( new StackContents.Item( 4, typeof( object ) ) );
System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" );
new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance ) );
new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler ) );
new Label( xCurrentMethodLabel + "_After_IsInstance_Call" );
Assembler.Stack.Pop();
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };

View file

@ -33,7 +33,7 @@ namespace Cosmos.IL2CPU.X86.IL
System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" );
new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance) );
new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler));
new Label( GetLabel( aMethod, aOpCode ) + "_After_IsInstance_Call" );
Assembler.Stack.Pop();

View file

@ -15,13 +15,12 @@ namespace Cosmos.IL2CPU.X86.IL
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
{
#warning TODO: Implement exception
// new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
// new CPUx86.Move { DestinationRef = ElementReference.New( DataMember.GetStaticFieldName( Assembler.Assembler.CurrentExceptionRef ) ), DestinationIsIndirect = true, SourceReg = CPUx86.Registers.EAX };
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
new CPUx86.Move { DestinationRef = ElementReference.New( DataMember.GetStaticFieldName( ExceptionHelperRefs.CurrentExceptionRef ) ), DestinationIsIndirect = true, SourceReg = CPUx86.Registers.EAX };
//new CPUx86.Call { DestinationLabel = aExceptionOccurredLabel };
//new CPUx86.Move { DestinationReg = CPUx86.Registers.ECX, SourceValue = 3 };
//Call.EmitExceptionLogic( Assembler, ( uint )aCurrentILOffset, aMethodInfo, null, false, null );
new CPUx86.ClrInterruptFlag();
new CPUx86.Halt();
new CPUx86.Move { DestinationReg = CPUx86.Registers.ECX, SourceValue = 3 };
Call.EmitExceptionLogic( Assembler,aMethod, aOpCode, false, null );
Assembler.Stack.Pop();

View file

@ -38,7 +38,7 @@ namespace Cosmos.IL2CPU.X86.IL
new CPUx86.Push { DestinationRef = ElementReference.New( xTypeID ), DestinationIsIndirect = true };
Assembler.Stack.Push( new StackContents.Item( 4, typeof( uint ) ) );
System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" );
new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance ) );
new Call(Assembler).Execute(aMethod, new OpMethod(ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler));
new Label( BaseLabel + "_After_IsInstance_Call" );
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };

View file

@ -38,7 +38,7 @@ namespace Cosmos.IL2CPU.X86.IL
new CPUx86.Push { DestinationRef = ElementReference.New( xTypeID ), DestinationIsIndirect = true };
Assembler.Stack.Push( new StackContents.Item( 4, typeof( uint ) ) );
System.Reflection.MethodBase xMethodIsInstance = ReflectionUtilities.GetMethodBase( typeof( VTablesImpl ), "IsInstance", "System.Int32", "System.Int32" );
new Call( Assembler ).Execute( aMethod, new OpMethod( ILOpCode.Code.Call, 0, 0, xMethodIsInstance ) );
new Call(Assembler).Execute(aMethod, new OpMethod(ILOpCode.Code.Call, 0, 0, xMethodIsInstance, aOpCode.CurrentExceptionHandler));
new Label( BaseLabel + "_After_IsInstance_Call" );
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };

View file

@ -19,12 +19,12 @@ namespace Cosmos.IL2CPU.X86 {
Assembler = (Assembler)aAsmblr;
}
protected void Jump_Exception(MethodInfo aMethod) {
protected static void Jump_Exception(MethodInfo aMethod) {
// todo: port to numeric labels
new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AssemblerNasm.EndOfMethodLabelNameException };
}
protected void Jump_End(MethodInfo aMethod) {
protected static void Jump_End(MethodInfo aMethod) {
new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AssemblerNasm.EndOfMethodLabelNameNormal };
}
@ -123,5 +123,74 @@ namespace Cosmos.IL2CPU.X86 {
orderby item.Offset descending
select item.Offset + item.Size).FirstOrDefault();
}
public static void EmitExceptionLogic(Assembler aAssembler, MethodInfo aMethodInfo, ILOpCode aCurrentOpCode, bool aDoTest, Action aCleanup)
{
string xJumpTo = null;
if (aCurrentOpCode != null && aCurrentOpCode.CurrentExceptionHandler != null)
{
// todo add support for nested handlers, see comment in Engine.cs
//if (!((aMethodInfo.CurrentHandler.HandlerOffset < aCurrentOpOffset) || (aMethodInfo.CurrentHandler.HandlerLength + aMethodInfo.CurrentHandler.HandlerOffset) <= aCurrentOpOffset)) {
new Comment(String.Format("CurrentOffset = {0}, HandlerStartOffset = {1}", aCurrentOpCode.Position, aCurrentOpCode.CurrentExceptionHandler.HandlerOffset));
if (aCurrentOpCode.CurrentExceptionHandler.HandlerOffset > aCurrentOpCode.Position)
{
switch (aCurrentOpCode.CurrentExceptionHandler.Flags)
{
case ExceptionHandlingClauseOptions.Clause:
{
xJumpTo = ILOp.GetLabel(aMethodInfo, aCurrentOpCode.CurrentExceptionHandler.HandlerOffset);
break;
}
case ExceptionHandlingClauseOptions.Finally:
{
xJumpTo = ILOp.GetLabel(aMethodInfo, aCurrentOpCode.CurrentExceptionHandler.HandlerOffset);
break;
}
default:
{
throw new Exception("ExceptionHandlerType '" + aCurrentOpCode.CurrentExceptionHandler.Flags.ToString() + "' not supported yet!");
}
}
}
}
if (!aDoTest)
{
//new CPUx86.Call("_CODE_REQUESTED_BREAK_");
if (xJumpTo == null)
{
Jump_End(aMethodInfo);
}
else
{
new CPUx86.Jump { DestinationLabel = xJumpTo };
}
}
else
{
new CPUx86.Test { DestinationReg = CPUx86.Registers.ECX, SourceValue = 2 };
if (aCleanup != null)
{
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Equal, DestinationLabel = ILOp.GetLabel(aMethodInfo, aCurrentOpCode.NextPosition) };
aCleanup();
if (xJumpTo == null)
{
Jump_End(aMethodInfo);
}
else
{ new CPUx86.Jump { DestinationLabel = xJumpTo }; }
}
else
{
if (xJumpTo == null)
{
Jump_End(aMethodInfo);
}
else
{ new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = xJumpTo }; }
}
}
}
}
}

View file

@ -2,12 +2,24 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace Cosmos.IL2CPU {
public static class ExceptionHelper {
public static Exception CurrentException;
public static void ThrowNotImplemented(string aError) {
Console.WriteLine(aError);
throw new NotImplementedException(aError);
}
}
public static class ExceptionHelperRefs
{
public static readonly FieldInfo CurrentExceptionRef;
static ExceptionHelperRefs()
{
CurrentExceptionRef = typeof(ExceptionHelper).GetField("CurrentException");
}
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SR = System.Reflection;
namespace Cosmos.IL2CPU {
// ILOpcode represents the opcode during for scanning.
@ -248,10 +249,13 @@ namespace Cosmos.IL2CPU {
// position of the next instruction
public readonly int NextPosition;
protected ILOpCode(Code aOpCode, int aPos, int aNextPos) {
public readonly SR.ExceptionHandlingClause CurrentExceptionHandler;
protected ILOpCode(Code aOpCode, int aPos, int aNextPos, SR.ExceptionHandlingClause aCurrentExceptionHandler) {
OpCode = aOpCode;
Position = aPos;
NextPosition = aNextPos;
CurrentExceptionHandler = aCurrentExceptionHandler;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpBranch : ILOpCode {
public readonly int Value;
public OpBranch(Code aOpCode, int aPos, int aNextPos, int aValue)
: base(aOpCode, aPos, aNextPos) {
public OpBranch(Code aOpCode, int aPos, int aNextPos, int aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpDouble : ILOpCode {
public readonly Double Value;
public OpDouble(Code aOpCode, int aPos, int aNextPos, Double aValue)
: base(aOpCode, aPos, aNextPos) {
public OpDouble(Code aOpCode, int aPos, int aNextPos, Double aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -8,8 +8,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpField : ILOpCode {
public readonly FieldInfo Value;
public OpField(Code aOpCode, int aPos, int aNextPos, FieldInfo aValue)
: base(aOpCode, aPos, aNextPos) {
public OpField(Code aOpCode, int aPos, int aNextPos, FieldInfo aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpInt : ILOpCode {
public readonly UInt32 Value;
public OpInt(Code aOpCode, int aPos, int aNextPos, UInt32 aValue)
: base(aOpCode, aPos, aNextPos) {
public OpInt(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpInt64 : ILOpCode {
public readonly UInt64 Value;
public OpInt64(Code aOpCode, int aPos, int aNextPos, UInt64 aValue)
: base(aOpCode, aPos, aNextPos) {
public OpInt64(Code aOpCode, int aPos, int aNextPos, UInt64 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -11,8 +11,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public MethodBase BaseMethod;
public uint BaseMethodUID;
public OpMethod(Code aOpCode, int aPos, int aNextPos, MethodBase aValue)
: base(aOpCode, aPos, aNextPos) {
public OpMethod(Code aOpCode, int aPos, int aNextPos, MethodBase aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -6,8 +6,8 @@ using System.Text;
namespace Cosmos.IL2CPU.ILOpCodes {
public class OpNone : ILOpCode {
public OpNone(Code aOpCode, int aPos, int aNextPos)
: base(aOpCode, aPos, aNextPos) {
public OpNone(Code aOpCode, int aPos, int aNextPos, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpSig : ILOpCode {
public readonly UInt32 Value;
public OpSig(Code aOpCode, int aPos, int aNextPos, UInt32 aValue)
: base(aOpCode, aPos, aNextPos) {
public OpSig(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpSingle : ILOpCode {
public readonly Single Value;
public OpSingle(Code aOpCode, int aPos, int aNextPos, Single aValue)
: base(aOpCode, aPos, aNextPos) {
public OpSingle(Code aOpCode, int aPos, int aNextPos, Single aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpString : ILOpCode {
public readonly string Value;
public OpString(Code aOpCode, int aPos, int aNextPos, string aValue)
: base(aOpCode, aPos, aNextPos) {
public OpString(Code aOpCode, int aPos, int aNextPos, string aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpSwitch : ILOpCode {
public readonly int[] BranchLocations;
public OpSwitch(Code aOpCode, int aPos, int aNextPos, int[] aBranchLocations)
: base(aOpCode, aPos, aNextPos) {
public OpSwitch(Code aOpCode, int aPos, int aNextPos, int[] aBranchLocations, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
BranchLocations = aBranchLocations;
}
}

View file

@ -41,8 +41,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
}
}
public OpToken(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, Module aModule, Type[] aTypeGenericArgs, Type[] aMethodGenericArgs)
: base(aOpCode, aPos, aNextPos) {
public OpToken(Code aOpCode, int aPos, int aNextPos, UInt32 aValue, Module aModule, Type[] aTypeGenericArgs, Type[] aMethodGenericArgs, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
if (ValueIsField)
{

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpType : ILOpCode {
public readonly Type Value;
public OpType(Code aOpCode, int aPos, int aNextPos, Type aValue)
: base(aOpCode, aPos, aNextPos) {
public OpType(Code aOpCode, int aPos, int aNextPos, Type aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -7,8 +7,8 @@ namespace Cosmos.IL2CPU.ILOpCodes {
public class OpVar : ILOpCode {
public readonly UInt16 Value;
public OpVar(Code aOpCode, int aPos, int aNextPos, UInt16 aValue)
: base(aOpCode, aPos, aNextPos) {
public OpVar(Code aOpCode, int aPos, int aNextPos, UInt16 aValue, System.Reflection.ExceptionHandlingClause aCurrentExceptionHandler)
: base(aOpCode, aPos, aNextPos, aCurrentExceptionHandler) {
Value = aValue;
}
}

View file

@ -60,7 +60,68 @@ namespace Cosmos.IL2CPU {
var xIL = xBody.GetILAsByteArray();
int xPos = 0;
while (xPos < xIL.Length) {
ILOpCode.Code xOpCodeVal;
ExceptionHandlingClause xCurrentHandler = null;
#region Determine current handler
// todo: add support for nested handlers using a stack or so..
foreach (ExceptionHandlingClause xHandler in xBody.ExceptionHandlingClauses)
{
if (xHandler.TryOffset > 0)
{
if (xHandler.TryOffset <= xPos && (xHandler.TryLength + xHandler.TryOffset + 1) > xPos) // + 1 because index should be less than the try
{
if (xCurrentHandler == null)
{
xCurrentHandler = xHandler;
continue;
}
else if (xHandler.TryOffset > xCurrentHandler.TryOffset && (xHandler.TryLength + xHandler.TryOffset) < (xCurrentHandler.TryLength + xCurrentHandler.TryOffset))
{
// only replace if the current found handler is narrower
xCurrentHandler = xHandler;
continue;
}
}
}
if (xHandler.HandlerOffset > 0)
{
if (xHandler.HandlerOffset <= xPos && (xHandler.HandlerOffset + xHandler.HandlerLength + 1) > xPos)
{
if (xCurrentHandler == null)
{
xCurrentHandler = xHandler;
continue;
}
else if (xHandler.HandlerOffset > xCurrentHandler.HandlerOffset && (xHandler.HandlerOffset + xHandler.HandlerLength) < (xCurrentHandler.HandlerOffset + xCurrentHandler.HandlerLength))
{
// only replace if the current found handler is narrower
xCurrentHandler = xHandler;
continue;
}
}
}
if ((xHandler.Flags & ExceptionHandlingClauseOptions.Filter) > 0)
{
if (xHandler.FilterOffset > 0)
{
if (xHandler.FilterOffset <= xPos)
{
if (xCurrentHandler == null)
{
xCurrentHandler = xHandler;
continue;
}
else if (xHandler.FilterOffset > xCurrentHandler.FilterOffset)
{
// only replace if the current found handler is narrower
xCurrentHandler = xHandler;
continue;
}
}
}
}
}
#endregion
ILOpCode.Code xOpCodeVal;
OpCode xOpCode;
int xOpPos = xPos;
if (xIL[xPos] == 0xFE) {
@ -82,73 +143,73 @@ namespace Cosmos.IL2CPU {
// by allowing them to ignore the shortcuts
switch (xOpCodeVal) {
case ILOpCode.Code.Ldarg_0:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 0);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 0, xCurrentHandler);
break;
case ILOpCode.Code.Ldarg_1:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 1);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 1, xCurrentHandler);
break;
case ILOpCode.Code.Ldarg_2:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 2);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 2, xCurrentHandler);
break;
case ILOpCode.Code.Ldarg_3:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 3);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos, 3, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_0:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_1:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 1);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 1, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_2:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 2);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 2, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_3:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 3);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 3, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_4:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 4);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 4, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_5:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 5);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 5, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_6:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 6);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 6, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_7:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 7);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 7, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_8:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 8);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 8, xCurrentHandler);
break;
case ILOpCode.Code.Ldc_I4_M1:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0xFFFFFFFF);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos, 0xFFFFFFFF, xCurrentHandler);
break;
case ILOpCode.Code.Ldloc_0:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 0);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 0, xCurrentHandler);
break;
case ILOpCode.Code.Ldloc_1:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 1);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 1, xCurrentHandler);
break;
case ILOpCode.Code.Ldloc_2:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 2);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 2, xCurrentHandler);
break;
case ILOpCode.Code.Ldloc_3:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 3);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos, 3, xCurrentHandler);
break;
case ILOpCode.Code.Stloc_0:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 0);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 0, xCurrentHandler);
break;
case ILOpCode.Code.Stloc_1:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 1);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 1, xCurrentHandler);
break;
case ILOpCode.Code.Stloc_2:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 2);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 2, xCurrentHandler);
break;
case ILOpCode.Code.Stloc_3:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 3);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos, 3, xCurrentHandler);
break;
default:
xILOpCode = new ILOpCodes.OpNone(xOpCodeVal, xOpPos, xPos);
xILOpCode = new ILOpCodes.OpNone(xOpCodeVal, xOpPos, xPos, xCurrentHandler);
break;
}
break;
@ -162,49 +223,49 @@ namespace Cosmos.IL2CPU {
CheckBranch(xTarget, xIL.Length);
switch (xOpCodeVal) {
case ILOpCode.Code.Beq_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Beq, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Beq, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Bge_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Bge_Un_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge_Un, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bge_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Bgt_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Bgt_Un_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt_Un, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bgt_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Ble_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Ble_Un_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble_Un, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Ble_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Blt_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Blt_Un_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt_Un, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Blt_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Bne_Un_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bne_Un, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Bne_Un, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Br_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Br, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Br, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Brfalse_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brfalse, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brfalse, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Brtrue_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brtrue, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Brtrue, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
case ILOpCode.Code.Leave_S:
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Leave, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(ILOpCode.Code.Leave, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
default:
xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 1, xTarget);
xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 1, xTarget, xCurrentHandler);
break;
}
xPos = xPos + 1;
@ -213,7 +274,7 @@ namespace Cosmos.IL2CPU {
case OperandType.InlineBrTarget: {
int xTarget = xPos + 4 + (Int32)ReadUInt32(xIL, xPos);
CheckBranch(xTarget, xIL.Length);
xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 4, xTarget);
xILOpCode = new ILOpCodes.OpBranch(xOpCodeVal, xOpPos, xPos + 4, xTarget, xCurrentHandler);
xPos = xPos + 4;
break;
}
@ -221,36 +282,36 @@ namespace Cosmos.IL2CPU {
case OperandType.ShortInlineI:
switch (xOpCodeVal) {
case ILOpCode.Code.Ldc_I4_S:
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
default:
xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
}
xPos = xPos + 1;
break;
case OperandType.InlineI:
xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos));
xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), xCurrentHandler);
xPos = xPos + 4;
break;
case OperandType.InlineI8:
xILOpCode = new ILOpCodes.OpInt64(xOpCodeVal, xOpPos, xPos + 8, ReadUInt64(xIL, xPos));
xILOpCode = new ILOpCodes.OpInt64(xOpCodeVal, xOpPos, xPos + 8, ReadUInt64(xIL, xPos), xCurrentHandler);
xPos = xPos + 8;
break;
case OperandType.ShortInlineR:
xILOpCode = new ILOpCodes.OpSingle(xOpCodeVal, xOpPos, xPos + 4, BitConverter.ToSingle(xIL, xPos));
xILOpCode = new ILOpCodes.OpSingle(xOpCodeVal, xOpPos, xPos + 4, BitConverter.ToSingle(xIL, xPos), xCurrentHandler);
xPos = xPos + 4;
break;
case OperandType.InlineR:
xILOpCode = new ILOpCodes.OpDouble(xOpCodeVal, xOpPos, xPos + 8, BitConverter.ToDouble(xIL, xPos));
xILOpCode = new ILOpCodes.OpDouble(xOpCodeVal, xOpPos, xPos + 8, BitConverter.ToDouble(xIL, xPos), xCurrentHandler);
xPos = xPos + 8;
break;
// The operand is a 32-bit metadata token.
case OperandType.InlineField: {
var xValue = aMethod.Module.ResolveField((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs);
xILOpCode = new ILOpCodes.OpField(xOpCodeVal, xOpPos, xPos + 4, xValue);
xILOpCode = new ILOpCodes.OpField(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler);
xPos = xPos + 4;
break;
}
@ -258,7 +319,7 @@ namespace Cosmos.IL2CPU {
// The operand is a 32-bit metadata token.
case OperandType.InlineMethod: {
var xValue = aMethod.Module.ResolveMethod((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs);
xILOpCode = new ILOpCodes.OpMethod(xOpCodeVal, xOpPos, xPos + 4, xValue);
xILOpCode = new ILOpCodes.OpMethod(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler);
xPos = xPos + 4;
break;
}
@ -266,12 +327,12 @@ namespace Cosmos.IL2CPU {
// 32-bit metadata signature token.
case OperandType.InlineSig:
//TODO: What are these used for? A breakpoint causes no breaks with current tests...
xILOpCode = new ILOpCodes.OpSig(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos));
xILOpCode = new ILOpCodes.OpSig(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), xCurrentHandler);
xPos = xPos + 4;
break;
case OperandType.InlineString:
xILOpCode = new ILOpCodes.OpString(xOpCodeVal, xOpPos, xPos + 4, aMethod.Module.ResolveString((int)ReadUInt32(xIL, xPos)));
xILOpCode = new ILOpCodes.OpString(xOpCodeVal, xOpPos, xPos + 4, aMethod.Module.ResolveString((int)ReadUInt32(xIL, xPos)), xCurrentHandler);
xPos = xPos + 4;
break;
@ -284,21 +345,21 @@ namespace Cosmos.IL2CPU {
xBranchLocations[i] = xNextOpPos + (int)ReadUInt32(xIL, xPos + i * 4);
CheckBranch(xBranchLocations[i], xIL.Length);
}
xILOpCode = new ILOpCodes.OpSwitch(xOpCodeVal, xOpPos, xPos, xBranchLocations);
xILOpCode = new ILOpCodes.OpSwitch(xOpCodeVal, xOpPos, xPos, xBranchLocations, xCurrentHandler);
xPos = xNextOpPos;
break;
}
// The operand is a FieldRef, MethodRef, or TypeRef token.
case OperandType.InlineTok:
xILOpCode = new ILOpCodes.OpToken(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), aMethod.Module, xTypeGenArgs, xMethodGenArgs);
xILOpCode = new ILOpCodes.OpToken(xOpCodeVal, xOpPos, xPos + 4, ReadUInt32(xIL, xPos), aMethod.Module, xTypeGenArgs, xMethodGenArgs, xCurrentHandler);
xPos = xPos + 4;
break;
// 32-bit metadata token.
case OperandType.InlineType: {
var xValue = aMethod.Module.ResolveType((int)ReadUInt32(xIL, xPos), xTypeGenArgs, xMethodGenArgs);
xILOpCode = new ILOpCodes.OpType(xOpCodeVal, xOpPos, xPos + 4, xValue);
xILOpCode = new ILOpCodes.OpType(xOpCodeVal, xOpPos, xPos + 4, xValue, xCurrentHandler);
xPos = xPos + 4;
break;
}
@ -306,31 +367,31 @@ namespace Cosmos.IL2CPU {
case OperandType.ShortInlineVar:
switch (xOpCodeVal) {
case ILOpCode.Code.Ldloc_S:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloc, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
case ILOpCode.Code.Ldloca_S:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloca, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldloca, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
case ILOpCode.Code.Ldarg_S:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarg, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
case ILOpCode.Code.Ldarga_S:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarga, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Ldarga, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
case ILOpCode.Code.Starg_S:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Starg, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Starg, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
case ILOpCode.Code.Stloc_S:
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(ILOpCode.Code.Stloc, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
default:
xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos]);
xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);
break;
}
xPos = xPos + 1;
break;
case OperandType.InlineVar:
xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 2, ReadUInt16(xIL, xPos));
xILOpCode = new ILOpCodes.OpVar(xOpCodeVal, xOpPos, xPos + 2, ReadUInt16(xIL, xPos), xCurrentHandler);
xPos = xPos + 2;
break;

View file

@ -243,6 +243,7 @@ namespace Cosmos.IL2CPU {
Queue(xThrowHelper.GetMethod("ThrowInvalidOperationException", BindingFlags.NonPublic | BindingFlags.Static), null, "Explicit Entry");
Queue(typeof(MulticastDelegate).GetMethod("GetInvocationList"), null, "Explicit Entry");
Queue(ExceptionHelperRefs.CurrentExceptionRef, null, "Explicit Entry");
//System_Delegate____System_MulticastDelegate_GetInvocationList__
// Start from entry point of this program