forked from dotnet/runtimelab
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeSpecification and MethodSpecification (dotnet#21)
These are pretty boring, but adding them adds more testing opportunities for dotnet#4 since these all have a blob that dotnet#4 should be able to parse/rewrite.
- Loading branch information
1 parent
ba4c4fc
commit 984c9f9
Showing
3 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/coreclr/tools/ILTrim/ILTrim/DependencyAnalysis/TokenBased/MethodSpecificationNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Reflection.Metadata; | ||
|
||
namespace ILTrim.DependencyAnalysis | ||
{ | ||
/// <summary> | ||
/// Represents an entry in the MethodSpec metadata table (an instantiated generic method). | ||
/// </summary> | ||
public sealed class MethodSpecificationNode : TokenBasedNode | ||
{ | ||
public MethodSpecificationNode(EcmaModule module, MethodSpecificationHandle handle) | ||
: base(module, handle) | ||
{ | ||
} | ||
|
||
private MethodSpecificationHandle Handle => (MethodSpecificationHandle)_handle; | ||
|
||
public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory) | ||
{ | ||
MethodSpecification methodSpec = _module.MetadataReader.GetMethodSpecification(Handle); | ||
|
||
// TODO: report dependencies from the signature | ||
|
||
yield return new(factory.GetNodeForToken(_module, methodSpec.Method), "Instantiated method"); | ||
} | ||
|
||
protected override EntityHandle WriteInternal(ModuleWritingContext writeContext) | ||
{ | ||
MetadataReader reader = _module.MetadataReader; | ||
|
||
MethodSpecification methodSpec = reader.GetMethodSpecification(Handle); | ||
|
||
var builder = writeContext.MetadataBuilder; | ||
|
||
// TODO: the signature blob might contain references to tokens we need to rewrite | ||
var signatureBlob = reader.GetBlobBytes(methodSpec.Signature); | ||
|
||
return builder.AddMethodSpecification( | ||
writeContext.TokenMap.MapToken(methodSpec.Method), | ||
builder.GetOrAddBlob(signatureBlob)); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
// TODO: would be nice to have a common formatter we can call into | ||
return "MethodSpecification"; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/coreclr/tools/ILTrim/ILTrim/DependencyAnalysis/TokenBased/TypeSpecificationNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Reflection.Metadata; | ||
|
||
namespace ILTrim.DependencyAnalysis | ||
{ | ||
/// <summary> | ||
/// Represents an entry in the TypeSpec metadata table (a constructed type). | ||
/// </summary> | ||
public sealed class TypeSpecificationNode : TokenBasedNode | ||
{ | ||
public TypeSpecificationNode(EcmaModule module, TypeSpecificationHandle handle) | ||
: base(module, handle) | ||
{ | ||
} | ||
|
||
private TypeSpecificationHandle Handle => (TypeSpecificationHandle)_handle; | ||
|
||
public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory) | ||
{ | ||
TypeSpecification typeSpec = _module.MetadataReader.GetTypeSpecification(Handle); | ||
|
||
// TODO: report dependencies from the signature | ||
yield break; | ||
} | ||
|
||
protected override EntityHandle WriteInternal(ModuleWritingContext writeContext) | ||
{ | ||
MetadataReader reader = _module.MetadataReader; | ||
|
||
TypeSpecification typeSpec = reader.GetTypeSpecification(Handle); | ||
|
||
var builder = writeContext.MetadataBuilder; | ||
|
||
// TODO: the signature blob might contain references to tokens we need to rewrite | ||
var signatureBlob = reader.GetBlobBytes(typeSpec.Signature); | ||
|
||
return builder.AddTypeSpecification( | ||
builder.GetOrAddBlob(signatureBlob)); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
// TODO: would be nice to have a common formatter we can call into | ||
return "TypeSpecification"; | ||
} | ||
} | ||
} |