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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
//===--------------- CompilerMode.swift - Swift Compiler Mode -------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
/// The mode of the compiler.
@_spi(Testing) public enum CompilerMode: Equatable {
/// A standard compilation, using multiple frontend invocations and -primary-file.
case standardCompile
/// A batch compilation, using multiple frontend invocations with
/// multiple -primary-file options per invocation.
case batchCompile(BatchModeInfo)
/// A compilation using a single frontend invocation without -primary-file.
case singleCompile
/// Invoke the REPL.
case repl
/// Compile and execute the inputs immediately.
case immediate
/// Compile a Clang module (.pcm).
case compilePCM
/// Dump information about a precompiled Clang module
case dumpPCM
/// Introduce the user to Swift concepts depending on context.
case intro
}
/// Information about batch mode, which is used to determine how to form
/// the batches of jobs.
@_spi(Testing) public struct BatchModeInfo: Equatable {
let seed: Int?
let count: Int?
let sizeLimit: Int?
}
extension CompilerMode {
/// Whether this compilation mode uses -primary-file to specify its inputs.
public var usesPrimaryFileInputs: Bool {
switch self {
case .immediate, .repl, .singleCompile, .compilePCM, .dumpPCM, .intro:
return false
case .standardCompile, .batchCompile:
return true
}
}
/// Whether this compilation mode compiles the whole target in one job.
public var isSingleCompilation: Bool {
switch self {
case .immediate, .repl, .standardCompile, .batchCompile, .intro:
return false
case .singleCompile, .compilePCM, .dumpPCM:
return true
}
}
public var isStandardCompilationForPlanning: Bool {
switch self {
case .immediate, .repl, .compilePCM, .dumpPCM, .intro:
return false
case .batchCompile, .standardCompile, .singleCompile:
return true
}
}
public var batchModeInfo: BatchModeInfo? {
switch self {
case let .batchCompile(info):
return info
default:
return nil
}
}
public var isBatchCompile: Bool {
batchModeInfo != nil
}
// Whether this compilation mode supports the use of bridging pre-compiled
// headers.
public var supportsBridgingPCH: Bool {
switch self {
case .batchCompile, .singleCompile, .standardCompile, .compilePCM, .dumpPCM:
return true
case .immediate, .repl, .intro:
return false
}
}
}
extension CompilerMode: CustomStringConvertible {
public var description: String {
switch self {
case .standardCompile:
return "standard compilation"
case .batchCompile:
return "batch compilation"
case .singleCompile:
return "whole module optimization"
case .repl:
return "read-eval-print-loop compilation"
case .immediate:
return "immediate compilation"
case .compilePCM:
return "compile Clang module (.pcm)"
case .dumpPCM:
return "dump Clang module (.pcm)"
case .intro:
return "introduction to Swift and packages"
}
}
}
|