Skip to content

Commit

Permalink
refactor ExportedMethodsRootProvider class (dotnet#4986)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Dec 31, 2017
1 parent 7f7e1d7 commit 9d581df
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions src/ILCompiler.Compiler/src/Compiler/ExportedMethodsRootProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace ILCompiler
public class ExportedMethodsRootProvider : ICompilationRootProvider
{
private EcmaModule _module;
private List<EcmaMethod> _methods;

public ExportedMethodsRootProvider(EcmaModule module)
{
Expand All @@ -26,47 +25,38 @@ public IEnumerable<EcmaMethod> ExportedMethods
{
get
{
if (_methods != null)
return _methods;

_methods = new List<EcmaMethod>();
var methods = new List<EcmaMethod>();

foreach (var type in _module.GetAllTypes())
{
foreach (var method in type.GetMethods())
{
EcmaMethod ecmaMethod = (EcmaMethod)method;
if (ecmaMethod.IsNativeCallable)
_methods.Add(ecmaMethod);
if (ecmaMethod.IsRuntimeExport || ecmaMethod.IsNativeCallable)
methods.Add(ecmaMethod);
}
}

return _methods;
return methods;
}
}

public void AddCompilationRoots(IRootingServiceProvider rootProvider)
{
foreach (var type in _module.GetAllTypes())
foreach (var ecmaMethod in ExportedMethods)
{
foreach (var method in type.GetMethods())
if (ecmaMethod.IsRuntimeExport)
{
EcmaMethod ecmaMethod = (EcmaMethod)method;

if (ecmaMethod.IsRuntimeExport)
{
string runtimeExportName = ecmaMethod.GetRuntimeExportName();
if (runtimeExportName != null)
rootProvider.AddCompilationRoot(method, "Runtime export", runtimeExportName);
}
string runtimeExportName = ecmaMethod.GetRuntimeExportName();
if (runtimeExportName != null)
rootProvider.AddCompilationRoot((MethodDesc)ecmaMethod, "Runtime export", runtimeExportName);
}
else if (ecmaMethod.IsNativeCallable)
{
string nativeCallableExportName = ecmaMethod.GetNativeCallableExportName();
if (nativeCallableExportName != null)
rootProvider.AddCompilationRoot((MethodDesc)ecmaMethod, "Native callable", nativeCallableExportName);
}
}

foreach (var ecmaMethod in ExportedMethods)
{
string nativeCallableExportName = ecmaMethod.GetNativeCallableExportName();
if (nativeCallableExportName != null)
rootProvider.AddCompilationRoot((MethodDesc)ecmaMethod, "Native callable", nativeCallableExportName);
}
}
}
Expand Down

0 comments on commit 9d581df

Please sign in to comment.