This commit is contained in:
kudzu_cp 2009-07-24 15:16:04 +00:00
parent 9e0e732327
commit ecfd73e408
4 changed files with 122 additions and 95 deletions

View file

@ -51,6 +51,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="ILOp.cs" /> <Compile Include="ILOp.cs" />
<Compile Include="ILOpCode.cs" /> <Compile Include="ILOpCode.cs" />
<Compile Include="ILOpCodes\InlineNone.cs" />
<Compile Include="ILReader.cs" /> <Compile Include="ILReader.cs" />
<Compile Include="OpCodeAttribute.cs" /> <Compile Include="OpCodeAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -9,6 +9,7 @@ namespace Cosmos.IL2CPU {
// Include reference to ILOp, the scanner should do that // Include reference to ILOp, the scanner should do that
// Include referense to System.Reflection.Emit, this is metadata // Include referense to System.Reflection.Emit, this is metadata
// only needed by reader and not ILOpCode // only needed by reader and not ILOpCode
//TODO: Change this to an abstract class and make constructor protected
public class ILOpCode { public class ILOpCode {
public readonly Code Value; public readonly Code Value;

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cosmos.IL2CPU.ILOpCodes {
public class InlineNone : ILOpCode {
public InlineNone(Code aValue) : base(aValue) {
}
}
}

View file

@ -77,9 +77,60 @@ namespace Cosmos.IL2CPU {
// Callvirt: QueueMethod(aReader.OperandValueMethod); // Callvirt: QueueMethod(aReader.OperandValueMethod);
// Newobj: QueueMethod(aReader.OperandValueMethod); // Newobj: QueueMethod(aReader.OperandValueMethod);
// TODO: Move all this parsing and moving forward logic into the ILOpCode instances. // Get arguments before Shortcut expansion.
// Default behaviour for most, but ones like switch should override. //TODO: Are all shortcuts wo arguments? if so we can skip this step for shortcuts
if (xOpCodeVal == ILOpCode.Code.Switch) {
int xOperandSize;
ILOpCode xILOpCode = null;
switch (xOpCode.OperandType) {
// The operand is a 32-bit integer branch target.
case OperandType.InlineBrTarget:
xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 32-bit metadata token.
case OperandType.InlineField:
xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 32-bit integer.
case OperandType.InlineI:
xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 64-bit integer.
case OperandType.InlineI8:
xOperandSize = 8;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 32-bit metadata token.
case OperandType.InlineMethod:
xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// No operand.
case OperandType.InlineNone:
xOperandSize = 0;
xILOpCode = new ILOpCodes.InlineNone(xOpCodeVal);
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 64-bit IEEE floating point number.
case OperandType.InlineR:
xOperandSize = 8;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 32-bit metadata signature token.
case OperandType.InlineSig:
xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
// The operand is a 32-bit metadata string token.
case OperandType.InlineString:
xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break;
case OperandType.InlineSwitch: {
int xCount = ReadInt32(xIL, 1); int xCount = ReadInt32(xIL, 1);
int[] xBranchLocations = new int[xCount]; int[] xBranchLocations = new int[xCount];
uint[] xBranchValues = new uint[xCount]; uint[] xBranchValues = new uint[xCount];
@ -91,89 +142,51 @@ namespace Cosmos.IL2CPU {
// } else { // } else {
// xResult[i] = (uint)(mPosition + xBranchLocations1[i]); // xResult[i] = (uint)(mPosition + xBranchLocations1[i]);
// } // }
xPos = xOpCodeSize + 4 + xCount * 4;
} }
} else { xOperandSize = 4 + xCount * 4;
// Get arguments before Shortcut expansion. xILOpCode = new ILOpCode(xOpCodeVal);
//TODO: Are all shortcuts wo arguments? if so we can skip this step for shortcuts break;
}
//TODO: case statements can eb consolidated, but later
// this will be expanded to handle the ILOpCode creations, so don't consolidate
int xOperandSize;
switch (xOpCode.OperandType) {
// The operand is a 32-bit integer branch target.
case OperandType.InlineBrTarget:
xOperandSize = 4;
break;
// The operand is a 32-bit metadata token.
case OperandType.InlineField:
xOperandSize = 4;
break;
// The operand is a 32-bit integer.
case OperandType.InlineI:
xOperandSize = 4;
break;
// The operand is a 64-bit integer.
case OperandType.InlineI8:
xOperandSize = 8;
break;
// The operand is a 32-bit metadata token.
case OperandType.InlineMethod:
xOperandSize = 4;
break;
// No operand.
case OperandType.InlineNone:
xOperandSize = 0;
break;
// The operand is a 64-bit IEEE floating point number.
case OperandType.InlineR:
xOperandSize = 8;
break;
// The operand is a 32-bit metadata signature token.
case OperandType.InlineSig:
xOperandSize = 4;
break;
// The operand is a 32-bit metadata string token.
case OperandType.InlineString:
xOperandSize = 4;
break;
// The operand is the 32-bit integer argument to a switch instruction.
case OperandType.InlineSwitch:
xOperandSize = 4;
break;
// The operand is a FieldRef, MethodRef, or TypeRef token. // The operand is a FieldRef, MethodRef, or TypeRef token.
case OperandType.InlineTok: case OperandType.InlineTok:
xOperandSize = 4; xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
// The operand is a 32-bit metadata token. // The operand is a 32-bit metadata token.
case OperandType.InlineType: case OperandType.InlineType:
xOperandSize = 4; xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
// OperandType.OperandType.OperandType.The operand is 16-bit integer containing the ordinal of a local variable or an argument. // OperandType.OperandType.OperandType.The operand is 16-bit integer containing the ordinal of a local variable or an argument.
case OperandType.InlineVar: case OperandType.InlineVar:
xOperandSize = 2; xOperandSize = 2;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
// The operand is an 8-bit integer branch target. // The operand is an 8-bit integer branch target.
case OperandType.ShortInlineBrTarget: case OperandType.ShortInlineBrTarget:
xOperandSize = 1; xOperandSize = 1;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
// The operand is an 8-bit integer. // The operand is an 8-bit integer.
case OperandType.ShortInlineI: case OperandType.ShortInlineI:
xOperandSize = 1; xOperandSize = 1;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
// The operand is a 32-bit IEEE floating point number. // The operand is a 32-bit IEEE floating point number.
case OperandType.ShortInlineR: case OperandType.ShortInlineR:
xOperandSize = 4; xOperandSize = 4;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
// The operand is an 8-bit integer containing the ordinal of a local variable or an argumenta. // The operand is an 8-bit integer containing the ordinal of a local variable or an argumenta.
case OperandType.ShortInlineVar: case OperandType.ShortInlineVar:
xOperandSize = 1; xOperandSize = 1;
xILOpCode = new ILOpCode(xOpCodeVal);
break; break;
default: default:
throw new Exception("Unknown OperandType"); throw new Exception("Unknown OperandType");
} }
xPos = xPos + xOpCodeSize + xOperandSize; xPos = xPos + xOpCodeSize + xOperandSize;
}
// TODO: Optimize this. Can possibly fill slots in the mOpCodesHi // TODO: Optimize this. Can possibly fill slots in the mOpCodesHi
// with the target op, or a translator fuction in the delegate // with the target op, or a translator fuction in the delegate
@ -186,7 +199,6 @@ namespace Cosmos.IL2CPU {
} }
} }
var xILOpCode = new ILOpCode(xOpCodeVal);
xResult.Add(xILOpCode); xResult.Add(xILOpCode);
} }
return xResult; return xResult;