Skip to content

Commit

Permalink
Added OpenILModuleReaderFromStream
Browse files Browse the repository at this point in the history
  • Loading branch information
TIHan committed Aug 30, 2019
1 parent 23856f7 commit 067b547
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,18 @@ type StreamView(s: Stream) =
s.Seek (int64 addr, SeekOrigin.Begin) |> ignore
r.ReadUInt16 ()

override bfv.Finalize() =
(bfv :> IDisposable).Dispose()

interface IDisposable with

member this.Dispose() =
GC.SurpressFinalize(this)
r.Dispose()

[<DebuggerDisplay("{FileName}")>]
type StreamFile(fileName: string, bytes: byte[]) =
let view = ByteView bytes
do stats.byteFileCount <- stats.byteFileCount + 1
type StreamFile(fileName: string, s: Stream) =
let view = StreamView s
member __.FileName = fileName
interface BinaryFile with
override bf.GetView() = view :> BinaryView
Expand Down Expand Up @@ -4062,6 +4070,11 @@ let OpenILModuleReaderFromBytes fileName bytes opts =
let ilModule, ilAssemblyRefs, pdb = openPE (fileName, pefile, opts.pdbDirPath, (opts.reduceMemoryUsage = ReduceMemoryFlag.Yes), opts.ilGlobals, true)
new ILModuleReaderImpl(ilModule, ilAssemblyRefs, (fun () -> ClosePdbReader pdb)) :> ILModuleReader

let OpenILModuleReaderFromStream fileName s opts =
let pefile = StreamFile(fileName, s) :> BinaryFile
let ilModule, ilAssemblyRefs, pdb = openPE (fileName, pefile, opts.pdbDirPath, (opts.reduceMemoryUsage = ReduceMemoryFlag.Yes), opts.ilGlobals, true)
new ILModuleReaderImpl(ilModule, ilAssemblyRefs, (fun () -> ClosePdbReader pdb)) :> ILModuleReader

let ClearAllILModuleReaderCache() =
ilModuleReaderCache1.Clear(ILModuleReaderCache1LockToken())
ilModuleReaderCache2.Clear()
Expand Down
4 changes: 4 additions & 0 deletions src/absil/ilread.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ val internal ClearAllILModuleReaderCache : unit -> unit
/// Open a binary reader based on the given bytes.
val internal OpenILModuleReaderFromBytes: fileNameForDebugOutput:string -> assemblyContents: byte[] -> options: ILReaderOptions -> ILModuleReader

/// Open a binary reader based on the given stream.
/// The ILModuleReader will own the lifetime of the stream.
val internal OpenILModuleReaderFromStream: fileNameForDebugOutput:string -> assemblyContents: Stream -> options: ILReaderOptions -> ILModuleReader

type Statistics =
{ mutable rawMemoryFileCount : int
mutable memoryMapFileOpenedCount : int
Expand Down

0 comments on commit 067b547

Please sign in to comment.