mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
This commit is contained in:
parent
9e0e732327
commit
ecfd73e408
4 changed files with 122 additions and 95 deletions
|
|
@ -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" />
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
13
source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/InlineNone.cs
Normal file
13
source2/IL2PCU/Cosmos.IL2CPU/ILOpCodes/InlineNone.cs
Normal 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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -77,103 +77,116 @@ 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 xCount = ReadInt32(xIL, 1);
|
|
||||||
int[] xBranchLocations = new int[xCount];
|
|
||||||
uint[] xBranchValues = new uint[xCount];
|
|
||||||
for (int i = 0; i < xCount; i++) {
|
|
||||||
xBranchLocations[i] = xIL[i + 5];
|
|
||||||
//xBranchValues[i] =
|
|
||||||
// if ((mPosition + xBranchLocations1[i]) < 0) {
|
|
||||||
// xResult[i] = (uint)xBranchLocations1[i];
|
|
||||||
// } else {
|
|
||||||
// xResult[i] = (uint)(mPosition + xBranchLocations1[i]);
|
|
||||||
// }
|
|
||||||
xPos = xOpCodeSize + 4 + xCount * 4;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Get arguments before Shortcut expansion.
|
|
||||||
//TODO: Are all shortcuts wo arguments? if so we can skip this step for shortcuts
|
|
||||||
|
|
||||||
//TODO: case statements can eb consolidated, but later
|
int xOperandSize;
|
||||||
// this will be expanded to handle the ILOpCode creations, so don't consolidate
|
ILOpCode xILOpCode = null;
|
||||||
int xOperandSize;
|
switch (xOpCode.OperandType) {
|
||||||
switch (xOpCode.OperandType) {
|
// The operand is a 32-bit integer branch target.
|
||||||
// The operand is a 32-bit integer branch target.
|
case OperandType.InlineBrTarget:
|
||||||
case OperandType.InlineBrTarget:
|
xOperandSize = 4;
|
||||||
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[] xBranchLocations = new int[xCount];
|
||||||
|
uint[] xBranchValues = new uint[xCount];
|
||||||
|
for (int i = 0; i < xCount; i++) {
|
||||||
|
xBranchLocations[i] = xIL[i + 5];
|
||||||
|
//xBranchValues[i] =
|
||||||
|
// if ((mPosition + xBranchLocations1[i]) < 0) {
|
||||||
|
// xResult[i] = (uint)xBranchLocations1[i];
|
||||||
|
// } else {
|
||||||
|
// xResult[i] = (uint)(mPosition + xBranchLocations1[i]);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
xOperandSize = 4 + xCount * 4;
|
||||||
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
break;
|
break;
|
||||||
// The operand is a 32-bit metadata token.
|
}
|
||||||
case OperandType.InlineField:
|
|
||||||
xOperandSize = 4;
|
// The operand is a FieldRef, MethodRef, or TypeRef token.
|
||||||
break;
|
case OperandType.InlineTok:
|
||||||
// The operand is a 32-bit integer.
|
xOperandSize = 4;
|
||||||
case OperandType.InlineI:
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
xOperandSize = 4;
|
break;
|
||||||
break;
|
// The operand is a 32-bit metadata token.
|
||||||
// The operand is a 64-bit integer.
|
case OperandType.InlineType:
|
||||||
case OperandType.InlineI8:
|
xOperandSize = 4;
|
||||||
xOperandSize = 8;
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
break;
|
break;
|
||||||
// The operand is a 32-bit metadata token.
|
// OperandType.OperandType.OperandType.The operand is 16-bit integer containing the ordinal of a local variable or an argument.
|
||||||
case OperandType.InlineMethod:
|
case OperandType.InlineVar:
|
||||||
xOperandSize = 4;
|
xOperandSize = 2;
|
||||||
break;
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
// No operand.
|
break;
|
||||||
case OperandType.InlineNone:
|
// The operand is an 8-bit integer branch target.
|
||||||
xOperandSize = 0;
|
case OperandType.ShortInlineBrTarget:
|
||||||
break;
|
xOperandSize = 1;
|
||||||
// The operand is a 64-bit IEEE floating point number.
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
case OperandType.InlineR:
|
break;
|
||||||
xOperandSize = 8;
|
// The operand is an 8-bit integer.
|
||||||
break;
|
case OperandType.ShortInlineI:
|
||||||
// The operand is a 32-bit metadata signature token.
|
xOperandSize = 1;
|
||||||
case OperandType.InlineSig:
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
xOperandSize = 4;
|
break;
|
||||||
break;
|
// The operand is a 32-bit IEEE floating point number.
|
||||||
// The operand is a 32-bit metadata string token.
|
case OperandType.ShortInlineR:
|
||||||
case OperandType.InlineString:
|
xOperandSize = 4;
|
||||||
xOperandSize = 4;
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
break;
|
break;
|
||||||
// The operand is the 32-bit integer argument to a switch instruction.
|
// The operand is an 8-bit integer containing the ordinal of a local variable or an argumenta.
|
||||||
case OperandType.InlineSwitch:
|
case OperandType.ShortInlineVar:
|
||||||
xOperandSize = 4;
|
xOperandSize = 1;
|
||||||
break;
|
xILOpCode = new ILOpCode(xOpCodeVal);
|
||||||
// The operand is a FieldRef, MethodRef, or TypeRef token.
|
break;
|
||||||
case OperandType.InlineTok:
|
default:
|
||||||
xOperandSize = 4;
|
throw new Exception("Unknown OperandType");
|
||||||
break;
|
|
||||||
// The operand is a 32-bit metadata token.
|
|
||||||
case OperandType.InlineType:
|
|
||||||
xOperandSize = 4;
|
|
||||||
break;
|
|
||||||
// OperandType.OperandType.OperandType.The operand is 16-bit integer containing the ordinal of a local variable or an argument.
|
|
||||||
case OperandType.InlineVar:
|
|
||||||
xOperandSize = 2;
|
|
||||||
break;
|
|
||||||
// The operand is an 8-bit integer branch target.
|
|
||||||
case OperandType.ShortInlineBrTarget:
|
|
||||||
xOperandSize = 1;
|
|
||||||
break;
|
|
||||||
// The operand is an 8-bit integer.
|
|
||||||
case OperandType.ShortInlineI:
|
|
||||||
xOperandSize = 1;
|
|
||||||
break;
|
|
||||||
// The operand is a 32-bit IEEE floating point number.
|
|
||||||
case OperandType.ShortInlineR:
|
|
||||||
xOperandSize = 4;
|
|
||||||
break;
|
|
||||||
// The operand is an 8-bit integer containing the ordinal of a local variable or an argumenta.
|
|
||||||
case OperandType.ShortInlineVar:
|
|
||||||
xOperandSize = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue