Recognise JIT intrinsics (#54)

This commit is contained in:
Patrick Stevens
2025-06-15 21:38:18 +01:00
committed by GitHub
parent 2c249edfc7
commit a85bfd93b6
2 changed files with 92 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ namespace WoofWare.PawPrint
#nowarn "9"
open System
open System.Collections.Generic
open System.Collections.Immutable
open System.Reflection
open System.Reflection.Metadata
@@ -214,6 +215,28 @@ type MethodInfo<'typeGenerics, 'methodGenerics
member this.IsPinvokeImpl : bool =
this.MethodAttributes.HasFlag MethodAttributes.PinvokeImpl
member this.IsJITIntrinsic
(getMemberRefParentType : MemberReferenceHandle -> TypeRef)
(methodDefs : IReadOnlyDictionary<MethodDefinitionHandle, MethodInfo<FakeUnit, GenericParameter>>)
: bool
=
this.CustomAttributes
|> Seq.exists (fun attr ->
match attr.Constructor with
| MetadataToken.MethodDef handle ->
let constructor = methodDefs.[handle]
constructor.DeclaringType.Name = "IntrinsicAttribute"
&& constructor.DeclaringType.Assembly.FullName.StartsWith (
"System.Private.CoreLib, ",
StringComparison.Ordinal
)
| MetadataToken.MemberReference handle ->
let ty = getMemberRefParentType handle
ty.Namespace = "System" && ty.Name = "IntrinsicAttribute"
| con -> failwith $"TODO: {con}"
)
[<RequireQualifiedAccess>]
module MethodInfo =
let mapTypeGenerics<'a, 'b, 'methodGen