Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MemoryMarshalIntrinsics.cs « Stubs « IL « TypeSystem « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aaa56db0888c7436e83d62eb0bc4672c954df29c (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
46
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#if READYTORUN
using ILCompiler;
#endif
using Internal.TypeSystem;

using Debug = System.Diagnostics.Debug;

namespace Internal.IL.Stubs
{
    /// <summary>
    /// Provides method bodies for System.Runtime.InteropServices.MemoryMarshal intrinsics.
    /// </summary>
    public static class MemoryMarshalIntrinsics
    {
        public static MethodIL EmitIL(MethodDesc method)
        {
            Debug.Assert(((MetadataType)method.OwningType).Name == "MemoryMarshal");
            string methodName = method.Name;

            if (method.Instantiation.Length != 1)
            {
                return null; // we only handle the generic method GetArrayDataReference<T>(T[])
            }

            if (methodName == "GetArrayDataReference")
            {
                var rawArrayData = method.Context.SystemModule.GetKnownType("System.Runtime.CompilerServices", "RawArrayData");
#if READYTORUN
                if (!rawArrayData.IsNonVersionable())
                    return null; // This is only an intrinsic if we can prove that RawArrayData is known to be of fixed offset
#endif
                ILEmitter emit = new ILEmitter();
                ILCodeStream codeStream = emit.NewCodeStream();
                codeStream.EmitLdArg(0);
                codeStream.Emit(ILOpcode.ldflda, emit.NewToken(rawArrayData.GetField("Data")));
                codeStream.Emit(ILOpcode.ret);
                return emit.Link(method);
            }

            // unknown method
            return null;
        }
    }
}