mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-05 06:08:39 +00:00
Compare commits
2 Commits
55677a507b
...
a9b2598525
Author | SHA1 | Date | |
---|---|---|---|
|
a9b2598525 | ||
|
e05abbb724 |
@@ -331,6 +331,13 @@ module ConcreteActivePatterns =
|
||||
| ConcreteTypeHandle.Pointer inner -> Some inner
|
||||
| _ -> None
|
||||
|
||||
type IAssemblyLoad =
|
||||
abstract LoadAssembly :
|
||||
loadedAssemblies : ImmutableDictionary<string, DumpedAssembly> ->
|
||||
referencedIn : AssemblyName ->
|
||||
handle : AssemblyReferenceHandle ->
|
||||
ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module TypeConcretization =
|
||||
|
||||
@@ -406,8 +413,7 @@ module TypeConcretization =
|
||||
|
||||
// Helper function for assembly loading with retry pattern
|
||||
let private loadAssemblyAndResolveTypeRef
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(ctx : ConcretizationContext<'corelib>)
|
||||
(currentAssembly : AssemblyName)
|
||||
(typeRef : TypeRef)
|
||||
@@ -428,7 +434,8 @@ module TypeConcretization =
|
||||
// Need to load the assembly
|
||||
match typeRef.ResolutionScope with
|
||||
| TypeRefResolutionScope.Assembly assyRef ->
|
||||
let newAssemblies, _ = loadAssembly currentAssembly assyRef
|
||||
let newAssemblies, _ =
|
||||
loadAssembly.LoadAssembly ctx.LoadedAssemblies currentAssembly assyRef
|
||||
|
||||
let newCtx =
|
||||
{ ctx with
|
||||
@@ -584,8 +591,7 @@ module TypeConcretization =
|
||||
ImmutableArray.Empty // No generic parameters
|
||||
|
||||
let private concretizeTypeReference
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(ctx : ConcretizationContext<'corelib>)
|
||||
(currentAssembly : AssemblyName)
|
||||
(typeRef : TypeRef)
|
||||
@@ -609,8 +615,7 @@ module TypeConcretization =
|
||||
/// Concretize a type in a specific generic context
|
||||
let rec concretizeType
|
||||
(ctx : ConcretizationContext<DumpedAssembly>)
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(assembly : AssemblyName)
|
||||
(typeGenerics : ImmutableArray<ConcreteTypeHandle>)
|
||||
(methodGenerics : ImmutableArray<ConcreteTypeHandle>)
|
||||
@@ -706,8 +711,7 @@ module TypeConcretization =
|
||||
|
||||
and private concretizeGenericInstantiation
|
||||
(ctx : ConcretizationContext<DumpedAssembly>)
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(assembly : AssemblyName)
|
||||
(typeGenerics : ImmutableArray<ConcreteTypeHandle>)
|
||||
(methodGenerics : ImmutableArray<ConcreteTypeHandle>)
|
||||
@@ -786,7 +790,8 @@ module TypeConcretization =
|
||||
|
||||
| false, _ ->
|
||||
// Need to load the assembly
|
||||
let newAssemblies, loadedAssy = loadAssembly assembly assyRef
|
||||
let newAssemblies, loadedAssy =
|
||||
loadAssembly.LoadAssembly ctx.LoadedAssemblies assembly assyRef
|
||||
|
||||
let ctxWithNewAssy =
|
||||
{ ctxAfterArgs with
|
||||
@@ -865,8 +870,7 @@ module Concretization =
|
||||
/// Helper to concretize an array of types
|
||||
let private concretizeTypeArray
|
||||
(ctx : TypeConcretization.ConcretizationContext<DumpedAssembly>)
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(assembly : AssemblyName)
|
||||
(typeArgs : ImmutableArray<ConcreteTypeHandle>)
|
||||
(methodArgs : ImmutableArray<ConcreteTypeHandle>)
|
||||
@@ -889,8 +893,7 @@ module Concretization =
|
||||
/// Helper to concretize a method signature
|
||||
let private concretizeMethodSignature
|
||||
(ctx : TypeConcretization.ConcretizationContext<DumpedAssembly>)
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(assembly : AssemblyName)
|
||||
(typeArgs : ImmutableArray<ConcreteTypeHandle>)
|
||||
(methodArgs : ImmutableArray<ConcreteTypeHandle>)
|
||||
@@ -926,8 +929,7 @@ module Concretization =
|
||||
|
||||
/// Helper to ensure base type assembly is loaded
|
||||
let rec private ensureBaseTypeAssembliesLoaded
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(assemblies : ImmutableDictionary<string, DumpedAssembly>)
|
||||
(assyName : AssemblyName)
|
||||
(baseTypeInfo : BaseTypeInfo option)
|
||||
@@ -947,7 +949,7 @@ module Concretization =
|
||||
| true, _ -> assemblies
|
||||
| false, _ ->
|
||||
// Need to load the assembly - pass the assembly that contains the reference
|
||||
let newAssemblies, _ = loadAssembly assy.Name assyRef
|
||||
let newAssemblies, _ = loadAssembly.LoadAssembly assemblies assy.Name assyRef
|
||||
newAssemblies
|
||||
| _ -> assemblies
|
||||
| Some (BaseTypeInfo.TypeDef _)
|
||||
@@ -957,8 +959,7 @@ module Concretization =
|
||||
/// Concretize a method's signature and body
|
||||
let concretizeMethod
|
||||
(ctx : AllConcreteTypes)
|
||||
(loadAssembly :
|
||||
AssemblyName -> AssemblyReferenceHandle -> ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly)
|
||||
(loadAssembly : IAssemblyLoad)
|
||||
(assemblies : ImmutableDictionary<string, DumpedAssembly>)
|
||||
(baseTypes : BaseClassTypes<DumpedAssembly>)
|
||||
(method : WoofWare.PawPrint.MethodInfo<'ty, GenericParamFromMetadata, TypeDefn>)
|
||||
|
@@ -61,16 +61,6 @@ module TestPureCases =
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
}
|
||||
{
|
||||
FileName = "AdvancedStructLayout.cs"
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
}
|
||||
{
|
||||
FileName = "OverlappingStructs.cs"
|
||||
ExpectedReturnCode = 0
|
||||
NativeImpls = MockEnv.make ()
|
||||
}
|
||||
]
|
||||
|
||||
let cases : EndToEndTestCase list =
|
||||
|
@@ -222,5 +222,5 @@ module AbstractMachine =
|
||||
|> ExecutionResult.Stepped
|
||||
| IlOp.Switch immutableArray -> failwith "TODO: Switch unimplemented"
|
||||
| IlOp.UnaryStringToken (unaryStringTokenIlOp, stringHandle) ->
|
||||
UnaryStringTokenIlOp.execute baseClassTypes unaryStringTokenIlOp stringHandle state thread
|
||||
UnaryStringTokenIlOp.execute loggerFactory baseClassTypes unaryStringTokenIlOp stringHandle state thread
|
||||
|> ExecutionResult.Stepped
|
||||
|
@@ -460,20 +460,22 @@ module CliType =
|
||||
// The field type might reference generic parameters of the declaring type
|
||||
let methodGenerics = ImmutableArray.Empty // Fields don't have method generics
|
||||
|
||||
let loadAssembly
|
||||
(assyName : AssemblyName)
|
||||
(ref : AssemblyReferenceHandle)
|
||||
: ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly
|
||||
=
|
||||
match assemblies.TryGetValue assyName.FullName with
|
||||
| true, currentAssy ->
|
||||
let targetAssyRef = currentAssy.AssemblyReferences.[ref]
|
||||
let loadAssembly =
|
||||
{ new IAssemblyLoad with
|
||||
member _.LoadAssembly loaded assyName ref =
|
||||
match loaded.TryGetValue assyName.FullName with
|
||||
| true, currentAssy ->
|
||||
let targetAssyRef = currentAssy.AssemblyReferences.[ref]
|
||||
|
||||
match assemblies.TryGetValue targetAssyRef.Name.FullName with
|
||||
| true, targetAssy -> assemblies, targetAssy
|
||||
| false, _ ->
|
||||
failwithf "Assembly %s not loaded when trying to resolve reference" targetAssyRef.Name.FullName
|
||||
| false, _ -> failwithf "Current assembly %s not loaded when trying to resolve reference" assyName.FullName
|
||||
match loaded.TryGetValue targetAssyRef.Name.FullName with
|
||||
| true, targetAssy -> loaded, targetAssy
|
||||
| false, _ ->
|
||||
failwithf
|
||||
"Assembly %s not loaded when trying to resolve reference"
|
||||
targetAssyRef.Name.FullName
|
||||
| false, _ ->
|
||||
failwithf "Current assembly %s not loaded when trying to resolve reference" assyName.FullName
|
||||
}
|
||||
|
||||
let handle, newCtx =
|
||||
TypeConcretization.concretizeType
|
||||
|
@@ -149,7 +149,73 @@ type StateLoadResult =
|
||||
module IlMachineState =
|
||||
type private Dummy = class end
|
||||
|
||||
let private loadAssembly'
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(dotnetRuntimeDirs : string seq)
|
||||
(referencedInAssembly : DumpedAssembly)
|
||||
(r : AssemblyReferenceHandle)
|
||||
(assemblies : ImmutableDictionary<string, DumpedAssembly>)
|
||||
=
|
||||
let assemblyRef = referencedInAssembly.AssemblyReferences.[r]
|
||||
let assemblyName = assemblyRef.Name
|
||||
|
||||
match assemblies.TryGetValue assemblyName.FullName with
|
||||
| true, v -> v, assemblyName
|
||||
| false, _ ->
|
||||
let logger = loggerFactory.CreateLogger typeof<Dummy>.DeclaringType
|
||||
|
||||
let assy =
|
||||
dotnetRuntimeDirs
|
||||
|> Seq.choose (fun dir ->
|
||||
let file = Path.Combine (dir, assemblyName.Name + ".dll")
|
||||
|
||||
try
|
||||
use f = File.OpenRead file
|
||||
logger.LogInformation ("Loading assembly from file {AssemblyFileLoadPath}", file)
|
||||
Assembly.read loggerFactory (Some file) f |> Some
|
||||
with :? FileNotFoundException ->
|
||||
None
|
||||
)
|
||||
|> Seq.toList
|
||||
|
||||
match assy |> List.tryHead with
|
||||
| None -> failwith $"Could not find a readable DLL in any runtime dir with name %s{assemblyName.Name}.dll"
|
||||
| Some assy -> assy, assemblyName
|
||||
|
||||
/// <summary>
|
||||
/// Create a new IlMachineState which has loaded the given assembly.
|
||||
/// This involves reading assemblies from the disk and doing a complete parse of them, so it might be quite slow!
|
||||
///
|
||||
/// This function doesn't do anything if the referenced assembly has already been loaded.
|
||||
/// </summary>
|
||||
/// <param name="loggerFactory">LoggerFactory into which to emit logs.</param>
|
||||
/// <param name="referencedInAssembly">The assembly which contains an AssemblyReference which causes us to want to load a new assembly.</param>
|
||||
/// <param name="r">The AssemblyReferenceHandle pointing at an assembly we want to load. *Important*: this is an AssemblyReferenceHandle from <c>referencedInAssembly</c>; in general, AssemblyReferenceHandles are only well-defined if you know what assembly they were defined in.</param>
|
||||
/// <param name="state">The immutable state to augment with the new assembly.</param>
|
||||
let loadAssembly
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(referencedInAssembly : DumpedAssembly)
|
||||
(r : AssemblyReferenceHandle)
|
||||
(state : IlMachineState)
|
||||
: IlMachineState * DumpedAssembly * AssemblyName
|
||||
=
|
||||
let dumped, assy =
|
||||
loadAssembly' loggerFactory state.DotnetRuntimeDirs referencedInAssembly r state._LoadedAssemblies
|
||||
|
||||
state.WithLoadedAssembly assy dumped, dumped, assy
|
||||
|
||||
let private loader (loggerFactory : ILoggerFactory) (state : IlMachineState) : IAssemblyLoad =
|
||||
{ new IAssemblyLoad with
|
||||
member _.LoadAssembly loaded assyName ref =
|
||||
let targetAssy, name =
|
||||
loadAssembly' loggerFactory state.DotnetRuntimeDirs loaded.[assyName.FullName] ref loaded
|
||||
|
||||
let newAssys = loaded.SetItem (name.FullName, targetAssy)
|
||||
newAssys, targetAssy
|
||||
}
|
||||
|
||||
let concretizeType
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(baseClassTypes : BaseClassTypes<DumpedAssembly>)
|
||||
(state : IlMachineState)
|
||||
(declaringAssembly : AssemblyName)
|
||||
@@ -169,14 +235,7 @@ module IlMachineState =
|
||||
let handle, ctx =
|
||||
TypeConcretization.concretizeType
|
||||
ctx
|
||||
(fun assyName ref ->
|
||||
let currentAssy = state.LoadedAssembly assyName |> Option.get
|
||||
|
||||
let targetAssy =
|
||||
currentAssy.AssemblyReferences.[ref].Name |> state.LoadedAssembly |> Option.get
|
||||
|
||||
state._LoadedAssemblies, targetAssy
|
||||
)
|
||||
(loader loggerFactory state)
|
||||
declaringAssembly
|
||||
typeGenerics
|
||||
methodGenerics
|
||||
@@ -190,51 +249,6 @@ module IlMachineState =
|
||||
|
||||
state, handle
|
||||
|
||||
/// <summary>
|
||||
/// Create a new IlMachineState which has loaded the given assembly.
|
||||
/// This involves reading assemblies from the disk and doing a complete parse of them, so it might be quite slow!
|
||||
///
|
||||
/// This function doesn't do anything if the referenced assembly has already been loaded.
|
||||
/// </summary>
|
||||
/// <param name="loggerFactory">LoggerFactory into which to emit logs.</param>
|
||||
/// <param name="referencedInAssembly">The assembly which contains an AssemblyReference which causes us to want to load a new assembly.</param>
|
||||
/// <param name="r">The AssemblyReferenceHandle pointing at an assembly we want to load. *Important*: this is an AssemblyReferenceHandle from <c>referencedInAssembly</c>; in general, AssemblyReferenceHandles are only well-defined if you know what assembly they were defined in.</param>
|
||||
/// <param name="state">The immutable state to augment with the new assembly.</param>
|
||||
let loadAssembly
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(referencedInAssembly : DumpedAssembly)
|
||||
(r : AssemblyReferenceHandle)
|
||||
(state : IlMachineState)
|
||||
: IlMachineState * DumpedAssembly * AssemblyName
|
||||
=
|
||||
let assemblyRef = referencedInAssembly.AssemblyReferences.[r]
|
||||
let assemblyName = assemblyRef.Name
|
||||
|
||||
match state.LoadedAssembly assemblyName with
|
||||
| Some v -> state, v, assemblyName
|
||||
| None ->
|
||||
let logger = loggerFactory.CreateLogger typeof<Dummy>.DeclaringType
|
||||
|
||||
let assy =
|
||||
state.DotnetRuntimeDirs
|
||||
|> Seq.choose (fun dir ->
|
||||
let file = Path.Combine (dir, assemblyName.Name + ".dll")
|
||||
|
||||
try
|
||||
use f = File.OpenRead file
|
||||
logger.LogInformation ("Loading assembly from file {AssemblyFileLoadPath}", file)
|
||||
Assembly.read loggerFactory (Some file) f |> Some
|
||||
with :? FileNotFoundException ->
|
||||
None
|
||||
)
|
||||
|> Seq.toList
|
||||
|
||||
match assy |> List.tryHead with
|
||||
| None -> failwith $"Could not find a readable DLL in any runtime dir with name %s{assemblyName.Name}.dll"
|
||||
| Some assy ->
|
||||
|
||||
state.WithLoadedAssembly assemblyName assy, assy, assemblyName
|
||||
|
||||
let rec internal resolveTypeFromName
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(ns : string option)
|
||||
@@ -530,26 +544,6 @@ module IlMachineState =
|
||||
BaseTypes = baseClassTypes
|
||||
}
|
||||
|
||||
// Helper function to get assembly from reference
|
||||
let loadAssembly
|
||||
(currentAssembly : AssemblyName)
|
||||
(assyRef : AssemblyReferenceHandle)
|
||||
: ImmutableDictionary<string, DumpedAssembly> * DumpedAssembly
|
||||
=
|
||||
let assyToLoad =
|
||||
match state.LoadedAssembly currentAssembly with
|
||||
| Some assy -> assy
|
||||
| None -> failwithf "Assembly %s not loaded" currentAssembly.FullName
|
||||
|
||||
let referencedAssy = assyToLoad.AssemblyReferences.[assyRef]
|
||||
|
||||
match state.LoadedAssembly referencedAssy.Name with
|
||||
| Some assy -> state._LoadedAssemblies, assy
|
||||
| None ->
|
||||
// Need to load the assembly
|
||||
let newState, loadedAssy, _ = loadAssembly loggerFactory assyToLoad assyRef state
|
||||
newState._LoadedAssemblies, loadedAssy
|
||||
|
||||
// Concretize each generic argument first
|
||||
let mutable currentCtx = ctx
|
||||
let genericHandles = ImmutableArray.CreateBuilder declaringType.Generics.Length
|
||||
@@ -558,7 +552,7 @@ module IlMachineState =
|
||||
let handle, newCtx =
|
||||
TypeConcretization.concretizeType
|
||||
currentCtx
|
||||
loadAssembly
|
||||
(loader loggerFactory state)
|
||||
declaringType.Assembly
|
||||
ImmutableArray.Empty // No type generics in this context
|
||||
ImmutableArray.Empty // No method generics in this context
|
||||
@@ -570,12 +564,13 @@ module IlMachineState =
|
||||
// Now we need to concretize the type definition itself
|
||||
// If it's a non-generic type, we can use concretizeTypeDefinition directly
|
||||
if declaringType.Generics.IsEmpty then
|
||||
let handle, newCtx =
|
||||
let handle, currentCtx =
|
||||
TypeConcretization.concretizeTypeDefinition currentCtx declaringType.Assembly declaringType.Definition
|
||||
|
||||
let newState =
|
||||
{ state with
|
||||
ConcreteTypes = newCtx.ConcreteTypes
|
||||
ConcreteTypes = currentCtx.ConcreteTypes
|
||||
_LoadedAssemblies = currentCtx.LoadedAssemblies
|
||||
}
|
||||
|
||||
handle, newState
|
||||
@@ -631,7 +626,7 @@ module IlMachineState =
|
||||
state.WithLoadedAssembly assy.Name assy
|
||||
|
||||
let state, handle =
|
||||
concretizeType baseClassTypes state assy.Name typeGenerics methodGenerics ty
|
||||
concretizeType loggerFactory baseClassTypes state assy.Name typeGenerics methodGenerics ty
|
||||
|
||||
// Now get the zero value
|
||||
let zero, state = cliTypeZeroOfHandle state baseClassTypes handle
|
||||
@@ -807,22 +802,7 @@ module IlMachineState =
|
||||
let concretizedMethod, newConcreteTypes, newAssemblies =
|
||||
Concretization.concretizeMethod
|
||||
state.ConcreteTypes
|
||||
(fun assyName ref ->
|
||||
match state.LoadedAssembly assyName with
|
||||
| Some currentAssy ->
|
||||
let targetAssyRef = currentAssy.AssemblyReferences.[ref]
|
||||
|
||||
match state.LoadedAssembly targetAssyRef.Name with
|
||||
| Some _ ->
|
||||
// Assembly already loaded, return existing state
|
||||
state._LoadedAssemblies, state._LoadedAssemblies.[targetAssyRef.Name.FullName]
|
||||
| None ->
|
||||
// Need to load the assembly
|
||||
let newState, loadedAssy, _ = loadAssembly loggerFactory currentAssy ref state
|
||||
newState._LoadedAssemblies, loadedAssy
|
||||
| None ->
|
||||
failwithf "Current assembly %s not loaded when trying to resolve reference" assyName.FullName
|
||||
)
|
||||
(loader loggerFactory state)
|
||||
state._LoadedAssemblies
|
||||
baseClassTypes
|
||||
methodToCall
|
||||
@@ -868,6 +848,7 @@ module IlMachineState =
|
||||
for i = 0 to generics.Length - 1 do
|
||||
let state2, handle =
|
||||
concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
callingAssembly
|
||||
@@ -923,14 +904,7 @@ module IlMachineState =
|
||||
let handle, newCtx =
|
||||
TypeConcretization.concretizeType
|
||||
ctx
|
||||
(fun assyName ref ->
|
||||
let currentAssy = state.LoadedAssembly assyName |> Option.get
|
||||
|
||||
let targetAssy =
|
||||
currentAssy.AssemblyReferences.[ref].Name |> state.LoadedAssembly |> Option.get
|
||||
|
||||
state._LoadedAssemblies, targetAssy
|
||||
)
|
||||
(loader loggerFactory state)
|
||||
(state.ActiveAssembly thread).Name
|
||||
ImmutableArray.Empty // No type generics for the concretization context
|
||||
ImmutableArray.Empty // No method generics for the concretization context
|
||||
@@ -941,6 +915,7 @@ module IlMachineState =
|
||||
state <-
|
||||
{ state with
|
||||
ConcreteTypes = newCtx.ConcreteTypes
|
||||
_LoadedAssemblies = newCtx.LoadedAssemblies
|
||||
}
|
||||
|
||||
handles.ToImmutable (), state
|
||||
@@ -1045,14 +1020,7 @@ module IlMachineState =
|
||||
let declaringHandle, newCtx =
|
||||
TypeConcretization.concretizeType
|
||||
ctx
|
||||
(fun assyName ref ->
|
||||
let currentAssy = state.LoadedAssembly assyName |> Option.get
|
||||
|
||||
let targetAssy =
|
||||
currentAssy.AssemblyReferences.[ref].Name |> state.LoadedAssembly |> Option.get
|
||||
|
||||
state._LoadedAssemblies, targetAssy
|
||||
)
|
||||
(loader loggerFactory state)
|
||||
field.DeclaringType.Assembly
|
||||
contextTypeGenerics
|
||||
contextMethodGenerics
|
||||
@@ -1302,6 +1270,7 @@ module IlMachineState =
|
||||
// TODO: generics?
|
||||
let state, t =
|
||||
concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
targetType.Assembly
|
||||
@@ -1319,6 +1288,7 @@ module IlMachineState =
|
||||
// Concretize the field signature from the member reference
|
||||
let state, concreteFieldSig =
|
||||
concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
(state.ActiveAssembly(currentThread).Name)
|
||||
@@ -1336,6 +1306,7 @@ module IlMachineState =
|
||||
// Concretize the field's signature for comparison
|
||||
let state, fieldSigConcrete =
|
||||
concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
assy.Name
|
||||
@@ -1373,6 +1344,7 @@ module IlMachineState =
|
||||
state
|
||||
(fun state ty ->
|
||||
concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
(state.ActiveAssembly(currentThread).Name)
|
||||
@@ -1390,6 +1362,7 @@ module IlMachineState =
|
||||
state
|
||||
(fun state ty ->
|
||||
concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
assy.Name
|
||||
@@ -1556,6 +1529,7 @@ module IlMachineState =
|
||||
|
||||
/// Returns the type handle and an allocated System.RuntimeType.
|
||||
let getOrAllocateType
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(baseClassTypes : BaseClassTypes<DumpedAssembly>)
|
||||
(defn : ConcreteTypeHandle)
|
||||
(state : IlMachineState)
|
||||
@@ -1567,7 +1541,13 @@ module IlMachineState =
|
||||
baseClassTypes.Corelib.Name.FullName,
|
||||
SignatureTypeKind.Class
|
||||
)
|
||||
|> concretizeType baseClassTypes state baseClassTypes.Corelib.Name ImmutableArray.Empty ImmutableArray.Empty
|
||||
|> concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
baseClassTypes.Corelib.Name
|
||||
ImmutableArray.Empty
|
||||
ImmutableArray.Empty
|
||||
|
||||
let result, reg, state =
|
||||
TypeHandleRegistry.getOrAllocate
|
||||
@@ -1611,7 +1591,13 @@ module IlMachineState =
|
||||
baseClassTypes.Corelib.Name.FullName,
|
||||
SignatureTypeKind.Class
|
||||
)
|
||||
|> concretizeType baseClassTypes state baseClassTypes.Corelib.Name ImmutableArray.Empty ImmutableArray.Empty
|
||||
|> concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
baseClassTypes.Corelib.Name
|
||||
ImmutableArray.Empty
|
||||
ImmutableArray.Empty
|
||||
|
||||
let result, reg, state =
|
||||
FieldHandleRegistry.getOrAllocate
|
||||
|
@@ -10,6 +10,7 @@ open Microsoft.Extensions.Logging
|
||||
[<RequireQualifiedAccess>]
|
||||
module IlMachineStateExecution =
|
||||
let getTypeOfObj
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(baseClassTypes : BaseClassTypes<DumpedAssembly>)
|
||||
(state : IlMachineState)
|
||||
(esv : EvalStackValue)
|
||||
@@ -19,6 +20,7 @@ module IlMachineStateExecution =
|
||||
| EvalStackValue.Int32 _ ->
|
||||
DumpedAssembly.typeInfoToTypeDefn' baseClassTypes state._LoadedAssemblies baseClassTypes.Int32
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
baseClassTypes.Corelib.Name
|
||||
@@ -27,6 +29,7 @@ module IlMachineStateExecution =
|
||||
| EvalStackValue.Int64 _ ->
|
||||
DumpedAssembly.typeInfoToTypeDefn' baseClassTypes state._LoadedAssemblies baseClassTypes.Int64
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
baseClassTypes.Corelib.Name
|
||||
@@ -36,6 +39,7 @@ module IlMachineStateExecution =
|
||||
| EvalStackValue.Float _ ->
|
||||
DumpedAssembly.typeInfoToTypeDefn' baseClassTypes state._LoadedAssemblies baseClassTypes.Double
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
baseClassTypes.Corelib.Name
|
||||
@@ -156,7 +160,8 @@ module IlMachineStateExecution =
|
||||
| None -> failwith "unexpectedly no `this` on the eval stack of instance method"
|
||||
| Some this -> this
|
||||
|
||||
let state, callingObjTyHandle = getTypeOfObj baseClassTypes state callingObj
|
||||
let state, callingObjTyHandle =
|
||||
getTypeOfObj loggerFactory baseClassTypes state callingObj
|
||||
|
||||
let callingObjTy =
|
||||
let ty =
|
||||
@@ -200,6 +205,7 @@ module IlMachineStateExecution =
|
||||
let state, retType =
|
||||
meth.Signature.ReturnType
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
meth.DeclaringType.Assembly
|
||||
@@ -211,6 +217,7 @@ module IlMachineStateExecution =
|
||||
||> Seq.mapFold (fun state ty ->
|
||||
ty
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
meth.DeclaringType.Assembly
|
||||
@@ -573,6 +580,7 @@ module IlMachineStateExecution =
|
||||
// Concretize the base type
|
||||
let state, baseTypeHandle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
sourceAssembly.Name
|
||||
@@ -612,6 +620,7 @@ module IlMachineStateExecution =
|
||||
// Concretize the base type
|
||||
let state, baseTypeHandle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
sourceAssembly.Name
|
||||
@@ -663,6 +672,7 @@ module IlMachineStateExecution =
|
||||
state
|
||||
(fun state typeDefn ->
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
concreteType.Assembly
|
||||
@@ -687,6 +697,7 @@ module IlMachineStateExecution =
|
||||
||> Seq.fold (fun (state, acc) typeDefn ->
|
||||
let state, handle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
concreteType.Assembly
|
||||
|
@@ -10,6 +10,7 @@ open Microsoft.Extensions.Logging
|
||||
module Program =
|
||||
/// Returns the pointer to the resulting array on the heap.
|
||||
let allocateArgs
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(args : string list)
|
||||
(corelib : BaseClassTypes<DumpedAssembly>)
|
||||
(state : IlMachineState)
|
||||
@@ -18,6 +19,7 @@ module Program =
|
||||
let state, stringType =
|
||||
DumpedAssembly.typeInfoToTypeDefn' corelib state._LoadedAssemblies corelib.String
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
corelib
|
||||
state
|
||||
corelib.Corelib.Name
|
||||
@@ -285,7 +287,7 @@ module Program =
|
||||
let arrayAllocation, state =
|
||||
match mainMethodFromMetadata.Signature.ParameterTypes |> Seq.toList with
|
||||
| [ TypeDefn.OneDimensionalArrayLowerBoundZero (TypeDefn.PrimitiveType PrimitiveType.String) ] ->
|
||||
allocateArgs argv baseClassTypes state
|
||||
allocateArgs loggerFactory argv baseClassTypes state
|
||||
| _ -> failwith "Main method must take an array of strings; other signatures not yet implemented"
|
||||
|
||||
match mainMethodFromMetadata.Signature.ReturnType with
|
||||
|
@@ -33,6 +33,7 @@ module internal UnaryMetadataIlOp =
|
||||
||> Seq.fold (fun (state, acc) typeDefn ->
|
||||
let state, concreteType =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
(state.ActiveAssembly thread).Name
|
||||
@@ -138,6 +139,7 @@ module internal UnaryMetadataIlOp =
|
||||
||> Seq.fold (fun (state, acc) typeDefn ->
|
||||
let state, concreteType =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
(state.ActiveAssembly thread).Name
|
||||
@@ -475,6 +477,7 @@ module internal UnaryMetadataIlOp =
|
||||
|
||||
let state, targetConcreteType =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
activeAssy.Name
|
||||
@@ -1227,6 +1230,7 @@ module internal UnaryMetadataIlOp =
|
||||
|
||||
let state, handle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
activeAssy.Name
|
||||
@@ -1234,7 +1238,8 @@ module internal UnaryMetadataIlOp =
|
||||
methodGenerics
|
||||
typeDefn
|
||||
|
||||
let alloc, state = IlMachineState.getOrAllocateType baseClassTypes handle state
|
||||
let alloc, state =
|
||||
IlMachineState.getOrAllocateType loggerFactory baseClassTypes handle state
|
||||
|
||||
let vt =
|
||||
// https://github.com/dotnet/runtime/blob/2b21c73fa2c32fa0195e4a411a435dda185efd08/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs#L92
|
||||
@@ -1285,6 +1290,7 @@ module internal UnaryMetadataIlOp =
|
||||
|
||||
let state, handle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
assy.Name
|
||||
@@ -1292,7 +1298,8 @@ module internal UnaryMetadataIlOp =
|
||||
methodGenerics
|
||||
typeDefn
|
||||
|
||||
let alloc, state = IlMachineState.getOrAllocateType baseClassTypes handle state
|
||||
let alloc, state =
|
||||
IlMachineState.getOrAllocateType loggerFactory baseClassTypes handle state
|
||||
|
||||
let vt =
|
||||
{
|
||||
@@ -1320,6 +1327,7 @@ module internal UnaryMetadataIlOp =
|
||||
|
||||
let state, handle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
assy.Name
|
||||
@@ -1327,7 +1335,8 @@ module internal UnaryMetadataIlOp =
|
||||
methodGenerics
|
||||
typeDefn
|
||||
|
||||
let alloc, state = IlMachineState.getOrAllocateType baseClassTypes handle state
|
||||
let alloc, state =
|
||||
IlMachineState.getOrAllocateType loggerFactory baseClassTypes handle state
|
||||
|
||||
let vt =
|
||||
{
|
||||
@@ -1369,6 +1378,7 @@ module internal UnaryMetadataIlOp =
|
||||
|
||||
let state, typeHandle =
|
||||
IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
assy.Name
|
||||
|
@@ -2,12 +2,13 @@ namespace WoofWare.PawPrint
|
||||
|
||||
open System.Collections.Immutable
|
||||
open System.Reflection
|
||||
open System.Reflection.Metadata
|
||||
open Microsoft.Extensions.Logging
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
|
||||
module internal UnaryStringTokenIlOp =
|
||||
let execute
|
||||
(loggerFactory : ILoggerFactory)
|
||||
(baseClassTypes : BaseClassTypes<DumpedAssembly>)
|
||||
(op : UnaryStringTokenIlOp)
|
||||
(sh : StringToken)
|
||||
@@ -66,6 +67,7 @@ module internal UnaryStringTokenIlOp =
|
||||
let state, stringType =
|
||||
DumpedAssembly.typeInfoToTypeDefn' baseClassTypes state._LoadedAssemblies baseClassTypes.String
|
||||
|> IlMachineState.concretizeType
|
||||
loggerFactory
|
||||
baseClassTypes
|
||||
state
|
||||
baseClassTypes.Corelib.Name
|
||||
|
Reference in New Issue
Block a user