blob: 2b716787bf5463a6338fb18172befc1dfeff742f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;
using Internal.IL.Stubs.StartupCode;
namespace ILCompiler
{
/// <summary>
/// Computes a compilation root based on the entrypoint of the assembly.
/// </summary>
public class MainMethodRootProvider : ICompilationRootProvider
{
/// <summary>
/// Symbolic name under which the managed entrypoint is exported.
/// </summary>
public const string ManagedEntryPointMethodName = "__managed__Main";
private EcmaModule _module;
private IReadOnlyCollection<MethodDesc> _libraryInitializers;
public MainMethodRootProvider(EcmaModule module, IReadOnlyCollection<MethodDesc> libraryInitializers)
{
_module = module;
_libraryInitializers = libraryInitializers;
}
public void AddCompilationRoots(IRootingServiceProvider rootProvider)
{
MethodDesc mainMethod = _module.EntryPoint;
if (mainMethod == null)
throw new Exception("No managed entrypoint defined for executable module");
TypeDesc owningType = _module.GetGlobalModuleType();
var startupCodeMain = new StartupCodeMainMethod(owningType, mainMethod, _libraryInitializers);
rootProvider.AddCompilationRoot(startupCodeMain, "Startup Code Main Method", ManagedEntryPointMethodName);
}
}
}
|