Skip to content

✨ Display method signature instead of source list #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions source/Cosmos.IL2CPU/ILScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
using IL2CPU.API;
using IL2CPU.API.Attribs;
using XSharp.Assembler;
using static XSharp.x86.Register;

namespace Cosmos.IL2CPU
{
public class ScannerQueueItem
{
public MemberInfo Item { get; }
public string QueueReason { get; }
public string SourceItem { get; }
public List<string> SourceItems { get; set; }

public ScannerQueueItem(MemberInfo aMemberInfo, string aQueueReason, string aSourceItem)
public ScannerQueueItem(MemberInfo aMemberInfo, string aQueueReason, List<string> aSourceItems = null)
{
Item = aMemberInfo;
QueueReason = aQueueReason;
SourceItem = aSourceItem;
SourceItems = aSourceItems;
}

public override string ToString()
Expand Down Expand Up @@ -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<string> aSourceItems = null)
{
CompilerHelpers.Debug($"Enqueing: {aItem.DeclaringType?.Name ?? ""}.{aItem.Name} from {aSrc}");
if (aItem == null)
Expand Down Expand Up @@ -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));
}
}
}

Expand Down Expand Up @@ -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<string> 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];
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<string>();
}
ScanMethod(xMethod, false, xItem.SourceItems);
}
else if (xItem.Item is Type xType)
{
Expand Down