forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfscmain.fs
97 lines (77 loc) · 3.38 KB
/
fscmain.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
module internal FSharp.Compiler.CommandLineMain
open System
open System.Reflection
open System.Runtime.CompilerServices
open System.Threading
open Internal.Utilities.Library
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.AbstractIL.ILBinaryReader
open FSharp.Compiler.CompilerConfig
open FSharp.Compiler.Driver
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Text
[<Dependency("FSharp.Compiler.Service", LoadHint.Always)>]
do ()
[<EntryPoint>]
let main (argv) =
let compilerName =
// the 64 bit desktop version of the compiler is name fscAnyCpu.exe, all others are fsc.exe
if
Environment.Is64BitProcess
&& typeof<obj>.Assembly.GetName().Name <> "System.Private.CoreLib"
then
"fscAnyCpu.exe"
else
"fsc.exe"
Thread.CurrentThread.Name <- "F# Main Thread"
// Set the initial phase to garbage collector to batch mode, which improves overall performance.
use _ = UseBuildPhase BuildPhase.Parameter
try
// We are on a compilation thread
let ctok = AssumeCompilationThreadWithoutEvidence()
// The F# compiler expects 'argv' to include the executable name, though it makes no use of it.
let argv = Array.append [| compilerName |] argv
// Check for --pause as the very first step so that a debugger can be attached here.
let pauseFlag = argv |> Array.exists (fun x -> x = "/pause" || x = "--pause")
if pauseFlag then
System.Console.WriteLine("Press return to continue...")
System.Console.ReadLine() |> ignore
// Set up things for the --times testing flag
let timesFlag = argv |> Array.exists (fun x -> x = "/times" || x = "--times")
if timesFlag then
let stats = ILBinaryReader.GetStatistics()
AppDomain.CurrentDomain.ProcessExit.Add(fun _ ->
printfn
"STATS: #ByteArrayFile = %d, #MemoryMappedFileOpen = %d, #MemoryMappedFileClosed = %d, #RawMemoryFile = %d, #WeakByteArrayFile = %d"
stats.byteFileCount
stats.memoryMapFileOpenedCount
stats.memoryMapFileClosedCount
stats.rawMemoryFileCount
stats.weakByteFileCount)
// Get the handler for legacy resolution of references via MSBuild.
let legacyReferenceResolver = LegacyMSBuildReferenceResolver.getResolver ()
// Perform the main compilation.
//
// This is the only place where ReduceMemoryFlag.No is set. This is because fsc.exe is not a long-running process and
// thus we can use file-locking memory mapped files.
//
// This is also one of only two places where CopyFSharpCoreFlag.Yes is set. The other is in LegacyHostedCompilerForTesting.
CompileFromCommandLineArguments(
ctok,
argv,
legacyReferenceResolver,
false,
ReduceMemoryFlag.No,
CopyFSharpCoreFlag.Yes,
QuitProcessExiter,
ConsoleLoggerProvider(),
None,
None
)
0
with e ->
// Last-chance error recovery (note, with a poor error range)
errorRecovery e Range.range0
1