mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
Now plugs which aren't being used aren't being compiled anymore.
This commit is contained in:
parent
a37de93ccb
commit
19160c30d4
15 changed files with 119 additions and 134 deletions
|
|
@ -17,7 +17,7 @@ namespace DebugCompiler
|
||||||
var xEngine = new Engine();
|
var xEngine = new Engine();
|
||||||
// Sets the time before an error is registered. For example if set to 60 then if a kernel runs for more than 60 seconds then
|
// Sets the time before an error is registered. For example if set to 60 then if a kernel runs for more than 60 seconds then
|
||||||
// that kernel will be marked as a failure and terminated
|
// that kernel will be marked as a failure and terminated
|
||||||
xEngine.AllowedSecondsInKernel = 30;
|
xEngine.AllowedSecondsInKernel = 300;
|
||||||
|
|
||||||
// If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are run.
|
// If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are run.
|
||||||
xEngine.RunTargets.Add(RunTargetEnum.Bochs);
|
xEngine.RunTargets.Add(RunTargetEnum.Bochs);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace Cosmos.Core.Plugs.System
|
||||||
[Plug(Target = typeof(Buffer))]
|
[Plug(Target = typeof(Buffer))]
|
||||||
public class BufferImpl
|
public class BufferImpl
|
||||||
{
|
{
|
||||||
|
[PlugMethod(IsOptional = true)]
|
||||||
public static unsafe void __Memcpy(byte* src, byte* dest, int count)
|
public static unsafe void __Memcpy(byte* src, byte* dest, int count)
|
||||||
{
|
{
|
||||||
global::System.Buffer.BlockCopy((Array)(object)*src, 0, (Array)(object)*dest, 0, count);
|
global::System.Buffer.BlockCopy((Array)(object)*src, 0, (Array)(object)*dest, 0, count);
|
||||||
|
|
@ -22,6 +22,7 @@ namespace Cosmos.Core.Plugs.System
|
||||||
/// <param name="dest">Destination address to copy data into.</param>
|
/// <param name="dest">Destination address to copy data into.</param>
|
||||||
/// <param name="src">Source address from where copy data.</param>
|
/// <param name="src">Source address from where copy data.</param>
|
||||||
/// <param name="count">Count of bytes to copy.</param>
|
/// <param name="count">Count of bytes to copy.</param>
|
||||||
|
[PlugMethod(IsOptional = true)]
|
||||||
public static unsafe void __Memmove(byte* dest, byte* src, uint count)
|
public static unsafe void __Memmove(byte* dest, byte* src, uint count)
|
||||||
{
|
{
|
||||||
uint t;
|
uint t;
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,11 @@ namespace Cosmos.Core.Plugs.System
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe bool InternalEqualTypes(uint** a, uint** b)
|
public static unsafe bool InternalEqualTypes([ObjectPointerAccess] uint** a, [ObjectPointerAccess] uint** b)
|
||||||
{
|
{
|
||||||
var xTypeA = a[0][0];
|
var xTypeA = a[0][0];
|
||||||
var xTypeB = b[0][0];
|
var xTypeB = b[0][0];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return xTypeA == xTypeB;
|
return xTypeA == xTypeB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace Cosmos.Core.Plugs.System
|
||||||
[Plug(Target = typeof(object))]
|
[Plug(Target = typeof(object))]
|
||||||
public class ObjectImpl
|
public class ObjectImpl
|
||||||
{
|
{
|
||||||
public static unsafe uint MemberwiseClone(uint aThis)
|
public static unsafe uint MemberwiseClone([ObjectPointerAccess] uint aThis)
|
||||||
{
|
{
|
||||||
// pointers are handles!
|
// pointers are handles!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -820,6 +820,7 @@ namespace Cosmos.Core.Plugs.System
|
||||||
return new string(new char[length]);
|
return new string(new char[length]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PlugMethod(IsOptional = true)]
|
||||||
public static string TrimStart(string aThis, string aSubStr)
|
public static string TrimStart(string aThis, string aSubStr)
|
||||||
{
|
{
|
||||||
char[] ci = aThis.ToCharArray();
|
char[] ci = aThis.ToCharArray();
|
||||||
|
|
|
||||||
2
source/Cosmos.IL2CPU.Plugs/.editorconfig
Normal file
2
source/Cosmos.IL2CPU.Plugs/.editorconfig
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
[*.cs]
|
||||||
|
indent_size=2
|
||||||
|
|
@ -90,6 +90,7 @@
|
||||||
<Compile Include="FieldTypeAttribute.cs" />
|
<Compile Include="FieldTypeAttribute.cs" />
|
||||||
<Compile Include="FieldAccessAttribute.cs" />
|
<Compile Include="FieldAccessAttribute.cs" />
|
||||||
<Compile Include="InlineAttribute.cs" />
|
<Compile Include="InlineAttribute.cs" />
|
||||||
|
<Compile Include="ObjectAccessPointerAttribute.cs" />
|
||||||
<Compile Include="PlugAttribute.cs" />
|
<Compile Include="PlugAttribute.cs" />
|
||||||
<Compile Include="PlugFieldAttribute.cs" />
|
<Compile Include="PlugFieldAttribute.cs" />
|
||||||
<Compile Include="PlugMethodAttribute.cs" />
|
<Compile Include="PlugMethodAttribute.cs" />
|
||||||
|
|
@ -99,6 +100,7 @@
|
||||||
<None Include="Key.snk" />
|
<None Include="Key.snk" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include=".editorconfig" />
|
||||||
<Content Include="ReadMe.html" />
|
<Content Include="ReadMe.html" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
13
source/Cosmos.IL2CPU.Plugs/ObjectAccessPointerAttribute.cs
Normal file
13
source/Cosmos.IL2CPU.Plugs/ObjectAccessPointerAttribute.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cosmos.IL2CPU.Plugs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This attribute is used on plug parameters, that need the unsafe pointer to an object's data area
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Parameter)]
|
||||||
|
public class ObjectPointerAccessAttribute : Attribute
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,5 +12,6 @@ namespace Cosmos.IL2CPU.Plugs
|
||||||
public bool PlugRequired = false;
|
public bool PlugRequired = false;
|
||||||
public bool IsWildcard = false;
|
public bool IsWildcard = false;
|
||||||
public bool WildcardMatchParameters = false;
|
public bool WildcardMatchParameters = false;
|
||||||
|
public bool IsOptional = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -209,26 +209,21 @@ namespace Cosmos.IL2CPU
|
||||||
{
|
{
|
||||||
DebugInfo.AddDocument(mSequences[0].Document);
|
DebugInfo.AddDocument(mSequences[0].Document);
|
||||||
|
|
||||||
var xMethod = new Method()
|
var xMethod = new Method();
|
||||||
|
xMethod.ID = mCurrentMethodGuid;
|
||||||
|
xMethod.TypeToken = aMethod.MethodBase.DeclaringType.MetadataToken;
|
||||||
|
xMethod.MethodToken = aMethod.MethodBase.MetadataToken;
|
||||||
|
xMethod.LabelStartID = xLabelGuid;
|
||||||
|
xMethod.LabelEndID = mCurrentMethodLabelEndGuid;
|
||||||
|
xMethod.LabelCall = xMethodLabel;
|
||||||
|
long xAssemblyFileID;
|
||||||
|
if (DebugInfo.AssemblyGUIDs.TryGetValue(aMethod.MethodBase.DeclaringType.Assembly, out xAssemblyFileID))
|
||||||
{
|
{
|
||||||
ID = mCurrentMethodGuid,
|
xMethod.AssemblyFileID = xAssemblyFileID;
|
||||||
TypeToken = aMethod.MethodBase.DeclaringType.MetadataToken,
|
}
|
||||||
MethodToken = aMethod.MethodBase.MetadataToken,
|
xMethod.DocumentID = DebugInfo.DocumentGUIDs[mSequences[0].Document.ToLower()];
|
||||||
|
xMethod.LineColStart = ((Int64)mSequences[0].LineStart << 32) + mSequences[0].ColStart;
|
||||||
LabelStartID = xLabelGuid,
|
xMethod.LineColEnd = ((Int64)(mSequences[mSequences.Length - 1].LineEnd) << 32) + mSequences[mSequences.Length - 1].ColEnd;
|
||||||
LabelEndID = mCurrentMethodLabelEndGuid,
|
|
||||||
LabelCall = xMethodLabel,
|
|
||||||
|
|
||||||
AssemblyFileID = DebugInfo.AssemblyGUIDs[aMethod.MethodBase.DeclaringType.Assembly],
|
|
||||||
DocumentID = DebugInfo.DocumentGUIDs[mSequences[0].Document.ToLower()],
|
|
||||||
|
|
||||||
// Storing Line + Col as one item makes comparisons MUCH easier, otherwise we have to
|
|
||||||
// check for things like col < start col but line > start line.
|
|
||||||
//
|
|
||||||
// () around << are VERY important.. + has precedence over <<
|
|
||||||
LineColStart = ((Int64)mSequences[0].LineStart << 32) + mSequences[0].ColStart,
|
|
||||||
LineColEnd = ((Int64)(mSequences[mSequences.Length - 1].LineEnd) << 32) + mSequences[mSequences.Length - 1].ColEnd
|
|
||||||
};
|
|
||||||
DebugInfo.AddMethod(xMethod);
|
DebugInfo.AddMethod(xMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -475,6 +470,11 @@ namespace Cosmos.IL2CPU
|
||||||
throw new Exception("Method needs plug, but no plug was assigned.");
|
throw new Exception("Method needs plug, but no plug was assigned.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aMethod.MethodBase.Name == "InitializeArray")
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
// todo: MtW: how to do this? we need some extra space.
|
// todo: MtW: how to do this? we need some extra space.
|
||||||
// see ConstructLabel for extra info
|
// see ConstructLabel for extra info
|
||||||
if (aMethod.UID > 0x00FFFFFF)
|
if (aMethod.UID > 0x00FFFFFF)
|
||||||
|
|
@ -492,7 +492,7 @@ namespace Cosmos.IL2CPU
|
||||||
}
|
}
|
||||||
else if (aMethod.IsInlineAssembler)
|
else if (aMethod.IsInlineAssembler)
|
||||||
{
|
{
|
||||||
aMethod.MethodBase.Invoke("", new object[aMethod.MethodBase.GetParameters().Length]);
|
aMethod.MethodBase.Invoke(null, new object[aMethod.MethodBase.GetParameters().Length]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Cosmos.IL2CPU
|
||||||
mAsmblr = aAsmblr;
|
mAsmblr = aAsmblr;
|
||||||
mReader = new ILReader();
|
mReader = new ILReader();
|
||||||
|
|
||||||
mPlugManager = new PlugManager(this.LogException, this.ScanMethod, this.Queue);
|
mPlugManager = new PlugManager(LogException);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool EnableLogging(string aPathname)
|
public bool EnableLogging(string aPathname)
|
||||||
|
|
@ -94,6 +94,11 @@ namespace Cosmos.IL2CPU
|
||||||
|
|
||||||
protected void Queue(_MemberInfo aItem, object aSrc, string aSrcType, string sourceItem = null)
|
protected void Queue(_MemberInfo aItem, object aSrc, string aSrcType, string sourceItem = null)
|
||||||
{
|
{
|
||||||
|
if (aItem == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(aItem));
|
||||||
|
}
|
||||||
|
|
||||||
var xMemInfo = aItem as MemberInfo;
|
var xMemInfo = aItem as MemberInfo;
|
||||||
//TODO: fix this, as each label/symbol should also contain an assembly specifier.
|
//TODO: fix this, as each label/symbol should also contain an assembly specifier.
|
||||||
|
|
||||||
|
|
@ -373,7 +378,6 @@ namespace Cosmos.IL2CPU
|
||||||
// isn't guaranteed.
|
// isn't guaranteed.
|
||||||
//string xMethodFullName = LabelName.GenerateFullName(aMethod);
|
//string xMethodFullName = LabelName.GenerateFullName(aMethod);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < xParams.Length; i++)
|
for (int i = 0; i < xParams.Length; i++)
|
||||||
{
|
{
|
||||||
xParamTypes[i] = xParams[i].ParameterType;
|
xParamTypes[i] = xParams[i].ParameterType;
|
||||||
|
|
@ -479,10 +483,19 @@ namespace Cosmos.IL2CPU
|
||||||
|
|
||||||
MethodBase xPlug = null;
|
MethodBase xPlug = null;
|
||||||
// Plugs may use plugs, but plugs won't be plugged over themself
|
// Plugs may use plugs, but plugs won't be plugged over themself
|
||||||
|
var inl = aMethod.GetCustomAttribute<InlineAttribute>();
|
||||||
if (!aIsPlug && !xIsDynamicMethod)
|
if (!aIsPlug && !xIsDynamicMethod)
|
||||||
{
|
{
|
||||||
// Check to see if method is plugged, if it is we don't scan body
|
// Check to see if method is plugged, if it is we don't scan body
|
||||||
xPlug = mPlugManager.ResolvePlug(aMethod, xParamTypes);
|
xPlug = mPlugManager.ResolvePlug(aMethod, xParamTypes);
|
||||||
|
if (xPlug != null)
|
||||||
|
{
|
||||||
|
//ScanMethod(xPlug, true, "Plug method");
|
||||||
|
if (inl == null)
|
||||||
|
{
|
||||||
|
Queue(xPlug, aMethod, "Plug method");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xPlug == null)
|
if (xPlug == null)
|
||||||
|
|
@ -517,11 +530,6 @@ namespace Cosmos.IL2CPU
|
||||||
//TODO: Dont queue new items if they are plugged
|
//TODO: Dont queue new items if they are plugged
|
||||||
// or do we need to queue them with a resolved ref in a new list?
|
// or do we need to queue them with a resolved ref in a new list?
|
||||||
|
|
||||||
InlineAttribute inl = null;
|
|
||||||
foreach (InlineAttribute inli in aMethod.GetCustomAttributes(typeof(InlineAttribute), false))
|
|
||||||
{
|
|
||||||
inl = inli;
|
|
||||||
}
|
|
||||||
if (inl != null)
|
if (inl != null)
|
||||||
return; // cancel inline
|
return; // cancel inline
|
||||||
|
|
||||||
|
|
@ -651,6 +659,7 @@ namespace Cosmos.IL2CPU
|
||||||
// and will reduce compares
|
// and will reduce compares
|
||||||
if (xItem.Item is MethodBase)
|
if (xItem.Item is MethodBase)
|
||||||
{
|
{
|
||||||
|
//if (xItem.QueueReason == "Plug m")
|
||||||
ScanMethod((MethodBase)xItem.Item, false, xItem.SourceItem);
|
ScanMethod((MethodBase)xItem.Item, false, xItem.SourceItem);
|
||||||
}
|
}
|
||||||
else if (xItem.Item is Type)
|
else if (xItem.Item is Type)
|
||||||
|
|
@ -834,20 +843,33 @@ namespace Cosmos.IL2CPU
|
||||||
var xMethodType = MethodInfo.TypeEnum.Normal;
|
var xMethodType = MethodInfo.TypeEnum.Normal;
|
||||||
Type xPlugAssembler = null;
|
Type xPlugAssembler = null;
|
||||||
MethodInfo xPlugInfo = null;
|
MethodInfo xPlugInfo = null;
|
||||||
|
var xMethodInline = xMethod.GetCustomAttribute<InlineAttribute>();
|
||||||
|
if (xMethodInline != null)
|
||||||
|
{
|
||||||
|
// inline assembler, shouldn't come here..
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var xMethodIdMethod = mItemsList.IndexOf(xMethod);
|
||||||
|
if (xMethodIdMethod == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Method not in scanner list!");
|
||||||
|
}
|
||||||
if (xPlug != null)
|
if (xPlug != null)
|
||||||
{
|
{
|
||||||
xMethodType = MethodInfo.TypeEnum.NeedsPlug;
|
xMethodType = MethodInfo.TypeEnum.NeedsPlug;
|
||||||
PlugMethodAttribute xAttrib = null;
|
var xAttrib = xPlug.GetCustomAttribute<PlugMethodAttribute>();
|
||||||
foreach (PlugMethodAttribute attrib in xPlug.GetCustomAttributes(typeof(PlugMethodAttribute), true))
|
var xInline = xPlug.GetCustomAttribute<InlineAttribute>();
|
||||||
|
var xMethodIdPlug = mItemsList.IndexOf(xPlug);
|
||||||
|
if (xMethodIdPlug == -1 && xInline == null)
|
||||||
{
|
{
|
||||||
xAttrib = attrib;
|
throw new Exception("Plug method not in scanner list!");
|
||||||
}
|
}
|
||||||
if (xAttrib != null)
|
if (xAttrib != null && xInline == null)
|
||||||
{
|
{
|
||||||
xPlugAssembler = xAttrib.Assembler;
|
xPlugAssembler = xAttrib.Assembler;
|
||||||
xPlugInfo = new MethodInfo(xPlug, (uint)mItemsList.IndexOf(xPlug), MethodInfo.TypeEnum.Plug, null, xPlugAssembler);
|
xPlugInfo = new MethodInfo(xPlug, (uint)xMethodIdPlug, MethodInfo.TypeEnum.Plug, null, xPlugAssembler);
|
||||||
|
|
||||||
var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo/*, xPlugAssembler*/);
|
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo/*, xPlugAssembler*/);
|
||||||
if (xAttrib != null && xAttrib.IsWildcard)
|
if (xAttrib != null && xAttrib.IsWildcard)
|
||||||
{
|
{
|
||||||
xPlugInfo.PluggedMethod = xMethodInfo;
|
xPlugInfo.PluggedMethod = xMethodInfo;
|
||||||
|
|
@ -862,16 +884,16 @@ namespace Cosmos.IL2CPU
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InlineAttribute inl = null;
|
if (xInline != null)
|
||||||
foreach (InlineAttribute inli in xPlug.GetCustomAttributes(typeof(InlineAttribute), false))
|
|
||||||
{
|
{
|
||||||
inl = inli;
|
var xMethodID = mItemsList.IndexOf(xItem);
|
||||||
|
if (xMethodID == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Method not in list!");
|
||||||
}
|
}
|
||||||
if (inl != null)
|
xPlugInfo = new MethodInfo(xPlug, (uint)xMethodID, MethodInfo.TypeEnum.Plug, null, true);
|
||||||
{
|
|
||||||
xPlugInfo = new MethodInfo(xPlug, (uint)mItemsList.IndexOf(xItem), MethodInfo.TypeEnum.Plug, null, true);
|
|
||||||
|
|
||||||
var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo/*, xPlugAssembler*/);
|
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo/*, xPlugAssembler*/);
|
||||||
|
|
||||||
xPlugInfo.PluggedMethod = xMethodInfo;
|
xPlugInfo.PluggedMethod = xMethodInfo;
|
||||||
var xInstructions = mReader.ProcessMethod(xPlug);
|
var xInstructions = mReader.ProcessMethod(xPlug);
|
||||||
|
|
@ -884,19 +906,9 @@ namespace Cosmos.IL2CPU
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xPlugInfo = new MethodInfo(xPlug, (uint)mItemsList.IndexOf(xPlug), MethodInfo.TypeEnum.Plug, null, xPlugAssembler);
|
xPlugInfo = new MethodInfo(xPlug, (uint)xMethodIdPlug, MethodInfo.TypeEnum.Plug, null, xPlugAssembler);
|
||||||
|
|
||||||
var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo/*, xPlugAssembler*/);
|
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo/*, xPlugAssembler*/);
|
||||||
if (xAttrib != null && xAttrib.IsWildcard)
|
|
||||||
{
|
|
||||||
xPlugInfo.PluggedMethod = xMethodInfo;
|
|
||||||
var xInstructions = mReader.ProcessMethod(xPlug);
|
|
||||||
if (xInstructions != null)
|
|
||||||
{
|
|
||||||
ProcessInstructions(xInstructions);
|
|
||||||
mAsmblr.ProcessMethod(xPlugInfo, xInstructions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mAsmblr.GenerateMethodForward(xMethodInfo, xPlugInfo);
|
mAsmblr.GenerateMethodForward(xMethodInfo, xPlugInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -921,7 +933,7 @@ namespace Cosmos.IL2CPU
|
||||||
xPlugAssembler = xAttrib.Assembler;
|
xPlugAssembler = xAttrib.Assembler;
|
||||||
}
|
}
|
||||||
|
|
||||||
var xMethodInfo = new MethodInfo(xMethod, (uint)mItemsList.IndexOf(xMethod), xMethodType, xPlugInfo, xPlugAssembler);
|
var xMethodInfo = new MethodInfo(xMethod, (uint)xMethodIdMethod, xMethodType, xPlugInfo, xPlugAssembler);
|
||||||
var xInstructions = mReader.ProcessMethod(xMethod);
|
var xInstructions = mReader.ProcessMethod(xMethod);
|
||||||
if (xInstructions != null)
|
if (xInstructions != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ namespace Cosmos.IL2CPU
|
||||||
|
|
||||||
public LogExceptionDelegate LogException = null;
|
public LogExceptionDelegate LogException = null;
|
||||||
|
|
||||||
public delegate void ScanMethodDelegate(MethodBase aMethod, bool aIsPlug, string sourceItem);
|
////public delegate void ScanMethodDelegate(MethodBase aMethod, bool aIsPlug, string sourceItem);
|
||||||
public ScanMethodDelegate ScanMethod = null;
|
//public ScanMethodDelegate ScanMethod = null;
|
||||||
public delegate void QueueDelegate(_MemberInfo aItem, object aSrc, string aSrcType, string sourceItem = null);
|
//public delegate void QueueDelegate(_MemberInfo aItem, object aSrc, string aSrcType, string sourceItem = null);
|
||||||
public QueueDelegate Queue = null;
|
//public QueueDelegate Queue = null;
|
||||||
|
|
||||||
// Contains a list of plug implementor classes
|
// Contains a list of plug implementor classes
|
||||||
// Key = Target Class
|
// Key = Target Class
|
||||||
|
|
@ -67,12 +67,6 @@ namespace Cosmos.IL2CPU
|
||||||
{
|
{
|
||||||
LogException = aLogException;
|
LogException = aLogException;
|
||||||
}
|
}
|
||||||
public PlugManager(LogExceptionDelegate aLogException, ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod)
|
|
||||||
{
|
|
||||||
LogException = aLogException;
|
|
||||||
ScanMethod = aScanMethod;
|
|
||||||
Queue = aQueueMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FindPlugImpls()
|
public void FindPlugImpls()
|
||||||
{
|
{
|
||||||
|
|
@ -185,9 +179,11 @@ namespace Cosmos.IL2CPU
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Skip checking methods related to fields because it's just too messy...
|
// Skip checking methods related to fields because it's just too messy...
|
||||||
if (xMethod.GetParameters().Where(delegate (ParameterInfo x)
|
// We also skip methods which do method access.
|
||||||
|
if (xMethod.GetParameters().Where(x =>
|
||||||
{
|
{
|
||||||
return x.GetCustomAttributes(typeof(FieldAccessAttribute)).Count() > 0;
|
return x.GetCustomAttributes(typeof(FieldAccessAttribute)).Count() > 0
|
||||||
|
|| x.GetCustomAttributes(typeof(ObjectPointerAccessAttribute)).Count() > 0;
|
||||||
}).Count() > 0)
|
}).Count() > 0)
|
||||||
{
|
{
|
||||||
OK = true;
|
OK = true;
|
||||||
|
|
@ -306,41 +302,21 @@ namespace Cosmos.IL2CPU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OK)
|
if (!OK)
|
||||||
{
|
{
|
||||||
if (ScanMethod != null)
|
if (xAttrib == null
|
||||||
|
|| xAttrib.IsOptional)
|
||||||
{
|
{
|
||||||
ScanMethod(xMethod, true, "Plug Sub Method");
|
throw new Exception("Invalid plug method! Target method not found. : " + xMethod.GetFullName());
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (LogException != null)
|
|
||||||
{
|
|
||||||
LogException(new Exception("Invalid plug method! Target method not found. : " + xMethod.GetFullName()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (xAttrib.IsWildcard && xAttrib.Assembler == null)
|
if (xAttrib.IsWildcard
|
||||||
|
&& xAttrib.Assembler == null)
|
||||||
{
|
{
|
||||||
Exception anEx = new Exception("Wildcard PlugMethods need to use an assembler for now.");
|
throw new Exception("Wildcard PlugMethods need to use an assembler for now.");
|
||||||
if (ThrowExceptions)
|
|
||||||
{
|
|
||||||
throw anEx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogException(anEx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (xAttrib.Enabled && !xAttrib.IsMonoOnly)
|
|
||||||
{
|
|
||||||
if (ScanMethod != null)
|
|
||||||
{
|
|
||||||
ScanMethod(xMethod, true, ".Net plug Method");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -356,15 +332,7 @@ namespace Cosmos.IL2CPU
|
||||||
}
|
}
|
||||||
if (xFields.ContainsKey(xField.FieldId))
|
if (xFields.ContainsKey(xField.FieldId))
|
||||||
{
|
{
|
||||||
Exception anEx = new Exception("Duplicate PlugField found for field '" + xField.FieldId + "'!");
|
throw new Exception("Duplicate PlugField found for field '" + xField.FieldId + "'!");
|
||||||
if (ThrowExceptions)
|
|
||||||
{
|
|
||||||
throw anEx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogException(anEx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xFields.Add(xField.FieldId, xField);
|
xFields.Add(xField.FieldId, xField);
|
||||||
}
|
}
|
||||||
|
|
@ -644,21 +612,6 @@ namespace Cosmos.IL2CPU
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
InlineAttribute xInlineAttrib = null;
|
|
||||||
foreach (InlineAttribute inli in xResult.GetCustomAttributes(typeof(InlineAttribute), false))
|
|
||||||
{
|
|
||||||
xInlineAttrib = inli;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xInlineAttrib == null)
|
|
||||||
{
|
|
||||||
if (Queue != null)
|
|
||||||
{
|
|
||||||
CompilerHelpers.Debug("Queueing Plug:", xResult.DeclaringType, "::", xResult.Name);
|
|
||||||
Queue(xResult, null, "Plug Method");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (xAttrib != null && xAttrib.Signature != null)
|
//if (xAttrib != null && xAttrib.Signature != null)
|
||||||
//{
|
//{
|
||||||
// var xTargetMethods = aTargetType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
// var xTargetMethods = aTargetType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace Cosmos.IL2CPU.Plugs.System.Runtime.CompilerServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inline(TargetPlatform = TargetPlatform.x86)]
|
[Inline(TargetPlatform = TargetPlatform.x86)]
|
||||||
|
[PlugMethod]
|
||||||
public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle) {
|
public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle) {
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// Array aArray, RuntimeFieldHandle aFieldHandle
|
// Array aArray, RuntimeFieldHandle aFieldHandle
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,7 @@ namespace Cosmos.System.Plugs.System.IO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PlugMethod(IsOptional = true)]
|
||||||
public static bool HasIllegalCharacters(string aPath, bool aCheckAdditional)
|
public static bool HasIllegalCharacters(string aPath, bool aCheckAdditional)
|
||||||
{
|
{
|
||||||
if (aCheckAdditional)
|
if (aCheckAdditional)
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ namespace PlugsInspector
|
||||||
|
|
||||||
plugManager = new PlugManager((Exception ex) => {
|
plugManager = new PlugManager((Exception ex) => {
|
||||||
AddExceptionEntry(ex.Message);
|
AddExceptionEntry(ex.Message);
|
||||||
}, this.ScanMethod, null);
|
});
|
||||||
plugManager.ThrowExceptions = false;
|
plugManager.ThrowExceptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue