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

StringAllocatorMethodNode.cs « DependencyAnalysis « Compiler « src « ILCompiler.Compiler « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4e68d5536e369deac2898d43e2fb643a00896453 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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.Collections.Generic;

using ILCompiler.DependencyAnalysisFramework;

using Internal.IL;
using Internal.Text;
using Internal.TypeSystem;

using Debug = System.Diagnostics.Debug;

namespace ILCompiler.DependencyAnalysis
{
    /// <summary>
    /// NEWOBJ operation on String type is actually a call to a static method that returns a String
    /// instance (i.e. there's an explicit call to the runtime allocator from the static method body).
    /// This node is used to model the behavior. It represents the symbol for the target allocator
    /// method and makes sure the String type is marked as constructed.
    /// </summary>
    class StringAllocatorMethodNode : DependencyNodeCore<NodeFactory>, IMethodNode
    {
        private readonly MethodDesc _allocationMethod;
        private readonly MethodDesc _constructorMethod;

        public MethodDesc Method => _allocationMethod;

        public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
        {
            sb.Append(nameMangler.GetMangledMethodName(_allocationMethod));
        }
        public int Offset => 0;
        public bool RepresentsIndirectionCell => false;

        public StringAllocatorMethodNode(MethodDesc constructorMethod)
        {
            Debug.Assert(constructorMethod.IsConstructor && constructorMethod.OwningType.IsString);

            // Find the allocator method that matches the constructor signature.
            var signatureBuilder = new MethodSignatureBuilder(constructorMethod.Signature);
            signatureBuilder.Flags = MethodSignatureFlags.Static;
            signatureBuilder.ReturnType = constructorMethod.OwningType;

            _allocationMethod = constructorMethod.OwningType.GetKnownMethod("Ctor", signatureBuilder.ToSignature());
            _constructorMethod = constructorMethod;
        }

        public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory)
        {
            DependencyList result = new DependencyList();

            result.Add(
                factory.ConstructedTypeSymbol(factory.TypeSystemContext.GetWellKnownType(WellKnownType.String)),
                "String constructor call");
            result.Add(
                factory.MethodEntrypoint(_allocationMethod),
                "String constructor call");

            factory.MetadataManager.GetDependenciesDueToReflectability(ref result, factory, _constructorMethod);

            return result;
        }

        public override bool HasConditionalStaticDependencies => false;
        public override bool HasDynamicDependencies => false;
        public override bool InterestingForDynamicDependencyAnalysis => false;
        public override bool StaticDependenciesAreComputed => true;

        public override IEnumerable<CombinedDependencyListEntry> GetConditionalStaticDependencies(NodeFactory factory) => null;
        public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null;

        protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

        int ISortableNode.ClassCode => 1991750873;

        int ISortableNode.CompareToImpl(ISortableNode other, CompilerComparer comparer)
        {
            return comparer.Compare(_allocationMethod, ((StringAllocatorMethodNode)other)._allocationMethod);
        }
    }
}