mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 13:58:47 +00:00
This commit is contained in:
parent
fe74f892e3
commit
f36b48532e
5 changed files with 44 additions and 16 deletions
|
|
@ -41,6 +41,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ILOpX86.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
12
source2/IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs
Normal file
12
source2/IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.IL2CPU.X86 {
|
||||
public abstract class ILOpX86 : Cosmos.IL2CPU.ILOp {
|
||||
protected ILOpX86(ILOpCode aOpCode):base(aOpCode)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
|
||||
namespace Cosmos.IL2CPU.X86 {
|
||||
public class ILOpX86 : Cosmos.IL2CPU.ILOp {
|
||||
public abstract class ILOpX86 : Cosmos.IL2CPU.ILOp {
|
||||
protected ILOpX86(ILOpCode aOpCode):base(aOpCode)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,20 +31,6 @@ namespace Cosmos.IL2CPU {
|
|||
}
|
||||
}
|
||||
|
||||
//protected void LoadILOpCodes(Type aAssemblerBaseOp) {
|
||||
// foreach (var xType in aAssemblerBaseOp.Assembly.GetExportedTypes()) {
|
||||
// if (xType.IsSubclassOf(aAssemblerBaseOp)) {
|
||||
// var xAttrib = (OpCodeAttribute)xType.GetCustomAttributes(typeof(OpCodeAttribute), false)[0];
|
||||
// var xOpCodeValue = (ushort)xAttrib.OpCode;
|
||||
// if (xOpCodeValue <= 0xFF) {
|
||||
// mILOpCodesLo[xOpCodeValue] = xType;
|
||||
// } else {
|
||||
// mILOpCodesHi[xOpCodeValue & 0xFF] = xType;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
public List<ILOpCode> ProcessMethod(MethodBase aMethod) {
|
||||
var xResult = new List<ILOpCode>();
|
||||
var xBody = aMethod.GetMethodBody();
|
||||
|
|
|
|||
|
|
@ -25,8 +25,31 @@ namespace Cosmos.IL2CPU {
|
|||
private HashSet<FieldInfo> mFieldsSet = new HashSet<FieldInfo>();
|
||||
protected ILReader mReader;
|
||||
|
||||
// TODO: Investigate this and see if Matthi's emit way
|
||||
// is a lot faster than calling GetConstructor than invoke
|
||||
protected ConstructorInfo[] mILOpsLo = new ConstructorInfo[256];
|
||||
protected ConstructorInfo[] mILOpsHi = new ConstructorInfo[256];
|
||||
|
||||
public ILScanner(Type aAssemblerBaseOp) {
|
||||
mReader = new ILReader();
|
||||
LoadILOps(aAssemblerBaseOp);
|
||||
foreach(var xCode in Enum.GetValues(typeof(ILOpCode.Code))) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void LoadILOps(Type aAssemblerBaseOp) {
|
||||
foreach (var xType in aAssemblerBaseOp.Assembly.GetExportedTypes()) {
|
||||
if (xType.IsSubclassOf(aAssemblerBaseOp)) {
|
||||
var xAttrib = (OpCodeAttribute)xType.GetCustomAttributes(typeof(OpCodeAttribute), false)[0];
|
||||
var xOpCode = (ushort)xAttrib.OpCode;
|
||||
var xCtor = xType.GetConstructors()[0];
|
||||
if (xOpCode <= 0xFF) {
|
||||
mILOpsLo[xOpCode] = xCtor;
|
||||
} else {
|
||||
mILOpsHi[xOpCode & 0xFF] = xCtor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(MethodInfo aEntry) {
|
||||
|
|
@ -61,7 +84,13 @@ namespace Cosmos.IL2CPU {
|
|||
if (xOpCodes != null) {
|
||||
foreach (var xOpCode in xOpCodes) {
|
||||
//InstructionCount++;
|
||||
//xOpCode.Scan(xReader, this);
|
||||
ConstructorInfo xCtor;
|
||||
if ((uint)xOpCode.OpCode <= 0xFF) {
|
||||
xCtor = mILOpsLo[(uint)xOpCode.OpCode];
|
||||
} else {
|
||||
xCtor = mILOpsHi[(uint)xOpCode.OpCode];
|
||||
}
|
||||
var xILOp = xCtor.Invoke(new object[] {xOpCode});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue