From f36b48532ef5113ca8d335ebf7e9e77ddb4aace3 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Fri, 24 Jul 2009 18:47:55 +0000 Subject: [PATCH] --- .../Cosmos.IL2CPU.Profiler.csproj | 1 + .../IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs | 12 +++++++ source2/IL2PCU/Cosmos.IL2CPU.X86/ILOpX86.cs | 2 +- source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs | 14 --------- source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs | 31 ++++++++++++++++++- 5 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 source2/IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs diff --git a/source2/IL2PCU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj b/source2/IL2PCU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj index 8e2e9ec6e..e89797d80 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj +++ b/source2/IL2PCU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj @@ -41,6 +41,7 @@ + diff --git a/source2/IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs b/source2/IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs new file mode 100644 index 000000000..5030eb0ae --- /dev/null +++ b/source2/IL2PCU/Cosmos.IL2CPU.Profiler/ILOpX86.cs @@ -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) + { + } + } +} diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOpX86.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOpX86.cs index ec00425aa..5030eb0ae 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOpX86.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOpX86.cs @@ -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) { } diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs index 10c9dcf85..ba3d7b7c1 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs @@ -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 ProcessMethod(MethodBase aMethod) { var xResult = new List(); var xBody = aMethod.GetMethodBody(); diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs index 00ace96a0..f321639f6 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs @@ -25,8 +25,31 @@ namespace Cosmos.IL2CPU { private HashSet mFieldsSet = new HashSet(); 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}); } } }