diff --git a/.gitignore b/.gitignore
index b1a739b148d..c7f1828c733 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,12 +66,6 @@ tests/projects/Sample_VS2012_FSharp_ConsoleApp_net45_with_resource/Sample_VS2012
obj
extras
ossreadme*.txt
-tests/fsharp/typecheck/sigs/*.exe
-tests/fsharp/typecheck/sigs/*.diff
-tests/fsharp/typecheck/sigs/*.err
-tests/fsharp/typecheck/sigs/*.vsdiff
-tests/fsharp/typecheck/sigs/*.dll
-tests/fsharp/typecheck/sigs/*.vserr
src/fsharp/FSharp.LanguageService.Compiler/illex.*
src/fsharp/FSharp.LanguageService.Compiler/ilpars.*
src/fsharp/FSharp.LanguageService.Compiler/lex.*
@@ -79,16 +73,9 @@ src/fsharp/FSharp.LanguageService.Compiler/pars.*
src/fsharp/FSharp.LanguageService.Compiler/pplex.fs
src/fsharp/FSharp.LanguageService.Compiler/pppars.fs
src/fsharp/FSharp.LanguageService.Compiler/pppars.fsi
-tests/fsharp/typecheck/sigs/*.dll
-tests/fsharp/typecheck/sigs/*.exe
-tests/fsharp/typeProviders/builtin/SqlDataConnection/DataDirectory/
-tests/fsharp/typeProviders/builtin/SqlDataConnection/ExampleResolutionFolder/
-tests/fsharp/typeProviders/builtin/SqlEntityConnection/DataDirectory/
vsintegration/src/unittests/Unittests.fsi
tests/fsharpqa/Source/CodeGen/EmittedIL/StaticInit/StaticInit_Module01.dll
tests/fsharpqa/Source/CodeGen/EmittedIL/StaticInit/StaticInit_Module01.pdb
-tests/fsharp/typeProviders/helloWorld/bincompat1/
-tests/fsharp/typeProviders/helloWorld/bincompat2/
tests/XFSharpQA_Failures.log.*
vsintegration/src/vs/FsPkgs/FSharp.Project/FS/FSharp.ProjectSystem.FSharp.fsi
vsintegration/src/vs/FsPkgs/FSharp.Project/FS/ctofiles/
@@ -96,6 +83,7 @@ tests/fsharpqa/Source/CodeGen/EmittedIL/QueryExpressionStepping/Utils.dll
tests/fsharpqa/Source/CodeGen/EmittedIL/ComputationExpressions/ComputationExprLibrary.dll
*.csproj.user
+*.sln.DotSettings.user
*.ide
*.log
@@ -103,3 +91,5 @@ tests/fsharpqa/Source/CodeGen/EmittedIL/ComputationExpressions/ComputationExprLi
*.chk
*.bak
*.orig
+*.mdf
+*.ldf
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e4e6059f68e..f89fec89692 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -3,6 +3,7 @@
The Visual F# team is proud to be a contributor to F#, and urge you to join in too. F# users and the F# community are grateful for all contributions to F#.
Besides this overview, we recommend ["Becoming a contributor"](http://mrange.wordpress.com/2014/12/11/becoming-an-fsharp-contributor/), a community blog post by MÃ¥rten RÃ¥nge.
+For those contributing to the core of the F# compiler, we recommend ["The F# Compiler Technical Overview"](http://fsharp.github.io/2015/09/29/fsharp-compiler-guide.html)
###Getting Started
diff --git a/DEVGUIDE.md b/DEVGUIDE.md
index 257bceef898..42aa3905a02 100644
--- a/DEVGUIDE.md
+++ b/DEVGUIDE.md
@@ -1,10 +1,17 @@
# F# Compiler, Core Library and Visual F# Tools Open Contribution Repository
This repo is where you can contribute to the F# compiler, core library and the Visual F# Tools.
+To learn what F# is and why it's interesting, go to [fsharp.org](http://fsharp.org). To get a free F# environment, go to [fsharp.org](http://fsharp.org/use/windows).
-To learn what F# is and why it's interesting, go to [fsharp.org](http://fsharp.org).
+**Compiler Technical Documentation**
-To get a free F# environment, go to [fsharp.org](http://fsharp.org/use/windows).
+The primary technical documents for the F# compiler code are
+
+* [The F# Language Specification](http://fsharp.org/specs/language-spec/)
+
+* [The F# Compiler Technical Guide](http://fsharp.github.io/2015/09/29/fsharp-compiler-guide.html)
+ maintained by contributors to this repository. Please read
+ and contribute to that guide.
**License**
> Contributions made to this repo are subject to terms and conditions of the Apache License, Version 2.0. A copy of the license can be found in the [License.txt](License.txt) file at the root of this distribution.
@@ -15,7 +22,7 @@ To get a free F# environment, go to [fsharp.org](http://fsharp.org/use/windows).
## 0. A Shortcut to Build and Smoke Test
You can build a subset of functionality (including bootstrapped compiler and library) and run a very
-small number of 'smoke' tests using the script used by continuous integration:
+small number of 'smoke' tests using the script used by continuous integration on Windows:
.\appveyor-build.cmd
@@ -132,3 +139,8 @@ Restart Visual Studio, it should now be running your freshly-built Visual F# IDE
- We use this compiler to compile the source in this distribution, to produce a "proto" compiler, dropped to the `proto` directory. When run, this compiler still relies on `FSharp.Core.dll` with version X.
- We use the proto compiler to compile the source for `FSharp.Core.dll` in this distribution.
- We use the proto compiler to compile the source for `FSharp.Compiler.dll`, `fsc.exe`, `fsi.exe`, and other binaries found in this distribution.
+
+### Further technical resources
+
+The primary technical guide to the core compiler code is [The F# Compiler Technical Guide](http://fsharp.github.io/2015/09/29/fsharp-compiler-guide.html). Please read and contribute to that guide.
+
diff --git a/README.md b/README.md
index 37ec0d1da39..d231a8fa8c0 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-[](http://issuestats.com/github/microsoft/visualfsharp)
-[](http://issuestats.com/github/microsoft/visualfsharp)
[](https://ci.appveyor.com/project/KevinRansom/visualfsharp-radou/branch/fsharp4)
[](https://gitter.im/Microsoft/visualfsharp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -43,3 +41,4 @@ Although the primary focus of this repo is F# for Windows and the Visual Studio
###Get In Touch
Keep up with the Visual F# Team and the development of the Visual F# Tools by following us [@VisualFSharp](https://twitter.com/VisualFSharp) or subscribing to our [team blog](http://blogs.msdn.com/b/fsharpteam/).
+
diff --git a/appveyor.yml b/appveyor.yml
index 0dbbaa64802..f505dd51a79 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,4 +1,4 @@
-os: Windows Server 2012 R2
+os: Visual Studio 2015
init:
build_script:
diff --git a/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.Build.Tasks.dll b/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.Build.Tasks.dll
index e9bae5b1c34..9556f1b30ef 100644
Binary files a/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.Build.Tasks.dll and b/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.Build.Tasks.dll differ
diff --git a/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.targets b/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.targets
index 4792caf4f78..5e9362cdd27 100644
--- a/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.targets
+++ b/lkg/FSharp-4.0.30319.1/bin/FSharp.SRGen.targets
@@ -6,7 +6,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
-Copyright (C) Microsoft Corporation. All rights reserved.
+Copyright (C) Microsoft Corporation. Apache 2.0 License.
***********************************************************************************************
-->
@@ -59,7 +59,6 @@ Copyright (C) Microsoft Corporation. All rights reserved.
-
false
diff --git a/lkg/FSharp-4.0.30319.1/bin/FsLex.exe.config b/lkg/FSharp-4.0.30319.1/bin/FsLex.exe.config
new file mode 100644
index 00000000000..9e9fc740a8f
--- /dev/null
+++ b/lkg/FSharp-4.0.30319.1/bin/FsLex.exe.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/lkg/FSharp-4.0.30319.1/bin/FsSrGen.exe b/lkg/FSharp-4.0.30319.1/bin/FsSrGen.exe
index 1dce9d7e8c5..d0cc465cf8b 100644
Binary files a/lkg/FSharp-4.0.30319.1/bin/FsSrGen.exe and b/lkg/FSharp-4.0.30319.1/bin/FsSrGen.exe differ
diff --git a/lkg/FSharp-4.0.30319.1/bin/FsYacc.exe.config b/lkg/FSharp-4.0.30319.1/bin/FsYacc.exe.config
new file mode 100644
index 00000000000..9e9fc740a8f
--- /dev/null
+++ b/lkg/FSharp-4.0.30319.1/bin/FsYacc.exe.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/packages.config b/packages.config
index a7462f84250..b54a7653b29 100644
--- a/packages.config
+++ b/packages.config
@@ -1,5 +1,6 @@
-
+
+
\ No newline at end of file
diff --git a/src/FSharpSource.targets b/src/FSharpSource.targets
index 27b47b1c008..1203895c334 100644
--- a/src/FSharpSource.targets
+++ b/src/FSharpSource.targets
@@ -1,22 +1,23 @@
+
+ true
+ 4.4.0.9055
+ 2.4.0.9055
+ 3.7.4.9055
+ 3.47.4.9055
+ 3.78.4.9055
+ 3.259.4.9055
+
-
- true
-
-
- $(OtherFlags) --version:4.4.0.9055
- $(OtherFlags) --version:2.4.0.9055
- $(OtherFlags) --version:3.7.4.9055
- $(OtherFlags) --version:3.47.4.9055
- $(OtherFlags) --version:3.78.4.9055
- $(OtherFlags) --version:3.259.4.9055
+
+ $(OtherFlags) --version:$(FSCoreVersion)
$(OtherFlags) --delaysign+ --keyfile:"$(FSharpSourcesRoot)\fsharp\msft.pubkey"
STRONG_NAME_AND_DELAY_SIGN_FSHARP_COMPILER_WITH_MSFT_KEY;$(DefineConstants)
true
@@ -29,6 +30,12 @@
true
+
+
+
+ $(OtherFlags) --version:4.4.0.9055
+
+
$(OtherFlags) --version:4.4.0.9055 --delaysign+ --keyfile:"$(FSharpSourcesRoot)\fsharp\msft.pubkey"
@@ -101,7 +108,10 @@
2.6.4
2.6.4.14350
$(FSharpSourcesRoot)\..\packages\NUnit.$(NUnitVersion)\lib\
- $(FSharpSourcesRoot)\..\packages\NUnit.Runners.$(NUnitVersion)\tools\lib\
+ $(FSharpSourcesRoot)\..\packages\NUnit.Runners.$(NUnitVersion)\tools\lib\
+ 2.0.3
+ 2.0.3.0
+ $(FSharpSourcesRoot)\..\packages\FsCheck.$(FsCheckVersion)\lib\
@@ -729,7 +739,7 @@
Outputs="@(CustomCopyLocal->'$(OutDir)%(TargetFilename)')"
Condition="'$(targetCLIDir)'!='Silverlight/4.0/'"
>
-
+
diff --git a/src/absil/il.fs b/src/absil/il.fs
index 5fe7972f13c..f1d827216f5 100644
--- a/src/absil/il.fs
+++ b/src/absil/il.fs
@@ -215,22 +215,18 @@ module SHA1 =
else k60to79
- type chan = SHABytes of byte[]
- type sha_instream =
- { stream: chan;
+ type SHAStream =
+ { stream: byte[];
mutable pos: int;
mutable eof: bool; }
- let rot_left32 x n = (x <<< n) ||| (x >>>& (32-n))
+ let rotLeft32 x n = (x <<< n) ||| (x >>>& (32-n))
- let inline sha_eof sha = sha.eof
-
- (* padding and length (in bits!) recorded at end *)
- let sha_after_eof sha =
+
+ // padding and length (in bits!) recorded at end
+ let shaAfterEof sha =
let n = sha.pos
- let len =
- (match sha.stream with
- | SHABytes s -> s.Length)
+ let len = sha.stream.Length
if n = len then 0x80
else
let padded_len = (((len + 9 + 63) / 64) * 64) - 8
@@ -245,22 +241,21 @@ module SHA1 =
elif (n &&& 63) = 63 then (sha.eof <- true; int32 (int64 len * int64 8) &&& 0xff)
else 0x0
- let sha_read8 sha =
- let b =
- match sha.stream with
- | SHABytes s -> if sha.pos >= s.Length then sha_after_eof sha else int32 s.[sha.pos]
- sha.pos <- sha.pos + 1;
+ let shaRead8 sha =
+ let s = sha.stream
+ let b = if sha.pos >= s.Length then shaAfterEof sha else int32 s.[sha.pos]
+ sha.pos <- sha.pos + 1
b
- let sha_read32 sha =
- let b0 = sha_read8 sha
- let b1 = sha_read8 sha
- let b2 = sha_read8 sha
- let b3 = sha_read8 sha
+ let shaRead32 sha =
+ let b0 = shaRead8 sha
+ let b1 = shaRead8 sha
+ let b2 = shaRead8 sha
+ let b3 = shaRead8 sha
let res = (b0 <<< 24) ||| (b1 <<< 16) ||| (b2 <<< 8) ||| b3
res
- let sha1_hash sha =
+ let sha1Hash sha =
let mutable h0 = 0x67452301
let mutable h1 = 0xEFCDAB89
let mutable h2 = 0x98BADCFE
@@ -272,21 +267,21 @@ module SHA1 =
let mutable d = 0
let mutable e = 0
let w = Array.create 80 0x00
- while (not (sha_eof sha)) do
+ while (not sha.eof) do
for i = 0 to 15 do
- w.[i] <- sha_read32 sha
+ w.[i] <- shaRead32 sha
for t = 16 to 79 do
- w.[t] <- rot_left32 (w.[t-3] ^^^ w.[t-8] ^^^ w.[t-14] ^^^ w.[t-16]) 1
+ w.[t] <- rotLeft32 (w.[t-3] ^^^ w.[t-8] ^^^ w.[t-14] ^^^ w.[t-16]) 1
a <- h0
b <- h1
c <- h2
d <- h3
e <- h4
for t = 0 to 79 do
- let temp = (rot_left32 a 5) + f(t,b,c,d) + e + w.[t] + k(t)
+ let temp = (rotLeft32 a 5) + f(t,b,c,d) + e + w.[t] + k(t)
e <- d
d <- c
- c <- rot_left32 b 30
+ c <- rotLeft32 b 30
b <- a
a <- temp
h0 <- h0 + a
@@ -297,7 +292,7 @@ module SHA1 =
h0,h1,h2,h3,h4
let sha1HashBytes s =
- let (_h0,_h1,_h2,h3,h4) = sha1_hash { stream = SHABytes s; pos = 0; eof = false } // the result of the SHA algorithm is stored in registers 3 and 4
+ let (_h0,_h1,_h2,h3,h4) = sha1Hash { stream = s; pos = 0; eof = false } // the result of the SHA algorithm is stored in registers 3 and 4
Array.map byte [| b0 h4; b1 h4; b2 h4; b3 h4; b0 h3; b1 h3; b2 h3; b3 h3; |]
@@ -4690,7 +4685,7 @@ type ILTypeSigParser(tstring : string) =
let ilty = x.ParseType()
ILAttribElem.Type(Some(ilty))
-let decodeILAttribData ilg (ca: ILAttribute) scope =
+let decodeILAttribData ilg (ca: ILAttribute) =
let bytes = ca.Data
let sigptr = 0
let bb0,sigptr = sigptr_get_byte bytes sigptr
@@ -4784,15 +4779,19 @@ let decodeILAttribData ilg (ca: ILAttribute) scope =
let et,sigptr = sigptr_get_u8 bytes sigptr
// We have a named value
let ty,sigptr =
- // REVIEW: Post-M3, consider removing the restriction for scope - it's unnecessary
- // because you can reconstruct scope using the qualified name from the CA Blob
- if (0x50 = (int et) || 0x55 = (int et)) && Option.isSome scope then
+ if (0x50 = (int et) || 0x55 = (int et)) then
let qualified_tname,sigptr = sigptr_get_serstring bytes sigptr
- // we're already getting the qualified name from the binary blob
- // if we don't split out the unqualified name from the qualified name,
- // we'll write the qualified assembly reference string twice to the binary blob
- let unqualified_tname = qualified_tname.Split([|','|]).[0]
- let scoref = Option.get scope
+ let unqualified_tname, rest =
+ let pieces = qualified_tname.Split(',')
+ if pieces.Length > 1 then
+ pieces.[0], Some (String.concat "," pieces.[1..])
+ else
+ pieces.[0], None
+ let scoref =
+ match rest with
+ | Some aname -> ILScopeRef.Assembly(ILAssemblyRef.FromAssemblyName(System.Reflection.AssemblyName(aname)))
+ | None -> ilg.traits.ScopeRef
+
let tref = mkILTyRef (scoref,unqualified_tname)
let tspec = mkILNonGenericTySpec tref
ILType.Value(tspec),sigptr
diff --git a/src/absil/il.fsi b/src/absil/il.fsi
index 6daef27de12..0d27c0c764e 100644
--- a/src/absil/il.fsi
+++ b/src/absil/il.fsi
@@ -1797,11 +1797,9 @@ val destTypeDefsWithGlobalFunctionsFirst: ILGlobals -> ILTypeDefs -> ILTypeDef l
/// Note: not all custom attribute data can be decoded without binding types. In particular
/// enums must be bound in order to discover the size of the underlying integer.
/// The following assumes enums have size int32.
-/// It also does not completely decode System.Type attributes
val decodeILAttribData:
ILGlobals ->
ILAttribute ->
- ILScopeRef option ->
ILAttribElem list * (* fixed args *)
ILAttributeNamedArg list (* named args: values and flags indicating if they are fields or properties *)
diff --git a/src/absil/ilascii.fs b/src/absil/ilascii.fs
index f2bd0a4b2d3..bd4e1e8c354 100644
--- a/src/absil/ilascii.fs
+++ b/src/absil/ilascii.fs
@@ -12,7 +12,7 @@ open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
open Microsoft.FSharp.Compiler.AbstractIL.Extensions.ILX.Types
open Microsoft.FSharp.Compiler.AbstractIL.IL
-// set to the proper value at build.fs (BuildFrameworkTcImports)
+// set to the proper value at CompileOps.fs (BuildFrameworkTcImports)
let parseILGlobals = ref EcmaILGlobals
// --------------------------------------------------------------------
diff --git a/src/absil/ildiag.fsi b/src/absil/ildiag.fsi
index 5bef738cd52..6b833042636 100644
--- a/src/absil/ildiag.fsi
+++ b/src/absil/ildiag.fsi
@@ -2,7 +2,7 @@
/// Diagnostics from the AbsIL toolkit. You can reset the diagnostics
/// stream to point elsewhere, or turn it
-/// off altogether by setting it to 'None'. The logging channel initally
+/// off altogether by setting it to 'None'. The logging channel initially
/// points to stderr. All functions call flush() automatically.
///
/// REVIEW: review if we should just switch to System.Diagnostics
diff --git a/src/absil/illib.fs b/src/absil/illib.fs
index 7f2cb63dd4f..f6b3a4876f7 100644
--- a/src/absil/illib.fs
+++ b/src/absil/illib.fs
@@ -465,6 +465,7 @@ module Dictionary =
// FUTURE CLEANUP: remove this adhoc collection
type Hashset<'T> = Dictionary<'T,int>
+
[]
module Hashset =
let create (n:int) = new Hashset<'T>(n, HashIdentity.Structural)
@@ -498,6 +499,28 @@ type ResultOrException<'TResult> =
| Result of 'TResult
| Exception of System.Exception
+[]
+module ResultOrException =
+
+ let success a = Result a
+ let raze (b:exn) = Exception b
+
+ // map
+ let (|?>) res f =
+ match res with
+ | Result x -> Result(f x )
+ | Exception err -> Exception err
+
+ let ForceRaise res =
+ match res with
+ | Result x -> x
+ | Exception err -> raise err
+
+ let otherwise f x =
+ match x with
+ | Result x -> success x
+ | Exception _err -> f()
+
//-------------------------------------------------------------------------
// Library: extensions to flat list (immutable arrays)
@@ -744,7 +767,7 @@ type LazyWithContext<'T,'ctxt> =
match x.funcOrException with
| null -> x.value
| _ ->
- // Enter the lock in case another thread is in the process of evaluting the result
+ // Enter the lock in case another thread is in the process of evaluating the result
System.Threading.Monitor.Enter(x);
try
x.UnsynchronizedForce(ctxt)
diff --git a/src/absil/ilmorph.fs b/src/absil/ilmorph.fs
index 8df078b7db6..396db5de82a 100644
--- a/src/absil/ilmorph.fs
+++ b/src/absil/ilmorph.fs
@@ -292,7 +292,7 @@ let cattr_typ2typ ilg f c =
// dev11 M3 defensive coding: if anything goes wrong with attribute decoding or encoding, then back out.
if morphCustomAttributeData then
try
- let elems,namedArgs = IL.decodeILAttribData ilg c (Some(meth.MethodRef.EnclosingTypeRef.Scope))
+ let elems,namedArgs = IL.decodeILAttribData ilg c
let elems = elems |> List.map (celem_typ2typ f)
let namedArgs = namedArgs |> List.map (cnamedarg_typ2typ f)
IL.mkILCustomAttribMethRef ilg (meth, elems, namedArgs)
diff --git a/src/absil/ilread.fs b/src/absil/ilread.fs
index 11acfcee40c..3b2c8754fe7 100644
--- a/src/absil/ilread.fs
+++ b/src/absil/ilread.fs
@@ -44,48 +44,66 @@ let checking = false
let logging = false
let _ = if checking then dprintn "warning : Ilread.checking is on"
-/// Read file into cached memory blocks to avoid taking any kind of a
-/// lock on the file, and avoid needing any cleanup of files.
-type MemChannel =
- { mutable mcPos: int;
- mcBlocks: byte[] }
-
- static member OpenIn f =
- let mcBlocks = FileSystem.ReadAllBytesShim f
- { mcPos = 0; mcBlocks = mcBlocks }
-
- static member OpenBytes f =
- let mcBlocks = f
- { mcPos = 0; mcBlocks = mcBlocks }
-
- member mc.InputByte() =
- let p = mc.mcPos
- let res = mc.mcBlocks.[p]
- mc.mcPos <- p + 1;
- res
+let singleOfBits (x:int32) = System.BitConverter.ToSingle(System.BitConverter.GetBytes(x),0)
+let doubleOfBits (x:int64) = System.BitConverter.Int64BitsToDouble(x)
- member mc.InputBytes len =
- let p = mc.mcPos
- let res = Array.sub mc.mcBlocks p len
- mc.mcPos <- p + len;
- res
+//---------------------------------------------------------------------
+// Utilities.
+//---------------------------------------------------------------------
- member mc.InputInt32() =
- let b0 = mc.InputByte()
- let b1 = mc.InputByte()
- let b2 = mc.InputByte()
- let b3 = mc.InputByte()
- int b0 ||| (int b1 <<< 8) ||| (int b2 <<< 16) ||| (int b3 <<< 24)
+let align alignment n = ((n + alignment - 0x1) / alignment) * alignment
- member mc.InputUInt16() =
- let b0 = mc.InputByte()
- let b1 = mc.InputByte()
- uint16 b0 ||| (uint16 b1 <<< 8)
+let uncodedToken (tab:TableName) idx = ((tab.Index <<< 24) ||| idx)
+
+let i32ToUncodedToken tok =
+ let idx = tok &&& 0xffffff
+ let tab = tok >>>& 24
+ (TableName.FromIndex tab, idx)
+
+
+[]
+type TaggedIndex<'T> =
+ val tag: 'T
+ val index : int32
+ new(tag,index) = { tag=tag; index=index }
- member mc.Seek addr =
- mc.mcPos <- addr
+let uncodedTokenToTypeDefOrRefOrSpec (tab,tok) =
+ let tag =
+ if tab = TableNames.TypeDef then tdor_TypeDef
+ elif tab = TableNames.TypeRef then tdor_TypeRef
+ elif tab = TableNames.TypeSpec then tdor_TypeSpec
+ else failwith "bad table in uncodedTokenToTypeDefOrRefOrSpec"
+ TaggedIndex(tag,tok)
- member mc.Close() = ()
+let uncodedTokenToMethodDefOrRef (tab,tok) =
+ let tag =
+ if tab = TableNames.Method then mdor_MethodDef
+ elif tab = TableNames.MemberRef then mdor_MemberRef
+ else failwith "bad table in uncodedTokenToMethodDefOrRef"
+ TaggedIndex(tag,tok)
+
+let (|TaggedIndex|) (x:TaggedIndex<'T>) = x.tag, x.index
+let tokToTaggedIdx f nbits tok =
+ let tagmask =
+ if nbits = 1 then 1
+ elif nbits = 2 then 3
+ elif nbits = 3 then 7
+ elif nbits = 4 then 15
+ elif nbits = 5 then 31
+ else failwith "too many nbits"
+ let tag = tok &&& tagmask
+ let idx = tok >>>& nbits
+ TaggedIndex(f tag, idx)
+
+
+[]
+type BinaryFile() =
+ abstract ReadByte : addr:int -> byte
+ abstract ReadBytes : addr:int -> int -> byte[]
+ abstract ReadInt32 : addr:int -> int
+ abstract ReadUInt16 : addr:int -> uint16
+ abstract CountUtf8String : addr:int -> int
+ abstract ReadUTF8String : addr: int -> string
/// Read file from memory mapped files
module MemoryMapping =
@@ -140,6 +158,7 @@ let derefByte (p:nativeint) =
NativePtr.read (NativePtr.ofNativeInt p)
type MemoryMappedFile(hMap: MemoryMapping.HANDLE, start:nativeint) =
+ inherit BinaryFile()
static member Create fileName =
//printf "fileName = %s\n" fileName;
@@ -163,264 +182,135 @@ type MemoryMappedFile(hMap: MemoryMapping.HANDLE, start:nativeint) =
member m.Addr (i:int) : nativeint =
start + nativeint i
- member m.ReadByte i =
+ override m.ReadByte i =
derefByte (m.Addr i)
- member m.ReadBytes i len =
+ override m.ReadBytes i len =
let res = Bytes.zeroCreate len
Marshal.Copy(m.Addr i, res, 0,len);
res
- member m.ReadInt32 i =
+ override m.ReadInt32 i =
NativePtr.read (NativePtr.ofNativeInt (m.Addr i))
- member m.ReadUInt16 i =
+ override m.ReadUInt16 i =
NativePtr.read (NativePtr.ofNativeInt (m.Addr i))
member m.Close() =
ignore(MemoryMapping.UnmapViewOfFile start);
ignore(MemoryMapping.CloseHandle hMap)
- member m.CountUtf8String i =
+ override m.CountUtf8String i =
let start = m.Addr i
let mutable p = start
while derefByte p <> 0uy do
p <- p + 1n
int (p - start)
- member m.ReadUTF8String i =
+ override m.ReadUTF8String i =
let n = m.CountUtf8String i
new System.String(NativePtr.ofNativeInt (m.Addr i), 0, n, System.Text.Encoding.UTF8)
-type MMapChannel =
- { mutable mmPos: int;
- mmMap: MemoryMappedFile }
+//---------------------------------------------------------------------
+// Read file from memory blocks
+//---------------------------------------------------------------------
- static member OpenIn f =
- let mmap = MemoryMappedFile.Create f
- { mmPos = 0; mmMap = mmap }
- member mc.InputByte() =
- let res = mc.mmMap.ReadByte mc.mmPos
- mc.mmPos <- mc.mmPos + 1;
- res
+type ByteFile(bytes:byte[]) =
+ inherit BinaryFile()
- member mc.InputInt32() =
- let res = mc.mmMap.ReadInt32 mc.mmPos
- mc.mmPos <- mc.mmPos + 4;
- res
+ static member OpenIn f = ByteFile(FileSystem.ReadAllBytesShim f)
+ static member OpenBytes bytes = ByteFile(bytes)
- member mc.InputUInt16() =
- let res = mc.mmMap.ReadUInt16 mc.mmPos
- mc.mmPos <- mc.mmPos + 2;
- res
+ override mc.ReadByte addr = bytes.[addr]
+ override mc.ReadBytes addr len = Array.sub bytes addr len
+ override m.CountUtf8String addr =
+ let mutable p = addr
+ while bytes.[p] <> 0uy do
+ p <- p + 1
+ p - addr
- member mc.InputBytes len =
- let res = mc.mmMap.ReadBytes mc.mmPos len
- mc.mmPos <- mc.mmPos + len;
- res
-
- member mc.PeekUTF8String () =
- mc.mmMap.ReadUTF8String mc.mmPos
+ override m.ReadUTF8String addr =
+ let n = m.CountUtf8String addr
+ System.Text.Encoding.UTF8.GetString (bytes, addr, n)
- member mc.Seek addr = mc.mmPos <- addr
-
- member mc.Close() = mc.mmMap.Close()
+ override is.ReadInt32 addr =
+ let b0 = is.ReadByte addr
+ let b1 = is.ReadByte (addr+1)
+ let b2 = is.ReadByte (addr+2)
+ let b3 = is.ReadByte (addr+3)
+ int b0 ||| (int b1 <<< 8) ||| (int b2 <<< 16) ||| (int b3 <<< 24)
-//---------------------------------------------------------------------
-// Read file from cached memory blocks or via 'seek'
-//---------------------------------------------------------------------
+ override is.ReadUInt16 addr =
+ let b0 = is.ReadByte addr
+ let b1 = is.ReadByte (addr+1)
+ uint16 b0 ||| (uint16 b1 <<< 8)
-type InputChannel =
- | Chan of string * System.IO.BinaryReader option ref
- | Mem of MemChannel
- | MMap of MMapChannel
-
-let readByte is =
- match is with
- | Chan (_,{contents=Some ic}) -> ic.ReadByte()
- | Chan (s,_) -> failwith ("readByte: input channel "+s+" was closed" )
- | Mem mc -> mc.InputByte()
- | MMap mc -> mc.InputByte ()
-
-let readByteAsInt32 is = int32 (readByte is)
-
-let seek is addr =
- match is with
- | Chan (_,{contents=Some ic}) -> ic.BaseStream.Seek(int64 addr,SeekOrigin.Begin) |> ignore
- | Chan (s,_) -> failwith ("seek: input channel "+s+" was closed" )
- | Mem mc -> mc.Seek addr
- | MMap mc -> mc.Seek addr
-
-let readBytes is len =
- match is with
- | Chan (_,{contents=Some ic}) -> ic.ReadBytes len
- | Chan (s,_) -> failwith ("readBytes: input channel "+s+" was closed" )
- | Mem mc -> mc.InputBytes len
- | MMap mc -> mc.InputBytes len
-
-let readInt64 is =
- let b0 = readByte is
- let b1 = readByte is
- let b2 = readByte is
- let b3 = readByte is
- let b4 = readByte is
- let b5 = readByte is
- let b6 = readByte is
- let b7 = readByte is
+let seekReadByte (is:BinaryFile) addr = is.ReadByte addr
+let seekReadBytes (is:BinaryFile) addr len = is.ReadBytes addr len
+let seekReadInt32 (is:BinaryFile) addr = is.ReadInt32 addr
+let seekReadUInt16 (is:BinaryFile) addr = is.ReadUInt16 addr
+
+let seekReadByteAsInt32 is addr = int32 (seekReadByte is addr)
+
+let seekReadInt64 is addr =
+ let b0 = seekReadByte is addr
+ let b1 = seekReadByte is (addr+1)
+ let b2 = seekReadByte is (addr+2)
+ let b3 = seekReadByte is (addr+3)
+ let b4 = seekReadByte is (addr+4)
+ let b5 = seekReadByte is (addr+5)
+ let b6 = seekReadByte is (addr+6)
+ let b7 = seekReadByte is (addr+7)
int64 b0 ||| (int64 b1 <<< 8) ||| (int64 b2 <<< 16) ||| (int64 b3 <<< 24) |||
(int64 b4 <<< 32) ||| (int64 b5 <<< 40) ||| (int64 b6 <<< 48) ||| (int64 b7 <<< 56)
-let readInt32 is =
- match is with
- | Chan (_,{contents=Some ic}) -> ic.ReadInt32()
- | Chan (s,_) -> failwith ("readBytes: input channel "+s+" was closed" )
- | MMap mm -> mm.InputInt32()
- | Mem mm -> mm.InputInt32()
-
-
-//---------------------------------------------------------------------
-// Derived reading
-//---------------------------------------------------------------------
-
-let readUInt16 is =
- match is with
- | MMap mm -> mm.InputUInt16()
- | _ ->
- let b0 = readByte is
- let b1 = readByte is
- uint16 b0 ||| (uint16 b1 <<< 8)
-
-let readUInt16AsInt32 is = int32 (readUInt16 is)
-
-let readSByte is = sbyte (readByte is)
-
-let singleOfBits (x:int32) = System.BitConverter.ToSingle(System.BitConverter.GetBytes(x),0)
-let doubleOfBits (x:int64) = System.BitConverter.Int64BitsToDouble(x)
+let seekReadUInt16AsInt32 is addr = int32 (seekReadUInt16 is addr)
-let readSingle is = singleOfBits (readInt32 is)
-let readDouble is = doubleOfBits (readInt64 is)
-
-let readCompressedUInt32 is =
- let b0 = readByte is
- if b0 <= 0x7Fuy then int b0
+let seekReadCompressedUInt32 is addr =
+ let b0 = seekReadByte is addr
+ if b0 <= 0x7Fuy then int b0, addr+1
elif b0 <= 0xBFuy then
let b0 = b0 &&& 0x7Fuy
- let b1 = readByteAsInt32 is
- (int b0 <<< 8) ||| int b1
+ let b1 = seekReadByteAsInt32 is (addr+1)
+ (int b0 <<< 8) ||| int b1, addr+2
else
let b0 = b0 &&& 0x3Fuy
- let b1 = readByte is
- let b2 = readByte is
- let b3 = readByte is
- (int b0 <<< 24) ||| (int b1 <<< 16) ||| (int b2 <<< 8) ||| int b3
-
-let seekReadInt32 is addr = seek is addr; readInt32 is
-let seekReadInt64 is addr = seek is addr; readInt64 is
-let seekReadUInt16AsInt32 is addr = seek is addr; readUInt16AsInt32 is
-let seekReadUInt16 is addr = seek is addr; readUInt16 is
-let seekReadByte is addr = seek is addr; readByte is
-let seekReadByteAsInt32 is addr = seek is addr; readByteAsInt32 is
-let seekReadSByte is addr = seek is addr; readSByte is
-let seekReadSingle is addr = seek is addr; readSingle is
-let seekReadDouble is addr = seek is addr; readDouble is
-let seekReadBytes is addr len = seek is addr; readBytes is len
+ let b1 = seekReadByteAsInt32 is (addr+1)
+ let b2 = seekReadByteAsInt32 is (addr+2)
+ let b3 = seekReadByteAsInt32 is (addr+3)
+ (int b0 <<< 24) ||| (int b1 <<< 16) ||| (int b2 <<< 8) ||| int b3, addr+4
+
+let seekReadSByte is addr = sbyte (seekReadByte is addr)
+let seekReadSingle is addr = singleOfBits (seekReadInt32 is addr)
+let seekReadDouble is addr = doubleOfBits (seekReadInt64 is addr)
-let rec countUtf8String is n =
- let c = readByteAsInt32 is
+let rec seekCountUtf8String is addr n =
+ let c = seekReadByteAsInt32 is addr
if c = 0 then n
- else countUtf8String is (n+1)
+ else seekCountUtf8String is (addr+1) (n+1)
let seekReadUTF8String is addr =
- seek is addr;
- match is with
- | MMap mc ->
- // optimized implementation
- mc.PeekUTF8String()
- | _ ->
- let n = countUtf8String is 0
- let bytes = seekReadBytes is addr (n)
+ let n = seekCountUtf8String is addr 0
+ let bytes = seekReadBytes is addr n
System.Text.Encoding.UTF8.GetString (bytes, 0, bytes.Length)
-let readBlob is =
- let len = readCompressedUInt32 is
- readBytes is len
-
let seekReadBlob is addr =
- seek is addr;
- readBlob is
-
-let readUserString is =
- let len = readCompressedUInt32 is
- let bytes = readBytes is (len - 1)
- System.Text.Encoding.Unicode.GetString(bytes, 0, bytes.Length)
+ let len, addr = seekReadCompressedUInt32 is addr
+ seekReadBytes is addr len
let seekReadUserString is addr =
- seek is addr;
- readUserString is
-
-let readGuid is =
- readBytes is 0x10
-
-let seekReadGuid is addr =
- seek is addr;
- readGuid is
+ let len, addr = seekReadCompressedUInt32 is addr
+ let bytes = seekReadBytes is addr (len - 1)
+ System.Text.Encoding.Unicode.GetString(bytes, 0, bytes.Length)
-//---------------------------------------------------------------------
-// Utilities.
-//---------------------------------------------------------------------
-
-let align alignment n = ((n + alignment - 0x1) / alignment) * alignment
-
-let uncodedToken (tab:TableName) idx = ((tab.Index <<< 24) ||| idx)
-
-let i32ToUncodedToken tok =
- let idx = tok &&& 0xffffff
- let tab = tok >>>& 24
- (TableName.FromIndex tab, idx)
-
-let readUncodedToken is = i32ToUncodedToken (readInt32 is)
-
-[]
-type TaggedIndex<'T> =
- val tag: 'T
- val index : int32
- new(tag,index) = { tag=tag; index=index }
-
-let uncodedTokenToTypeDefOrRefOrSpec (tab,tok) =
- let tag =
- if tab = TableNames.TypeDef then tdor_TypeDef
- elif tab = TableNames.TypeRef then tdor_TypeRef
- elif tab = TableNames.TypeSpec then tdor_TypeSpec
- else failwith "bad table in uncodedTokenToTypeDefOrRefOrSpec"
- TaggedIndex(tag,tok)
-
-let uncodedTokenToMethodDefOrRef (tab,tok) =
- let tag =
- if tab = TableNames.Method then mdor_MethodDef
- elif tab = TableNames.MemberRef then mdor_MemberRef
- else failwith "bad table in uncodedTokenToMethodDefOrRef"
- TaggedIndex(tag,tok)
+let seekReadGuid is addr = seekReadBytes is addr 0x10
let seekReadUncodedToken is addr =
- seek is addr;
- readUncodedToken is
+ i32ToUncodedToken (seekReadInt32 is addr)
-let (|TaggedIndex|) (x:TaggedIndex<'T>) = x.tag, x.index
-let readTaggedIdx f nbits big is =
- let tok = if big then readInt32 is else readUInt16AsInt32 is
- let tagmask =
- if nbits = 1 then 1
- elif nbits = 2 then 3
- elif nbits = 3 then 7
- elif nbits = 4 then 15
- elif nbits = 5 then 31
- else failwith "too many nbits"
- let tag = tok &&& tagmask
- let idx = tok >>>& nbits
- TaggedIndex(f tag, idx)
-
+
//---------------------------------------------------------------------
// Primitives to help read signatures. These do not use the file cursor
//---------------------------------------------------------------------
@@ -1044,11 +934,12 @@ type ILReaderContext =
resourcesAddr:int32;
strongnameAddr:int32;
vtableFixupsAddr:int32;
- is: InputChannel;
+ is: BinaryFile;
infile:string;
userStringsStreamPhysicalLoc: int32;
stringsStreamPhysicalLoc: int32;
blobsStreamPhysicalLoc: int32;
+ blobsStreamSize: int32;
readUserStringHeap: (int32 -> string);
memoizeString: string -> string;
readStringHeap: (int32 -> string);
@@ -1128,28 +1019,6 @@ type ILReaderContext =
seekReadMethodDefAsMethodData : int -> MethodData;
seekReadGenericParams : GenericParamsIdx -> ILGenericParameterDef list;
seekReadFieldDefAsFieldSpec : int -> ILFieldSpec; }
-
-let readUntaggedIdx (tab:TableName) ctxt =
- if ctxt.tableBigness.[tab.Index]
- then readInt32 ctxt.is
- else readUInt16AsInt32 ctxt.is
-
-let readResolutionScopeIdx ctxt = readTaggedIdx mkResolutionScopeTag 2 ctxt.rsBigness ctxt.is
-let readTypeDefOrRefOrSpecIdx ctxt = readTaggedIdx mkTypeDefOrRefOrSpecTag 2 ctxt.tdorBigness ctxt.is
-let readTypeOrMethodDefIdx ctxt = readTaggedIdx mkTypeOrMethodDefTag 1 ctxt.tomdBigness ctxt.is
-let readHasConstantIdx ctxt = readTaggedIdx mkHasConstantTag 2 ctxt.hcBigness ctxt.is
-let readHasCustomAttributeIdx ctxt = readTaggedIdx mkHasCustomAttributeTag 5 ctxt.hcaBigness ctxt.is
-let readHasFieldMarshalIdx ctxt = readTaggedIdx mkHasFieldMarshalTag 1 ctxt.hfmBigness ctxt.is
-let readHasDeclSecurityIdx ctxt = readTaggedIdx mkHasDeclSecurityTag 2 ctxt.hdsBigness ctxt.is
-let readMemberRefParentIdx ctxt = readTaggedIdx mkMemberRefParentTag 3 ctxt.mrpBigness ctxt.is
-let readHasSemanticsIdx ctxt = readTaggedIdx mkHasSemanticsTag 1 ctxt.hsBigness ctxt.is
-let readMethodDefOrRefIdx ctxt = readTaggedIdx mkMethodDefOrRefTag 1 ctxt.mdorBigness ctxt.is
-let readMemberForwardedIdx ctxt = readTaggedIdx mkMemberForwardedTag 1 ctxt.mfBigness ctxt.is
-let readImplementationIdx ctxt = readTaggedIdx mkImplementationTag 2 ctxt.iBigness ctxt.is
-let readCustomAttributeTypeIdx ctxt = readTaggedIdx mkILCustomAttributeTypeTag 3 ctxt.catBigness ctxt.is
-let readStringIdx ctxt = if ctxt.stringsBigness then readInt32 ctxt.is else readUInt16AsInt32 ctxt.is
-let readGuidIdx ctxt = if ctxt.guidsBigness then readInt32 ctxt.is else readUInt16AsInt32 ctxt.is
-let readBlobIdx ctxt = if ctxt.blobsBigness then readInt32 ctxt.is else readUInt16AsInt32 ctxt.is
let count c =
#if DEBUG
@@ -1159,25 +1028,68 @@ let count c =
()
#endif
+
+let seekReadUInt16Adv ctxt (addr: byref) =
+ let res = seekReadUInt16 ctxt.is addr
+ addr <- addr + 2
+ res
+
+let seekReadInt32Adv ctxt (addr: byref) =
+ let res = seekReadInt32 ctxt.is addr
+ addr <- addr+4
+ res
+
+let seekReadUInt16AsInt32Adv ctxt (addr: byref) =
+ let res = seekReadUInt16AsInt32 ctxt.is addr
+ addr <- addr+2
+ res
+
+let seekReadTaggedIdx f nbits big is (addr: byref) =
+ let tok = if big then seekReadInt32Adv is &addr else seekReadUInt16AsInt32Adv is &addr
+ tokToTaggedIdx f nbits tok
+
+
+let seekReadIdx big ctxt (addr: byref) =
+ if big then seekReadInt32Adv ctxt &addr else seekReadUInt16AsInt32Adv ctxt &addr
+
+let seekReadUntaggedIdx (tab:TableName) ctxt (addr: byref) =
+ seekReadIdx ctxt.tableBigness.[tab.Index] ctxt &addr
+
+
+let seekReadResolutionScopeIdx ctxt (addr: byref) = seekReadTaggedIdx mkResolutionScopeTag 2 ctxt.rsBigness ctxt &addr
+let seekReadTypeDefOrRefOrSpecIdx ctxt (addr: byref) = seekReadTaggedIdx mkTypeDefOrRefOrSpecTag 2 ctxt.tdorBigness ctxt &addr
+let seekReadTypeOrMethodDefIdx ctxt (addr: byref) = seekReadTaggedIdx mkTypeOrMethodDefTag 1 ctxt.tomdBigness ctxt &addr
+let seekReadHasConstantIdx ctxt (addr: byref) = seekReadTaggedIdx mkHasConstantTag 2 ctxt.hcBigness ctxt &addr
+let seekReadHasCustomAttributeIdx ctxt (addr: byref) = seekReadTaggedIdx mkHasCustomAttributeTag 5 ctxt.hcaBigness ctxt &addr
+let seekReadHasFieldMarshalIdx ctxt (addr: byref) = seekReadTaggedIdx mkHasFieldMarshalTag 1 ctxt.hfmBigness ctxt &addr
+let seekReadHasDeclSecurityIdx ctxt (addr: byref) = seekReadTaggedIdx mkHasDeclSecurityTag 2 ctxt.hdsBigness ctxt &addr
+let seekReadMemberRefParentIdx ctxt (addr: byref) = seekReadTaggedIdx mkMemberRefParentTag 3 ctxt.mrpBigness ctxt &addr
+let seekReadHasSemanticsIdx ctxt (addr: byref) = seekReadTaggedIdx mkHasSemanticsTag 1 ctxt.hsBigness ctxt &addr
+let seekReadMethodDefOrRefIdx ctxt (addr: byref) = seekReadTaggedIdx mkMethodDefOrRefTag 1 ctxt.mdorBigness ctxt &addr
+let seekReadMemberForwardedIdx ctxt (addr: byref) = seekReadTaggedIdx mkMemberForwardedTag 1 ctxt.mfBigness ctxt &addr
+let seekReadImplementationIdx ctxt (addr: byref) = seekReadTaggedIdx mkImplementationTag 2 ctxt.iBigness ctxt &addr
+let seekReadCustomAttributeTypeIdx ctxt (addr: byref) = seekReadTaggedIdx mkILCustomAttributeTypeTag 3 ctxt.catBigness ctxt &addr
+let seekReadStringIdx ctxt (addr: byref) = seekReadIdx ctxt.stringsBigness ctxt &addr
+let seekReadGuidIdx ctxt (addr: byref) = seekReadIdx ctxt.guidsBigness ctxt &addr
+let seekReadBlobIdx ctxt (addr: byref) = seekReadIdx ctxt.blobsBigness ctxt &addr
+
let seekReadModuleRow ctxt idx =
if idx = 0 then failwith "cannot read Module table row 0";
- let addr = ctxt.rowAddr TableNames.Module idx
- seek ctxt.is addr;
- let generation = readUInt16 ctxt.is
- let nameIdx = readStringIdx ctxt
- let mvidIdx = readGuidIdx ctxt
- let encidIdx = readGuidIdx ctxt
- let encbaseidIdx = readGuidIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Module idx
+ let generation = seekReadUInt16Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let mvidIdx = seekReadGuidIdx ctxt &addr
+ let encidIdx = seekReadGuidIdx ctxt &addr
+ let encbaseidIdx = seekReadGuidIdx ctxt &addr
(generation, nameIdx, mvidIdx, encidIdx, encbaseidIdx)
/// Read Table ILTypeRef
let seekReadTypeRefRow ctxt idx =
count ctxt.countTypeRef;
- let addr = ctxt.rowAddr TableNames.TypeRef idx
- seek ctxt.is addr;
- let scopeIdx = readResolutionScopeIdx ctxt
- let nameIdx = readStringIdx ctxt
- let namespaceIdx = readStringIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.TypeRef idx
+ let scopeIdx = seekReadResolutionScopeIdx ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let namespaceIdx = seekReadStringIdx ctxt &addr
(scopeIdx,nameIdx,namespaceIdx)
/// Read Table ILTypeDef
@@ -1185,47 +1097,43 @@ let seekReadTypeDefRow ctxt idx = ctxt.seekReadTypeDefRow idx
let seekReadTypeDefRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countTypeDef;
- let addr = ctxt.rowAddr TableNames.TypeDef idx
- seek ctxt.is addr;
- let flags = readInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let namespaceIdx = readStringIdx ctxt
- let extendsIdx = readTypeDefOrRefOrSpecIdx ctxt
- let fieldsIdx = readUntaggedIdx TableNames.Field ctxt
- let methodsIdx = readUntaggedIdx TableNames.Method ctxt
+ let mutable addr = ctxt.rowAddr TableNames.TypeDef idx
+ let flags = seekReadInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let namespaceIdx = seekReadStringIdx ctxt &addr
+ let extendsIdx = seekReadTypeDefOrRefOrSpecIdx ctxt &addr
+ let fieldsIdx = seekReadUntaggedIdx TableNames.Field ctxt &addr
+ let methodsIdx = seekReadUntaggedIdx TableNames.Method ctxt &addr
(flags, nameIdx, namespaceIdx, extendsIdx, fieldsIdx, methodsIdx)
/// Read Table Field
let seekReadFieldRow ctxt idx =
count ctxt.countField;
- let addr = ctxt.rowAddr TableNames.Field idx
- seek ctxt.is addr;
- let flags = readUInt16AsInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let typeIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Field idx
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let typeIdx = seekReadBlobIdx ctxt &addr
(flags,nameIdx,typeIdx)
/// Read Table Method
let seekReadMethodRow ctxt idx =
count ctxt.countMethod;
- let addr = ctxt.rowAddr TableNames.Method idx
- seek ctxt.is addr;
- let codeRVA = readInt32 ctxt.is
- let implflags = readUInt16AsInt32 ctxt.is
- let flags = readUInt16AsInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let typeIdx = readBlobIdx ctxt
- let paramIdx = readUntaggedIdx TableNames.Param ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Method idx
+ let codeRVA = seekReadInt32Adv ctxt &addr
+ let implflags = seekReadUInt16AsInt32Adv ctxt &addr
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let typeIdx = seekReadBlobIdx ctxt &addr
+ let paramIdx = seekReadUntaggedIdx TableNames.Param ctxt &addr
(codeRVA, implflags, flags, nameIdx, typeIdx, paramIdx)
/// Read Table Param
let seekReadParamRow ctxt idx =
count ctxt.countParam;
- let addr = ctxt.rowAddr TableNames.Param idx
- seek ctxt.is addr;
- let flags = readUInt16AsInt32 ctxt.is
- let seq = (readUInt16AsInt32 ctxt.is)
- let nameIdx = readStringIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Param idx
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let seq = seekReadUInt16AsInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
(flags,seq,nameIdx)
/// Read Table InterfaceImpl
@@ -1233,20 +1141,18 @@ let seekReadInterfaceImplRow ctxt idx = ctxt.seekReadInterfaceImplRow idx
let seekReadInterfaceImplRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countInterfaceImpl;
- let addr = ctxt.rowAddr TableNames.InterfaceImpl idx
- seek ctxt.is addr;
- let tidx = readUntaggedIdx TableNames.TypeDef ctxt
- let intfIdx = readTypeDefOrRefOrSpecIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx
+ let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
+ let intfIdx = seekReadTypeDefOrRefOrSpecIdx ctxt &addr
(tidx,intfIdx)
/// Read Table MemberRef
let seekReadMemberRefRow ctxt idx =
count ctxt.countMemberRef;
- let addr = ctxt.rowAddr TableNames.MemberRef idx
- seek ctxt.is addr;
- let mrpIdx = readMemberRefParentIdx ctxt
- let nameIdx = readStringIdx ctxt
- let typeIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.MemberRef idx
+ let mrpIdx = seekReadMemberRefParentIdx ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let typeIdx = seekReadBlobIdx ctxt &addr
(mrpIdx,nameIdx,typeIdx)
/// Read Table Constant
@@ -1254,21 +1160,19 @@ let seekReadConstantRow ctxt idx = ctxt.seekReadConstantRow idx
let seekReadConstantRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countConstant;
- let addr = ctxt.rowAddr TableNames.Constant idx
- seek ctxt.is addr;
- let kind = readUInt16 ctxt.is
- let parentIdx = readHasConstantIdx ctxt
- let valIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Constant idx
+ let kind = seekReadUInt16Adv ctxt &addr
+ let parentIdx = seekReadHasConstantIdx ctxt &addr
+ let valIdx = seekReadBlobIdx ctxt &addr
(kind, parentIdx, valIdx)
/// Read Table CustomAttribute
let seekReadCustomAttributeRow ctxt idx =
count ctxt.countCustomAttribute;
- let addr = ctxt.rowAddr TableNames.CustomAttribute idx
- seek ctxt.is addr;
- let parentIdx = readHasCustomAttributeIdx ctxt
- let typeIdx = readCustomAttributeTypeIdx ctxt
- let valIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.CustomAttribute idx
+ let parentIdx = seekReadHasCustomAttributeIdx ctxt &addr
+ let typeIdx = seekReadCustomAttributeTypeIdx ctxt &addr
+ let valIdx = seekReadBlobIdx ctxt &addr
(parentIdx, typeIdx, valIdx)
/// Read Table FieldMarshal
@@ -1276,66 +1180,59 @@ let seekReadFieldMarshalRow ctxt idx = ctxt.seekReadFieldMarshalRow idx
let seekReadFieldMarshalRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countFieldMarshal;
- let addr = ctxt.rowAddr TableNames.FieldMarshal idx
- seek ctxt.is addr;
- let parentIdx = readHasFieldMarshalIdx ctxt
- let typeIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.FieldMarshal idx
+ let parentIdx = seekReadHasFieldMarshalIdx ctxt &addr
+ let typeIdx = seekReadBlobIdx ctxt &addr
(parentIdx, typeIdx)
/// Read Table Permission
let seekReadPermissionRow ctxt idx =
count ctxt.countPermission;
- let addr = ctxt.rowAddr TableNames.Permission idx
- seek ctxt.is addr;
- let action = readUInt16 ctxt.is
- let parentIdx = readHasDeclSecurityIdx ctxt
- let typeIdx = readBlobIdx ctxt
- (action,parentIdx, typeIdx)
+ let mutable addr = ctxt.rowAddr TableNames.Permission idx
+ let action = seekReadUInt16Adv ctxt &addr
+ let parentIdx = seekReadHasDeclSecurityIdx ctxt &addr
+ let typeIdx = seekReadBlobIdx ctxt &addr
+ (action, parentIdx, typeIdx)
/// Read Table ClassLayout
let seekReadClassLayoutRow ctxt idx =
count ctxt.countClassLayout;
- let addr = ctxt.rowAddr TableNames.ClassLayout idx
- seek ctxt.is addr;
- let pack = readUInt16 ctxt.is
- let size = readInt32 ctxt.is
- let tidx = readUntaggedIdx TableNames.TypeDef ctxt
+ let mutable addr = ctxt.rowAddr TableNames.ClassLayout idx
+ let pack = seekReadUInt16Adv ctxt &addr
+ let size = seekReadInt32Adv ctxt &addr
+ let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
(pack,size,tidx)
/// Read Table FieldLayout
let seekReadFieldLayoutRow ctxt idx =
count ctxt.countFieldLayout;
- let addr = ctxt.rowAddr TableNames.FieldLayout idx
- seek ctxt.is addr;
- let offset = readInt32 ctxt.is
- let fidx = readUntaggedIdx TableNames.Field ctxt
+ let mutable addr = ctxt.rowAddr TableNames.FieldLayout idx
+ let offset = seekReadInt32Adv ctxt &addr
+ let fidx = seekReadUntaggedIdx TableNames.Field ctxt &addr
(offset,fidx)
//// Read Table StandAloneSig
let seekReadStandAloneSigRow ctxt idx =
count ctxt.countStandAloneSig;
- let addr = ctxt.rowAddr TableNames.StandAloneSig idx
- seek ctxt.is addr;
- let sigIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.StandAloneSig idx
+ let sigIdx = seekReadBlobIdx ctxt &addr
sigIdx
/// Read Table EventMap
let seekReadEventMapRow ctxt idx =
count ctxt.countEventMap;
- let addr = ctxt.rowAddr TableNames.EventMap idx
- seek ctxt.is addr;
- let tidx = readUntaggedIdx TableNames.TypeDef ctxt
- let eventsIdx = readUntaggedIdx TableNames.Event ctxt
+ let mutable addr = ctxt.rowAddr TableNames.EventMap idx
+ let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
+ let eventsIdx = seekReadUntaggedIdx TableNames.Event ctxt &addr
(tidx,eventsIdx)
/// Read Table Event
let seekReadEventRow ctxt idx =
count ctxt.countEvent;
- let addr = ctxt.rowAddr TableNames.Event idx
- seek ctxt.is addr;
- let flags = readUInt16AsInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let typIdx = readTypeDefOrRefOrSpecIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Event idx
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let typIdx = seekReadTypeDefOrRefOrSpecIdx ctxt &addr
(flags,nameIdx,typIdx)
/// Read Table PropertyMap
@@ -1343,20 +1240,18 @@ let seekReadPropertyMapRow ctxt idx = ctxt.seekReadPropertyMapRow idx
let seekReadPropertyMapRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countPropertyMap;
- let addr = ctxt.rowAddr TableNames.PropertyMap idx
- seek ctxt.is addr;
- let tidx = readUntaggedIdx TableNames.TypeDef ctxt
- let propsIdx = readUntaggedIdx TableNames.Property ctxt
+ let mutable addr = ctxt.rowAddr TableNames.PropertyMap idx
+ let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
+ let propsIdx = seekReadUntaggedIdx TableNames.Property ctxt &addr
(tidx,propsIdx)
/// Read Table Property
let seekReadPropertyRow ctxt idx =
count ctxt.countProperty;
- let addr = ctxt.rowAddr TableNames.Property idx
- seek ctxt.is addr;
- let flags = readUInt16AsInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let typIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Property idx
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let typIdx = seekReadBlobIdx ctxt &addr
(flags,nameIdx,typIdx)
/// Read Table MethodSemantics
@@ -1364,122 +1259,111 @@ let seekReadMethodSemanticsRow ctxt idx = ctxt.seekReadMethodSemanticsRow idx
let seekReadMethodSemanticsRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countMethodSemantics;
- let addr = ctxt.rowAddr TableNames.MethodSemantics idx
- seek ctxt.is addr;
- let flags = readUInt16AsInt32 ctxt.is
- let midx = readUntaggedIdx TableNames.Method ctxt
- let assocIdx = readHasSemanticsIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.MethodSemantics idx
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let midx = seekReadUntaggedIdx TableNames.Method ctxt &addr
+ let assocIdx = seekReadHasSemanticsIdx ctxt &addr
(flags,midx,assocIdx)
/// Read Table MethodImpl
let seekReadMethodImplRow ctxt idx =
count ctxt.countMethodImpl;
- let addr = ctxt.rowAddr TableNames.MethodImpl idx
- seek ctxt.is addr;
- let tidx = readUntaggedIdx TableNames.TypeDef ctxt
- let mbodyIdx = readMethodDefOrRefIdx ctxt
- let mdeclIdx = readMethodDefOrRefIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.MethodImpl idx
+ let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
+ let mbodyIdx = seekReadMethodDefOrRefIdx ctxt &addr
+ let mdeclIdx = seekReadMethodDefOrRefIdx ctxt &addr
(tidx,mbodyIdx,mdeclIdx)
/// Read Table ILModuleRef
let seekReadModuleRefRow ctxt idx =
count ctxt.countModuleRef;
- let addr = ctxt.rowAddr TableNames.ModuleRef idx
- seek ctxt.is addr;
- let nameIdx = readStringIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.ModuleRef idx
+ let nameIdx = seekReadStringIdx ctxt &addr
nameIdx
/// Read Table ILTypeSpec
let seekReadTypeSpecRow ctxt idx =
count ctxt.countTypeSpec;
- let addr = ctxt.rowAddr TableNames.TypeSpec idx
- seek ctxt.is addr;
- let blobIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.TypeSpec idx
+ let blobIdx = seekReadBlobIdx ctxt &addr
blobIdx
/// Read Table ImplMap
let seekReadImplMapRow ctxt idx =
count ctxt.countImplMap;
- let addr = ctxt.rowAddr TableNames.ImplMap idx
- seek ctxt.is addr;
- let flags = readUInt16AsInt32 ctxt.is
- let forwrdedIdx = readMemberForwardedIdx ctxt
- let nameIdx = readStringIdx ctxt
- let scopeIdx = readUntaggedIdx TableNames.ModuleRef ctxt
+ let mutable addr = ctxt.rowAddr TableNames.ImplMap idx
+ let flags = seekReadUInt16AsInt32Adv ctxt &addr
+ let forwrdedIdx = seekReadMemberForwardedIdx ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let scopeIdx = seekReadUntaggedIdx TableNames.ModuleRef ctxt &addr
(flags, forwrdedIdx, nameIdx, scopeIdx)
/// Read Table FieldRVA
let seekReadFieldRVARow ctxt idx =
count ctxt.countFieldRVA;
- let addr = ctxt.rowAddr TableNames.FieldRVA idx
- seek ctxt.is addr;
- let rva = readInt32 ctxt.is
- let fidx = readUntaggedIdx TableNames.Field ctxt
+ let mutable addr = ctxt.rowAddr TableNames.FieldRVA idx
+ let rva = seekReadInt32Adv ctxt &addr
+ let fidx = seekReadUntaggedIdx TableNames.Field ctxt &addr
(rva,fidx)
/// Read Table Assembly
let seekReadAssemblyRow ctxt idx =
count ctxt.countAssembly;
- let addr = ctxt.rowAddr TableNames.Assembly idx
- seek ctxt.is addr;
- let hash = readInt32 ctxt.is
- let v1 = readUInt16 ctxt.is
- let v2 = readUInt16 ctxt.is
- let v3 = readUInt16 ctxt.is
- let v4 = readUInt16 ctxt.is
- let flags = readInt32 ctxt.is
- let publicKeyIdx = readBlobIdx ctxt
- let nameIdx = readStringIdx ctxt
- let localeIdx = readStringIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Assembly idx
+ let hash = seekReadInt32Adv ctxt &addr
+ let v1 = seekReadUInt16Adv ctxt &addr
+ let v2 = seekReadUInt16Adv ctxt &addr
+ let v3 = seekReadUInt16Adv ctxt &addr
+ let v4 = seekReadUInt16Adv ctxt &addr
+ let flags = seekReadInt32Adv ctxt &addr
+ let publicKeyIdx = seekReadBlobIdx ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let localeIdx = seekReadStringIdx ctxt &addr
(hash,v1,v2,v3,v4,flags,publicKeyIdx, nameIdx, localeIdx)
/// Read Table ILAssemblyRef
let seekReadAssemblyRefRow ctxt idx =
count ctxt.countAssemblyRef;
- let addr = ctxt.rowAddr TableNames.AssemblyRef idx
- seek ctxt.is addr;
- let v1 = readUInt16 ctxt.is
- let v2 = readUInt16 ctxt.is
- let v3 = readUInt16 ctxt.is
- let v4 = readUInt16 ctxt.is
- let flags = readInt32 ctxt.is
- let publicKeyOrTokenIdx = readBlobIdx ctxt
- let nameIdx = readStringIdx ctxt
- let localeIdx = readStringIdx ctxt
- let hashValueIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.AssemblyRef idx
+ let v1 = seekReadUInt16Adv ctxt &addr
+ let v2 = seekReadUInt16Adv ctxt &addr
+ let v3 = seekReadUInt16Adv ctxt &addr
+ let v4 = seekReadUInt16Adv ctxt &addr
+ let flags = seekReadInt32Adv ctxt &addr
+ let publicKeyOrTokenIdx = seekReadBlobIdx ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let localeIdx = seekReadStringIdx ctxt &addr
+ let hashValueIdx = seekReadBlobIdx ctxt &addr
(v1,v2,v3,v4,flags,publicKeyOrTokenIdx, nameIdx, localeIdx,hashValueIdx)
/// Read Table File
let seekReadFileRow ctxt idx =
count ctxt.countFile;
- let addr = ctxt.rowAddr TableNames.File idx
- seek ctxt.is addr;
- let flags = readInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let hashValueIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.File idx
+ let flags = seekReadInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let hashValueIdx = seekReadBlobIdx ctxt &addr
(flags, nameIdx, hashValueIdx)
/// Read Table ILExportedTypeOrForwarder
let seekReadExportedTypeRow ctxt idx =
count ctxt.countExportedType;
- let addr = ctxt.rowAddr TableNames.ExportedType idx
- seek ctxt.is addr;
- let flags = readInt32 ctxt.is
- let tok = readInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let namespaceIdx = readStringIdx ctxt
- let implIdx = readImplementationIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.ExportedType idx
+ let flags = seekReadInt32Adv ctxt &addr
+ let tok = seekReadInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let namespaceIdx = seekReadStringIdx ctxt &addr
+ let implIdx = seekReadImplementationIdx ctxt &addr
(flags,tok,nameIdx,namespaceIdx,implIdx)
/// Read Table ManifestResource
let seekReadManifestResourceRow ctxt idx =
count ctxt.countManifestResource;
- let addr = ctxt.rowAddr TableNames.ManifestResource idx
- seek ctxt.is addr;
- let offset = readInt32 ctxt.is
- let flags = readInt32 ctxt.is
- let nameIdx = readStringIdx ctxt
- let implIdx = readImplementationIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.ManifestResource idx
+ let offset = seekReadInt32Adv ctxt &addr
+ let flags = seekReadInt32Adv ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
+ let implIdx = seekReadImplementationIdx ctxt &addr
(offset,flags,nameIdx,implIdx)
/// Read Table Nested
@@ -1487,41 +1371,38 @@ let seekReadNestedRow ctxt idx = ctxt.seekReadNestedRow idx
let seekReadNestedRowUncached ctxtH idx =
let ctxt = getHole ctxtH
count ctxt.countNested;
- let addr = ctxt.rowAddr TableNames.Nested idx
- seek ctxt.is addr;
- let nestedIdx = readUntaggedIdx TableNames.TypeDef ctxt
- let enclIdx = readUntaggedIdx TableNames.TypeDef ctxt
+ let mutable addr = ctxt.rowAddr TableNames.Nested idx
+ let nestedIdx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
+ let enclIdx = seekReadUntaggedIdx TableNames.TypeDef ctxt &addr
(nestedIdx,enclIdx)
/// Read Table GenericParam
let seekReadGenericParamRow ctxt idx =
count ctxt.countGenericParam;
- let addr = ctxt.rowAddr TableNames.GenericParam idx
- seek ctxt.is addr;
- let seq = readUInt16 ctxt.is
- let flags = readUInt16 ctxt.is
- let ownerIdx = readTypeOrMethodDefIdx ctxt
- let nameIdx = readStringIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.GenericParam idx
+ let seq = seekReadUInt16Adv ctxt &addr
+ let flags = seekReadUInt16Adv ctxt &addr
+ let ownerIdx = seekReadTypeOrMethodDefIdx ctxt &addr
+ let nameIdx = seekReadStringIdx ctxt &addr
(idx,seq,flags,ownerIdx,nameIdx)
// Read Table GenericParamConstraint
let seekReadGenericParamConstraintRow ctxt idx =
count ctxt.countGenericParamConstraint;
- let addr = ctxt.rowAddr TableNames.GenericParamConstraint idx
- seek ctxt.is addr;
- let pidx = readUntaggedIdx TableNames.GenericParam ctxt
- let constraintIdx = readTypeDefOrRefOrSpecIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx
+ let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt &addr
+ let constraintIdx = seekReadTypeDefOrRefOrSpecIdx ctxt &addr
(pidx,constraintIdx)
/// Read Table ILMethodSpec
let seekReadMethodSpecRow ctxt idx =
count ctxt.countMethodSpec;
- let addr = ctxt.rowAddr TableNames.MethodSpec idx
- seek ctxt.is addr;
- let mdorIdx = readMethodDefOrRefIdx ctxt
- let instIdx = readBlobIdx ctxt
+ let mutable addr = ctxt.rowAddr TableNames.MethodSpec idx
+ let mdorIdx = seekReadMethodDefOrRefIdx ctxt &addr
+ let instIdx = seekReadBlobIdx ctxt &addr
(mdorIdx,instIdx)
+
let readUserStringHeapUncached ctxtH idx =
let ctxt = getHole ctxtH
seekReadUserString ctxt.is (ctxt.userStringsStreamPhysicalLoc + idx)
@@ -1534,9 +1415,13 @@ let readStringHeapUncached ctxtH idx =
let readStringHeap ctxt idx = ctxt.readStringHeap idx
let readStringHeapOption ctxt idx = if idx = 0 then None else Some (readStringHeap ctxt idx)
+let emptyByteArray: byte[] = [||]
let readBlobHeapUncached ctxtH idx =
let ctxt = getHole ctxtH
- seekReadBlob ctxt.is (ctxt.blobsStreamPhysicalLoc + idx)
+ // valid index lies in range [1..streamSize)
+ // NOTE: idx cannot be 0 - Blob\String heap has first empty element that is one byte 0
+ if idx <= 0 || idx >= ctxt.blobsStreamSize then emptyByteArray
+ else seekReadBlob ctxt.is (ctxt.blobsStreamPhysicalLoc + idx)
let readBlobHeap ctxt idx = ctxt.readBlobHeap idx
let readBlobHeapOption ctxt idx = if idx = 0 then None else Some (readBlobHeap ctxt idx)
@@ -3973,6 +3858,7 @@ let rec genOpenBinaryReader infile is opts =
userStringsStreamPhysicalLoc = userStringsStreamPhysicalLoc;
stringsStreamPhysicalLoc = stringsStreamPhysicalLoc;
blobsStreamPhysicalLoc = blobsStreamPhysicalLoc;
+ blobsStreamSize = blobsStreamSize;
memoizeString = Tables.memoize id;
readUserStringHeap = cacheUserStringHeap (readUserStringHeapUncached ctxtH);
readStringHeap = cacheStringHeap (readStringHeapUncached ctxtH);
@@ -4079,23 +3965,19 @@ let ClosePdbReader pdb =
let OpenILModuleReader infile opts =
try
- let mmap = MMapChannel.OpenIn infile
- let modul,ilAssemblyRefs,pdb = genOpenBinaryReader infile (MMap mmap) opts
+ let mmap = MemoryMappedFile.Create infile
+ let modul,ilAssemblyRefs,pdb = genOpenBinaryReader infile mmap opts
{ modul = modul;
ilAssemblyRefs=ilAssemblyRefs;
dispose = (fun () ->
mmap.Close();
ClosePdbReader pdb) }
- with :? System.DllNotFoundException ->
- let stream = FileSystem.FileStreamReadShim infile
- let is = new BinaryReader(stream)
- let cell = ref (Some is)
- let modul,ilAssemblyRefs,pdb = genOpenBinaryReader infile (Chan (infile,cell)) opts
+ with _ ->
+ let mc = ByteFile.OpenIn infile
+ let modul,ilAssemblyRefs,pdb = genOpenBinaryReader infile mc opts
{ modul = modul;
ilAssemblyRefs = ilAssemblyRefs;
dispose = (fun () ->
- cell := None;
- is.Close();
ClosePdbReader pdb) }
// ++GLOBAL MUTABLE STATE
@@ -4117,8 +3999,8 @@ let OpenILModuleReaderAfterReadingAllBytes infile opts =
match cacheResult with
| Some(ilModuleReader) -> ilModuleReader
| None ->
- let mc = MemChannel.OpenIn infile
- let modul,ilAssemblyRefs,pdb = genOpenBinaryReader infile (Mem mc) opts
+ let mc = ByteFile.OpenIn infile
+ let modul,ilAssemblyRefs,pdb = genOpenBinaryReader infile mc opts
let ilModuleReader =
{ modul = modul;
ilAssemblyRefs = ilAssemblyRefs
@@ -4129,8 +4011,8 @@ let OpenILModuleReaderAfterReadingAllBytes infile opts =
let OpenILModuleReaderFromBytes fileNameForDebugOutput bytes opts =
assert opts.pdbPath.IsNone
- let mc = MemChannel.OpenBytes bytes
- let modul,ilAssemblyRefs,pdb = genOpenBinaryReader fileNameForDebugOutput (Mem mc) opts
+ let mc = ByteFile.OpenBytes bytes
+ let modul,ilAssemblyRefs,pdb = genOpenBinaryReader fileNameForDebugOutput mc opts
let ilModuleReader =
{ modul = modul;
ilAssemblyRefs = ilAssemblyRefs
@@ -4140,4 +4022,3 @@ let OpenILModuleReaderFromBytes fileNameForDebugOutput bytes opts =
-
diff --git a/src/absil/ilread.fsi b/src/absil/ilread.fsi
index 650745691f4..d042ca98002 100644
--- a/src/absil/ilread.fsi
+++ b/src/absil/ilread.fsi
@@ -41,7 +41,7 @@ type ILReaderOptions =
val mkDefault : ILGlobals -> ILReaderOptions
// The non-memory resources (i.e. the file handle) associated with
-// the read can be recovered by calling CloseILModuleReader. Any reamining
+// the read can be recovered by calling CloseILModuleReader. Any remaining
// lazily-computed items in the metadata graph returned by MetadataOfILModuleReader
// will no longer be valid.
[]
diff --git a/src/absil/ilreflect.fs b/src/absil/ilreflect.fs
index efc6b644d83..e5cccbe85cc 100644
--- a/src/absil/ilreflect.fs
+++ b/src/absil/ilreflect.fs
@@ -336,11 +336,11 @@ let convTypeRefAux (cenv:cenv) (tref:ILTypeRef) =
| None ->
let asmName = convAssemblyRef asmref
FileSystem.AssemblyLoad(asmName)
- let typT = assembly.GetType(qualifiedName)
+ let typT = assembly.GetType(qualifiedName, throwOnError=true)
typT |> nonNull "convTypeRefAux"
| ILScopeRef.Module _
| ILScopeRef.Local _ ->
- let typT = Type.GetType(qualifiedName,true)
+ let typT = Type.GetType(qualifiedName, throwOnError=true)
typT |> nonNull "convTypeRefAux"
diff --git a/src/absil/ilsupp.fs b/src/absil/ilsupp.fs
index e419537b66b..30fd22852b8 100644
--- a/src/absil/ilsupp.fs
+++ b/src/absil/ilsupp.fs
@@ -1013,7 +1013,7 @@ type PdbDocumentWriter = { symDocWriter : ISymUnmanagedDocumentWriter } (* poin
type idd =
{ iddCharacteristics: int32;
iddMajorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
- iddMinorVersion: int32; (* acutally u16 in IMAGE_DEBUG_DIRECTORY *)
+ iddMinorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
iddType: int32;
iddData: byte[];}
diff --git a/src/absil/ilsupp.fsi b/src/absil/ilsupp.fsi
index 5e54476a072..8c8b07de5e7 100644
--- a/src/absil/ilsupp.fsi
+++ b/src/absil/ilsupp.fsi
@@ -87,7 +87,7 @@ type PdbDocumentWriter
type idd =
{ iddCharacteristics: int32;
iddMajorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
- iddMinorVersion: int32; (* acutally u16 in IMAGE_DEBUG_DIRECTORY *)
+ iddMinorVersion: int32; (* actually u16 in IMAGE_DEBUG_DIRECTORY *)
iddType: int32;
iddData: byte[];}
diff --git a/src/absil/ilwrite.fs b/src/absil/ilwrite.fs
index e206f3a7114..b6aaa862c3f 100644
--- a/src/absil/ilwrite.fs
+++ b/src/absil/ilwrite.fs
@@ -35,7 +35,7 @@ let reportTime =
let t = System.Diagnostics.Process.GetCurrentProcess().UserProcessorTime.TotalSeconds
let prev = match !tPrev with None -> 0.0 | Some t -> t
let first = match !tFirst with None -> (tFirst := Some t; t) | Some t -> t
- dprintf "ilwrite: TIME %10.3f (total) %10.3f (delta) - %s\n" (t - first) (t - prev) descr;
+ dprintf "ilwrite: TIME %10.3f (total) %10.3f (delta) - %s\n" (t - first) (t - prev) descr
tPrev := Some t
//---------------------------------------------------------------------
@@ -85,12 +85,12 @@ type ByteBuffer with
if n >= 0 && n <= 0x7F then
buf.EmitIntAsByte n
elif n >= 0x80 && n <= 0x3FFF then
- buf.EmitIntAsByte (0x80 ||| (n >>> 8));
+ buf.EmitIntAsByte (0x80 ||| (n >>> 8))
buf.EmitIntAsByte (n &&& 0xFF)
else
- buf.EmitIntAsByte (0xc0l ||| ((n >>> 24) &&& 0xFF));
- buf.EmitIntAsByte ( (n >>> 16) &&& 0xFF);
- buf.EmitIntAsByte ( (n >>> 8) &&& 0xFF);
+ buf.EmitIntAsByte (0xc0l ||| ((n >>> 24) &&& 0xFF))
+ buf.EmitIntAsByte ( (n >>> 16) &&& 0xFF)
+ buf.EmitIntAsByte ( (n >>> 8) &&& 0xFF)
buf.EmitIntAsByte ( n &&& 0xFF)
member buf.EmitPadding n =
@@ -142,15 +142,15 @@ let markerForUnicodeBytes (b:byte[]) =
/// Check that the data held at a fixup is some special magic value, as a sanity check
/// to ensure the fixup is being placed at a ood lcoation.
let checkFixup32 (data: byte[]) offset exp =
- if data.[offset + 3] <> b3 exp then failwith "fixup sanity check failed";
- if data.[offset + 2] <> b2 exp then failwith "fixup sanity check failed";
- if data.[offset + 1] <> b1 exp then failwith "fixup sanity check failed";
+ if data.[offset + 3] <> b3 exp then failwith "fixup sanity check failed"
+ if data.[offset + 2] <> b2 exp then failwith "fixup sanity check failed"
+ if data.[offset + 1] <> b1 exp then failwith "fixup sanity check failed"
if data.[offset] <> b0 exp then failwith "fixup sanity check failed"
let applyFixup32 (data:byte[]) offset v =
- data.[offset] <- b0 v;
- data.[offset+1] <- b1 v;
- data.[offset+2] <- b2 v;
+ data.[offset] <- b0 v
+ data.[offset+1] <- b1 v
+ data.[offset+2] <- b2 v
data.[offset+3] <- b3 v
// --------------------------------------------------------------------
@@ -160,39 +160,39 @@ let applyFixup32 (data:byte[]) offset v =
type PdbDocumentData = ILSourceDocument
type PdbLocalVar =
- { Name: string;
- Signature: byte[];
+ { Name: string
+ Signature: byte[]
/// the local index the name corresponds to
Index: int32 }
type PdbMethodScope =
- { Children: PdbMethodScope array;
- StartOffset: int;
- EndOffset: int;
- Locals: PdbLocalVar array;
- (* REVIEW open_namespaces: pdb_namespace array; *) }
+ { Children: PdbMethodScope array
+ StartOffset: int
+ EndOffset: int
+ Locals: PdbLocalVar array
+ (* REVIEW open_namespaces: pdb_namespace array *) }
type PdbSourceLoc =
- { Document: int;
- Line: int;
- Column: int; }
+ { Document: int
+ Line: int
+ Column: int }
type PdbSequencePoint =
- { Document: int;
- Offset: int;
- Line: int;
- Column: int;
- EndLine: int;
- EndColumn: int; }
+ { Document: int
+ Offset: int
+ Line: int
+ Column: int
+ EndLine: int
+ EndColumn: int }
override x.ToString() = sprintf "(%d,%d)-(%d,%d)" x.Line x.Column x.EndLine x.EndColumn
type PdbMethodData =
- { MethToken: int32;
- MethName:string;
- Params: PdbLocalVar array;
- RootScope: PdbMethodScope;
- Range: (PdbSourceLoc * PdbSourceLoc) option;
- SequencePoints: PdbSequencePoint array; }
+ { MethToken: int32
+ MethName:string
+ Params: PdbLocalVar array
+ RootScope: PdbMethodScope
+ Range: (PdbSourceLoc * PdbSourceLoc) option
+ SequencePoints: PdbSequencePoint array }
module SequencePoint =
let orderBySource sp1 sp2 =
@@ -210,10 +210,10 @@ let sizeof_IMAGE_DEBUG_DIRECTORY = 28
[]
type PdbData =
- { EntryPoint: int32 option;
+ { EntryPoint: int32 option
// MVID of the generated .NET module (used by MDB files to identify debug info)
- ModuleID: byte[];
- Documents: PdbDocumentData[];
+ ModuleID: byte[]
+ Documents: PdbDocumentData[]
Methods: PdbMethodData[] }
//---------------------------------------------------------------------
@@ -222,7 +222,7 @@ type PdbData =
//---------------------------------------------------------------------
let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
- (try FileSystem.FileDelete fpdb with _ -> ());
+ (try FileSystem.FileDelete fpdb with _ -> ())
let pdbw = ref Unchecked.defaultof
try
@@ -235,12 +235,12 @@ let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
let docs = info.Documents |> Array.map (fun doc -> pdbDefineDocument !pdbw doc.File)
let getDocument i =
- if i < 0 || i > docs.Length then failwith "getDocument: bad doc number";
+ if i < 0 || i > docs.Length then failwith "getDocument: bad doc number"
docs.[i]
- reportTime showTimes (sprintf "PDB: Defined %d documents" info.Documents.Length);
- Array.sortInPlaceBy (fun x -> x.MethToken) info.Methods;
+ reportTime showTimes (sprintf "PDB: Defined %d documents" info.Documents.Length)
+ Array.sortInPlaceBy (fun x -> x.MethToken) info.Methods
- reportTime showTimes (sprintf "PDB: Sorted %d methods" info.Methods.Length);
+ reportTime showTimes (sprintf "PDB: Sorted %d methods" info.Methods.Length)
// This next bit is a workaround. The sequence points we get
// from F# (which has nothing to do with this module) are actually expression
@@ -258,7 +258,7 @@ let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
let allSps = Array.mapi (fun i sp -> (i,sp)) allSps
if fixupOverlappingSequencePoints then
// sort the sequence points into source order
- Array.sortInPlaceWith (fun (_,sp1) (_,sp2) -> SequencePoint.orderBySource sp1 sp2) allSps;
+ Array.sortInPlaceWith (fun (_,sp1) (_,sp2) -> SequencePoint.orderBySource sp1 sp2) allSps
// shorten the ranges of any that overlap with following sequence points
// sort the sequence points back into offset order
for i = 0 to Array.length allSps - 2 do
@@ -269,9 +269,9 @@ let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
(sp1.EndLine = sp2.Line &&
sp1.EndColumn >= sp2.Column)) then
let adjustToPrevLine = (sp1.Line < sp2.Line)
- allSps.[i] <- n,{sp1 with EndLine = (if adjustToPrevLine then sp2.Line-1 else sp2.Line);
- EndColumn = (if adjustToPrevLine then 80 else sp2.Column); }
- Array.sortInPlaceBy fst allSps;
+ allSps.[i] <- n,{sp1 with EndLine = (if adjustToPrevLine then sp2.Line-1 else sp2.Line)
+ EndColumn = (if adjustToPrevLine then 80 else sp2.Column) }
+ Array.sortInPlaceBy fst allSps
@@ -279,15 +279,15 @@ let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
info.Methods |> Array.iteri (fun i minfo ->
let sps = Array.sub allSps !spOffset spCounts.[i]
- spOffset := !spOffset + spCounts.[i];
+ spOffset := !spOffset + spCounts.[i]
begin match minfo.Range with
| None -> ()
| Some (a,b) ->
- pdbOpenMethod !pdbw minfo.MethToken;
+ pdbOpenMethod !pdbw minfo.MethToken
pdbSetMethodRange !pdbw
(getDocument a.Document) a.Line a.Column
- (getDocument b.Document) b.Line b.Column;
+ (getDocument b.Document) b.Line b.Column
// Partition the sequence points by document
let spsets =
@@ -304,34 +304,34 @@ let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
spsets |> List.iter (fun spset ->
if spset.Length > 0 then
- Array.sortInPlaceWith SequencePoint.orderByOffset spset;
+ Array.sortInPlaceWith SequencePoint.orderByOffset spset
let sps =
spset |> Array.map (fun sp ->
- // Ildiag.dprintf "token 0x%08lx has an sp at offset 0x%08x\n" minfo.MethToken sp.Offset;
+ // Ildiag.dprintf "token 0x%08lx has an sp at offset 0x%08x\n" minfo.MethToken sp.Offset
(sp.Offset, sp.Line, sp.Column,sp.EndLine, sp.EndColumn))
// Use of alloca in implementation of pdbDefineSequencePoints can give stack overflow here
if sps.Length < 5000 then
- pdbDefineSequencePoints !pdbw (getDocument spset.[0].Document) sps;);
+ pdbDefineSequencePoints !pdbw (getDocument spset.[0].Document) sps)
// Write the scopes
let rec writePdbScope top sco =
if top || sco.Locals.Length <> 0 || sco.Children.Length <> 0 then
- pdbOpenScope !pdbw sco.StartOffset;
- sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index);
- sco.Children |> Array.iter (writePdbScope false);
- pdbCloseScope !pdbw sco.EndOffset;
- writePdbScope true minfo.RootScope;
+ pdbOpenScope !pdbw sco.StartOffset
+ sco.Locals |> Array.iter (fun v -> pdbDefineLocalVariable !pdbw v.Name v.Signature v.Index)
+ sco.Children |> Array.iter (writePdbScope false)
+ pdbCloseScope !pdbw sco.EndOffset
+ writePdbScope true minfo.RootScope
pdbCloseMethod !pdbw
- end);
- reportTime showTimes "PDB: Wrote methods";
+ end)
+ reportTime showTimes "PDB: Wrote methods"
let res = pdbGetDebugInfo !pdbw
for pdbDoc in docs do
pdbCloseDocument pdbDoc
pdbClose !pdbw f fpdb;
- reportTime showTimes "PDB: Closed";
+ reportTime showTimes "PDB: Closed"
res
//---------------------------------------------------------------------
@@ -383,7 +383,7 @@ let createWriter (f:string) =
let WriteMdbInfo fmdb f info =
// Note, if we can’t delete it code will fail later
- (try FileSystem.FileDelete fmdb with _ -> ());
+ (try FileSystem.FileDelete fmdb with _ -> ())
// Try loading the MDB symbol writer from an assembly available on Mono dynamically
// Report an error if the assembly is not available.
@@ -514,7 +514,7 @@ type ILStrongNameSigner =
member s.SignatureSize =
try Support.signerSignatureSize(s.PublicKey)
with e ->
- failwith ("A call to StrongNameSignatureSize failed ("+e.Message+")");
+ failwith ("A call to StrongNameSignatureSize failed ("+e.Message+")")
0x80
member s.SignFile file =
@@ -755,48 +755,48 @@ let envForOverrideSpec (ospec:ILOverridesSpec) = { EnclosingTyparCount=ospec.Enc
[]
type MetadataTable<'T> =
- { name: string;
- dict: Dictionary<'T, int>; // given a row, find its entry number
+ { name: string
+ dict: Dictionary<'T, int> // given a row, find its entry number
#if DEBUG
- mutable lookups: int;
+ mutable lookups: int
#endif
- mutable rows: ResizeArray<'T> ; }
+ mutable rows: ResizeArray<'T> }
member x.Count = x.rows.Count
static member New(nm,hashEq) =
- { name=nm;
+ { name=nm
#if DEBUG
- lookups=0;
+ lookups=0
#endif
- dict = new Dictionary<_,_>(100, hashEq);
- rows= new ResizeArray<_>(); }
+ dict = new Dictionary<_,_>(100, hashEq)
+ rows= new ResizeArray<_>() }
member tbl.EntriesAsArray =
#if DEBUG
- if showEntryLookups then dprintf "--> table %s had %d entries and %d lookups\n" tbl.name tbl.Count tbl.lookups;
+ if showEntryLookups then dprintf "--> table %s had %d entries and %d lookups\n" tbl.name tbl.Count tbl.lookups
#endif
tbl.rows |> ResizeArray.toArray
member tbl.Entries =
#if DEBUG
- if showEntryLookups then dprintf "--> table %s had %d entries and %d lookups\n" tbl.name tbl.Count tbl.lookups;
+ if showEntryLookups then dprintf "--> table %s had %d entries and %d lookups\n" tbl.name tbl.Count tbl.lookups
#endif
tbl.rows |> ResizeArray.toList
member tbl.AddSharedEntry x =
let n = tbl.rows.Count + 1
- tbl.dict.[x] <- n;
- tbl.rows.Add(x);
+ tbl.dict.[x] <- n
+ tbl.rows.Add(x)
n
member tbl.AddUnsharedEntry x =
let n = tbl.rows.Count + 1
- tbl.rows.Add(x);
+ tbl.rows.Add(x)
n
member tbl.FindOrAddSharedEntry x =
#if DEBUG
- tbl.lookups <- tbl.lookups + 1;
+ tbl.lookups <- tbl.lookups + 1
#endif
let mutable res = Unchecked.defaultof<_>
let ok = tbl.dict.TryGetValue(x,&res)
@@ -806,9 +806,9 @@ type MetadataTable<'T> =
/// This is only used in one special place - see further below.
member tbl.SetRowsOfTable t =
- tbl.rows <- ResizeArray.ofArray t;
+ tbl.rows <- ResizeArray.ofArray t
let h = tbl.dict
- h.Clear();
+ h.Clear()
t |> Array.iteri (fun i x -> h.[x] <- (i+1))
member tbl.AddUniqueEntry nm geterr x =
@@ -877,52 +877,52 @@ type TypeDefTableKey = TdKey of string list (* enclosing *) * string (* type nam
[]
type cenv =
- { primaryAssembly: ILScopeRef;
- ilg: ILGlobals;
- emitTailcalls: bool;
- showTimes: bool;
- desiredMetadataVersion: ILVersionInfo;
- requiredDataFixups: (int32 * (int * bool)) list ref;
+ { primaryAssembly: ILScopeRef
+ ilg: ILGlobals
+ emitTailcalls: bool
+ showTimes: bool
+ desiredMetadataVersion: ILVersionInfo
+ requiredDataFixups: (int32 * (int * bool)) list ref
/// References to strings in codestreams: offset of code and a (fixup-location , string token) list)
- mutable requiredStringFixups: (int32 * (int * int) list) list;
- codeChunks: ByteBuffer;
- mutable nextCodeAddr: int32;
+ mutable requiredStringFixups: (int32 * (int * int) list) list
+ codeChunks: ByteBuffer
+ mutable nextCodeAddr: int32
// Collected debug information
mutable moduleGuid: byte[]
- generatePdb: bool;
- pdbinfo: ResizeArray;
- documents: MetadataTable;
+ generatePdb: bool
+ pdbinfo: ResizeArray
+ documents: MetadataTable
/// Raw data, to go into the data section
- data: ByteBuffer;
+ data: ByteBuffer
/// Raw resource data, to go into the data section
- resources: ByteBuffer;
- mutable entrypoint: (bool * int) option;
+ resources: ByteBuffer
+ mutable entrypoint: (bool * int) option
/// Caches
- trefCache: Dictionary;
+ trefCache: Dictionary
/// The following are all used to generate unique items in the output
- tables: array>;
- AssemblyRefs: MetadataTable;
- fieldDefs: MetadataTable;
- methodDefIdxsByKey: MetadataTable;
- methodDefIdxs: Dictionary;
- propertyDefs: MetadataTable;
- eventDefs: MetadataTable;
- typeDefs: MetadataTable;
- guids: MetadataTable;
- blobs: MetadataTable;
- strings: MetadataTable;
- userStrings: MetadataTable;
+ tables: array>
+ AssemblyRefs: MetadataTable
+ fieldDefs: MetadataTable
+ methodDefIdxsByKey: MetadataTable
+ methodDefIdxs: Dictionary
+ propertyDefs: MetadataTable
+ eventDefs: MetadataTable
+ typeDefs: MetadataTable
+ guids: MetadataTable
+ blobs: MetadataTable
+ strings: MetadataTable
+ userStrings: MetadataTable
}
member cenv.GetTable (tab:TableName) = cenv.tables.[tab.Index]
member cenv.AddCode ((reqdStringFixupsOffset,requiredStringFixups),code) =
- if align 4 cenv.nextCodeAddr <> cenv.nextCodeAddr then dprintn "warning: code not 4-byte aligned";
- cenv.requiredStringFixups <- (cenv.nextCodeAddr + reqdStringFixupsOffset, requiredStringFixups) :: cenv.requiredStringFixups;
- cenv.codeChunks.EmitBytes code;
+ if align 4 cenv.nextCodeAddr <> cenv.nextCodeAddr then dprintn "warning: code not 4-byte aligned"
+ cenv.requiredStringFixups <- (cenv.nextCodeAddr + reqdStringFixupsOffset, requiredStringFixups) :: cenv.requiredStringFixups
+ cenv.codeChunks.EmitBytes code
cenv.nextCodeAddr <- cenv.nextCodeAddr + code.Length
member cenv.GetCode() = cenv.codeChunks.Close()
@@ -964,14 +964,14 @@ let peOptionalHeaderByteByCLRVersion v =
// returned by writeBinaryAndReportMappings
[]
type ILTokenMappings =
- { TypeDefTokenMap: ILTypeDef list * ILTypeDef -> int32;
- FieldDefTokenMap: ILTypeDef list * ILTypeDef -> ILFieldDef -> int32;
- MethodDefTokenMap: ILTypeDef list * ILTypeDef -> ILMethodDef -> int32;
- PropertyTokenMap: ILTypeDef list * ILTypeDef -> ILPropertyDef -> int32;
+ { TypeDefTokenMap: ILTypeDef list * ILTypeDef -> int32
+ FieldDefTokenMap: ILTypeDef list * ILTypeDef -> ILFieldDef -> int32
+ MethodDefTokenMap: ILTypeDef list * ILTypeDef -> ILMethodDef -> int32
+ PropertyTokenMap: ILTypeDef list * ILTypeDef -> ILPropertyDef -> int32
EventTokenMap: ILTypeDef list * ILTypeDef -> ILEventDef -> int32 }
let recordRequiredDataFixup requiredDataFixups (buf: ByteBuffer) pos lab =
- requiredDataFixups := (pos,lab) :: !requiredDataFixups;
+ requiredDataFixups := (pos,lab) :: !requiredDataFixups
// Write a special value in that we check later when applying the fixup
buf.EmitInt32 0xdeaddddd
@@ -1007,7 +1007,7 @@ let GetTypeNameAsElemPair cenv n =
//=====================================================================
let rec GenTypeDefPass1 enc cenv (td:ILTypeDef) =
- ignore (cenv.typeDefs.AddUniqueEntry "type index" (fun (TdKey (_,n)) -> n) (TdKey (enc,td.Name)));
+ ignore (cenv.typeDefs.AddUniqueEntry "type index" (fun (TdKey (_,n)) -> n) (TdKey (enc,td.Name)))
GenTypeDefsPass1 (enc@[td.Name]) cenv td.NestedTypes.AsList
and GenTypeDefsPass1 enc cenv tds = List.iter (GenTypeDefPass1 enc cenv) tds
@@ -1053,9 +1053,9 @@ and GetModuleRefAsRow cenv (mref:ILModuleRef) =
and GetModuleRefAsFileRow cenv (mref:ILModuleRef) =
SimpleSharedRow
- [| ULong (if mref.HasMetadata then 0x0000 else 0x0001);
- StringE (GetStringHeapIdx cenv mref.Name);
- (match mref.Hash with None -> Blob 0 | Some s -> Blob (GetBytesAsBlobIdx cenv s)); |]
+ [| ULong (if mref.HasMetadata then 0x0000 else 0x0001)
+ StringE (GetStringHeapIdx cenv mref.Name)
+ (match mref.Hash with None -> Blob 0 | Some s -> Blob (GetBytesAsBlobIdx cenv s)) |]
and GetModuleRefAsIdx cenv mref =
FindOrAddRow cenv TableNames.ModuleRef (GetModuleRefAsRow cenv mref)
@@ -1094,7 +1094,7 @@ and GetTypeRefAsTypeRefIdx cenv tref =
let mutable res = 0
if cenv.trefCache.TryGetValue(tref,&res) then res else
let res = FindOrAddRow cenv TableNames.TypeRef (GetTypeRefAsTypeRefRow cenv tref)
- cenv.trefCache.[tref] <- res;
+ cenv.trefCache.[tref] <- res
res
and GetTypeDescAsTypeRefIdx cenv (scoref,enc,n) =
@@ -1131,10 +1131,10 @@ let getTypeDefOrRefAsUncodedToken (tag,idx) =
let EmitArrayShape (bb: ByteBuffer) (ILArrayShape shape) =
let sized = List.filter (function (_,Some _) -> true | _ -> false) shape
let lobounded = List.filter (function (Some _,_) -> true | _ -> false) shape
- bb.EmitZ32 shape.Length;
- bb.EmitZ32 sized.Length;
- sized |> List.iter (function (_,Some sz) -> bb.EmitZ32 sz | _ -> failwith "?");
- bb.EmitZ32 lobounded.Length;
+ bb.EmitZ32 shape.Length
+ bb.EmitZ32 sized.Length
+ sized |> List.iter (function (_,Some sz) -> bb.EmitZ32 sz | _ -> failwith "?")
+ bb.EmitZ32 lobounded.Length
lobounded |> List.iter (function (Some low,_) -> bb.EmitZ32 low | _ -> failwith "?")
let hasthisToByte hasthis =
@@ -1158,13 +1158,13 @@ let callconvToByte ntypars (Callconv (hasthis,bcc)) =
// REVIEW: write into an accumuating buffer
let rec EmitTypeSpec cenv env (bb: ByteBuffer) (et,tspec:ILTypeSpec) =
if ILList.isEmpty tspec.GenericArgs then
- bb.EmitByte et;
+ bb.EmitByte et
emitTypeInfoAsTypeDefOrRefEncoded cenv bb (tspec.Scope,tspec.Enclosing,tspec.Name)
else
- bb.EmitByte et_WITH;
- bb.EmitByte et;
- emitTypeInfoAsTypeDefOrRefEncoded cenv bb (tspec.Scope,tspec.Enclosing,tspec.Name);
- bb.EmitZ32 tspec.GenericArgs.Length;
+ bb.EmitByte et_WITH
+ bb.EmitByte et
+ emitTypeInfoAsTypeDefOrRefEncoded cenv bb (tspec.Scope,tspec.Enclosing,tspec.Name)
+ bb.EmitZ32 tspec.GenericArgs.Length
EmitTypes cenv env bb tspec.GenericArgs
and GetTypeAsTypeDefOrRef cenv env (ty:ILType) =
@@ -1218,41 +1218,41 @@ and EmitType cenv env bb ty =
| ILType.TypeVar tv ->
let cgparams = env.EnclosingTyparCount
if int32 tv < cgparams then
- bb.EmitByte et_VAR;
+ bb.EmitByte et_VAR
bb.EmitZ32 (int32 tv)
else
- bb.EmitByte et_MVAR;
+ bb.EmitByte et_MVAR
bb.EmitZ32 (int32 tv - cgparams)
| ILType.Byref typ ->
- bb.EmitByte et_BYREF;
+ bb.EmitByte et_BYREF
EmitType cenv env bb typ
| ILType.Ptr typ ->
- bb.EmitByte et_PTR;
+ bb.EmitByte et_PTR
EmitType cenv env bb typ
| ILType.Void ->
bb.EmitByte et_VOID
| ILType.FunctionPointer x ->
- bb.EmitByte et_FNPTR;
+ bb.EmitByte et_FNPTR
EmitCallsig cenv env bb (x.CallingConv,x.ArgTypes,x.ReturnType,None,0)
| ILType.Modified (req,tref,ty) ->
- bb.EmitByte (if req then et_CMOD_REQD else et_CMOD_OPT);
- emitTypeInfoAsTypeDefOrRefEncoded cenv bb (tref.Scope, tref.Enclosing,tref.Name);
+ bb.EmitByte (if req then et_CMOD_REQD else et_CMOD_OPT)
+ emitTypeInfoAsTypeDefOrRefEncoded cenv bb (tref.Scope, tref.Enclosing,tref.Name)
EmitType cenv env bb ty
| _ -> failwith "EmitType"
and EmitCallsig cenv env bb (callconv,args:ILTypes,ret,varargs:ILVarArgs,genarity) =
- bb.EmitByte (callconvToByte genarity callconv);
- if genarity > 0 then bb.EmitZ32 genarity;
- bb.EmitZ32 ((args.Length + (match varargs with None -> 0 | Some l -> l.Length)));
- EmitType cenv env bb ret;
- args |> ILList.iter (EmitType cenv env bb);
+ bb.EmitByte (callconvToByte genarity callconv)
+ if genarity > 0 then bb.EmitZ32 genarity
+ bb.EmitZ32 ((args.Length + (match varargs with None -> 0 | Some l -> l.Length)))
+ EmitType cenv env bb ret
+ args |> ILList.iter (EmitType cenv env bb)
match varargs with
| None -> ()// no extra arg = no sentinel
| Some tys ->
if ILList.isEmpty tys then () // no extra arg = no sentinel
else
- bb.EmitByte et_SENTINEL;
+ bb.EmitByte et_SENTINEL
ILList.iter (EmitType cenv env bb) tys
and GetCallsigAsBytes cenv env x = emitBytesViaBuffer (fun bb -> EmitCallsig cenv env bb x)
@@ -1300,41 +1300,41 @@ and EmitNativeType bb ty =
let u1 = System.Text.Encoding.UTF8.GetBytes nativeTypeName
let u2 = System.Text.Encoding.UTF8.GetBytes custMarshallerName
let u3 = cookieString
- bb.EmitByte nt_CUSTOMMARSHALER;
- bb.EmitZ32 guid.Length;
- bb.EmitBytes guid;
- bb.EmitZ32 u1.Length; bb.EmitBytes u1;
- bb.EmitZ32 u2.Length; bb.EmitBytes u2;
+ bb.EmitByte nt_CUSTOMMARSHALER
+ bb.EmitZ32 guid.Length
+ bb.EmitBytes guid
+ bb.EmitZ32 u1.Length; bb.EmitBytes u1
+ bb.EmitZ32 u2.Length; bb.EmitBytes u2
bb.EmitZ32 u3.Length; bb.EmitBytes u3
| ILNativeType.FixedSysString i ->
- bb.EmitByte nt_FIXEDSYSSTRING;
+ bb.EmitByte nt_FIXEDSYSSTRING
bb.EmitZ32 i
| ILNativeType.FixedArray i ->
- bb.EmitByte nt_FIXEDARRAY;
+ bb.EmitByte nt_FIXEDARRAY
bb.EmitZ32 i
| (* COM interop *) ILNativeType.SafeArray (vt,name) ->
- bb.EmitByte nt_SAFEARRAY;
- bb.EmitZ32 (GetVariantTypeAsInt32 vt);
+ bb.EmitByte nt_SAFEARRAY
+ bb.EmitZ32 (GetVariantTypeAsInt32 vt)
match name with
| None -> ()
| Some n ->
let u1 = Bytes.stringAsUtf8NullTerminated n
bb.EmitZ32 (Array.length u1) ; bb.EmitBytes u1
| ILNativeType.Array (nt,sizeinfo) -> (* REVIEW: check if this corresponds to the ECMA spec *)
- bb.EmitByte nt_ARRAY;
+ bb.EmitByte nt_ARRAY
match nt with
| None -> bb.EmitZ32 (int nt_MAX)
| Some ntt ->
(if ntt = ILNativeType.Empty then
bb.EmitZ32 (int nt_MAX)
else
- EmitNativeType bb ntt);
+ EmitNativeType bb ntt)
match sizeinfo with
| None -> () // chunk out with zeroes because some tools (e.g. asmmeta) read these poorly and expect further elements.
| Some (pnum,additive) ->
// ParamNum
- bb.EmitZ32 pnum;
+ bb.EmitZ32 pnum
(* ElemMul *) (* z_u32 0x1l *)
match additive with
| None -> ()
@@ -1450,11 +1450,11 @@ let rec GetTypeDefAsRow cenv env _enc (td:ILTypeDef) =
let tdorTag, tdorRow = GetTypeOptionAsTypeDefOrRef cenv env td.Extends
UnsharedRow
- [| ULong flags ;
- nelem;
- nselem;
- TypeDefOrRefOrSpec (tdorTag, tdorRow);
- SimpleIndex (TableNames.Field, cenv.fieldDefs.Count + 1);
+ [| ULong flags
+ nelem
+ nselem
+ TypeDefOrRefOrSpec (tdorTag, tdorRow)
+ SimpleIndex (TableNames.Field, cenv.fieldDefs.Count + 1)
SimpleIndex (TableNames.Method,cenv.methodDefIdxsByKey.Count + 1) |]
and GetTypeOptionAsTypeDefOrRef cenv env tyOpt =
@@ -1464,12 +1464,12 @@ and GetTypeOptionAsTypeDefOrRef cenv env tyOpt =
and GetTypeDefAsPropertyMapRow cenv tidx =
UnsharedRow
- [| SimpleIndex (TableNames.TypeDef, tidx);
+ [| SimpleIndex (TableNames.TypeDef, tidx)
SimpleIndex (TableNames.Property, cenv.propertyDefs.Count + 1) |]
and GetTypeDefAsEventMapRow cenv tidx =
UnsharedRow
- [| SimpleIndex (TableNames.TypeDef, tidx);
+ [| SimpleIndex (TableNames.TypeDef, tidx)
SimpleIndex (TableNames.Event, cenv.eventDefs.Count + 1) |]
and GetKeyForFieldDef tidx (fd: ILFieldDef) =
@@ -1486,10 +1486,10 @@ and GenMethodDefPass2 cenv tidx md =
cenv.methodDefIdxsByKey.AddUniqueEntry
"method"
(fun (key:MethodDefKey) ->
- dprintn "Duplicate in method table is:";
- dprintn (" Type index: "+string key.TypeIdx);
- dprintn (" Method name: "+key.Name);
- dprintn (" Method arity (num generic params): "+string key.GenericArity);
+ dprintn "Duplicate in method table is:"
+ dprintn (" Type index: "+string key.TypeIdx)
+ dprintn (" Method name: "+key.Name)
+ dprintn (" Method arity (num generic params): "+string key.GenericArity)
key.Name
)
(GetKeyForMethodDef tidx md)
@@ -1505,7 +1505,7 @@ and GenPropertyDefPass2 cenv tidx x =
and GetTypeAsImplementsRow cenv env tidx ty =
let tdorTag,tdorRow = GetTypeAsTypeDefOrRef cenv env ty
UnsharedRow
- [| SimpleIndex (TableNames.TypeDef, tidx);
+ [| SimpleIndex (TableNames.TypeDef, tidx)
TypeDefOrRefOrSpec (tdorTag,tdorRow) |]
and GenImplementsPass2 cenv env tidx ty =
@@ -1522,33 +1522,33 @@ and GenTypeDefPass2 pidx enc cenv (td:ILTypeDef) =
let env = envForTypeDef td
let tidx = GetIdxForTypeDef cenv (TdKey(enc,td.Name))
let tidx2 = AddUnsharedRow cenv TableNames.TypeDef (GetTypeDefAsRow cenv env enc td)
- if tidx <> tidx2 then failwith "index of typedef on second pass does not match index on first pass";
+ if tidx <> tidx2 then failwith "index of typedef on second pass does not match index on first pass"
// Add entries to auxiliary mapping tables, e.g. Nested, PropertyMap etc.
// Note Nested is organised differntly to the others...
if nonNil enc then
AddUnsharedRow cenv TableNames.Nested
(UnsharedRow
- [| SimpleIndex (TableNames.TypeDef, tidx);
- SimpleIndex (TableNames.TypeDef, pidx) |]) |> ignore;
+ [| SimpleIndex (TableNames.TypeDef, tidx)
+ SimpleIndex (TableNames.TypeDef, pidx) |]) |> ignore
let props = td.Properties.AsList
if nonNil props then
- AddUnsharedRow cenv TableNames.PropertyMap (GetTypeDefAsPropertyMapRow cenv tidx) |> ignore;
+ AddUnsharedRow cenv TableNames.PropertyMap (GetTypeDefAsPropertyMapRow cenv tidx) |> ignore
let events = td.Events.AsList
if nonNil events then
- AddUnsharedRow cenv TableNames.EventMap (GetTypeDefAsEventMapRow cenv tidx) |> ignore;
+ AddUnsharedRow cenv TableNames.EventMap (GetTypeDefAsEventMapRow cenv tidx) |> ignore
// Now generate or assign index numbers for tables referenced by the maps.
// Don't yet generate contents of these tables - leave that to pass3, as
// code may need to embed these entries.
- td.Implements |> ILList.iter (GenImplementsPass2 cenv env tidx);
- props |> List.iter (GenPropertyDefPass2 cenv tidx);
- events |> List.iter (GenEventDefPass2 cenv tidx);
- td.Fields.AsList |> List.iter (GenFieldDefPass2 cenv tidx);
- td.Methods |> Seq.iter (GenMethodDefPass2 cenv tidx);
+ td.Implements |> ILList.iter (GenImplementsPass2 cenv env tidx)
+ props |> List.iter (GenPropertyDefPass2 cenv tidx)
+ events |> List.iter (GenEventDefPass2 cenv tidx)
+ td.Fields.AsList |> List.iter (GenFieldDefPass2 cenv tidx)
+ td.Methods |> Seq.iter (GenMethodDefPass2 cenv tidx)
td.NestedTypes.AsList |> GenTypeDefsPass2 tidx (enc@[td.Name]) cenv
with e ->
- failwith ("Error in pass2 for type "+td.Name+", error: "+e.Message);
+ failwith ("Error in pass2 for type "+td.Name+", error: "+e.Message)
and GenTypeDefsPass2 pidx enc cenv tds =
List.iter (GenTypeDefPass2 pidx enc cenv) tds
@@ -1575,14 +1575,14 @@ let FindMethodDefIdx cenv mdkey =
| Some x -> x
| None -> raise MethodDefNotFound
let (TdKey (tenc,tname)) = typeNameOfIdx mdkey.TypeIdx
- dprintn ("The local method '"+(String.concat "." (tenc@[tname]))+"'::'"+mdkey.Name+"' was referenced but not declared");
- dprintn ("generic arity: "+string mdkey.GenericArity);
+ dprintn ("The local method '"+(String.concat "." (tenc@[tname]))+"'::'"+mdkey.Name+"' was referenced but not declared")
+ dprintn ("generic arity: "+string mdkey.GenericArity)
cenv.methodDefIdxsByKey.dict |> Seq.iter (fun (KeyValue(mdkey2,_)) ->
if mdkey2.TypeIdx = mdkey.TypeIdx && mdkey.Name = mdkey2.Name then
let (TdKey (tenc2,tname2)) = typeNameOfIdx mdkey2.TypeIdx
- dprintn ("A method in '"+(String.concat "." (tenc2@[tname2]))+"' had the right name but the wrong signature:");
- dprintn ("generic arity: "+string mdkey2.GenericArity) ;
- dprintn (sprintf "mdkey2: %A" mdkey2)) ;
+ dprintn ("A method in '"+(String.concat "." (tenc2@[tname2]))+"' had the right name but the wrong signature:")
+ dprintn ("generic arity: "+string mdkey2.GenericArity)
+ dprintn (sprintf "mdkey2: %A" mdkey2))
raise MethodDefNotFound
@@ -1592,7 +1592,7 @@ let rec GetMethodDefIdx cenv md =
and FindFieldDefIdx cenv fdkey =
try cenv.fieldDefs.GetTableEntry fdkey
with :? KeyNotFoundException ->
- errorR(InternalError("The local field "+fdkey.Name+" was referenced but not declared",range0));
+ errorR(InternalError("The local field "+fdkey.Name+" was referenced but not declared",range0))
1
and GetFieldDefAsFieldDefIdx cenv tidx fd =
@@ -1609,12 +1609,12 @@ let GetMethodRefAsMethodDefIdx cenv (mref:ILMethodRef) =
let tref = mref.EnclosingTypeRef
try
if not (isTypeRefLocal tref) then
- failwithf "method referred to by method impl, event or property is not in a type defined in this module, method ref is %A" mref;
+ failwithf "method referred to by method impl, event or property is not in a type defined in this module, method ref is %A" mref
let tidx = GetIdxForTypeDef cenv (TdKey(tref.Enclosing,tref.Name))
let mdkey = MethodDefKey (tidx,mref.GenericArity, mref.Name, mref.ReturnType, mref.ArgTypes, mref.CallingConv.IsStatic)
FindMethodDefIdx cenv mdkey
with e ->
- failwithf "Error in GetMethodRefAsMethodDefIdx for mref = %A, error: %s" (mref.Name, tref.Name) e.Message;
+ failwithf "Error in GetMethodRefAsMethodDefIdx for mref = %A, error: %s" (mref.Name, tref.Name) e.Message
let rec MethodRefInfoAsMemberRefRow cenv env fenv (nm,typ,callconv,args,ret,varargs,genarity) =
MemberRefRow(GetTypeAsMemberRefParent cenv env typ,
@@ -1631,7 +1631,7 @@ let GetMethodRefInfoAsMemberRefIdx cenv env ((_,typ,_,_,_,_,_) as minfo) =
let GetMethodRefInfoAsMethodRefOrDef isAlwaysMethodDef cenv env ((nm,typ:ILType,cc,args,ret,varargs,genarity) as minfo) =
if isNone varargs && (isAlwaysMethodDef || isTypeLocal typ) then
- if not typ.IsNominal then failwith "GetMethodRefInfoAsMethodRefOrDef: unexpected local tref-typ";
+ if not typ.IsNominal then failwith "GetMethodRefInfoAsMethodRefOrDef: unexpected local tref-typ"
try (mdor_MethodDef, GetMethodRefAsMethodDefIdx cenv (mkILMethRefRaw(typ.TypeRef, cc, nm, genarity, args,ret)))
with MethodDefNotFound -> (mdor_MemberRef, GetMethodRefInfoAsMemberRefIdx cenv env minfo)
else (mdor_MemberRef, GetMethodRefInfoAsMemberRefIdx cenv env minfo)
@@ -1645,12 +1645,12 @@ let rec GetMethodSpecInfoAsMethodSpecIdx cenv env (nm,typ,cc,args,ret,varargs,mi
let mdorTag,mdorRow = GetMethodRefInfoAsMethodRefOrDef false cenv env (nm,typ,cc,args,ret,varargs,minst.Length)
let blob =
emitBytesViaBuffer (fun bb ->
- bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_GENERICINST;
- bb.EmitZ32 minst.Length;
+ bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_GENERICINST
+ bb.EmitZ32 minst.Length
minst |> ILList.iter (EmitType cenv env bb))
FindOrAddRow cenv TableNames.MethodSpec
(SimpleSharedRow
- [| MethodDefOrRef (mdorTag,mdorRow);
+ [| MethodDefOrRef (mdorTag,mdorRow)
Blob (GetBytesAsBlobIdx cenv blob) |])
and GetMethodDefOrRefAsUncodedToken (tag,idx) =
@@ -1709,7 +1709,7 @@ let rec GetOverridesSpecAsMemberRefIdx cenv env ospec =
and GetOverridesSpecAsMethodDefOrRef cenv env (ospec:ILOverridesSpec) =
let typ = ospec.EnclosingType
if isTypeLocal typ then
- if not typ.IsNominal then failwith "GetOverridesSpecAsMethodDefOrRef: unexpected local tref-typ";
+ if not typ.IsNominal then failwith "GetOverridesSpecAsMethodDefOrRef: unexpected local tref-typ"
try (mdor_MethodDef, GetMethodRefAsMethodDefIdx cenv ospec.MethodRef)
with MethodDefNotFound -> (mdor_MemberRef, GetOverridesSpecAsMemberRefIdx cenv env ospec)
else
@@ -1752,9 +1752,9 @@ let rec GetCustomAttrDataAsBlobIdx cenv (data:byte[]) =
and GetCustomAttrRow cenv hca attr =
let cat = GetMethodRefAsCustomAttribType cenv attr.Method.MethodRef
UnsharedRow
- [| HasCustomAttribute (fst hca, snd hca);
- CustomAttributeType (fst cat, snd cat);
- Blob (GetCustomAttrDataAsBlobIdx cenv attr.Data); |]
+ [| HasCustomAttribute (fst hca, snd hca)
+ CustomAttributeType (fst cat, snd cat)
+ Blob (GetCustomAttrDataAsBlobIdx cenv attr.Data) |]
and GenCustomAttrPass3Or4 cenv hca attr =
AddUnsharedRow cenv TableNames.CustomAttribute (GetCustomAttrRow cenv hca attr) |> ignore
@@ -1768,9 +1768,9 @@ and GenCustomAttrsPass3Or4 cenv hca (attrs: ILAttributes) =
let rec GetSecurityDeclRow cenv hds (PermissionSet (action, s)) =
UnsharedRow
- [| UShort (uint16 (List.assoc action (Lazy.force ILSecurityActionMap)));
- HasDeclSecurity (fst hds, snd hds);
- Blob (GetBytesAsBlobIdx cenv s); |]
+ [| UShort (uint16 (List.assoc action (Lazy.force ILSecurityActionMap)))
+ HasDeclSecurity (fst hds, snd hds)
+ Blob (GetBytesAsBlobIdx cenv s) |]
and GenSecurityDeclPass3 cenv hds attr =
AddUnsharedRow cenv TableNames.Permission (GetSecurityDeclRow cenv hds attr) |> ignore
@@ -1793,7 +1793,7 @@ and GetFieldSpecAsMemberRefIdx cenv env fspec =
// REVIEW: write into an accumuating buffer
and EmitFieldSpecSig cenv env (bb: ByteBuffer) (fspec:ILFieldSpec) =
- bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_FIELD;
+ bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_FIELD
EmitType cenv env bb fspec.FormalType
and GetFieldSpecSigAsBytes cenv env x =
@@ -1805,7 +1805,7 @@ and GetFieldSpecSigAsBlobIdx cenv env x =
and GetFieldSpecAsFieldDefOrRef cenv env (fspec:ILFieldSpec) =
let typ = fspec.EnclosingType
if isTypeLocal typ then
- if not typ.IsNominal then failwith "GetFieldSpecAsFieldDefOrRef: unexpected local tref-typ";
+ if not typ.IsNominal then failwith "GetFieldSpecAsFieldDefOrRef: unexpected local tref-typ"
let tref = typ.TypeRef
let tidx = GetIdxForTypeDef cenv (TdKey(tref.Enclosing,tref.Name))
let fdkey = FieldDefKey (tidx,fspec.Name, fspec.FormalType)
@@ -1838,8 +1838,8 @@ let GetCallsigAsStandAloneSigIdx cenv env info =
// --------------------------------------------------------------------
let EmitLocalSig cenv env (bb: ByteBuffer) (locals: ILLocals) =
- bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_LOCAL_SIG;
- bb.EmitZ32 locals.Length;
+ bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_LOCAL_SIG
+ bb.EmitZ32 locals.Length
locals |> ILList.iter (fun l -> EmitType cenv env bb l.Type)
let GetLocalSigAsBlobHeapIdx cenv env locals =
@@ -1867,21 +1867,21 @@ type CodeBuffer =
// - locations of embedded handles into the string table
// - the exception table
// --------------------------------------------------------------------
- { code: ByteBuffer;
+ { code: ByteBuffer
/// (instruction; optional short form); start of instr in code buffer; code loc for the end of the instruction the fixup resides in ; where is the destination of the fixup
- mutable reqdBrFixups: ((int * int option) * int * ILCodeLabel list) list;
- availBrFixups: Dictionary ;
+ mutable reqdBrFixups: ((int * int option) * int * ILCodeLabel list) list
+ availBrFixups: Dictionary
/// code loc to fixup in code buffer
- mutable reqdStringFixupsInMethod: (int * int) list;
+ mutable reqdStringFixupsInMethod: (int * int) list
/// data for exception handling clauses
- mutable seh: ExceptionClauseSpec list;
- seqpoints: ResizeArray; }
+ mutable seh: ExceptionClauseSpec list
+ seqpoints: ResizeArray }
static member Create _nm =
- { seh = [];
- code= ByteBuffer.Create 200;
- reqdBrFixups=[];
- reqdStringFixupsInMethod=[];
+ { seh = []
+ code= ByteBuffer.Create 200
+ reqdBrFixups=[]
+ reqdStringFixupsInMethod=[]
availBrFixups = Dictionary<_,_>(10, HashIdentity.Structural)
seqpoints = new ResizeArray<_>(10)
}
@@ -1893,12 +1893,12 @@ type CodeBuffer =
// table indexes are 1-based, document array indexes are 0-based
let doc = (cenv.documents.FindOrAddSharedEntry m.Document) - 1
codebuf.seqpoints.Add
- { Document=doc;
- Offset= codebuf.code.Position;
- Line=m.Line;
- Column=m.Column;
- EndLine=m.EndLine;
- EndColumn=m.EndColumn; }
+ { Document=doc
+ Offset= codebuf.code.Position
+ Line=m.Line
+ Column=m.Column
+ EndLine=m.EndLine
+ EndColumn=m.EndColumn }
member codebuf.EmitByte x = codebuf.code.EmitIntAsByte x
member codebuf.EmitUInt16 x = codebuf.code.EmitUInt16 x
@@ -1908,17 +1908,17 @@ type CodeBuffer =
member codebuf.EmitUncodedToken u = codebuf.EmitInt32 u
member codebuf.RecordReqdStringFixup stringidx =
- codebuf.reqdStringFixupsInMethod <- (codebuf.code.Position, stringidx) :: codebuf.reqdStringFixupsInMethod;
+ codebuf.reqdStringFixupsInMethod <- (codebuf.code.Position, stringidx) :: codebuf.reqdStringFixupsInMethod
// Write a special value in that we check later when applying the fixup
codebuf.EmitInt32 0xdeadbeef
member codebuf.RecordReqdBrFixups i tgs =
- codebuf.reqdBrFixups <- (i, codebuf.code.Position, tgs) :: codebuf.reqdBrFixups;
+ codebuf.reqdBrFixups <- (i, codebuf.code.Position, tgs) :: codebuf.reqdBrFixups
// Write a special value in that we check later when applying the fixup
// Value is 0x11 {deadbbbb}* where 11 is for the instruction and deadbbbb is for each target
- codebuf.EmitByte 0x11; // for the instruction
+ codebuf.EmitByte 0x11 // for the instruction
(if fst i = i_switch then
- codebuf.EmitInt32 tgs.Length);
+ codebuf.EmitInt32 tgs.Length)
List.iter (fun _ -> codebuf.EmitInt32 0xdeadbbbb) tgs
member codebuf.RecordReqdBrFixup i tg = codebuf.RecordReqdBrFixups i [tg]
@@ -1973,25 +1973,25 @@ module Codebuf = begin
// Copy over a chunk of non-branching code
let nobranch_len = origEndOfNoBranchBlock - origStartOfNoBranchBlock
- newCode.EmitBytes origCode.[origStartOfNoBranchBlock..origStartOfNoBranchBlock+nobranch_len-1];
+ newCode.EmitBytes origCode.[origStartOfNoBranchBlock..origStartOfNoBranchBlock+nobranch_len-1]
// Record how to adjust addresses in this range, including the branch instruction
// we write below, or the end of the method if we're doing the last bblock
- adjustments := (origStartOfNoBranchBlock,origEndOfNoBranchBlock,newStartOfNoBranchBlock) :: !adjustments;
+ adjustments := (origStartOfNoBranchBlock,origEndOfNoBranchBlock,newStartOfNoBranchBlock) :: !adjustments
// Increment locations to the branch instruction we're really interested in
- origWhere := origEndOfNoBranchBlock;
- newWhere := !newWhere + nobranch_len;
+ origWhere := origEndOfNoBranchBlock
+ newWhere := !newWhere + nobranch_len
// Now do the branch instruction. Decide whether the fixup will be short or long in the new code
if doingLast then
doneLast := true
else
let (i,origStartOfInstr,tgs:ILCodeLabel list) = List.head !remainingReqdFixups
- remainingReqdFixups := List.tail !remainingReqdFixups;
- if origCode.[origStartOfInstr] <> 0x11uy then failwith "br fixup sanity check failed (1)";
+ remainingReqdFixups := List.tail !remainingReqdFixups
+ if origCode.[origStartOfInstr] <> 0x11uy then failwith "br fixup sanity check failed (1)"
let i_length = if fst i = i_switch then 5 else 1
- origWhere := !origWhere + i_length;
+ origWhere := !origWhere + i_length
let origEndOfInstr = origStartOfInstr + i_length + 4 * tgs.Length
let newEndOfInstrIfSmall = !newWhere + i_length + 1
@@ -2005,7 +2005,7 @@ module Codebuf = begin
// Use the original offsets to compute if the branch is small or large. This is
// a safe approximation because code only gets smaller.
if not (origAvailBrFixups.ContainsKey tg) then
- dprintn ("branch target " + formatCodeLabel tg + " not found in code");
+ dprintn ("branch target " + formatCodeLabel tg + " not found in code")
let origDest =
if origAvailBrFixups.ContainsKey tg then origAvailBrFixups.[tg]
else 666666
@@ -2013,33 +2013,33 @@ module Codebuf = begin
-128 <= origRelOffset && origRelOffset <= 127
end
->
- newCode.EmitIntAsByte i_short;
+ newCode.EmitIntAsByte i_short
true
| (i_long,_),_ ->
- newCode.EmitIntAsByte i_long;
+ newCode.EmitIntAsByte i_long
(if i_long = i_switch then
- newCode.EmitInt32 tgs.Length);
+ newCode.EmitInt32 tgs.Length)
false
- newWhere := !newWhere + i_length;
- if !newWhere <> newCode.Position then dprintn "mismatch between newWhere and newCode";
+ newWhere := !newWhere + i_length
+ if !newWhere <> newCode.Position then dprintn "mismatch between newWhere and newCode"
tgs |> List.iter (fun tg ->
let origFixupLoc = !origWhere
- checkFixup32 origCode origFixupLoc 0xdeadbbbb;
+ checkFixup32 origCode origFixupLoc 0xdeadbbbb
if short then
- newReqdBrFixups := (!newWhere, newEndOfInstrIfSmall, tg, true) :: !newReqdBrFixups;
- newCode.EmitIntAsByte 0x98; (* sanity check *)
- newWhere := !newWhere + 1;
+ newReqdBrFixups := (!newWhere, newEndOfInstrIfSmall, tg, true) :: !newReqdBrFixups
+ newCode.EmitIntAsByte 0x98 (* sanity check *)
+ newWhere := !newWhere + 1
else
- newReqdBrFixups := (!newWhere, newEndOfInstrIfBig, tg, false) :: !newReqdBrFixups;
- newCode.EmitInt32 0xf00dd00f; (* sanity check *)
- newWhere := !newWhere + 4;
- if !newWhere <> newCode.Position then dprintn "mismatch between newWhere and newCode";
- origWhere := !origWhere + 4);
+ newReqdBrFixups := (!newWhere, newEndOfInstrIfBig, tg, false) :: !newReqdBrFixups
+ newCode.EmitInt32 0xf00dd00f (* sanity check *)
+ newWhere := !newWhere + 4
+ if !newWhere <> newCode.Position then dprintn "mismatch between newWhere and newCode"
+ origWhere := !origWhere + 4)
- if !origWhere <> origEndOfInstr then dprintn "mismatch between origWhere and origEndOfInstr";
+ if !origWhere <> origEndOfInstr then dprintn "mismatch between origWhere and origEndOfInstr"
let adjuster =
let arr = Array.ofList (List.rev !adjustments)
@@ -2074,25 +2074,25 @@ module Codebuf = begin
let newScopes =
let rec remap scope =
- {scope with StartOffset = adjuster scope.StartOffset;
- EndOffset = adjuster scope.EndOffset;
+ {scope with StartOffset = adjuster scope.StartOffset
+ EndOffset = adjuster scope.EndOffset
Children = Array.map remap scope.Children }
List.map remap origScopes
// Now apply the adjusted fixups in the new code
newReqdBrFixups |> List.iter (fun (newFixupLoc,endOfInstr,tg, small) ->
if not (newAvailBrFixups.ContainsKey tg) then
- failwith ("target "+formatCodeLabel tg+" not found in new fixups");
+ failwith ("target "+formatCodeLabel tg+" not found in new fixups")
try
let n = newAvailBrFixups.[tg]
let relOffset = (n - endOfInstr)
if small then
- if Bytes.get newCode newFixupLoc <> 0x98 then failwith "br fixupsanity check failed";
- newCode.[newFixupLoc] <- b0 relOffset;
+ if Bytes.get newCode newFixupLoc <> 0x98 then failwith "br fixupsanity check failed"
+ newCode.[newFixupLoc] <- b0 relOffset
else
- checkFixup32 newCode newFixupLoc 0xf00dd00fl;
+ checkFixup32 newCode newFixupLoc 0xf00dd00fl
applyFixup32 newCode newFixupLoc relOffset
- with :? KeyNotFoundException -> ());
+ with :? KeyNotFoundException -> ())
newCode, newReqdStringFixups, newExnClauses, newSeqPoints, newScopes
@@ -2129,44 +2129,44 @@ module Codebuf = begin
/// Emit the code for an instruction
let emitInstrCode (codebuf: CodeBuffer) i =
if i > 0xFF then
- assert (i >>> 8 = 0xFE);
- codebuf.EmitByte ((i >>> 8) &&& 0xFF);
- codebuf.EmitByte (i &&& 0xFF);
+ assert (i >>> 8 = 0xFE)
+ codebuf.EmitByte ((i >>> 8) &&& 0xFF)
+ codebuf.EmitByte (i &&& 0xFF)
else
codebuf.EmitByte i
let emitTypeInstr cenv codebuf env i ty =
- emitInstrCode codebuf i;
+ emitInstrCode codebuf i
codebuf.EmitUncodedToken (getTypeDefOrRefAsUncodedToken (GetTypeAsTypeDefOrRef cenv env ty))
let emitMethodSpecInfoInstr cenv codebuf env i mspecinfo =
- emitInstrCode codebuf i;
+ emitInstrCode codebuf i
codebuf.EmitUncodedToken (GetMethodSpecInfoAsUncodedToken cenv env mspecinfo)
let emitMethodSpecInstr cenv codebuf env i mspec =
- emitInstrCode codebuf i;
+ emitInstrCode codebuf i
codebuf.EmitUncodedToken (GetMethodSpecAsUncodedToken cenv env mspec)
let emitFieldSpecInstr cenv codebuf env i fspec =
- emitInstrCode codebuf i;
+ emitInstrCode codebuf i
codebuf.EmitUncodedToken (GetFieldDefOrRefAsUncodedToken (GetFieldSpecAsFieldDefOrRef cenv env fspec))
let emitShortUInt16Instr codebuf (i_short,i) x =
let n = int32 x
if n <= 255 then
- emitInstrCode codebuf i_short;
- codebuf.EmitByte n;
+ emitInstrCode codebuf i_short
+ codebuf.EmitByte n
else
- emitInstrCode codebuf i;
- codebuf.EmitUInt16 x;
+ emitInstrCode codebuf i
+ codebuf.EmitUInt16 x
let emitShortInt32Instr codebuf (i_short,i) x =
if x >= (-128) && x <= 127 then
- emitInstrCode codebuf i_short;
- codebuf.EmitByte (if x < 0x0 then x + 256 else x);
+ emitInstrCode codebuf i_short
+ codebuf.EmitByte (if x < 0x0 then x + 256 else x)
else
- emitInstrCode codebuf i;
- codebuf.EmitInt32 x;
+ emitInstrCode codebuf i
+ codebuf.EmitInt32 x
let emitTailness (cenv: cenv) codebuf tl =
if tl = Tailcall && cenv.emitTailcalls then emitInstrCode codebuf i_tail
@@ -2178,7 +2178,7 @@ module Codebuf = begin
if tl = Volatile then emitInstrCode codebuf i_volatile
let emitConstrained cenv codebuf env ty =
- emitInstrCode codebuf i_constrained;
+ emitInstrCode codebuf i_constrained
codebuf.EmitUncodedToken (getTypeDefOrRefAsUncodedToken (GetTypeAsTypeDefOrRef cenv env ty))
let emitAlignment codebuf tl =
@@ -2198,17 +2198,17 @@ module Codebuf = begin
| I_seqpoint s -> codebuf.EmitSeqPoint cenv s
| I_leave tg -> codebuf.RecordReqdBrFixup (i_leave,Some i_leave_s) tg
| I_call (tl,mspec,varargs) ->
- emitTailness cenv codebuf tl;
- emitMethodSpecInstr cenv codebuf env i_call (mspec,varargs);
+ emitTailness cenv codebuf tl
+ emitMethodSpecInstr cenv codebuf env i_call (mspec,varargs)
emitAfterTailcall codebuf tl
| I_callvirt (tl,mspec,varargs) ->
- emitTailness cenv codebuf tl;
- emitMethodSpecInstr cenv codebuf env i_callvirt (mspec,varargs);
+ emitTailness cenv codebuf tl
+ emitMethodSpecInstr cenv codebuf env i_callvirt (mspec,varargs)
emitAfterTailcall codebuf tl
| I_callconstraint (tl,ty,mspec,varargs) ->
- emitTailness cenv codebuf tl;
- emitConstrained cenv codebuf env ty;
- emitMethodSpecInstr cenv codebuf env i_callvirt (mspec,varargs);
+ emitTailness cenv codebuf tl
+ emitConstrained cenv codebuf env ty
+ emitMethodSpecInstr cenv codebuf env i_callvirt (mspec,varargs)
emitAfterTailcall codebuf tl
| I_newobj (mspec,varargs) ->
emitMethodSpecInstr cenv codebuf env i_newobj (mspec,varargs)
@@ -2218,9 +2218,9 @@ module Codebuf = begin
emitMethodSpecInstr cenv codebuf env i_ldvirtftn (mspec,None)
| I_calli (tl,callsig,varargs) ->
- emitTailness cenv codebuf tl;
- emitInstrCode codebuf i_calli;
- codebuf.EmitUncodedToken (getUncodedToken TableNames.StandAloneSig (GetCallsigAsStandAloneSigIdx cenv env (callsig,varargs)));
+ emitTailness cenv codebuf tl
+ emitInstrCode codebuf i_calli
+ codebuf.EmitUncodedToken (getUncodedToken TableNames.StandAloneSig (GetCallsigAsStandAloneSigIdx cenv env (callsig,varargs)))
emitAfterTailcall codebuf tl
| I_ldarg u16 -> emitShortUInt16Instr codebuf (i_ldarg_s,i_ldarg) u16
@@ -2231,29 +2231,29 @@ module Codebuf = begin
| I_ldloca u16 -> emitShortUInt16Instr codebuf (i_ldloca_s,i_ldloca) u16
| I_cpblk (al,vol) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitInstrCode codebuf i_cpblk
| I_initblk (al,vol) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitInstrCode codebuf i_initblk
| (AI_ldc (DT_I4, ILConst.I4 x)) ->
emitShortInt32Instr codebuf (i_ldc_i4_s,i_ldc_i4) x
| (AI_ldc (DT_I8, ILConst.I8 x)) ->
- emitInstrCode codebuf i_ldc_i8;
- codebuf.EmitInt64 x;
+ emitInstrCode codebuf i_ldc_i8
+ codebuf.EmitInt64 x
| (AI_ldc (_, ILConst.R4 x)) ->
- emitInstrCode codebuf i_ldc_r4;
+ emitInstrCode codebuf i_ldc_r4
codebuf.EmitInt32 (bitsOfSingle x)
| (AI_ldc (_, ILConst.R8 x)) ->
- emitInstrCode codebuf i_ldc_r8;
+ emitInstrCode codebuf i_ldc_r8
codebuf.EmitInt64 (bitsOfDouble x)
| I_ldind (al,vol,dt) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitInstrCode codebuf
(match dt with
| DT_I -> i_ldind_i
@@ -2299,8 +2299,8 @@ module Codebuf = begin
| _ -> failwith "ldelem")
| I_stind (al,vol,dt) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitInstrCode codebuf
(match dt with
| DT_U | DT_I -> i_stind_i
@@ -2316,26 +2316,26 @@ module Codebuf = begin
| I_switch (labs,_) -> codebuf.RecordReqdBrFixups (i_switch,None) labs
| I_ldfld (al,vol,fspec) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitFieldSpecInstr cenv codebuf env i_ldfld fspec
| I_ldflda fspec ->
emitFieldSpecInstr cenv codebuf env i_ldflda fspec
| I_ldsfld (vol,fspec) ->
- emitVolatility codebuf vol;
+ emitVolatility codebuf vol
emitFieldSpecInstr cenv codebuf env i_ldsfld fspec
| I_ldsflda fspec ->
emitFieldSpecInstr cenv codebuf env i_ldsflda fspec
| I_stfld (al,vol,fspec) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitFieldSpecInstr cenv codebuf env i_stfld fspec
| I_stsfld (vol,fspec) ->
- emitVolatility codebuf vol;
+ emitVolatility codebuf vol
emitFieldSpecInstr cenv codebuf env i_stsfld fspec
| I_ldtoken tok ->
- emitInstrCode codebuf i_ldtoken;
+ emitInstrCode codebuf i_ldtoken
codebuf.EmitUncodedToken
(match tok with
| ILToken.ILType typ ->
@@ -2355,7 +2355,7 @@ module Codebuf = begin
| (true,idx) -> getUncodedToken TableNames.Field idx
| (false,idx) -> getUncodedToken TableNames.MemberRef idx)
| I_ldstr s ->
- emitInstrCode codebuf i_ldstr;
+ emitInstrCode codebuf i_ldstr
codebuf.RecordReqdStringFixup (GetUserStringHeapIdx cenv s)
| I_box ty -> emitTypeInstr cenv codebuf env i_box ty
@@ -2385,7 +2385,7 @@ module Codebuf = begin
| I_ldelema (ro,_isNativePtr,shape,ty) ->
if (ro = ReadonlyAddress) then
- emitInstrCode codebuf i_readonly;
+ emitInstrCode codebuf i_readonly
if (shape = ILArrayShape.SingleDimensional) then
emitTypeInstr cenv codebuf env i_ldelema ty
else
@@ -2398,17 +2398,17 @@ module Codebuf = begin
| I_mkrefany ty -> emitTypeInstr cenv codebuf env i_mkrefany ty
| I_initobj ty -> emitTypeInstr cenv codebuf env i_initobj ty
| I_ldobj (al,vol,ty) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitTypeInstr cenv codebuf env i_ldobj ty
| I_stobj (al,vol,ty) ->
- emitAlignment codebuf al;
- emitVolatility codebuf vol;
+ emitAlignment codebuf al
+ emitVolatility codebuf vol
emitTypeInstr cenv codebuf env i_stobj ty
| I_cpobj ty -> emitTypeInstr cenv codebuf env i_cpobj ty
| I_sizeof ty -> emitTypeInstr cenv codebuf env i_sizeof ty
| EI_ldlen_multi (_,m) ->
- emitShortInt32Instr codebuf (i_ldc_i4_s,i_ldc_i4) m;
+ emitShortInt32Instr codebuf (i_ldc_i4_s,i_ldc_i4) m
emitInstr cenv codebuf env (mkNormalCall(mkILNonGenericMethSpecInTy(cenv.ilg.typ_Array, ILCallingConv.Instance, "GetLength", [(cenv.ilg.typ_int32)], (cenv.ilg.typ_int32))))
| _ -> failwith "an IL instruction cannot be emitted"
@@ -2417,31 +2417,31 @@ module Codebuf = begin
let mkScopeNode cenv (localSigs: _[]) (a,b,ls,ch) =
if (isNil ls || not cenv.generatePdb) then ch
else
- [ { Children= Array.ofList ch;
- StartOffset=a;
- EndOffset=b;
+ [ { Children= Array.ofList ch
+ StartOffset=a
+ EndOffset=b
Locals=
Array.ofList
(List.map
- (fun x -> { Name=x.LocalName;
- Signature= (try localSigs.[x.LocalIndex] with _ -> failwith ("local variable index "+string x.LocalIndex+"in debug info does not reference a valid local"));
+ (fun x -> { Name=x.LocalName
+ Signature= (try localSigs.[x.LocalIndex] with _ -> failwith ("local variable index "+string x.LocalIndex+"in debug info does not reference a valid local"))
Index= x.LocalIndex } )
(List.filter (fun v -> v.LocalName <> "") ls)) } ]
let rec emitCode cenv localSigs codebuf env (susp,code) =
match code with
| TryBlock (c,seh) ->
- commitSusp codebuf susp (uniqueEntryOfCode c);
+ commitSusp codebuf susp (uniqueEntryOfCode c)
let tryStart = codebuf.code.Position
let susp,child1,scope1 = emitCode cenv localSigs codebuf env (None,c)
- commitSuspNoDest codebuf susp;
+ commitSuspNoDest codebuf susp
let tryFinish = codebuf.code.Position
let exnBranches =
match seh with
| FaultBlock flt ->
let handlerStart = codebuf.code.Position
let susp,child2,scope2 = emitCode cenv localSigs codebuf env (None,flt)
- commitSuspNoDest codebuf susp;
+ commitSuspNoDest codebuf susp
let handlerFinish = codebuf.code.Position
[ Some (tryStart,(tryFinish - tryStart),
handlerStart,(handlerFinish - handlerStart),
@@ -2451,7 +2451,7 @@ module Codebuf = begin
| FinallyBlock flt ->
let handlerStart = codebuf.code.Position
let susp,child2,scope2 = emitCode cenv localSigs codebuf env (None,flt)
- commitSuspNoDest codebuf susp;
+ commitSuspNoDest codebuf susp
let handlerFinish = codebuf.code.Position
[ Some (tryStart,(tryFinish - tryStart),
handlerStart,(handlerFinish - handlerStart),
@@ -2464,7 +2464,7 @@ module Codebuf = begin
| TypeFilter typ ->
let handlerStart = codebuf.code.Position
let susp,child2,scope2 = emitCode cenv localSigs codebuf env (None,ctch)
- commitSuspNoDest codebuf susp;
+ commitSuspNoDest codebuf susp
let handlerFinish = codebuf.code.Position
Some (tryStart,(tryFinish - tryStart),
handlerStart,(handlerFinish - handlerStart),
@@ -2474,10 +2474,10 @@ module Codebuf = begin
let filterStart = codebuf.code.Position
let susp,child2,scope2 = emitCode cenv localSigs codebuf env (None,fltcode)
- commitSuspNoDest codebuf susp;
+ commitSuspNoDest codebuf susp
let handlerStart = codebuf.code.Position
let susp,child3,scope3 = emitCode cenv localSigs codebuf env (None,ctch)
- commitSuspNoDest codebuf susp;
+ commitSuspNoDest codebuf susp
let handlerFinish = codebuf.code.Position
Some (tryStart,
@@ -2506,8 +2506,8 @@ module Codebuf = begin
let childScopes = ref []
// Push the results of collecting one sub-block into the reference cells
let collect (susp,seh,scopes) =
- newSusp := susp;
- childSEH := seh :: !childSEH;
+ newSusp := susp
+ childSEH := seh :: !childSEH
childScopes := scopes :: !childScopes
// Close the collection by generating the (susp,node,scope-node) triple
let close () =
@@ -2520,12 +2520,12 @@ module Codebuf = begin
| [c] ->
// emitCodeLinear sequence of nested blocks
emitCodeLinear (!newSusp,c) (fun results ->
- collect results;
+ collect results
cont (close()))
| codes ->
// Multiple blocks: leave the linear sequence and process each seperately
- codes |> List.iter (fun c -> collect (emitCode cenv localSigs codebuf env (!newSusp,c)));
+ codes |> List.iter (fun c -> collect (emitCode cenv localSigs codebuf env (!newSusp,c)))
cont(close())
| c ->
// leave the linear sequence
@@ -2536,11 +2536,11 @@ module Codebuf = begin
| ILBasicBlock bb ->
// Leaf case: one basic block
- commitSusp codebuf susp bb.Label;
- codebuf.RecordAvailBrFixup bb.Label;
+ commitSusp codebuf susp bb.Label
+ codebuf.RecordAvailBrFixup bb.Label
let instrs = bb.Instructions
for i = 0 to instrs.Length - 1 do
- emitInstr cenv codebuf env instrs.[i];
+ emitInstr cenv codebuf env instrs.[i]
bb.Fallthrough, Tip, []
and brToSusp (codebuf: CodeBuffer) dest = codebuf.RecordReqdBrFixup (i_br,Some i_br_s) dest
@@ -2562,7 +2562,7 @@ module Codebuf = begin
| Node clauses -> List.iter (emitExceptionHandlerTree2 codebuf) clauses
and emitExceptionHandlerTree2 (codebuf: CodeBuffer) (x,childSEH) =
- List.iter (emitExceptionHandlerTree codebuf) childSEH; // internal first
+ List.iter (emitExceptionHandlerTree codebuf) childSEH // internal first
match x with
| None -> ()
| Some clause -> codebuf.EmitExceptionClause clause
@@ -2571,8 +2571,8 @@ module Codebuf = begin
let codebuf = CodeBuffer.Create nm
let finalSusp, SEHTree, origScopes =
emitCode cenv localSigs codebuf env (Some (uniqueEntryOfCode code),code)
- (match finalSusp with Some dest -> brToSusp codebuf dest | _ -> ());
- emitExceptionHandlerTree codebuf SEHTree;
+ (match finalSusp with Some dest -> brToSusp codebuf dest | _ -> ())
+ emitExceptionHandlerTree codebuf SEHTree
let origCode = codebuf.code.Close()
let origExnClauses = List.rev codebuf.seh
let origReqdStringFixups = codebuf.reqdStringFixupsInMethod
@@ -2584,10 +2584,10 @@ module Codebuf = begin
applyBrFixups origCode origExnClauses origReqdStringFixups origAvailBrFixups origReqdBrFixups origSeqPoints origScopes
let rootScope =
- { Children= Array.ofList newScopes;
- StartOffset=0;
- EndOffset=newCode.Length;
- Locals=[| |]; }
+ { Children= Array.ofList newScopes
+ StartOffset=0
+ EndOffset=newCode.Length
+ Locals=[| |] }
(newReqdStringFixups,newExnClauses, newCode, newSeqPoints, rootScope)
@@ -2597,7 +2597,7 @@ end
// ILMethodBody --> bytes
// --------------------------------------------------------------------
let GetFieldDefTypeAsBlobIdx cenv env ty =
- let bytes = emitBytesViaBuffer (fun bb -> bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_FIELD;
+ let bytes = emitBytesViaBuffer (fun bb -> bb.EmitByte e_IMAGE_CEE_CS_CALLCONV_FIELD
EmitType cenv env bb ty)
GetBytesAsBlobIdx cenv bytes
@@ -2606,7 +2606,7 @@ let GenILMethodBody mname cenv env (il: ILMethodBody) =
if cenv.generatePdb then
il.Locals |> ILList.toArray |> Array.map (fun l ->
// Write a fake entry for the local signature headed by e_IMAGE_CEE_CS_CALLCONV_FIELD. This is referenced by the PDB file
- ignore (FindOrAddRow cenv TableNames.StandAloneSig (SimpleSharedRow [| Blob (GetFieldDefTypeAsBlobIdx cenv env l.Type) |]));
+ ignore (FindOrAddRow cenv TableNames.StandAloneSig (SimpleSharedRow [| Blob (GetFieldDefTypeAsBlobIdx cenv env l.Type) |]))
// Now write the type
GetTypeAsBytes cenv env l.Type)
else
@@ -2621,9 +2621,9 @@ let GenILMethodBody mname cenv env (il: ILMethodBody) =
let alignedCodeSize = align 4 (codeSize + 1)
let codePadding = (alignedCodeSize - (codeSize + 1))
let requiredStringFixups' = (1,requiredStringFixups)
- methbuf.EmitByte (byte codeSize <<< 2 ||| e_CorILMethod_TinyFormat);
- methbuf.EmitBytes code;
- methbuf.EmitPadding codePadding;
+ methbuf.EmitByte (byte codeSize <<< 2 ||| e_CorILMethod_TinyFormat)
+ methbuf.EmitBytes code
+ methbuf.EmitPadding codePadding
(requiredStringFixups', methbuf.Close()), seqpoints, scopes
else
// Use Fat format
@@ -2640,13 +2640,13 @@ let GenILMethodBody mname cenv env (il: ILMethodBody) =
let alignedCodeSize = align 0x4 codeSize
let codePadding = (alignedCodeSize - codeSize)
- methbuf.EmitByte flags;
- methbuf.EmitByte 0x30uy; // last four bits record size of fat header in 4 byte chunks - this is always 12 bytes = 3 four word chunks
- methbuf.EmitUInt16 (uint16 il.MaxStack);
- methbuf.EmitInt32 codeSize;
- methbuf.EmitInt32 localToken;
- methbuf.EmitBytes code;
- methbuf.EmitPadding codePadding;
+ methbuf.EmitByte flags
+ methbuf.EmitByte 0x30uy // last four bits record size of fat header in 4 byte chunks - this is always 12 bytes = 3 four word chunks
+ methbuf.EmitUInt16 (uint16 il.MaxStack)
+ methbuf.EmitInt32 codeSize
+ methbuf.EmitInt32 localToken
+ methbuf.EmitBytes code
+ methbuf.EmitPadding codePadding
if nonNil seh then
// Can we use the small exception handling table format?
@@ -2669,31 +2669,31 @@ let GenILMethodBody mname cenv env (il: ILMethodBody) =
| TypeFilterClause uncoded -> uncoded
if canUseSmall then
- methbuf.EmitByte e_CorILMethod_Sect_EHTable;
- methbuf.EmitByte (b0 smallSize);
- methbuf.EmitByte 0x00uy;
- methbuf.EmitByte 0x00uy;
+ methbuf.EmitByte e_CorILMethod_Sect_EHTable
+ methbuf.EmitByte (b0 smallSize)
+ methbuf.EmitByte 0x00uy
+ methbuf.EmitByte 0x00uy
seh |> List.iter (fun (st1,sz1,st2,sz2,kind) ->
let k32 = kindAsInt32 kind
- methbuf.EmitInt32AsUInt16 k32;
- methbuf.EmitInt32AsUInt16 st1;
- methbuf.EmitByte (b0 sz1);
- methbuf.EmitInt32AsUInt16 st2;
- methbuf.EmitByte (b0 sz2);
+ methbuf.EmitInt32AsUInt16 k32
+ methbuf.EmitInt32AsUInt16 st1
+ methbuf.EmitByte (b0 sz1)
+ methbuf.EmitInt32AsUInt16 st2
+ methbuf.EmitByte (b0 sz2)
methbuf.EmitInt32 (kindAsExtraInt32 kind))
else
let bigSize = (seh.Length * 24 + 4)
- methbuf.EmitByte (e_CorILMethod_Sect_EHTable ||| e_CorILMethod_Sect_FatFormat);
- methbuf.EmitByte (b0 bigSize);
- methbuf.EmitByte (b1 bigSize);
- methbuf.EmitByte (b2 bigSize);
+ methbuf.EmitByte (e_CorILMethod_Sect_EHTable ||| e_CorILMethod_Sect_FatFormat)
+ methbuf.EmitByte (b0 bigSize)
+ methbuf.EmitByte (b1 bigSize)
+ methbuf.EmitByte (b2 bigSize)
seh |> List.iter (fun (st1,sz1,st2,sz2,kind) ->
let k32 = kindAsInt32 kind
- methbuf.EmitInt32 k32;
- methbuf.EmitInt32 st1;
- methbuf.EmitInt32 sz1;
- methbuf.EmitInt32 st2;
- methbuf.EmitInt32 sz2;
+ methbuf.EmitInt32 k32
+ methbuf.EmitInt32 st1
+ methbuf.EmitInt32 sz1
+ methbuf.EmitInt32 st2
+ methbuf.EmitInt32 sz2
methbuf.EmitInt32 (kindAsExtraInt32 kind))
let requiredStringFixups' = (12,requiredStringFixups)
@@ -2717,21 +2717,21 @@ let rec GetFieldDefAsFieldDefRow cenv env (fd: ILFieldDef) =
(if (fd.Marshal <> None) then 0x1000 else 0x0) |||
(if (fd.Data <> None) then 0x0100 else 0x0)
UnsharedRow
- [| UShort (uint16 flags);
- StringE (GetStringHeapIdx cenv fd.Name);
- Blob (GetFieldDefSigAsBlobIdx cenv env fd ); |]
+ [| UShort (uint16 flags)
+ StringE (GetStringHeapIdx cenv fd.Name)
+ Blob (GetFieldDefSigAsBlobIdx cenv env fd ) |]
and GetFieldDefSigAsBlobIdx cenv env fd = GetFieldDefTypeAsBlobIdx cenv env fd.Type
and GenFieldDefPass3 cenv env fd =
let fidx = AddUnsharedRow cenv TableNames.Field (GetFieldDefAsFieldDefRow cenv env fd)
- GenCustomAttrsPass3Or4 cenv (hca_FieldDef,fidx) fd.CustomAttrs;
+ GenCustomAttrsPass3Or4 cenv (hca_FieldDef,fidx) fd.CustomAttrs
// Write FieldRVA table - fixups into data section done later
match fd.Data with
| None -> ()
| Some b ->
let offs = cenv.data.Position
- cenv.data.EmitBytes b;
+ cenv.data.EmitBytes b
AddUnsharedRow cenv TableNames.FieldRVA
(UnsharedRow [| Data (offs, false); SimpleIndex (TableNames.Field,fidx) |]) |> ignore
// Write FieldMarshal table
@@ -2739,7 +2739,7 @@ and GenFieldDefPass3 cenv env fd =
| None -> ()
| Some ntyp ->
AddUnsharedRow cenv TableNames.FieldMarshal
- (UnsharedRow [| HasFieldMarshal (hfm_FieldDef, fidx);
+ (UnsharedRow [| HasFieldMarshal (hfm_FieldDef, fidx)
Blob (GetNativeTypeAsBlobIdx cenv ntyp) |]) |> ignore
// Write Contant table
match fd.LiteralValue with
@@ -2747,16 +2747,15 @@ and GenFieldDefPass3 cenv env fd =
| Some i ->
AddUnsharedRow cenv TableNames.Constant
(UnsharedRow
- [| GetFieldInitFlags i;
- HasConstant (hc_FieldDef, fidx);
+ [| GetFieldInitFlags i
+ HasConstant (hc_FieldDef, fidx)
Blob (GetFieldInitAsBlobIdx cenv i) |]) |> ignore
// Write FieldLayout table
match fd.Offset with
| None -> ()
| Some offset ->
AddUnsharedRow cenv TableNames.FieldLayout
- (UnsharedRow [| ULong offset;
- SimpleIndex (TableNames.Field, fidx) |]) |> ignore
+ (UnsharedRow [| ULong offset; SimpleIndex (TableNames.Field, fidx) |]) |> ignore
// --------------------------------------------------------------------
@@ -2776,22 +2775,22 @@ let rec GetGenericParamAsGenericParamRow cenv _env idx owner gp =
let mdVersionMajor,_ = metadataSchemaVersionSupportedByCLRVersion cenv.desiredMetadataVersion
if (mdVersionMajor = 1) then
SimpleSharedRow
- [| UShort (uint16 idx);
- UShort (uint16 flags);
- TypeOrMethodDef (fst owner, snd owner);
- StringE (GetStringHeapIdx cenv gp.Name);
- TypeDefOrRefOrSpec (tdor_TypeDef, 0); (* empty kind field in deprecated metadata *) |]
+ [| UShort (uint16 idx)
+ UShort (uint16 flags)
+ TypeOrMethodDef (fst owner, snd owner)
+ StringE (GetStringHeapIdx cenv gp.Name)
+ TypeDefOrRefOrSpec (tdor_TypeDef, 0) (* empty kind field in deprecated metadata *) |]
else
SimpleSharedRow
- [| UShort (uint16 idx);
- UShort (uint16 flags);
- TypeOrMethodDef (fst owner, snd owner);
+ [| UShort (uint16 idx)
+ UShort (uint16 flags)
+ TypeOrMethodDef (fst owner, snd owner)
StringE (GetStringHeapIdx cenv gp.Name) |]
and GenTypeAsGenericParamConstraintRow cenv env gpidx ty =
let tdorTag,tdorRow = GetTypeAsTypeDefOrRef cenv env ty
UnsharedRow
- [| SimpleIndex (TableNames.GenericParam, gpidx);
+ [| SimpleIndex (TableNames.GenericParam, gpidx)
TypeDefOrRefOrSpec (tdorTag,tdorRow) |]
and GenGenericParamConstraintPass4 cenv env gpidx ty =
@@ -2822,8 +2821,8 @@ let rec GetParamAsParamRow cenv _env seq param =
(if param.Marshal <> None then 0x2000 else 0x0000)
UnsharedRow
- [| UShort (uint16 flags);
- UShort (uint16 seq);
+ [| UShort (uint16 flags)
+ UShort (uint16 seq)
StringE (GetStringHeapIdxOption cenv param.Name) |]
and GenParamPass3 cenv env seq param =
@@ -2831,32 +2830,31 @@ and GenParamPass3 cenv env seq param =
then ()
else
let pidx = AddUnsharedRow cenv TableNames.Param (GetParamAsParamRow cenv env seq param)
- GenCustomAttrsPass3Or4 cenv (hca_ParamDef,pidx) param.CustomAttrs;
+ GenCustomAttrsPass3Or4 cenv (hca_ParamDef,pidx) param.CustomAttrs
// Write FieldRVA table - fixups into data section done later
match param.Marshal with
| None -> ()
| Some ntyp ->
AddUnsharedRow cenv TableNames.FieldMarshal
- (UnsharedRow [| HasFieldMarshal (hfm_ParamDef, pidx);
- Blob (GetNativeTypeAsBlobIdx cenv ntyp) |]) |> ignore
+ (UnsharedRow [| HasFieldMarshal (hfm_ParamDef, pidx); Blob (GetNativeTypeAsBlobIdx cenv ntyp) |]) |> ignore
let GenReturnAsParamRow (returnv : ILReturn) =
let flags = (if returnv.Marshal <> None then 0x2000 else 0x0000)
UnsharedRow
- [| UShort (uint16 flags);
- UShort 0us; (* sequence num. *)
+ [| UShort (uint16 flags)
+ UShort 0us (* sequence num. *)
StringE 0 |]
let GenReturnPass3 cenv (returnv: ILReturn) =
if isSome returnv.Marshal || nonNil returnv.CustomAttrs.AsList then
let pidx = AddUnsharedRow cenv TableNames.Param (GenReturnAsParamRow returnv)
- GenCustomAttrsPass3Or4 cenv (hca_ParamDef,pidx) returnv.CustomAttrs;
+ GenCustomAttrsPass3Or4 cenv (hca_ParamDef,pidx) returnv.CustomAttrs
match returnv.Marshal with
| None -> ()
| Some ntyp ->
AddUnsharedRow cenv TableNames.FieldMarshal
(UnsharedRow
- [| HasFieldMarshal (hfm_ParamDef, pidx);
+ [| HasFieldMarshal (hfm_ParamDef, pidx)
Blob (GetNativeTypeAsBlobIdx cenv ntyp) |]) |> ignore
// --------------------------------------------------------------------
@@ -2865,10 +2863,10 @@ let GenReturnPass3 cenv (returnv: ILReturn) =
let GetMethodDefSigAsBytes cenv env (mdef: ILMethodDef) =
emitBytesViaBuffer (fun bb ->
- bb.EmitByte (callconvToByte mdef.GenericParams.Length mdef.CallingConv);
- if mdef.GenericParams.Length > 0 then bb.EmitZ32 mdef.GenericParams.Length;
- bb.EmitZ32 mdef.Parameters.Length;
- EmitType cenv env bb mdef.Return.Type;
+ bb.EmitByte (callconvToByte mdef.GenericParams.Length mdef.CallingConv)
+ if mdef.GenericParams.Length > 0 then bb.EmitZ32 mdef.GenericParams.Length
+ bb.EmitZ32 mdef.Parameters.Length
+ EmitType cenv env bb mdef.Return.Type
mdef.ParameterTypes |> ILList.iter (EmitType cenv env bb))
let GenMethodDefSigAsBlobIdx cenv env mdef =
@@ -2910,7 +2908,7 @@ let GenMethodDefAsRow cenv env midx (md: ILMethodDef) =
if md.IsEntryPoint then
if cenv.entrypoint <> None then failwith "duplicate entrypoint"
- else cenv.entrypoint <- Some (true, midx);
+ else cenv.entrypoint <- Some (true, midx)
let codeAddr =
(match md.mdBody.Contents with
| MethodBody.IL ilmbody ->
@@ -2920,37 +2918,37 @@ let GenMethodDefAsRow cenv env midx (md: ILMethodDef) =
// Now record the PDB record for this method - we write this out later.
if cenv.generatePdb then
cenv.pdbinfo.Add
- { MethToken=getUncodedToken TableNames.Method midx;
- MethName=md.Name;
- Params= [| |]; (* REVIEW *)
- RootScope = rootScope;
+ { MethToken=getUncodedToken TableNames.Method midx
+ MethName=md.Name
+ Params= [| |] (* REVIEW *)
+ RootScope = rootScope
Range=
match ilmbody.SourceMarker with
| Some m when cenv.generatePdb ->
// table indexes are 1-based, document array indexes are 0-based
let doc = (cenv.documents.FindOrAddSharedEntry m.Document) - 1
- Some ({ Document=doc;
- Line=m.Line;
- Column=m.Column; },
- { Document=doc;
- Line=m.EndLine;
- Column=m.EndColumn; })
+ Some ({ Document=doc
+ Line=m.Line
+ Column=m.Column },
+ { Document=doc
+ Line=m.EndLine
+ Column=m.EndColumn })
| _ -> None
- SequencePoints=seqpoints; };
+ SequencePoints=seqpoints }
- cenv.AddCode code;
+ cenv.AddCode code
addr
| MethodBody.Native ->
- failwith "cannot write body of native method - Abstract IL cannot roundtrip mixed native/managed binaries";
+ failwith "cannot write body of native method - Abstract IL cannot roundtrip mixed native/managed binaries"
| _ -> 0x0000)
UnsharedRow
- [| ULong codeAddr ;
- UShort (uint16 implflags);
- UShort (uint16 flags);
- StringE (GetStringHeapIdx cenv md.Name);
- Blob (GenMethodDefSigAsBlobIdx cenv env md);
+ [| ULong codeAddr
+ UShort (uint16 implflags)
+ UShort (uint16 flags)
+ StringE (GetStringHeapIdx cenv md.Name)
+ Blob (GenMethodDefSigAsBlobIdx cenv env md)
SimpleIndex(TableNames.Param,cenv.GetTable(TableNames.Param).Count + 1) |]
let GenMethodImplPass3 cenv env _tgparams tidx mimpl =
@@ -2958,19 +2956,19 @@ let GenMethodImplPass3 cenv env _tgparams tidx mimpl =
let midx2Tag, midx2Row = GetOverridesSpecAsMethodDefOrRef cenv env mimpl.Overrides
AddUnsharedRow cenv TableNames.MethodImpl
(UnsharedRow
- [| SimpleIndex (TableNames.TypeDef, tidx);
- MethodDefOrRef (midxTag, midxRow);
+ [| SimpleIndex (TableNames.TypeDef, tidx)
+ MethodDefOrRef (midxTag, midxRow)
MethodDefOrRef (midx2Tag, midx2Row) |]) |> ignore
let GenMethodDefPass3 cenv env (md:ILMethodDef) =
let midx = GetMethodDefIdx cenv md
let idx2 = AddUnsharedRow cenv TableNames.Method (GenMethodDefAsRow cenv env midx md)
- if midx <> idx2 then failwith "index of method def on pass 3 does not match index on pass 2";
- GenReturnPass3 cenv md.Return;
- md.Parameters |> ILList.iteri (fun n param -> GenParamPass3 cenv env (n+1) param) ;
- md.CustomAttrs |> GenCustomAttrsPass3Or4 cenv (hca_MethodDef,midx) ;
- md.SecurityDecls.AsList |> GenSecurityDeclsPass3 cenv (hds_MethodDef,midx);
- md.GenericParams |> List.iteri (fun n gp -> GenGenericParamPass3 cenv env n (tomd_MethodDef, midx) gp) ;
+ if midx <> idx2 then failwith "index of method def on pass 3 does not match index on pass 2"
+ GenReturnPass3 cenv md.Return
+ md.Parameters |> ILList.iteri (fun n param -> GenParamPass3 cenv env (n+1) param)
+ md.CustomAttrs |> GenCustomAttrsPass3Or4 cenv (hca_MethodDef,midx)
+ md.SecurityDecls.AsList |> GenSecurityDeclsPass3 cenv (hds_MethodDef,midx)
+ md.GenericParams |> List.iteri (fun n gp -> GenGenericParamPass3 cenv env n (tomd_MethodDef, midx) gp)
match md.mdBody.Contents with
| MethodBody.PInvoke attr ->
let flags =
@@ -3002,10 +3000,10 @@ let GenMethodDefPass3 cenv env (md:ILMethodDef) =
(if attr.LastError then 0x0040 else 0x0000)
AddUnsharedRow cenv TableNames.ImplMap
(UnsharedRow
- [| UShort (uint16 flags);
- MemberForwarded (mf_MethodDef,midx);
- StringE (GetStringHeapIdx cenv attr.Name);
- SimpleIndex (TableNames.ModuleRef, GetModuleRefAsIdx cenv attr.Where); |]) |> ignore
+ [| UShort (uint16 flags)
+ MemberForwarded (mf_MethodDef,midx)
+ StringE (GetStringHeapIdx cenv attr.Name)
+ SimpleIndex (TableNames.ModuleRef, GetModuleRefAsIdx cenv attr.Where) |]) |> ignore
| _ -> ()
let GenMethodDefPass4 cenv env md =
@@ -3017,8 +3015,8 @@ let GenPropertyMethodSemanticsPass3 cenv pidx kind mref =
let midx = try GetMethodRefAsMethodDefIdx cenv mref with MethodDefNotFound -> 1
AddUnsharedRow cenv TableNames.MethodSemantics
(UnsharedRow
- [| UShort (uint16 kind);
- SimpleIndex (TableNames.Method,midx);
+ [| UShort (uint16 kind)
+ SimpleIndex (TableNames.Method,midx)
HasSemantics (hs_Property, pidx) |]) |> ignore
let rec GetPropertySigAsBlobIdx cenv env prop =
@@ -3027,9 +3025,9 @@ let rec GetPropertySigAsBlobIdx cenv env prop =
and GetPropertySigAsBytes cenv env prop =
emitBytesViaBuffer (fun bb ->
let b = ((hasthisToByte prop.CallingConv) ||| e_IMAGE_CEE_CS_CALLCONV_PROPERTY)
- bb.EmitByte b;
- bb.EmitZ32 prop.Args.Length;
- EmitType cenv env bb prop.Type;
+ bb.EmitByte b
+ bb.EmitZ32 prop.Args.Length
+ EmitType cenv env bb prop.Type
prop.Args |> ILList.iter (EmitType cenv env bb))
and GetPropertyAsPropertyRow cenv env (prop:ILPropertyDef) =
@@ -3038,23 +3036,23 @@ and GetPropertyAsPropertyRow cenv env (prop:ILPropertyDef) =
(if prop.IsRTSpecialName then 0x0400 else 0x0) |||
(if prop.Init <> None then 0x1000 else 0x0)
UnsharedRow
- [| UShort (uint16 flags);
- StringE (GetStringHeapIdx cenv prop.Name);
- Blob (GetPropertySigAsBlobIdx cenv env prop); |]
+ [| UShort (uint16 flags)
+ StringE (GetStringHeapIdx cenv prop.Name)
+ Blob (GetPropertySigAsBlobIdx cenv env prop) |]
/// ILPropertyDef --> Property Row + MethodSemantics entries
and GenPropertyPass3 cenv env prop =
let pidx = AddUnsharedRow cenv TableNames.Property (GetPropertyAsPropertyRow cenv env prop)
- prop.SetMethod |> Option.iter (GenPropertyMethodSemanticsPass3 cenv pidx 0x0001) ;
- prop.GetMethod |> Option.iter (GenPropertyMethodSemanticsPass3 cenv pidx 0x0002) ;
+ prop.SetMethod |> Option.iter (GenPropertyMethodSemanticsPass3 cenv pidx 0x0001)
+ prop.GetMethod |> Option.iter (GenPropertyMethodSemanticsPass3 cenv pidx 0x0002)
// Write Constant table
match prop.Init with
| None -> ()
| Some i ->
AddUnsharedRow cenv TableNames.Constant
(UnsharedRow
- [| GetFieldInitFlags i;
- HasConstant (hc_Property, pidx);
+ [| GetFieldInitFlags i
+ HasConstant (hc_Property, pidx)
Blob (GetFieldInitAsBlobIdx cenv i) |]) |> ignore
GenCustomAttrsPass3Or4 cenv (hca_Property,pidx) prop.CustomAttrs
@@ -3062,8 +3060,8 @@ let rec GenEventMethodSemanticsPass3 cenv eidx kind mref =
let addIdx = try GetMethodRefAsMethodDefIdx cenv mref with MethodDefNotFound -> 1
AddUnsharedRow cenv TableNames.MethodSemantics
(UnsharedRow
- [| UShort (uint16 kind);
- SimpleIndex (TableNames.Method,addIdx);
+ [| UShort (uint16 kind)
+ SimpleIndex (TableNames.Method,addIdx)
HasSemantics (hs_Event, eidx) |]) |> ignore
/// ILEventDef --> Event Row + MethodSemantics entries
@@ -3073,8 +3071,8 @@ and GenEventAsEventRow cenv env (md: ILEventDef) =
(if md.IsRTSpecialName then 0x0400 else 0x0)
let tdorTag, tdorRow = GetTypeOptionAsTypeDefOrRef cenv env md.Type
UnsharedRow
- [| UShort (uint16 flags);
- StringE (GetStringHeapIdx cenv md.Name);
+ [| UShort (uint16 flags)
+ StringE (GetStringHeapIdx cenv md.Name)
TypeDefOrRefOrSpec (tdorTag,tdorRow) |]
and GenEventPass3 cenv env (md: ILEventDef) =
@@ -3082,7 +3080,7 @@ and GenEventPass3 cenv env (md: ILEventDef) =
md.AddMethod |> GenEventMethodSemanticsPass3 cenv eidx 0x0008
md.RemoveMethod |> GenEventMethodSemanticsPass3 cenv eidx 0x0010
Option.iter (GenEventMethodSemanticsPass3 cenv eidx 0x0020) md.FireMethod
- List.iter (GenEventMethodSemanticsPass3 cenv eidx 0x0004) md.OtherMethods;
+ List.iter (GenEventMethodSemanticsPass3 cenv eidx 0x0004) md.OtherMethods
GenCustomAttrsPass3Or4 cenv (hca_Event,eidx) md.CustomAttrs
@@ -3101,17 +3099,17 @@ let rec GetResourceAsManifestResourceRow cenv r =
let alignedOffset = (align 0x8 offset)
let pad = alignedOffset - offset
let resourceSize = b.Length
- cenv.resources.EmitPadding pad;
- cenv.resources.EmitInt32 resourceSize;
- cenv.resources.EmitBytes b;
+ cenv.resources.EmitPadding pad
+ cenv.resources.EmitInt32 resourceSize
+ cenv.resources.EmitBytes b
Data (alignedOffset,true), (i_File, 0)
| ILResourceLocation.File (mref,offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref)
| ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref)
UnsharedRow
- [| data;
- ULong (match r.Access with ILResourceAccess.Public -> 0x01 | ILResourceAccess.Private -> 0x02);
- StringE (GetStringHeapIdx cenv r.Name);
- Implementation (fst impl, snd impl); |]
+ [| data
+ ULong (match r.Access with ILResourceAccess.Public -> 0x01 | ILResourceAccess.Private -> 0x02)
+ StringE (GetStringHeapIdx cenv r.Name)
+ Implementation (fst impl, snd impl) |]
and GenResourcePass3 cenv r =
let idx = AddUnsharedRow cenv TableNames.ManifestResource (GetResourceAsManifestResourceRow cenv r)
@@ -3125,11 +3123,11 @@ let rec GenTypeDefPass3 enc cenv (td:ILTypeDef) =
try
let env = envForTypeDef td
let tidx = GetIdxForTypeDef cenv (TdKey(enc,td.Name))
- td.Properties.AsList |> List.iter (GenPropertyPass3 cenv env);
- td.Events.AsList |> List.iter (GenEventPass3 cenv env);
- td.Fields.AsList |> List.iter (GenFieldDefPass3 cenv env);
- td.Methods |> Seq.iter (GenMethodDefPass3 cenv env);
- td.MethodImpls.AsList |> List.iter (GenMethodImplPass3 cenv env td.GenericParams.Length tidx);
+ td.Properties.AsList |> List.iter (GenPropertyPass3 cenv env)
+ td.Events.AsList |> List.iter (GenEventPass3 cenv env)
+ td.Fields.AsList |> List.iter (GenFieldDefPass3 cenv env)
+ td.Methods |> Seq.iter (GenMethodDefPass3 cenv env)
+ td.MethodImpls.AsList |> List.iter (GenMethodImplPass3 cenv env td.GenericParams.Length tidx)
// ClassLayout entry if needed
match td.Layout with
| ILTypeDefLayout.Auto -> ()
@@ -3137,16 +3135,16 @@ let rec GenTypeDefPass3 enc cenv (td:ILTypeDef) =
if isSome layout.Pack || isSome layout.Size then
AddUnsharedRow cenv TableNames.ClassLayout
(UnsharedRow
- [| UShort (match layout.Pack with None -> uint16 0x0 | Some p -> p);
- ULong (match layout.Size with None -> 0x0 | Some p -> p);
+ [| UShort (match layout.Pack with None -> uint16 0x0 | Some p -> p)
+ ULong (match layout.Size with None -> 0x0 | Some p -> p)
SimpleIndex (TableNames.TypeDef, tidx) |]) |> ignore
- td.SecurityDecls.AsList |> GenSecurityDeclsPass3 cenv (hds_TypeDef,tidx);
- td.CustomAttrs |> GenCustomAttrsPass3Or4 cenv (hca_TypeDef,tidx);
- td.GenericParams |> List.iteri (fun n gp -> GenGenericParamPass3 cenv env n (tomd_TypeDef,tidx) gp) ;
- td.NestedTypes.AsList |> GenTypeDefsPass3 (enc@[td.Name]) cenv;
+ td.SecurityDecls.AsList |> GenSecurityDeclsPass3 cenv (hds_TypeDef,tidx)
+ td.CustomAttrs |> GenCustomAttrsPass3Or4 cenv (hca_TypeDef,tidx)
+ td.GenericParams |> List.iteri (fun n gp -> GenGenericParamPass3 cenv env n (tomd_TypeDef,tidx) gp)
+ td.NestedTypes.AsList |> GenTypeDefsPass3 (enc@[td.Name]) cenv
with e ->
- failwith ("Error in pass3 for type "+td.Name+", error: "+e.Message);
+ failwith ("Error in pass3 for type "+td.Name+", error: "+e.Message)
reraise()
raise e
@@ -3160,11 +3158,11 @@ let rec GenTypeDefPass4 enc cenv (td:ILTypeDef) =
try
let env = envForTypeDef td
let tidx = GetIdxForTypeDef cenv (TdKey(enc,td.Name))
- td.Methods |> Seq.iter (GenMethodDefPass4 cenv env) ;
- List.iteri (fun n gp -> GenGenericParamPass4 cenv env n (tomd_TypeDef,tidx) gp) td.GenericParams;
- GenTypeDefsPass4 (enc@[td.Name]) cenv td.NestedTypes.AsList;
+ td.Methods |> Seq.iter (GenMethodDefPass4 cenv env)
+ List.iteri (fun n gp -> GenGenericParamPass4 cenv env n (tomd_TypeDef,tidx) gp) td.GenericParams
+ GenTypeDefsPass4 (enc@[td.Name]) cenv td.NestedTypes.AsList
with e ->
- failwith ("Error in pass4 for type "+td.Name+", error: "+e.Message);
+ failwith ("Error in pass4 for type "+td.Name+", error: "+e.Message)
reraise()
raise e
@@ -3180,12 +3178,12 @@ let rec GenNestedExportedTypePass3 cenv cidx (ce: ILNestedExportedType) =
let nidx =
AddUnsharedRow cenv TableNames.ExportedType
(UnsharedRow
- [| ULong flags ;
- ULong 0x0;
- StringE (GetStringHeapIdx cenv ce.Name);
- StringE 0;
+ [| ULong flags
+ ULong 0x0
+ StringE (GetStringHeapIdx cenv ce.Name)
+ StringE 0
Implementation (i_ExportedType, cidx) |])
- GenCustomAttrsPass3Or4 cenv (hca_ExportedType,nidx) ce.CustomAttrs;
+ GenCustomAttrsPass3Or4 cenv (hca_ExportedType,nidx) ce.CustomAttrs
GenNestedExportedTypesPass3 cenv nidx ce.Nested
and GenNestedExportedTypesPass3 cenv nidx (nce: ILNestedExportedTypes) =
@@ -3199,16 +3197,16 @@ and GenExportedTypePass3 cenv (ce: ILExportedTypeOrForwarder) =
let cidx =
AddUnsharedRow cenv TableNames.ExportedType
(UnsharedRow
- [| ULong flags ;
- ULong 0x0;
- nelem;
- nselem;
- Implementation (fst impl, snd impl); |])
- GenCustomAttrsPass3Or4 cenv (hca_ExportedType,cidx) ce.CustomAttrs;
+ [| ULong flags
+ ULong 0x0
+ nelem
+ nselem
+ Implementation (fst impl, snd impl) |])
+ GenCustomAttrsPass3Or4 cenv (hca_ExportedType,cidx) ce.CustomAttrs
GenNestedExportedTypesPass3 cenv cidx ce.Nested
and GenExportedTypesPass3 cenv (ce: ILExportedTypesAndForwarders) =
- List.iter (GenExportedTypePass3 cenv) ce.AsList;
+ List.iter (GenExportedTypePass3 cenv) ce.AsList
// --------------------------------------------------------------------
// manifest --> generate Assembly row
@@ -3216,11 +3214,11 @@ and GenExportedTypesPass3 cenv (ce: ILExportedTypesAndForwarders) =
and GetManifsetAsAssemblyRow cenv m =
UnsharedRow
- [|ULong m.AuxModuleHashAlgorithm;
- UShort (match m.Version with None -> 0us | Some (x,_,_,_) -> x);
- UShort (match m.Version with None -> 0us | Some (_,y,_,_) -> y);
- UShort (match m.Version with None -> 0us | Some (_,_,z,_) -> z);
- UShort (match m.Version with None -> 0us | Some (_,_,_,w) -> w);
+ [|ULong m.AuxModuleHashAlgorithm
+ UShort (match m.Version with None -> 0us | Some (x,_,_,_) -> x)
+ UShort (match m.Version with None -> 0us | Some (_,y,_,_) -> y)
+ UShort (match m.Version with None -> 0us | Some (_,_,z,_) -> z)
+ UShort (match m.Version with None -> 0us | Some (_,_,_,w) -> w)
ULong
( (match m.AssemblyLongevity with
| ILAssemblyLongevity.Unspecified -> 0x0000
@@ -3235,21 +3233,21 @@ and GetManifsetAsAssemblyRow cenv m =
(if m.JitTracking then 0x8000 else 0x0) |||
(if m.DisableJitOptimizations then 0x4000 else 0x0) |||
(match m.PublicKey with None -> 0x0000 | Some _ -> 0x0001) |||
- 0x0000);
- (match m.PublicKey with None -> Blob 0 | Some x -> Blob (GetBytesAsBlobIdx cenv x));
- StringE (GetStringHeapIdx cenv m.Name);
- (match m.Locale with None -> StringE 0 | Some x -> StringE (GetStringHeapIdx cenv x)); |]
+ 0x0000)
+ (match m.PublicKey with None -> Blob 0 | Some x -> Blob (GetBytesAsBlobIdx cenv x))
+ StringE (GetStringHeapIdx cenv m.Name)
+ (match m.Locale with None -> StringE 0 | Some x -> StringE (GetStringHeapIdx cenv x)) |]
and GenManifestPass3 cenv m =
let aidx = AddUnsharedRow cenv TableNames.Assembly (GetManifsetAsAssemblyRow cenv m)
- GenSecurityDeclsPass3 cenv (hds_Assembly,aidx) m.SecurityDecls.AsList;
- GenCustomAttrsPass3Or4 cenv (hca_Assembly,aidx) m.CustomAttrs;
- GenExportedTypesPass3 cenv m.ExportedTypes;
+ GenSecurityDeclsPass3 cenv (hds_Assembly,aidx) m.SecurityDecls.AsList
+ GenCustomAttrsPass3Or4 cenv (hca_Assembly,aidx) m.CustomAttrs
+ GenExportedTypesPass3 cenv m.ExportedTypes
// Record the entrypoint decl if needed.
match m.EntrypointElsewhere with
| Some mref ->
if cenv.entrypoint <> None then failwith "duplicate entrypoint"
- else cenv.entrypoint <- Some (false, GetModuleRefAsIdx cenv mref);
+ else cenv.entrypoint <- Some (false, GetModuleRefAsIdx cenv mref)
| None -> ()
and newGuid (modul: ILModuleDef) =
@@ -3263,10 +3261,10 @@ and GetModuleAsRow cenv (modul: ILModuleDef) =
let modulGuid = newGuid modul
cenv.moduleGuid <- modulGuid
UnsharedRow
- [| UShort (uint16 0x0);
- StringE (GetStringHeapIdx cenv modul.Name);
- Guid (GetGuidIdx cenv modulGuid);
- Guid 0;
+ [| UShort (uint16 0x0)
+ StringE (GetStringHeapIdx cenv modul.Name)
+ Guid (GetGuidIdx cenv modulGuid)
+ Guid 0
Guid 0 |]
@@ -3290,63 +3288,63 @@ let SortTableRows tab (rows:IGenericRow[]) =
let GenModule (cenv : cenv) (modul: ILModuleDef) =
let midx = AddUnsharedRow cenv TableNames.Module (GetModuleAsRow cenv modul)
- List.iter (GenResourcePass3 cenv) modul.Resources.AsList;
+ List.iter (GenResourcePass3 cenv) modul.Resources.AsList
let tds = destTypeDefsWithGlobalFunctionsFirst cenv.ilg modul.TypeDefs
- reportTime cenv.showTimes "Module Generation Preparation";
- GenTypeDefsPass1 [] cenv tds;
- reportTime cenv.showTimes "Module Generation Pass 1";
- GenTypeDefsPass2 0 [] cenv tds;
- reportTime cenv.showTimes "Module Generation Pass 2";
- (match modul.Manifest with None -> () | Some m -> GenManifestPass3 cenv m);
- GenTypeDefsPass3 [] cenv tds;
- reportTime cenv.showTimes "Module Generation Pass 3";
- GenCustomAttrsPass3Or4 cenv (hca_Module,midx) modul.CustomAttrs;
+ reportTime cenv.showTimes "Module Generation Preparation"
+ GenTypeDefsPass1 [] cenv tds
+ reportTime cenv.showTimes "Module Generation Pass 1"
+ GenTypeDefsPass2 0 [] cenv tds
+ reportTime cenv.showTimes "Module Generation Pass 2"
+ (match modul.Manifest with None -> () | Some m -> GenManifestPass3 cenv m)
+ GenTypeDefsPass3 [] cenv tds
+ reportTime cenv.showTimes "Module Generation Pass 3"
+ GenCustomAttrsPass3Or4 cenv (hca_Module,midx) modul.CustomAttrs
// GenericParam is the only sorted table indexed by Columns in other tables (GenericParamConstraint\CustomAttributes).
// Hence we need to sort it before we emit any entries in GenericParamConstraint\CustomAttributes that are attached to generic params.
// Note this mutates the rows in a table. 'SetRowsOfTable' clears
// the key --> index map since it is no longer valid
- cenv.GetTable(TableNames.GenericParam).SetRowsOfTable (SortTableRows TableNames.GenericParam (cenv.GetTable(TableNames.GenericParam).EntriesAsArray));
- GenTypeDefsPass4 [] cenv tds;
+ cenv.GetTable(TableNames.GenericParam).SetRowsOfTable (SortTableRows TableNames.GenericParam (cenv.GetTable(TableNames.GenericParam).EntriesAsArray))
+ GenTypeDefsPass4 [] cenv tds
reportTime cenv.showTimes "Module Generation Pass 4"
let generateIL requiredDataFixups (desiredMetadataVersion,generatePdb, ilg : ILGlobals, emitTailcalls,showTimes) (m : ILModuleDef) noDebugData cilStartAddress =
let isDll = m.IsDLL
let cenv =
- { primaryAssembly=ilg.traits.ScopeRef;
- emitTailcalls=emitTailcalls;
- showTimes=showTimes;
- ilg = mkILGlobals ilg.traits None noDebugData; // assumes mscorlib is Scope_assembly _ ILScopeRef
- desiredMetadataVersion=desiredMetadataVersion;
- requiredDataFixups= requiredDataFixups;
- requiredStringFixups = [];
- codeChunks=ByteBuffer.Create 40000;
- nextCodeAddr = cilStartAddress;
- data = ByteBuffer.Create 200;
- resources = ByteBuffer.Create 200;
- tables= Array.init 64 (fun i -> MetadataTable<_>.New ("row table "+string i,System.Collections.Generic.EqualityComparer.Default));
- AssemblyRefs = MetadataTable<_>.New("ILAssemblyRef",System.Collections.Generic.EqualityComparer.Default);
- documents=MetadataTable<_>.New("pdbdocs",System.Collections.Generic.EqualityComparer.Default);
- trefCache=new Dictionary<_,_>(100);
- pdbinfo= new ResizeArray<_>(200);
- moduleGuid= Array.zeroCreate 16;
- fieldDefs= MetadataTable<_>.New("field defs",System.Collections.Generic.EqualityComparer.Default);
- methodDefIdxsByKey = MetadataTable<_>.New("method defs",System.Collections.Generic.EqualityComparer.Default);
+ { primaryAssembly=ilg.traits.ScopeRef
+ emitTailcalls=emitTailcalls
+ showTimes=showTimes
+ ilg = mkILGlobals ilg.traits None noDebugData // assumes mscorlib is Scope_assembly _ ILScopeRef
+ desiredMetadataVersion=desiredMetadataVersion
+ requiredDataFixups= requiredDataFixups
+ requiredStringFixups = []
+ codeChunks=ByteBuffer.Create 40000
+ nextCodeAddr = cilStartAddress
+ data = ByteBuffer.Create 200
+ resources = ByteBuffer.Create 200
+ tables= Array.init 64 (fun i -> MetadataTable<_>.New ("row table "+string i,System.Collections.Generic.EqualityComparer.Default))
+ AssemblyRefs = MetadataTable<_>.New("ILAssemblyRef",System.Collections.Generic.EqualityComparer.Default)
+ documents=MetadataTable<_>.New("pdbdocs",System.Collections.Generic.EqualityComparer.Default)
+ trefCache=new Dictionary<_,_>(100)
+ pdbinfo= new ResizeArray<_>(200)
+ moduleGuid= Array.zeroCreate 16
+ fieldDefs= MetadataTable<_>.New("field defs",System.Collections.Generic.EqualityComparer.Default)
+ methodDefIdxsByKey = MetadataTable<_>.New("method defs",System.Collections.Generic.EqualityComparer.Default)
// This uses reference identity on ILMethodDef objects
- methodDefIdxs = new Dictionary<_,_>(100, HashIdentity.Reference);
- propertyDefs = MetadataTable<_>.New("property defs",System.Collections.Generic.EqualityComparer.Default);
- eventDefs = MetadataTable<_>.New("event defs",System.Collections.Generic.EqualityComparer.Default);
- typeDefs = MetadataTable<_>.New("type defs",System.Collections.Generic.EqualityComparer.Default);
- entrypoint=None;
- generatePdb=generatePdb;
+ methodDefIdxs = new Dictionary<_,_>(100, HashIdentity.Reference)
+ propertyDefs = MetadataTable<_>.New("property defs",System.Collections.Generic.EqualityComparer.Default)
+ eventDefs = MetadataTable<_>.New("event defs",System.Collections.Generic.EqualityComparer.Default)
+ typeDefs = MetadataTable<_>.New("type defs",System.Collections.Generic.EqualityComparer.Default)
+ entrypoint=None
+ generatePdb=generatePdb
// These must use structural comparison since they are keyed by arrays
- guids=MetadataTable<_>.New("guids",HashIdentity.Structural);
- blobs= MetadataTable<_>.New("blobs",HashIdentity.Structural);
- strings= MetadataTable<_>.New("strings",System.Collections.Generic.EqualityComparer.Default);
- userStrings= MetadataTable<_>.New("user strings",System.Collections.Generic.EqualityComparer.Default); }
+ guids=MetadataTable<_>.New("guids",HashIdentity.Structural)
+ blobs= MetadataTable<_>.New("blobs",HashIdentity.Structural)
+ strings= MetadataTable<_>.New("strings",System.Collections.Generic.EqualityComparer.Default)
+ userStrings= MetadataTable<_>.New("user strings",System.Collections.Generic.EqualityComparer.Default) }
// Now the main compilation step
- GenModule cenv m;
+ GenModule cenv m
// Fetch out some of the results
let entryPointToken =
@@ -3354,13 +3352,13 @@ let generateIL requiredDataFixups (desiredMetadataVersion,generatePdb, ilg : ILG
| Some (epHere,tok) ->
getUncodedToken (if epHere then TableNames.Method else TableNames.File) tok
| None ->
- if not isDll then dprintn "warning: no entrypoint specified in executable binary";
+ if not isDll then dprintn "warning: no entrypoint specified in executable binary"
0x0
let pdbData =
- { EntryPoint= (if isDll then None else Some entryPointToken);
- ModuleID = cenv.moduleGuid;
- Documents = cenv.documents.EntriesAsArray;
+ { EntryPoint= (if isDll then None else Some entryPointToken)
+ ModuleID = cenv.moduleGuid
+ Documents = cenv.documents.EntriesAsArray
Methods= cenv.pdbinfo.ToArray() }
let idxForNextedTypeDef (tds:ILTypeDef list, td:ILTypeDef) =
@@ -3376,20 +3374,20 @@ let generateIL requiredDataFixups (desiredMetadataVersion,generatePdb, ilg : ILG
// turn idx tbls into token maps
let mappings =
{ TypeDefTokenMap = (fun t ->
- getUncodedToken TableNames.TypeDef (idxForNextedTypeDef t));
+ getUncodedToken TableNames.TypeDef (idxForNextedTypeDef t))
FieldDefTokenMap = (fun t fd ->
let tidx = idxForNextedTypeDef t
- getUncodedToken TableNames.Field (GetFieldDefAsFieldDefIdx cenv tidx fd));
+ getUncodedToken TableNames.Field (GetFieldDefAsFieldDefIdx cenv tidx fd))
MethodDefTokenMap = (fun t md ->
let tidx = idxForNextedTypeDef t
- getUncodedToken TableNames.Method (FindMethodDefIdx cenv (GetKeyForMethodDef tidx md)));
+ getUncodedToken TableNames.Method (FindMethodDefIdx cenv (GetKeyForMethodDef tidx md)))
PropertyTokenMap = (fun t pd ->
let tidx = idxForNextedTypeDef t
- getUncodedToken TableNames.Property (cenv.propertyDefs.GetTableEntry (GetKeyForPropertyDef tidx pd)));
+ getUncodedToken TableNames.Property (cenv.propertyDefs.GetTableEntry (GetKeyForPropertyDef tidx pd)))
EventTokenMap = (fun t ed ->
let tidx = idxForNextedTypeDef t
getUncodedToken TableNames.Event (cenv.eventDefs.GetTableEntry (EventKey (tidx, ed.Name)))) }
- reportTime cenv.showTimes "Finalize Module Generation Results";
+ reportTime cenv.showTimes "Finalize Module Generation Results"
// New return the results
let data = cenv.data.Close()
let resources = cenv.resources.Close()
@@ -3401,7 +3399,7 @@ let generateIL requiredDataFixups (desiredMetadataVersion,generatePdb, ilg : ILG
//=====================================================================
type BinaryChunk =
- { size: int32;
+ { size: int32
addr: int32 }
let chunk sz next = ({addr=next; size=sz},next + sz)
@@ -3418,14 +3416,14 @@ module FileSystemUtilites =
if runningOnMono then
try
let monoPosix = Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756")
- if progress then eprintf "loading type Mono.Unix.UnixFileInfo...\n";
+ if progress then eprintf "loading type Mono.Unix.UnixFileInfo...\n"
let monoUnixFileInfo = monoPosix.GetType("Mono.Unix.UnixFileSystemInfo")
let fileEntry = monoUnixFileInfo.InvokeMember("GetFileSystemEntry", (BindingFlags.InvokeMethod ||| BindingFlags.Static ||| BindingFlags.Public), null, null, [| box filename |],System.Globalization.CultureInfo.InvariantCulture)
let prevPermissions = monoUnixFileInfo.InvokeMember("get_FileAccessPermissions", (BindingFlags.InvokeMethod ||| BindingFlags.Instance ||| BindingFlags.Public), null, fileEntry, [| |],System.Globalization.CultureInfo.InvariantCulture) |> unbox
// Add 0x000001ED (UserReadWriteExecute, GroupReadExecute, OtherReadExecute) to the access permissions on Unix
monoUnixFileInfo.InvokeMember("set_FileAccessPermissions", (BindingFlags.InvokeMethod ||| BindingFlags.Instance ||| BindingFlags.Public), null, fileEntry, [| box (prevPermissions ||| 0x000001ED) |],System.Globalization.CultureInfo.InvariantCulture) |> ignore
with e ->
- if progress then eprintf "failure: %s...\n" (e.ToString());
+ if progress then eprintf "failure: %s...\n" (e.ToString())
// Fail silently
let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls,showTimes) modul noDebugData cilStartAddress =
@@ -3439,7 +3437,7 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
let strings,userStrings,blobs,guids,tables,entryPointToken,code,requiredStringFixups,data,resources,pdbData,mappings =
generateIL requiredDataFixups (desiredMetadataVersion,generatePdb,ilg,emitTailcalls,showTimes) modul noDebugData cilStartAddress
- reportTime showTimes "Generated Tables and Code";
+ reportTime showTimes "Generated Tables and Code"
let tableSize (tab: TableName) = tables.[tab.Index].Length
// Now place the code
@@ -3512,7 +3510,7 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
(if tableSize (TableNames.GenericParamConstraint) > 0 then 0x00001000 else 0x00000000) |||
0x00000200
- reportTime showTimes "Layout Header of Tables";
+ reportTime showTimes "Layout Header of Tables"
let guidAddress n = (if n = 0 then 0 else (n - 1) * 0x10 + 0x01)
@@ -3520,48 +3518,48 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
let tab = Array.create (strings.Length + 1) 0
let pos = ref 1
for i = 1 to strings.Length do
- tab.[i] <- !pos;
+ tab.[i] <- !pos
let s = strings.[i - 1]
pos := !pos + s.Length
tab
let stringAddress n =
- if n >= Array.length stringAddressTable then failwith ("string index "+string n+" out of range");
+ if n >= Array.length stringAddressTable then failwith ("string index "+string n+" out of range")
stringAddressTable.[n]
let userStringAddressTable =
let tab = Array.create (Array.length userStrings + 1) 0
let pos = ref 1
for i = 1 to Array.length userStrings do
- tab.[i] <- !pos;
+ tab.[i] <- !pos
let s = userStrings.[i - 1]
let n = s.Length + 1
pos := !pos + n + ByteBuffer.Z32Size n
tab
let userStringAddress n =
- if n >= Array.length userStringAddressTable then failwith "userString index out of range";
+ if n >= Array.length userStringAddressTable then failwith "userString index out of range"
userStringAddressTable.[n]
let blobAddressTable =
let tab = Array.create (blobs.Length + 1) 0
let pos = ref 1
for i = 1 to blobs.Length do
- tab.[i] <- !pos;
+ tab.[i] <- !pos
let blob = blobs.[i - 1]
pos := !pos + blob.Length + ByteBuffer.Z32Size blob.Length
tab
let blobAddress n =
- if n >= blobAddressTable.Length then failwith "blob index out of range";
+ if n >= blobAddressTable.Length then failwith "blob index out of range"
blobAddressTable.[n]
- reportTime showTimes "Build String/Blob Address Tables";
+ reportTime showTimes "Build String/Blob Address Tables"
let sortedTables =
Array.init 64 (fun i -> tables.[i] |> SortTableRows (TableName.FromIndex i))
- reportTime showTimes "Sort Tables";
+ reportTime showTimes "Sort Tables"
let codedTables =
@@ -3657,18 +3655,18 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
// Now the coded tables themselves - first the schemata header
tablesBuf.EmitIntsAsBytes
[| 0x00; 0x00; 0x00; 0x00;
- mdtableVersionMajor; // major version of table schemata
- mdtableVersionMinor; // minor version of table schemata
+ mdtableVersionMajor // major version of table schemata
+ mdtableVersionMinor // minor version of table schemata
- ((if stringsBig then 0x01 else 0x00) ||| // bit vector for heap size
- (if guidsBig then 0x02 else 0x00) |||
- (if blobsBig then 0x04 else 0x00));
- 0x01; (* reserved, always 1 *) |];
+ ((if stringsBig then 0x01 else 0x00) ||| // bit vector for heap size
+ (if guidsBig then 0x02 else 0x00) |||
+ (if blobsBig then 0x04 else 0x00))
+ 0x01 (* reserved, always 1 *) |]
- tablesBuf.EmitInt32 valid1;
- tablesBuf.EmitInt32 valid2;
- tablesBuf.EmitInt32 sorted1;
- tablesBuf.EmitInt32 sorted2;
+ tablesBuf.EmitInt32 valid1
+ tablesBuf.EmitInt32 valid2
+ tablesBuf.EmitInt32 sorted1
+ tablesBuf.EmitInt32 sorted2
// Numbers of rows in various tables
for rows in sortedTables do
@@ -3676,7 +3674,7 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
tablesBuf.EmitInt32 rows.Length
- reportTime showTimes "Write Header of tablebuf";
+ reportTime showTimes "Write Header of tablebuf"
// The tables themselves
for rows in sortedTables do
@@ -3712,7 +3710,7 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
tablesBuf.Close()
- reportTime showTimes "Write Tables to tablebuf";
+ reportTime showTimes "Write Tables to tablebuf"
let tablesStreamUnpaddedSize = codedTables.Length
// QUERY: extra 4 empty bytes in array.exe - why? Include some extra padding after
@@ -3729,7 +3727,7 @@ let writeILMetadataAndCode (generatePdb,desiredMetadataVersion,ilg,emitTailcalls
let blobsChunk,_next = chunk blobsStreamPaddedSize next
let blobsStreamPadding = blobsChunk.size - blobsStreamUnpaddedSize
- reportTime showTimes "Layout Metadata";
+ reportTime showTimes "Layout Metadata"
let metadata =
let mdbuf = ByteBuffer.Create 500000
@@ -4217,117 +4215,117 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
// Note that the defaults differ between x86 and x64
if modul.Is64Bit then
let size = defaultArg modul.StackReserveSize 0x400000 |> int64
- writeInt64 os size; // Stack Reserve Size Always 0x400000 (4Mb) (see Section 23.1).
- writeInt64 os 0x4000L; // Stack Commit Size Always 0x4000 (16Kb) (see Section 23.1).
- writeInt64 os 0x100000L; // Heap Reserve Size Always 0x100000 (1Mb) (see Section 23.1).
+ writeInt64 os size // Stack Reserve Size Always 0x400000 (4Mb) (see Section 23.1).
+ writeInt64 os 0x4000L // Stack Commit Size Always 0x4000 (16Kb) (see Section 23.1).
+ writeInt64 os 0x100000L // Heap Reserve Size Always 0x100000 (1Mb) (see Section 23.1).
writeInt64 os 0x2000L // Heap Commit Size Always 0x800 (8Kb) (see Section 23.1).
else
let size = defaultArg modul.StackReserveSize 0x100000
- writeInt32 os size; // Stack Reserve Size Always 0x100000 (1Mb) (see Section 23.1).
- writeInt32 os 0x1000; // Stack Commit Size Always 0x1000 (4Kb) (see Section 23.1).
- writeInt32 os 0x100000; // Heap Reserve Size Always 0x100000 (1Mb) (see Section 23.1).
- writeInt32 os 0x1000; // Heap Commit Size Always 0x1000 (4Kb) (see Section 23.1).
+ writeInt32 os size // Stack Reserve Size Always 0x100000 (1Mb) (see Section 23.1).
+ writeInt32 os 0x1000 // Stack Commit Size Always 0x1000 (4Kb) (see Section 23.1).
+ writeInt32 os 0x100000 // Heap Reserve Size Always 0x100000 (1Mb) (see Section 23.1).
+ writeInt32 os 0x1000 // Heap Commit Size Always 0x1000 (4Kb) (see Section 23.1).
// 000000f0 - x86 location, moving on, for x64, add 0x10
- writeInt32 os 0x00; // Loader Flags Always 0 (see Section 23.1)
- writeInt32 os 0x10; // Number of Data Directories: Always 0x10 (see Section 23.1).
- writeInt32 os 0x00;
- writeInt32 os 0x00; // Export Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Loader Flags Always 0 (see Section 23.1)
+ writeInt32 os 0x10 // Number of Data Directories: Always 0x10 (see Section 23.1).
+ writeInt32 os 0x00
+ writeInt32 os 0x00 // Export Table Always 0 (see Section 23.1).
// 00000100
- writeDirectory os importTableChunk; // Import Table RVA of Import Table, (see clause 24.3.1). e.g. 0000b530
+ writeDirectory os importTableChunk // Import Table RVA of Import Table, (see clause 24.3.1). e.g. 0000b530
// Native Resource Table: ECMA says Always 0 (see Section 23.1), but mscorlib and other files with resources bound into executable do not. For the moment assume the resources table is always the first resource in the file.
- writeDirectory os nativeResourcesChunk;
+ writeDirectory os nativeResourcesChunk
// 00000110
- writeInt32 os 0x00; // Exception Table Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Exception Table Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Certificate Table Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Certificate Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Exception Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Exception Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Certificate Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Certificate Table Always 0 (see Section 23.1).
// 00000120
- writeDirectory os baseRelocTableChunk;
- writeDirectory os debugDirectoryChunk; // Debug Directory
+ writeDirectory os baseRelocTableChunk
+ writeDirectory os debugDirectoryChunk // Debug Directory
// 00000130
- writeInt32 os 0x00; // Copyright Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Copyright Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Global Ptr Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Global Ptr Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Copyright Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Copyright Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Global Ptr Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Global Ptr Always 0 (see Section 23.1).
// 00000140
- writeInt32 os 0x00; // Load Config Table Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Load Config Table Always 0 (see Section 23.1).
- writeInt32 os 0x00; // TLS Table Always 0 (see Section 23.1).
- writeInt32 os 0x00; // TLS Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Load Config Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Load Config Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // TLS Table Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // TLS Table Always 0 (see Section 23.1).
// 00000150
- writeInt32 os 0x00; // Bound Import Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Bound Import Always 0 (see Section 23.1).
- writeDirectory os importAddrTableChunk; // Import Addr Table, (see clause 24.3.1). e.g. 0x00002000
+ writeInt32 os 0x00 // Bound Import Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Bound Import Always 0 (see Section 23.1).
+ writeDirectory os importAddrTableChunk // Import Addr Table, (see clause 24.3.1). e.g. 0x00002000
// 00000160
- writeInt32 os 0x00; // Delay Import Descriptor Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Delay Import Descriptor Always 0 (see Section 23.1).
- writeDirectory os cliHeaderChunk;
+ writeInt32 os 0x00 // Delay Import Descriptor Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Delay Import Descriptor Always 0 (see Section 23.1).
+ writeDirectory os cliHeaderChunk
// 00000170
- writeInt32 os 0x00; // Reserved Always 0 (see Section 23.1).
- writeInt32 os 0x00; // Reserved Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Reserved Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // Reserved Always 0 (see Section 23.1).
- write (Some textSectionHeaderChunk.addr) os "text section header" [| |];
+ write (Some textSectionHeaderChunk.addr) os "text section header" [| |]
// 00000178
- writeBytes os [| 0x2euy; 0x74uy; 0x65uy; 0x78uy; 0x74uy; 0x00uy; 0x00uy; 0x00uy; |]; // ".text\000\000\000"
+ writeBytes os [| 0x2euy; 0x74uy; 0x65uy; 0x78uy; 0x74uy; 0x00uy; 0x00uy; 0x00uy; |] // ".text\000\000\000"
// 00000180
- writeInt32 os textSectionSize; // VirtualSize: Total size of the section when loaded into memory in bytes rounded to Section Alignment. If this value is greater than Size of Raw Data, the section is zero-padded. e.g. 0x00009584
- writeInt32 os textSectionAddr; // VirtualAddress For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. e.g. 0x00020000
- writeInt32 os textSectionPhysSize; // SizeOfRawData Size of the initialized data on disk in bytes, shall be a multiple of FileAlignment from the PE header. If this is less than VirtualSize the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized data, this field should be 0. 0x00009600
- writeInt32 os textSectionPhysLoc; // PointerToRawData RVA to section’s first page within the PE file. This shall be a multiple of FileAlignment from the optional header. When a section contains only uninitialized data, this field should be 0. e.g. 00000200
+ writeInt32 os textSectionSize // VirtualSize: Total size of the section when loaded into memory in bytes rounded to Section Alignment. If this value is greater than Size of Raw Data, the section is zero-padded. e.g. 0x00009584
+ writeInt32 os textSectionAddr // VirtualAddress For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. e.g. 0x00020000
+ writeInt32 os textSectionPhysSize // SizeOfRawData Size of the initialized data on disk in bytes, shall be a multiple of FileAlignment from the PE header. If this is less than VirtualSize the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized data, this field should be 0. 0x00009600
+ writeInt32 os textSectionPhysLoc // PointerToRawData RVA to section’s first page within the PE file. This shall be a multiple of FileAlignment from the optional header. When a section contains only uninitialized data, this field should be 0. e.g. 00000200
// 00000190
- writeInt32 os 0x00; // PointerToRelocations RVA of Relocation section.
- writeInt32 os 0x00; // PointerToLinenumbers Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // PointerToRelocations RVA of Relocation section.
+ writeInt32 os 0x00 // PointerToLinenumbers Always 0 (see Section 23.1).
// 00000198
- writeInt32AsUInt16 os 0x00;// NumberOfRelocations Number of relocations, set to 0 if unused.
- writeInt32AsUInt16 os 0x00; // NumberOfLinenumbers Always 0 (see Section 23.1).
- writeBytes os [| 0x20uy; 0x00uy; 0x00uy; 0x60uy |]; // Characteristics Flags describing section’s characteristics, see below. IMAGE_SCN_CNT_CODE || IMAGE_SCN_MEM_EXECUTE || IMAGE_SCN_MEM_READ
+ writeInt32AsUInt16 os 0x00// NumberOfRelocations Number of relocations, set to 0 if unused.
+ writeInt32AsUInt16 os 0x00 // NumberOfLinenumbers Always 0 (see Section 23.1).
+ writeBytes os [| 0x20uy; 0x00uy; 0x00uy; 0x60uy |] // Characteristics Flags describing section’s characteristics, see below. IMAGE_SCN_CNT_CODE || IMAGE_SCN_MEM_EXECUTE || IMAGE_SCN_MEM_READ
- write (Some dataSectionHeaderChunk.addr) os "data section header" [| |];
+ write (Some dataSectionHeaderChunk.addr) os "data section header" [| |]
// 000001a0
- writeBytes os [| 0x2euy; 0x72uy; 0x73uy; 0x72uy; 0x63uy; 0x00uy; 0x00uy; 0x00uy; |]; // ".rsrc\000\000\000"
- // writeBytes os [| 0x2e; 0x73; 0x64; 0x61; 0x74; 0x61; 0x00; 0x00; |]; // ".sdata\000\000"
- writeInt32 os dataSectionSize; // VirtualSize: Total size of the section when loaded into memory in bytes rounded to Section Alignment. If this value is greater than Size of Raw Data, the section is zero-padded. e.g. 0x0000000c
- writeInt32 os dataSectionAddr; // VirtualAddress For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. e.g. 0x0000c000
+ writeBytes os [| 0x2euy; 0x72uy; 0x73uy; 0x72uy; 0x63uy; 0x00uy; 0x00uy; 0x00uy; |] // ".rsrc\000\000\000"
+ // writeBytes os [| 0x2e; 0x73; 0x64; 0x61; 0x74; 0x61; 0x00; 0x00; |] // ".sdata\000\000"
+ writeInt32 os dataSectionSize // VirtualSize: Total size of the section when loaded into memory in bytes rounded to Section Alignment. If this value is greater than Size of Raw Data, the section is zero-padded. e.g. 0x0000000c
+ writeInt32 os dataSectionAddr // VirtualAddress For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. e.g. 0x0000c000
// 000001b0
- writeInt32 os dataSectionPhysSize; // SizeOfRawData Size of the initialized data on disk in bytes, shall be a multiple of FileAlignment from the PE header. If this is less than VirtualSize the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized data, this field should be 0. e.g. 0x00000200
- writeInt32 os dataSectionPhysLoc; // PointerToRawData QUERY: Why does ECMA say "RVA" here? Offset to section’s first page within the PE file. This shall be a multiple of FileAlignment from the optional header. When a section contains only uninitialized data, this field should be 0. e.g. 0x00009800
+ writeInt32 os dataSectionPhysSize // SizeOfRawData Size of the initialized data on disk in bytes, shall be a multiple of FileAlignment from the PE header. If this is less than VirtualSize the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized data, this field should be 0. e.g. 0x00000200
+ writeInt32 os dataSectionPhysLoc // PointerToRawData QUERY: Why does ECMA say "RVA" here? Offset to section’s first page within the PE file. This shall be a multiple of FileAlignment from the optional header. When a section contains only uninitialized data, this field should be 0. e.g. 0x00009800
// 000001b8
- writeInt32 os 0x00; // PointerToRelocations RVA of Relocation section.
- writeInt32 os 0x00; // PointerToLinenumbers Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // PointerToRelocations RVA of Relocation section.
+ writeInt32 os 0x00 // PointerToLinenumbers Always 0 (see Section 23.1).
// 000001c0
- writeInt32AsUInt16 os 0x00; // NumberOfRelocations Number of relocations, set to 0 if unused.
- writeInt32AsUInt16 os 0x00; // NumberOfLinenumbers Always 0 (see Section 23.1).
- writeBytes os [| 0x40uy; 0x00uy; 0x00uy; 0x40uy |]; // Characteristics Flags: IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA
+ writeInt32AsUInt16 os 0x00 // NumberOfRelocations Number of relocations, set to 0 if unused.
+ writeInt32AsUInt16 os 0x00 // NumberOfLinenumbers Always 0 (see Section 23.1).
+ writeBytes os [| 0x40uy; 0x00uy; 0x00uy; 0x40uy |] // Characteristics Flags: IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA
- write (Some relocSectionHeaderChunk.addr) os "reloc section header" [| |];
+ write (Some relocSectionHeaderChunk.addr) os "reloc section header" [| |]
// 000001a0
- writeBytes os [| 0x2euy; 0x72uy; 0x65uy; 0x6cuy; 0x6fuy; 0x63uy; 0x00uy; 0x00uy; |]; // ".reloc\000\000"
- writeInt32 os relocSectionSize; // VirtualSize: Total size of the section when loaded into memory in bytes rounded to Section Alignment. If this value is greater than Size of Raw Data, the section is zero-padded. e.g. 0x0000000c
- writeInt32 os relocSectionAddr; // VirtualAddress For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. e.g. 0x0000c000
+ writeBytes os [| 0x2euy; 0x72uy; 0x65uy; 0x6cuy; 0x6fuy; 0x63uy; 0x00uy; 0x00uy; |] // ".reloc\000\000"
+ writeInt32 os relocSectionSize // VirtualSize: Total size of the section when loaded into memory in bytes rounded to Section Alignment. If this value is greater than Size of Raw Data, the section is zero-padded. e.g. 0x0000000c
+ writeInt32 os relocSectionAddr // VirtualAddress For executable images this is the address of the first byte of the section, when loaded into memory, relative to the image base. e.g. 0x0000c000
// 000001b0
- writeInt32 os relocSectionPhysSize; // SizeOfRawData Size of the initialized reloc on disk in bytes, shall be a multiple of FileAlignment from the PE header. If this is less than VirtualSize the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized reloc, this field should be 0. e.g. 0x00000200
- writeInt32 os relocSectionPhysLoc; // PointerToRawData QUERY: Why does ECMA say "RVA" here? Offset to section’s first page within the PE file. This shall be a multiple of FileAlignment from the optional header. When a section contains only uninitialized reloc, this field should be 0. e.g. 0x00009800
+ writeInt32 os relocSectionPhysSize // SizeOfRawData Size of the initialized reloc on disk in bytes, shall be a multiple of FileAlignment from the PE header. If this is less than VirtualSize the remainder of the section is zero filled. Because this field is rounded while the VirtualSize field is not it is possible for this to be greater than VirtualSize as well. When a section contains only uninitialized reloc, this field should be 0. e.g. 0x00000200
+ writeInt32 os relocSectionPhysLoc // PointerToRawData QUERY: Why does ECMA say "RVA" here? Offset to section’s first page within the PE file. This shall be a multiple of FileAlignment from the optional header. When a section contains only uninitialized reloc, this field should be 0. e.g. 0x00009800
// 000001b8
- writeInt32 os 0x00; // PointerToRelocations RVA of Relocation section.
- writeInt32 os 0x00; // PointerToLinenumbers Always 0 (see Section 23.1).
+ writeInt32 os 0x00 // PointerToRelocations RVA of Relocation section.
+ writeInt32 os 0x00 // PointerToLinenumbers Always 0 (see Section 23.1).
// 000001c0
- writeInt32AsUInt16 os 0x00; // NumberOfRelocations Number of relocations, set to 0 if unused.
- writeInt32AsUInt16 os 0x00; // NumberOfLinenumbers Always 0 (see Section 23.1).
- writeBytes os [| 0x40uy; 0x00uy; 0x00uy; 0x42uy |]; // Characteristics Flags: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
+ writeInt32AsUInt16 os 0x00 // NumberOfRelocations Number of relocations, set to 0 if unused.
+ writeInt32AsUInt16 os 0x00 // NumberOfLinenumbers Always 0 (see Section 23.1).
+ writeBytes os [| 0x40uy; 0x00uy; 0x00uy; 0x42uy |] // Characteristics Flags: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
- writePadding os "pad to text begin" (textSectionPhysLoc - headerSize);
+ writePadding os "pad to text begin" (textSectionPhysLoc - headerSize)
// TEXT SECTION: e.g. 0x200
let textV2P v = v - textSectionAddr + textSectionPhysLoc
// e.g. 0x0200
- write (Some (textV2P importAddrTableChunk.addr)) os "import addr table" [| |];
- writeInt32 os importNameHintTableChunk.addr;
- writeInt32 os 0x00; // QUERY 4 bytes of zeros not 2 like ECMA 24.3.1 says
+ write (Some (textV2P importAddrTableChunk.addr)) os "import addr table" [| |]
+ writeInt32 os importNameHintTableChunk.addr
+ writeInt32 os 0x00 // QUERY 4 bytes of zeros not 2 like ECMA 24.3.1 says
// e.g. 0x0208
@@ -4340,106 +4338,106 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
let headerVersionMajor,headerVersionMinor = headerVersionSupportedByCLRVersion desiredMetadataVersion
writePadding os "pad to cli header" cliHeaderPadding
- write (Some (textV2P cliHeaderChunk.addr)) os "cli header" [| |];
- writeInt32 os 0x48; // size of header
- writeInt32AsUInt16 os headerVersionMajor; // Major part of minimum version of CLR reqd.
- writeInt32AsUInt16 os headerVersionMinor; // Minor part of minimum version of CLR reqd. ...
+ write (Some (textV2P cliHeaderChunk.addr)) os "cli header" [| |]
+ writeInt32 os 0x48 // size of header
+ writeInt32AsUInt16 os headerVersionMajor // Major part of minimum version of CLR reqd.
+ writeInt32AsUInt16 os headerVersionMinor // Minor part of minimum version of CLR reqd. ...
// e.g. 0x0210
- writeDirectory os metadataChunk;
- writeInt32 os flags;
+ writeDirectory os metadataChunk
+ writeInt32 os flags
- writeInt32 os entryPointToken;
- write None os "rest of cli header" [| |];
+ writeInt32 os entryPointToken
+ write None os "rest of cli header" [| |]
// e.g. 0x0220
- writeDirectory os resourcesChunk;
- writeDirectory os strongnameChunk;
+ writeDirectory os resourcesChunk
+ writeDirectory os strongnameChunk
// e.g. 0x0230
- writeInt32 os 0x00; // code manager table, always 0
- writeInt32 os 0x00; // code manager table, always 0
- writeDirectory os vtfixupsChunk;
+ writeInt32 os 0x00 // code manager table, always 0
+ writeInt32 os 0x00 // code manager table, always 0
+ writeDirectory os vtfixupsChunk
// e.g. 0x0240
- writeInt32 os 0x00; // export addr table jumps, always 0
- writeInt32 os 0x00; // export addr table jumps, always 0
- writeInt32 os 0x00; // managed native header, always 0
- writeInt32 os 0x00; // managed native header, always 0
+ writeInt32 os 0x00 // export addr table jumps, always 0
+ writeInt32 os 0x00 // export addr table jumps, always 0
+ writeInt32 os 0x00 // managed native header, always 0
+ writeInt32 os 0x00 // managed native header, always 0
- writeBytes os code;
- write None os "code padding" codePadding;
+ writeBytes os code
+ write None os "code padding" codePadding
- writeBytes os metadata;
+ writeBytes os metadata
// write 0x80 bytes of empty space for encrypted SHA1 hash, written by SN.EXE or call to signing API
if signer <> None then
- write (Some (textV2P strongnameChunk.addr)) os "strongname" (Array.create strongnameChunk.size 0x0uy);
+ write (Some (textV2P strongnameChunk.addr)) os "strongname" (Array.create strongnameChunk.size 0x0uy)
- write (Some (textV2P resourcesChunk.addr)) os "raw resources" [| |];
- writeBytes os resources;
- write (Some (textV2P rawdataChunk.addr)) os "raw data" [| |];
- writeBytes os data;
+ write (Some (textV2P resourcesChunk.addr)) os "raw resources" [| |]
+ writeBytes os resources
+ write (Some (textV2P rawdataChunk.addr)) os "raw data" [| |]
+ writeBytes os data
writePadding os "start of import table" importTableChunkPrePadding
// vtfixups would go here
- write (Some (textV2P importTableChunk.addr)) os "import table" [| |];
+ write (Some (textV2P importTableChunk.addr)) os "import table" [| |]
- writeInt32 os importLookupTableChunk.addr;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
- writeInt32 os mscoreeStringChunk.addr;
- writeInt32 os importAddrTableChunk.addr;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
+ writeInt32 os importLookupTableChunk.addr
+ writeInt32 os 0x00
+ writeInt32 os 0x00
+ writeInt32 os mscoreeStringChunk.addr
+ writeInt32 os importAddrTableChunk.addr
+ writeInt32 os 0x00
+ writeInt32 os 0x00
+ writeInt32 os 0x00
+ writeInt32 os 0x00
+ writeInt32 os 0x00
- write (Some (textV2P importLookupTableChunk.addr)) os "import lookup table" [| |];
- writeInt32 os importNameHintTableChunk.addr;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
- writeInt32 os 0x00;
+ write (Some (textV2P importLookupTableChunk.addr)) os "import lookup table" [| |]
+ writeInt32 os importNameHintTableChunk.addr
+ writeInt32 os 0x00
+ writeInt32 os 0x00
+ writeInt32 os 0x00
+ writeInt32 os 0x00
- write (Some (textV2P importNameHintTableChunk.addr)) os "import name hint table" [| |];
+ write (Some (textV2P importNameHintTableChunk.addr)) os "import name hint table" [| |]
// Two zero bytes of hint, then Case sensitive, null-terminated ASCII string containing name to import.
// Shall _CorExeMain a .exe file _CorDllMain for a .dll file.
if isDll then
writeBytes os [| 0x00uy; 0x00uy; 0x5fuy; 0x43uy ; 0x6fuy; 0x72uy; 0x44uy; 0x6cuy; 0x6cuy; 0x4duy; 0x61uy; 0x69uy; 0x6euy; 0x00uy |]
else
- writeBytes os [| 0x00uy; 0x00uy; 0x5fuy; 0x43uy; 0x6fuy; 0x72uy; 0x45uy; 0x78uy; 0x65uy; 0x4duy; 0x61uy; 0x69uy; 0x6euy; 0x00uy |];
+ writeBytes os [| 0x00uy; 0x00uy; 0x5fuy; 0x43uy; 0x6fuy; 0x72uy; 0x45uy; 0x78uy; 0x65uy; 0x4duy; 0x61uy; 0x69uy; 0x6euy; 0x00uy |]
write (Some (textV2P mscoreeStringChunk.addr)) os "mscoree string"
- [| 0x6duy; 0x73uy; 0x63uy; 0x6fuy ; 0x72uy; 0x65uy ; 0x65uy; 0x2euy ; 0x64uy; 0x6cuy ; 0x6cuy; 0x00uy ; |];
+ [| 0x6duy; 0x73uy; 0x63uy; 0x6fuy ; 0x72uy; 0x65uy ; 0x65uy; 0x2euy ; 0x64uy; 0x6cuy ; 0x6cuy; 0x00uy ; |]
- writePadding os "end of import tab" importTableChunkPadding;
+ writePadding os "end of import tab" importTableChunkPadding
- writePadding os "head of entrypoint" 0x03;
+ writePadding os "head of entrypoint" 0x03
let ep = (imageBaseReal + textSectionAddr)
write (Some (textV2P entrypointCodeChunk.addr)) os " entrypoint code"
- [| 0xFFuy; 0x25uy; (* x86 Instructions for entry *) b0 ep; b1 ep; b2 ep; b3 ep |];
+ [| 0xFFuy; 0x25uy; (* x86 Instructions for entry *) b0 ep; b1 ep; b2 ep; b3 ep |]
if isItanium then
write (Some (textV2P globalpointerCodeChunk.addr)) os " itanium global pointer"
- [| 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy |];
+ [| 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy; 0x0uy |]
if pdbfile.IsSome then
- write (Some (textV2P debugDirectoryChunk.addr)) os "debug directory" (Array.create sizeof_IMAGE_DEBUG_DIRECTORY 0x0uy);
- write (Some (textV2P debugDataChunk.addr)) os "debug data" (Array.create debugDataChunk.size 0x0uy);
+ write (Some (textV2P debugDirectoryChunk.addr)) os "debug directory" (Array.create sizeof_IMAGE_DEBUG_DIRECTORY 0x0uy)
+ write (Some (textV2P debugDataChunk.addr)) os "debug data" (Array.create debugDataChunk.size 0x0uy)
- writePadding os "end of .text" (dataSectionPhysLoc - textSectionPhysLoc - textSectionSize);
+ writePadding os "end of .text" (dataSectionPhysLoc - textSectionPhysLoc - textSectionSize)
// DATA SECTION
match nativeResources with
| [||] -> ()
| resources ->
- write (Some (dataSectionVirtToPhys nativeResourcesChunk.addr)) os "raw native resources" [| |];
- writeBytes os resources;
+ write (Some (dataSectionVirtToPhys nativeResourcesChunk.addr)) os "raw native resources" [| |]
+ writeBytes os resources
if dummydatap.size <> 0x0 then
- write (Some (dataSectionVirtToPhys dummydatap.addr)) os "dummy data" [| 0x0uy |];
+ write (Some (dataSectionVirtToPhys dummydatap.addr)) os "dummy data" [| 0x0uy |]
- writePadding os "end of .rsrc" (relocSectionPhysLoc - dataSectionPhysLoc - dataSectionSize);
+ writePadding os "end of .rsrc" (relocSectionPhysLoc - dataSectionPhysLoc - dataSectionSize)
// RELOC SECTION
@@ -4461,10 +4459,10 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
[| b0 entrypointFixupBlock; b1 entrypointFixupBlock; b2 entrypointFixupBlock; b3 entrypointFixupBlock;
0x0cuy; 0x00uy; 0x00uy; 0x00uy;
b0 reloc; b1 reloc;
- b0 reloc2; b1 reloc2; |];
- writePadding os "end of .reloc" (imageEndSectionPhysLoc - relocSectionPhysLoc - relocSectionSize);
+ b0 reloc2; b1 reloc2; |]
+ writePadding os "end of .reloc" (imageEndSectionPhysLoc - relocSectionPhysLoc - relocSectionSize)
- os.Close();
+ os.Close()
try
FileSystemUtilites.setExecutablePermission outfile
@@ -4475,13 +4473,13 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
// Looks like a finally...
with e ->
(try
- os.Close();
+ os.Close()
FileSystem.FileDelete outfile
- with _ -> ());
+ with _ -> ())
reraise()
- reportTime showTimes "Writing Image";
+ reportTime showTimes "Writing Image"
if dumpDebugInfo then
DumpDebugInfo outfile pdbData
@@ -4495,113 +4493,74 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
| Some fpdb ->
try
let idd = WritePdbInfo fixupOverlappingSequencePoints showTimes outfile fpdb pdbData
- reportTime showTimes "Generate PDB Info";
+ reportTime showTimes "Generate PDB Info"
// Now we have the debug data we can go back and fill in the debug directory in the image
let fs2 = new FileStream(outfile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read, 0x1000, false)
let os2 = new BinaryWriter(fs2)
try
// write the IMAGE_DEBUG_DIRECTORY
- os2.BaseStream.Seek (int64 (textV2P debugDirectoryChunk.addr), SeekOrigin.Begin) |> ignore;
- writeInt32 os2 idd.iddCharacteristics; // IMAGE_DEBUG_DIRECTORY.Characteristics
- writeInt32 os2 timestamp;
- writeInt32AsUInt16 os2 idd.iddMajorVersion;
- writeInt32AsUInt16 os2 idd.iddMinorVersion;
- writeInt32 os2 idd.iddType;
- writeInt32 os2 idd.iddData.Length; // IMAGE_DEBUG_DIRECTORY.SizeOfData
- writeInt32 os2 debugDataChunk.addr; // IMAGE_DEBUG_DIRECTORY.AddressOfRawData
- writeInt32 os2 (textV2P debugDataChunk.addr);// IMAGE_DEBUG_DIRECTORY.PointerToRawData
-
- (* dprintf "idd.iddCharacteristics = %ld\n" idd.iddCharacteristics;
- dprintf "iddMajorVersion = %ld\n" idd.iddMajorVersion;
- dprintf "iddMinorVersion = %ld\n" idd.iddMinorVersion;
- dprintf "iddType = %ld\n" idd.iddType;
- dprintf "iddData = (%A) = %s\n" idd.iddData (System.Text.Encoding.UTF8.GetString idd.iddData); *)
+ os2.BaseStream.Seek (int64 (textV2P debugDirectoryChunk.addr), SeekOrigin.Begin) |> ignore
+ writeInt32 os2 idd.iddCharacteristics // IMAGE_DEBUG_DIRECTORY.Characteristics
+ writeInt32 os2 timestamp
+ writeInt32AsUInt16 os2 idd.iddMajorVersion
+ writeInt32AsUInt16 os2 idd.iddMinorVersion
+ writeInt32 os2 idd.iddType
+ writeInt32 os2 idd.iddData.Length // IMAGE_DEBUG_DIRECTORY.SizeOfData
+ writeInt32 os2 debugDataChunk.addr // IMAGE_DEBUG_DIRECTORY.AddressOfRawData
+ writeInt32 os2 (textV2P debugDataChunk.addr)// IMAGE_DEBUG_DIRECTORY.PointerToRawData
+
+ (* dprintf "idd.iddCharacteristics = %ld\n" idd.iddCharacteristics
+ dprintf "iddMajorVersion = %ld\n" idd.iddMajorVersion
+ dprintf "iddMinorVersion = %ld\n" idd.iddMinorVersion
+ dprintf "iddType = %ld\n" idd.iddType
+ dprintf "iddData = (%A) = %s\n" idd.iddData (System.Text.Encoding.UTF8.GetString idd.iddData) *)
// write the debug raw data as given us by the PDB writer
- os2.BaseStream.Seek (int64 (textV2P debugDataChunk.addr), SeekOrigin.Begin) |> ignore;
+ os2.BaseStream.Seek (int64 (textV2P debugDataChunk.addr), SeekOrigin.Begin) |> ignore
if debugDataChunk.size < idd.iddData.Length then
- failwith "Debug data area is not big enough. Debug info may not be usable";
- writeBytes os2 idd.iddData;
+ failwith "Debug data area is not big enough. Debug info may not be usable"
+ writeBytes os2 idd.iddData
os2.Close()
with e ->
- failwith ("Error while writing debug directory entry: "+e.Message);
- (try os2.Close(); FileSystem.FileDelete outfile with _ -> ());
+ failwith ("Error while writing debug directory entry: "+e.Message)
+ (try os2.Close(); FileSystem.FileDelete outfile with _ -> ())
reraise()
with e ->
reraise()
- end;
- reportTime showTimes "Finalize PDB";
+ end
+ reportTime showTimes "Finalize PDB"
/// Sign the binary. No further changes to binary allowed past this point!
match signer with
| None -> ()
| Some s ->
try
- s.SignFile outfile;
+ s.SignFile outfile
s.Close()
with e ->
- failwith ("Warning: A call to StrongNameSignatureGeneration failed ("+e.Message+")");
- (try s.Close() with _ -> ());
- (try FileSystem.FileDelete outfile with _ -> ());
+ failwith ("Warning: A call to StrongNameSignatureGeneration failed ("+e.Message+")")
+ (try s.Close() with _ -> ())
+ (try FileSystem.FileDelete outfile with _ -> ())
()
- reportTime showTimes "Signing Image";
+ reportTime showTimes "Signing Image"
//Finished writing and signing the binary and debug info...
mappings
type options =
- { ilg: ILGlobals;
- pdbfile: string option;
- signer: ILStrongNameSigner option;
- fixupOverlappingSequencePoints: bool;
- emitTailcalls : bool;
- showTimes: bool;
+ { ilg: ILGlobals
+ pdbfile: string option
+ signer: ILStrongNameSigner option
+ fixupOverlappingSequencePoints: bool
+ emitTailcalls : bool
+ showTimes: bool
dumpDebugInfo:bool }
-let WriteILBinary outfile (args: options) modul noDebugData =
- ignore (writeBinaryAndReportMappings (outfile, args.ilg, args.pdbfile, args.signer, args.fixupOverlappingSequencePoints, args.emitTailcalls, args.showTimes, args.dumpDebugInfo) modul noDebugData)
-
-
-
-(******************************************************
-** Notes on supporting the Itanium **
-*******************************************************
-IA64 codegen on the CLR isn’t documented, and getting it working involved a certain amount of reverse-engineering
-peverify.exe and various binaries generated by ILAsm and other managed compiles. Here are some lessons learned,
-documented for posterity and the 0 other people writing managed compilers for the Itanium:
-
-- Even if you’re not utilizing the global pointer in your Itanium binary,
-you should be setting aside space for it in .text. (Preferably near the native stub.)
-- PEVerify checks for two .reloc table entries on the Itanium - one for the native stub, and one
-for the global pointer RVA. It doesn’t matter what you set these values to -
-their addresses can be zeroed out, but they must have IMAGE_REL_BASED_DIR64 set!
-(So, yes, you may find yourself setting this flag on an empty, unnecessary table slot!)
-- On the Itanium, it’s best to have your tables qword aligned. (Though, peverify checks for dword alignment.)
-- A different, weird set of DLL characteristics are necessary for the Itanium.
-I won’t detail them here, but it’s interesting given that this field isn’t supposed to vary between platforms,
-and is supposedly marked as deprecated.
-- There are two schools to generating CLR binaries on for the Itanium - I’ll call them the “ALink” school
-and the “ILAsm” school.
- - The ALink school relies on some quirks in the CLR to omit a lot of stuff that, admittedly, isn’t necessary. The binaries are basically IL-only, with some flags set to make them nominally Itanium:
- - It omits the .reloc table
- - It doesn’t set aside memory for global pointer storage
- - There’s no native stub
- - There’s no import table, mscoree reference / startup symbol hint
- - A manifest is inserted by default.
- These omissions are understandable, given the platform/jitting/capabilities of the language,
- but they’re basically relying on an idiosyncracy of the runtime to get away with creating a “bad” binary.
-
- - The ILAsm school actually writes everything out:
- - It has a reloc table with the requisite two entries
- - It sets aside memory for a global pointer, even if it doesn’t utilize one
- - It actually inserts a native stub for the Itanium! (Though, I have no idea what
- instructions, specifically, are emitted, and I couldn’t dig up the sources to ILAsm to
- find out)
- - There’s the requisite mscoree reference, etc.
- - No manifest is inserted
-*******************************************************)
+let WriteILBinary (outfile, args, ilModule, noDebugData) =
+ ignore (writeBinaryAndReportMappings (outfile, args.ilg, args.pdbfile, args.signer, args.fixupOverlappingSequencePoints, args.emitTailcalls, args.showTimes, args.dumpDebugInfo) ilModule noDebugData)
+
diff --git a/src/absil/ilwrite.fsi b/src/absil/ilwrite.fsi
index f63a65278ec..2d9f6e4385e 100644
--- a/src/absil/ilwrite.fsi
+++ b/src/absil/ilwrite.fsi
@@ -16,21 +16,16 @@ type ILStrongNameSigner =
static member OpenKeyContainer: string -> ILStrongNameSigner
type options =
- { ilg: ILGlobals
- pdbfile: string option;
- signer : ILStrongNameSigner option;
- fixupOverlappingSequencePoints : bool;
- emitTailcalls: bool;
- showTimes : bool;
- dumpDebugInfo : bool }
+ { ilg: ILGlobals
+ pdbfile: string option
+ signer : ILStrongNameSigner option
+ fixupOverlappingSequencePoints : bool
+ emitTailcalls: bool
+ showTimes : bool
+ dumpDebugInfo : bool }
/// Write a binary to the file system. Extra configuration parameters can also be specified.
-val WriteILBinary:
- filename: string ->
- options: options ->
- input: ILModuleDef ->
- noDebugData: bool ->
- unit
+val WriteILBinary: filename: string * options: options * input: ILModuleDef * noDebugData: bool -> unit
diff --git a/src/absil/ilx.fsi b/src/absil/ilx.fsi
index c624db6d941..ea016c38e8e 100644
--- a/src/absil/ilx.fsi
+++ b/src/absil/ilx.fsi
@@ -89,7 +89,7 @@ type IlxClosureApps =
| Apps_app of ILType * IlxClosureApps
| Apps_done of ILType
-/// ILX extensions to the intruction set
+/// ILX extensions to the instruction set
///
type IlxInstr =
diff --git a/src/fsharp/augment.fs b/src/fsharp/AugmentWithHashCompare.fs
similarity index 98%
rename from src/fsharp/augment.fs
rename to src/fsharp/AugmentWithHashCompare.fs
index 41c8e225d26..5b750bc75ff 100644
--- a/src/fsharp/augment.fs
+++ b/src/fsharp/AugmentWithHashCompare.fs
@@ -1,7 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// Generate the hash/compare functions we add to user-defined types by default.
-module internal Microsoft.FSharp.Compiler.Augment
+module internal Microsoft.FSharp.Compiler.AugmentWithHashCompare
+
open Internal.Utilities
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.AbstractIL
@@ -14,7 +15,7 @@ open Microsoft.FSharp.Compiler.Ast
open Microsoft.FSharp.Compiler.ErrorLogger
open Microsoft.FSharp.Compiler.PrettyNaming
open Microsoft.FSharp.Compiler.Lib
-open Microsoft.FSharp.Compiler.Env
+open Microsoft.FSharp.Compiler.TcGlobals
open Microsoft.FSharp.Compiler.Infos
let mkIComparableCompareToSlotSig g =
@@ -189,7 +190,7 @@ let mkRecdCompare g tcref (tycon:Tycon) =
let compe = mkILCallGetComparer g m
let mkTest (fspec:RecdField) =
let fty = fspec.FormalType
- let fref = mkNestedRecdFieldRef tcref fspec
+ let fref = tcref.MakeNestedRecdFieldRef fspec
let m = fref.Range
mkCallGenericComparisonWithComparerOuter g m fty
compe
@@ -213,7 +214,7 @@ let mkRecdCompareWithComparer g tcref (tycon:Tycon) (_thisv,thise) (_,thate) com
let mkTest (fspec:RecdField) =
let fty = fspec.FormalType
- let fref = mkNestedRecdFieldRef tcref fspec
+ let fref = tcref.MakeNestedRecdFieldRef fspec
let m = fref.Range
mkCallGenericComparisonWithComparerOuter g m fty
compe
@@ -237,7 +238,7 @@ let mkRecdEquality g tcref (tycon:Tycon) =
let thisv,thatv,thise,thate = mkThisVarThatVar g m ty
let mkTest (fspec:RecdField) =
let fty = fspec.FormalType
- let fref = mkNestedRecdFieldRef tcref fspec
+ let fref = tcref.MakeNestedRecdFieldRef fspec
let m = fref.Range
mkCallGenericEqualityEROuter g m fty
(mkRecdFieldGetViaExprAddr(thise, fref, tinst, m))
@@ -258,7 +259,7 @@ let mkRecdEqualityWithComparer g tcref (tycon:Tycon) (_thisv,thise) thatobje (th
let mkTest (fspec:RecdField) =
let fty = fspec.FormalType
- let fref = mkNestedRecdFieldRef tcref fspec
+ let fref = tcref.MakeNestedRecdFieldRef fspec
let m = fref.Range
mkCallGenericEqualityWithComparerOuter g m fty
@@ -338,7 +339,7 @@ let mkUnionCompare g tcref (tycon:Tycon) =
let expr =
let mbuilder = new MatchBuilder(NoSequencePointAtInvisibleBinding,m )
let mkCase ucase =
- let cref = mkNestedUnionCaseRef tcref ucase
+ let cref = tcref.MakeNestedUnionCaseRef ucase
let m = cref.Range
let thisucv,thisucve = mkCompGenLocal m "thisCast" (mkProvenUnionCaseTy cref tinst)
let thatucv,thatucve = mkCompGenLocal m "objCast" (mkProvenUnionCaseTy cref tinst)
@@ -395,7 +396,7 @@ let mkUnionCompareWithComparer g tcref (tycon:Tycon) (_thisv,thise) (thatv,thate
let expr =
let mbuilder = new MatchBuilder(NoSequencePointAtInvisibleBinding,m )
let mkCase ucase =
- let cref = mkNestedUnionCaseRef tcref ucase
+ let cref = tcref.MakeNestedUnionCaseRef ucase
let m = cref.Range
let thisucv,thisucve = mkCompGenLocal m "thisCastu" (mkProvenUnionCaseTy cref tinst)
let thatucv,thatucve = mkCompGenLocal m "thatCastu" (mkProvenUnionCaseTy cref tinst)
@@ -454,7 +455,7 @@ let mkUnionEquality g tcref (tycon:Tycon) =
let expr =
let mbuilder = new MatchBuilder(NoSequencePointAtInvisibleBinding,m )
let mkCase ucase =
- let cref = mkNestedUnionCaseRef tcref ucase
+ let cref = tcref.MakeNestedUnionCaseRef ucase
let m = cref.Range
let thisucv,thisucve = mkCompGenLocal m "thisCast" (mkProvenUnionCaseTy cref tinst)
let thatucv,thatucve = mkCompGenLocal m "objCast" (mkProvenUnionCaseTy cref tinst)
@@ -509,7 +510,7 @@ let mkUnionEqualityWithComparer g tcref (tycon:Tycon) (_thisv,thise) thatobje (t
let expr =
let mbuilder = new MatchBuilder(NoSequencePointAtInvisibleBinding,m )
let mkCase ucase =
- let cref = mkNestedUnionCaseRef tcref ucase
+ let cref = tcref.MakeNestedUnionCaseRef ucase
let m = cref.Range
let thisucv,thisucve = mkCompGenLocal m "thisCastu" (mkProvenUnionCaseTy cref tinst)
let thatucv,thatucve = mkCompGenLocal m "thatCastu" (mkProvenUnionCaseTy cref tinst)
@@ -566,7 +567,7 @@ let mkRecdHashWithComparer g tcref (tycon:Tycon) compe =
let thisv,thise = mkThisVar g m ty
let mkFieldHash (fspec:RecdField) =
let fty = fspec.FormalType
- let fref = mkNestedRecdFieldRef tcref fspec
+ let fref = tcref.MakeNestedRecdFieldRef fspec
let m = fref.Range
let e = mkRecdFieldGetViaExprAddr(thise, fref, tinst, m)
@@ -604,7 +605,7 @@ let mkUnionHashWithComparer g tcref (tycon:Tycon) compe =
let mbuilder = new MatchBuilder(NoSequencePointAtInvisibleBinding,m )
let accv,acce = mkMutableCompGenLocal m "i" g.int_ty
let mkCase i ucase1 =
- let c1ref = mkNestedUnionCaseRef tcref ucase1
+ let c1ref = tcref.MakeNestedUnionCaseRef ucase1
let ucv,ucve = mkCompGenLocal m "unionCase" (mkProvenUnionCaseTy c1ref tinst)
let m = c1ref.Range
let mkHash j (rfield:RecdField) =
@@ -817,7 +818,7 @@ let TyconIsCandidateForAugmentationWithHash g tycon = TyconIsCandidateForAugment
// IComparable semantics associated with F# types.
//-------------------------------------------------------------------------
-let slotImplMethod (final,c,slotsig) =
+let slotImplMethod (final,c,slotsig) : ValMemberInfo =
{ ImplementedSlotSigs=[slotsig];
MemberFlags=
{ IsInstance=true;
@@ -828,7 +829,7 @@ let slotImplMethod (final,c,slotsig) =
IsImplemented=false;
ApparentParent=c}
-let nonVirtualMethod c =
+let nonVirtualMethod c : ValMemberInfo =
{ ImplementedSlotSigs=[];
MemberFlags={ IsInstance=true;
IsDispatchSlot=false;
diff --git a/src/fsharp/augment.fsi b/src/fsharp/AugmentWithHashCompare.fsi
similarity index 94%
rename from src/fsharp/augment.fsi
rename to src/fsharp/AugmentWithHashCompare.fsi
index 602c0cc2bc0..5d0e7220be1 100644
--- a/src/fsharp/augment.fsi
+++ b/src/fsharp/AugmentWithHashCompare.fsi
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// Generate the hash/compare functions we add to user-defined types by default.
-module internal Microsoft.FSharp.Compiler.Augment
+module internal Microsoft.FSharp.Compiler.AugmentWithHashCompare
open Internal.Utilities
open Microsoft.FSharp.Compiler.AbstractIL
@@ -9,7 +9,7 @@ open Microsoft.FSharp.Compiler.AbstractIL.Internal
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.Tast
-open Microsoft.FSharp.Compiler.Env
+open Microsoft.FSharp.Compiler.TcGlobals
val CheckAugmentationAttribs : bool -> TcGlobals -> Import.ImportMap -> Tycon -> unit
val TyconIsCandidateForAugmentationWithCompare : TcGlobals -> Tycon -> bool
diff --git a/src/fsharp/formats.fs b/src/fsharp/CheckFormatStrings.fs
similarity index 95%
rename from src/fsharp/formats.fs
rename to src/fsharp/CheckFormatStrings.fs
index 12e79af2674..e9b6ce653b8 100644
--- a/src/fsharp/formats.fs
+++ b/src/fsharp/CheckFormatStrings.fs
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-module internal Microsoft.FSharp.Compiler.Formats
+module internal Microsoft.FSharp.Compiler.CheckFormatStrings
open Internal.Utilities
open Microsoft.FSharp.Compiler
@@ -11,7 +11,7 @@ open Microsoft.FSharp.Compiler.Ast
open Microsoft.FSharp.Compiler.ErrorLogger
open Microsoft.FSharp.Compiler.Tast
open Microsoft.FSharp.Compiler.Tastops
-open Microsoft.FSharp.Compiler.Env
+open Microsoft.FSharp.Compiler.TcGlobals
open Microsoft.FSharp.Compiler.ConstraintSolver
type FormatItem = Simple of TType | FuncAndVal
@@ -48,7 +48,7 @@ let newInfo ()=
addZeros = false;
precision = false}
-let ParseFormatString m g fmt bty cty dty =
+let parseFormatStringInternal m g fmt bty cty =
let len = String.length fmt
let rec parseLoop acc i =
@@ -58,10 +58,7 @@ let ParseFormatString m g fmt bty cty dty =
acc |> List.map snd |> List.rev
else
failwithf "%s" <| FSComp.SR.forPositionalSpecifiersNotPermitted()
-
- let aty = List.foldBack (-->) argtys dty
- let ety = mkTupledTy g argtys
- aty,ety
+ argtys
elif System.Char.IsSurrogatePair(fmt,i) then
parseLoop acc (i+2)
else
@@ -230,3 +227,16 @@ let ParseFormatString m g fmt bty cty dty =
| _ -> parseLoop acc (i+1)
parseLoop [] 0
+let ParseFormatString m g fmt bty cty dty =
+ let argtys = parseFormatStringInternal m g fmt bty cty
+ let aty = List.foldBack (-->) argtys dty
+ let ety = mkTupledTy g argtys
+ aty, ety
+
+let TryCountFormatStringArguments m g fmt bty cty =
+ try
+ parseFormatStringInternal m g fmt bty cty
+ |> List.length
+ |> Some
+ with _ ->
+ None
\ No newline at end of file
diff --git a/src/fsharp/formats.fsi b/src/fsharp/CheckFormatStrings.fsi
similarity index 62%
rename from src/fsharp/formats.fsi
rename to src/fsharp/CheckFormatStrings.fsi
index 1016ef34cc4..5dbe56e3321 100644
--- a/src/fsharp/formats.fsi
+++ b/src/fsharp/CheckFormatStrings.fsi
@@ -5,11 +5,14 @@
///
/// Must be updated if the Printf runtime component is updated.
-module internal Microsoft.FSharp.Compiler.Formats
+module internal Microsoft.FSharp.Compiler.CheckFormatStrings
open Internal.Utilities
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.Tast
+open Microsoft.FSharp.Compiler.TcGlobals
open Microsoft.FSharp.Compiler.AbstractIL.Internal
-val ParseFormatString : Range.range -> Env.TcGlobals -> string -> TType -> TType -> TType -> TType * TType
+val ParseFormatString : Range.range -> TcGlobals -> string -> TType -> TType -> TType -> TType * TType
+
+val TryCountFormatStringArguments : m:Range.range -> g:TcGlobals -> fmt:string -> bty:TType -> cty:TType -> int option
diff --git a/src/fsharp/build.fs b/src/fsharp/CompileOps.fs
similarity index 89%
rename from src/fsharp/build.fs
rename to src/fsharp/CompileOps.fs
index cda122e9a8d..f1804370554 100644
--- a/src/fsharp/build.fs
+++ b/src/fsharp/CompileOps.fs
@@ -1,28 +1,28 @@
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-/// Loading initial context, reporting errors etc.
-module internal Microsoft.FSharp.Compiler.Build
+/// Coordinating compiler operations - configuration, loading initial context, reporting errors etc.
+module internal Microsoft.FSharp.Compiler.CompileOps
+
open System
open System.Text
open System.IO
open System.Collections.Generic
open Internal.Utilities
open Internal.Utilities.Text
+open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.AbstractIL
open Microsoft.FSharp.Compiler.AbstractIL.IL
open Microsoft.FSharp.Compiler.AbstractIL.Internal
open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
open Microsoft.FSharp.Compiler.AbstractIL.Extensions.ILX
open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
-open Microsoft.FSharp.Compiler.Pickle
+open Microsoft.FSharp.Compiler.TastPickle
open Microsoft.FSharp.Compiler.Range
-open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.TypeChecker
open Microsoft.FSharp.Compiler.SR
open Microsoft.FSharp.Compiler.DiagnosticMessage
module Tc = Microsoft.FSharp.Compiler.TypeChecker
-module SR = Microsoft.FSharp.Compiler.SR
open Microsoft.FSharp.Compiler.AbstractIL.IL
open Microsoft.FSharp.Compiler.Range
@@ -31,14 +31,14 @@ open Microsoft.FSharp.Compiler.ErrorLogger
open Microsoft.FSharp.Compiler.Tast
open Microsoft.FSharp.Compiler.Tastops
open Microsoft.FSharp.Compiler.Tastops.DebugPrint
-open Microsoft.FSharp.Compiler.Env
+open Microsoft.FSharp.Compiler.TcGlobals
open Microsoft.FSharp.Compiler.Lexhelp
open Microsoft.FSharp.Compiler.Lib
open Microsoft.FSharp.Compiler.Infos
open Microsoft.FSharp.Compiler.ConstraintSolver
open Microsoft.FSharp.Compiler.MSBuildResolver
-open Microsoft.FSharp.Compiler.Typrelns
-open Microsoft.FSharp.Compiler.Nameres
+open Microsoft.FSharp.Compiler.TypeRelations
+open Microsoft.FSharp.Compiler.NameResolution
open Microsoft.FSharp.Compiler.PrettyNaming
open Internal.Utilities.FileSystem
open Internal.Utilities.Collections
@@ -71,13 +71,13 @@ open FullCompiler
// Some Globals
//--------------------------------------------------------------------------
-let sigSuffixes = [".mli";".fsi"]
+let FSharpSigFileSuffixes = [".mli";".fsi"]
let mlCompatSuffixes = [".mli";".ml"]
-let implSuffixes = [".ml";".fs";".fsscript";".fsx"]
+let FSharpImplFileSuffixes = [".ml";".fs";".fsscript";".fsx"]
let resSuffixes = [".resx"]
-let scriptSuffixes = [".fsscript";".fsx"]
-let doNotRequireNamespaceOrModuleSuffixes = [".mli";".ml"] @ scriptSuffixes
-let lightSyntaxDefaultExtensions : string list = [ ".fs";".fsscript";".fsx";".fsi" ]
+let FSharpScriptFileSuffixes = [".fsscript";".fsx"]
+let doNotRequireNamespaceOrModuleSuffixes = [".mli";".ml"] @ FSharpScriptFileSuffixes
+let FSharpLightSyntaxFileSuffixes : string list = [ ".fs";".fsscript";".fsx";".fsi" ]
//----------------------------------------------------------------------------
@@ -102,7 +102,7 @@ exception HashLoadedScriptConsideredSource of range
exception InvalidInternalsVisibleToAssemblyName of (*badName*)string * (*fileName option*) string option
-let RangeOfError(err:PhasedError) =
+let GetRangeOfError(err:PhasedError) =
let rec RangeFromException = function
| ErrorFromAddingConstraint(_,err2,_) -> RangeFromException err2
#if EXTENSIONTYPING
@@ -154,8 +154,8 @@ let RangeOfError(err:PhasedError) =
| FullAbstraction(_,m)
| InterfaceNotRevealed(_,_,m)
| WrappedError (_,m)
- | Patcompile.MatchIncomplete (_,_,m)
- | Patcompile.RuleNeverMatched m
+ | PatternMatchCompilation.MatchIncomplete (_,_,m)
+ | PatternMatchCompilation.RuleNeverMatched m
| ValNotMutable(_,_,m)
| ValNotLocal(_,_,m)
| MissingFields(_,m)
@@ -191,7 +191,6 @@ let RangeOfError(err:PhasedError) =
| UnresolvedOverloading(_,_,_,m)
| UnresolvedConversionOperator (_,_,_,m)
| PossibleOverload(_,_,_, m)
- //| PossibleBestOverload(_,_,m)
| VirtualAugmentationOnNullValuedType(m)
| NonVirtualAugmentationOnNullValuedType(m)
| NonRigidTypar(_,_,_,_,_,m)
@@ -266,8 +265,8 @@ let GetErrorNumber(err:PhasedError) =
| LetRecEvaluatedOutOfOrder _ -> 22
| NameClash _ -> 23
// 24 cannot be reused
- | Patcompile.MatchIncomplete _ -> 25
- | Patcompile.RuleNeverMatched _ -> 26
+ | PatternMatchCompilation.MatchIncomplete _ -> 25
+ | PatternMatchCompilation.RuleNeverMatched _ -> 26
| ValNotMutable _ -> 27
| ValNotLocal _ -> 28
| MissingFields _ -> 29
@@ -723,13 +722,9 @@ let OutputPhasedErrorR (os:System.Text.StringBuilder) (err:PhasedError) =
os.Append(Duplicate2E().Format k (DecompileOpName s)) |> ignore
| UndefinedName(_,k,id,_) ->
os.Append(k (DecompileOpName id.idText)) |> ignore
-
- | InternalUndefinedTyconItem(f,tcref,s) ->
- let _, errs = f((fullDisplayTextOfTyconRef tcref), s)
- os.Append(errs) |> ignore
- | InternalUndefinedItemRef(f,smr,ccuName,s) ->
- let _, errs = f(smr, ccuName, s)
- os.Append(errs) |> ignore
+ | InternalUndefinedItemRef(f,smr,ccuName,s) ->
+ let _, errs = f(smr, ccuName, s)
+ os.Append(errs) |> ignore
| FieldNotMutable _ ->
os.Append(FieldNotMutableE().Format) |> ignore
| FieldsFromDifferentTypes (_,fref1,fref2,_) ->
@@ -1203,7 +1198,7 @@ let OutputPhasedErrorR (os:System.Text.StringBuilder) (err:PhasedError) =
#endif
| FullAbstraction(s,_) -> os.Append(FullAbstractionE().Format s) |> ignore
| WrappedError (exn,_) -> OutputExceptionR os exn
- | Patcompile.MatchIncomplete (isComp,cexOpt,_) ->
+ | PatternMatchCompilation.MatchIncomplete (isComp,cexOpt,_) ->
os.Append(MatchIncomplete1E().Format) |> ignore
match cexOpt with
| None -> ()
@@ -1211,7 +1206,7 @@ let OutputPhasedErrorR (os:System.Text.StringBuilder) (err:PhasedError) =
| Some (cex,true) -> os.Append(MatchIncomplete3E().Format cex) |> ignore
if isComp then
os.Append(MatchIncomplete4E().Format) |> ignore
- | Patcompile.RuleNeverMatched _ -> os.Append(RuleNeverMatchedE().Format) |> ignore
+ | PatternMatchCompilation.RuleNeverMatched _ -> os.Append(RuleNeverMatchedE().Format) |> ignore
| ValNotMutable _ -> os.Append(ValNotMutableE().Format) |> ignore
| ValNotLocal _ -> os.Append(ValNotLocalE().Format) |> ignore
| ObsoleteError (s, _)
@@ -1350,6 +1345,7 @@ type ErrorStyle =
| EmacsErrors
| TestErrors
| VSErrors
+ | GccErrors
let SanitizeFileName fileName implicitIncludeDir =
// The assert below is almost ok, but it fires in two cases:
@@ -1371,35 +1367,33 @@ let SanitizeFileName fileName implicitIncludeDir =
with _ ->
fileName
+[]
type ErrorLocation =
- {
- Range : range
- File : string
- TextRepresentation : string
- IsEmpty : bool
- }
+ { Range : range
+ File : string
+ TextRepresentation : string
+ IsEmpty : bool }
+[]
type CanonicalInformation =
- {
- ErrorNumber : int
- Subcategory : string
- TextRepresentation : string
- }
+ { ErrorNumber : int
+ Subcategory : string
+ TextRepresentation : string }
+[]
type DetailedIssueInfo =
- {
- Location : ErrorLocation option
- Canonical : CanonicalInformation
- Message : string
- }
+ { Location : ErrorLocation option
+ Canonical : CanonicalInformation
+ Message : string }
+[]
type ErrorOrWarning =
| Short of bool * string
| Long of bool * DetailedIssueInfo
/// returns sequence that contains ErrorOrWarning for the given error + ErrorOrWarning for all related errors
let CollectErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,errorStyle,warn, err:PhasedError) =
- let outputWhere (showFullPaths,errorStyle) m =
+ let outputWhere (showFullPaths,errorStyle) m : ErrorLocation =
if m = rangeStartup || m = rangeCmdArgs then
{ Range = m; TextRepresentation = ""; IsEmpty = true; File = "" }
else
@@ -1426,6 +1420,11 @@ let CollectErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,errorS
let m = mkRange m.FileName (mkPos m.StartLine (m.StartColumn + 1)) (mkPos m.EndLine (m.EndColumn + 1) )
sprintf "%s(%d,%d-%d,%d): " file m.StartLine m.StartColumn m.EndLine m.EndColumn, m, file
+ | ErrorStyle.GccErrors ->
+ let file = file.Replace('/',System.IO.Path.DirectorySeparatorChar)
+ let m = mkRange m.FileName (mkPos m.StartLine (m.StartColumn + 1)) (mkPos m.EndLine (m.EndColumn + 1) )
+ sprintf "%s:%d:%d: " file m.StartLine m.StartColumn, m, file
+
// Here, we want the complete range information so Project Systems can generate proper squiggles
| ErrorStyle.VSErrors ->
// Show prefix only for real files. Otherise, we just want a truncated error like:
@@ -1449,11 +1448,11 @@ let CollectErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,errorS
let errors = ResizeArray()
let report err =
let OutputWhere(err) =
- match RangeOfError err with
+ match GetRangeOfError err with
| Some m -> Some(outputWhere (showFullPaths,errorStyle) m)
| None -> None
- let OutputCanonicalInformation(err:PhasedError,subcategory, errorNumber) =
+ let OutputCanonicalInformation(err:PhasedError,subcategory, errorNumber) : CanonicalInformation =
let text =
match errorStyle with
// Show the subcategory for --vserrors so that we can fish it out in Visual Studio and use it to determine error stickiness.
@@ -1469,7 +1468,7 @@ let CollectErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,errorS
OutputPhasedError os mainError flattenErrors;
os.ToString()
- let entry = { Location = where; Canonical = canonical; Message = message }
+ let entry : DetailedIssueInfo = { Location = where; Canonical = canonical; Message = message }
errors.Add ( ErrorOrWarning.Long( not warn, entry ) )
@@ -1484,7 +1483,7 @@ let CollectErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,errorS
OutputPhasedError os err flattenErrors
os.ToString()
- let entry = { Location = relWhere; Canonical = relCanonical; Message = relMessage}
+ let entry : DetailedIssueInfo = { Location = relWhere; Canonical = relCanonical; Message = relMessage}
errors.Add( ErrorOrWarning.Long (not warn, entry) )
| _ ->
@@ -1514,9 +1513,9 @@ let rec OutputErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,err
for e in errors do
Printf.bprintf os "\n"
match e with
- | Short(_, txt) ->
+ | ErrorOrWarning.Short(_, txt) ->
os.Append txt |> ignore
- | Long(_, details) ->
+ | ErrorOrWarning.Long(_, details) ->
match details.Location with
| Some l when not l.IsEmpty -> os.Append(l.TextRepresentation) |> ignore
| _ -> ()
@@ -1524,7 +1523,7 @@ let rec OutputErrorOrWarning (implicitIncludeDir,showFullPaths,flattenErrors,err
os.Append( details.Message ) |> ignore
let OutputErrorOrWarningContext prefix fileLineFn os err =
- match RangeOfError err with
+ match GetRangeOfError err with
| None -> ()
| Some m ->
let filename = m.FileName
@@ -1681,6 +1680,7 @@ type CompilerTarget =
type ResolveAssemblyReferenceMode = Speculative | ReportErrors
+/// Represents the file or string used for the --version flag
type VersionFlag =
| VersionString of string
| VersionFile of string
@@ -1741,7 +1741,7 @@ type ImportedAssembly =
IsProviderGenerated: bool
mutable TypeProviders: Tainted list;
#endif
- FSharpOptimizationData : Microsoft.FSharp.Control.Lazy