diff --git a/source/Cosmos.IL2CPU/ILScanner.cs b/source/Cosmos.IL2CPU/ILScanner.cs index ad9d15dc5..002bcdc20 100644 --- a/source/Cosmos.IL2CPU/ILScanner.cs +++ b/source/Cosmos.IL2CPU/ILScanner.cs @@ -9,6 +9,7 @@ using IL2CPU.API; using IL2CPU.API.Attribs; using XSharp.Assembler; +using static XSharp.x86.Register; namespace Cosmos.IL2CPU { @@ -16,13 +17,13 @@ public class ScannerQueueItem { public MemberInfo Item { get; } public string QueueReason { get; } - public string SourceItem { get; } + public List SourceItems { get; set; } - public ScannerQueueItem(MemberInfo aMemberInfo, string aQueueReason, string aSourceItem) + public ScannerQueueItem(MemberInfo aMemberInfo, string aQueueReason, List aSourceItems = null) { Item = aMemberInfo; QueueReason = aQueueReason; - SourceItem = aSourceItem; + SourceItems = aSourceItems; } public override string ToString() @@ -106,7 +107,7 @@ public bool EnableLogging(string aPathname) return true; } - protected void Queue(MemberInfo aItem, object aSrc, string aSrcType, string sourceItem = null) + protected void Queue(MemberInfo aItem, object aSrc, string aSrcType, List aSourceItems = null) { CompilerHelpers.Debug($"Enqueing: {aItem.DeclaringType?.Name ?? ""}.{aItem.Name} from {aSrc}"); if (aItem == null) @@ -150,12 +151,20 @@ protected void Queue(MemberInfo aItem, object aSrc, string aSrcType, string sour mItems.Add(aItem); mItemsList.Add(aItem); - if (aSrc is MethodBase xMethodBaseSrc) + if (aSourceItems != null) { - aSrc = xMethodBaseSrc.DeclaringType + "::" + aSrc; - } + if (aSrc is MethodBase xMethodBaseSrc) + { + // aSrc = xMethodBaseSrc.DeclaringType + "::" + aSrc; + aSourceItems.Add(DataMember.FilterStringForIncorrectChars(LabelName.GetFullName(xMethodBaseSrc))); + } - mQueue.Enqueue(new ScannerQueueItem(aItem, aSrcType, aSrc + Environment.NewLine + sourceItem)); + mQueue.Enqueue(new ScannerQueueItem(aItem, aSrcType, aSourceItems)); + } + else + { + mQueue.Enqueue(new ScannerQueueItem(aItem, aSrcType)); + } } } @@ -383,12 +392,11 @@ protected string LogItemText(object aItem) return "Other: " + aItem; } - protected void ScanMethod(MethodBase aMethod, bool aIsPlug, string sourceItem) + protected void ScanMethod(MethodBase aMethod, bool aIsPlug, List sourceItems) { CompilerHelpers.Debug($"ILScanner: ScanMethod"); CompilerHelpers.Debug($"Method = '{aMethod}'"); CompilerHelpers.Debug($"IsPlug = '{aIsPlug}'"); - CompilerHelpers.Debug($"Source = '{sourceItem}'"); var xParams = aMethod.GetParameters(); var xParamTypes = new Type[xParams.Length]; @@ -565,7 +573,7 @@ protected void ScanMethod(MethodBase aMethod, bool aIsPlug, string sourceItem) + " Need plug for: " + LabelName.GetFullName(aMethod, false) + "(Plug Signature: " + DataMember.FilterStringForIncorrectChars(LabelName.GetFullName(aMethod, false)) + " ). " + Environment.NewLine + " Static: " + aMethod.IsStatic + Environment.NewLine + " Assembly: " + aMethod.DeclaringType.Assembly.FullName + Environment.NewLine - + " Called from:" + Environment.NewLine + sourceItem + Environment.NewLine); + + " Called from:" + Environment.NewLine + string.Join("\n", sourceItems.Distinct().ToArray()) + Environment.NewLine); } //TODO: As we scan each method, we could update or put in a new list @@ -589,7 +597,7 @@ protected void ScanMethod(MethodBase aMethod, bool aIsPlug, string sourceItem) { if (xOpCode is ILOpCodes.OpMethod) { - Queue(((ILOpCodes.OpMethod)xOpCode).Value, aMethod, "Call", sourceItem); + Queue(((ILOpCodes.OpMethod)xOpCode).Value, aMethod, "Call", sourceItems); } else if (xOpCode is ILOpCodes.OpType xOpType) { @@ -748,7 +756,11 @@ protected void ScanQueue() // and will reduce compares if (xItem.Item is MethodBase xMethod) { - ScanMethod(xMethod, false, xItem.SourceItem); + if (xItem.SourceItems == null) + { + xItem.SourceItems = new List(); + } + ScanMethod(xMethod, false, xItem.SourceItems); } else if (xItem.Item is Type xType) {