|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using Internal.JitInterface; |
| 5 | +using Internal.Text; |
| 6 | +using Internal.TypeSystem; |
| 7 | +using Internal.ReadyToRunConstants; |
| 8 | +using ILCompiler.DependencyAnalysisFramework; |
| 9 | +using System.Collections.Generic; |
| 10 | + |
| 11 | +// TODO, andrewau, other architectures |
| 12 | +using ILCompiler.DependencyAnalysis.X64; |
| 13 | + |
| 14 | +namespace ILCompiler.DependencyAnalysis.ReadyToRun |
| 15 | +{ |
| 16 | + // An InterpreterStub is a small trampoline that |
| 17 | + // 1.) Push the InterpreterMethodInfo to the stack, and |
| 18 | + // 2.) Jump to the InterpreterMethod |
| 19 | + public class InterpreterStub : ObjectNode, ISymbolDefinitionNode |
| 20 | + { |
| 21 | + public InterpreterImport _interpreterImport; |
| 22 | + |
| 23 | + public InterpreterStub(InterpreterImport interpreterImport) |
| 24 | + { |
| 25 | + _interpreterImport = interpreterImport; |
| 26 | + } |
| 27 | + |
| 28 | + public override int CompareToImpl(ISortableNode other, CompilerComparer comparer) |
| 29 | + { |
| 30 | + return _interpreterImport._id - ((InterpreterStub)(other))._interpreterImport._id; |
| 31 | + } |
| 32 | + |
| 33 | + public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) |
| 34 | + { |
| 35 | + X64Emitter x64Emitter = new X64Emitter(factory, relocsOnly); |
| 36 | + x64Emitter.Builder.AddSymbol(this); |
| 37 | + x64Emitter.EmitMOV(Register.RCX, _interpreterImport); |
| 38 | + // TODO, andrewau, shouldn't have to do this if we can make node represent redirection cell |
| 39 | + AddrMode addr = new AddrMode(Register.RCX, null, 0, 0, AddrModeSize.Int64); |
| 40 | + x64Emitter.EmitMOV(Register.RCX, ref addr); |
| 41 | + x64Emitter.EmitJMP(factory.InterpreterRoutineImport); |
| 42 | + return x64Emitter.Builder.ToObjectData(); |
| 43 | + } |
| 44 | + |
| 45 | + public int Offset { get; set; } |
| 46 | + |
| 47 | + public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) |
| 48 | + => sb.Append(nameMangler.CompilationUnitPrefix).Append("InterpreterStub").Append(_interpreterImport._id.ToString()); |
| 49 | + |
| 50 | + public override ObjectNodeSection GetSection(NodeFactory factory) |
| 51 | + { |
| 52 | + return ObjectNodeSection.TextSection; |
| 53 | + } |
| 54 | + |
| 55 | + public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) |
| 56 | + { |
| 57 | + yield break; |
| 58 | + } |
| 59 | + |
| 60 | + protected override string GetName(NodeFactory context) => "InterpreterStub"; |
| 61 | + |
| 62 | + public override int ClassCode => 95566084; |
| 63 | + |
| 64 | + public override bool IsShareable => false; |
| 65 | + |
| 66 | + public override bool StaticDependenciesAreComputed => true; |
| 67 | + } |
| 68 | +} |
0 commit comments