blob: ab82c2d6f9f906fc4a260438100efa4eef088c5e (
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 Internal.TypeSystem;
using Internal.Runtime.TypeLoader;
using ILCompiler.DependencyAnalysis;
using Debug = System.Diagnostics.Debug;
namespace ILCompiler
{
/// <summary>
/// Jit specific version of virtual method slot resolution. Completely different from the compiler implementation
/// as it is able to function in a partial metadata environment.
/// </summary>
internal static class VirtualMethodSlotHelper
{
/// <summary>
/// Given a virtual method decl, return its VTable slot if the method is used on its containing type.
/// Return -1 if the virtual method is not used.
/// </summary>
public static int GetVirtualMethodSlot(NodeFactory factory, MethodDesc method, TypeDesc implType)
{
Debug.Assert(method.IsVirtual);
if (method.OwningType.IsInterface)
{
ushort slot;
if (!LazyVTableResolver.TryGetInterfaceSlotNumberFromMethod(method, out slot))
{
Environment.FailFast("Unable to get interface slot number for method");
}
return slot;
}
else
{
return LazyVTableResolver.VirtualMethodToSlotIndex(method);
}
}
}
}
|