File: Compiler\InteropStubManager.cs
Web Access
Project: ILCompiler.Compiler.csproj (ILCompiler.Compiler)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;

using Internal.IL;
using Internal.TypeSystem;
using ILCompiler.DependencyAnalysis;

using DependencyList = ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>.DependencyList;

namespace ILCompiler
{
    /// <summary>
    /// This class is responsible for managing stub methods for interop
    /// </summary>
    public abstract class InteropStubManager : ICompilationRootProvider
    {
        protected readonly PInvokeILEmitterConfiguration _configuration;

        public InteropStubManager(PInvokeILEmitterConfiguration configuration)
        {
            _configuration = configuration;
        }

        public abstract void AddDependenciesDueToMethodCodePresence(ref DependencyList dependencies, NodeFactory factory, MethodDesc method);

        public abstract void AddInterestingInteropConstructedTypeDependencies(ref DependencyList dependencies, NodeFactory factory, TypeDesc type);

        public abstract PInvokeILProvider CreatePInvokeILProvider();

        /// <summary>
        /// For Marshal generic APIs(eg. Marshal.StructureToPtr<T>, GetFunctionPointerForDelegate) we add
        /// the generic parameter as dependencies so that we can generate runtime data for them
        /// </summary>
        public abstract void AddMarshalAPIsGenericDependencies(ref DependencyList dependencies, NodeFactory factory, MethodDesc method);

        public virtual void AddToReadyToRunHeader(ReadyToRunHeaderNode header, NodeFactory nodeFactory, ExternalReferencesTableNode commonFixupsTableNode)
        {
        }

        public virtual void AddCompilationRoots(IRootingServiceProvider rootProvider)
        {
        }

        public string GetDirectCallExternName(MethodDesc method)
        {
            bool directCall = _configuration.GenerateDirectCall(method, out string externName);
            Debug.Assert(directCall);
            Debug.Assert(externName != null);
            return externName;
        }
    }
}