Move FrontendInputs into separate .h and .cpp files.

This commit is contained in:
David Ungar
2018-01-17 20:19:15 -08:00
parent 4ac390d24d
commit 361ff7244c
6 changed files with 308 additions and 218 deletions

View File

@@ -27,86 +27,6 @@
using namespace swift;
using namespace llvm::opt;
bool FrontendInputs::shouldTreatAsLLVM() const {
if (hasSingleInput()) {
StringRef Input(getFilenameOfFirstInput());
return llvm::sys::path::extension(Input).endswith(LLVM_BC_EXTENSION) ||
llvm::sys::path::extension(Input).endswith(LLVM_IR_EXTENSION);
}
return false;
}
bool FrontendInputs::shouldTreatAsSIL() const {
if (hasSingleInput()) {
// If we have exactly one input filename, and its extension is "sil",
// treat the input as SIL.
StringRef Input(getFilenameOfFirstInput());
return llvm::sys::path::extension(Input).endswith(SIL_EXTENSION);
}
// If we have one primary input and it's a filename with extension "sil",
// treat the input as SIL.
unsigned silPrimaryCount = numberOfPrimaryInputsEndingWith(SIL_EXTENSION);
if (silPrimaryCount == 0)
return false;
if (silPrimaryCount == primaryInputCount()) {
// Not clear what to do someday with multiple primaries
assertMustNotBeMoreThanOnePrimaryInput();
return true;
}
llvm_unreachable("Either all primaries or none must end with .sil");
}
unsigned
FrontendInputs::numberOfPrimaryInputsEndingWith(const char *extension) const {
return count_if(
PrimaryInputs, [&](const llvm::StringMapEntry<unsigned> &elem) -> bool {
StringRef filename = AllFiles[elem.second].file();
return llvm::sys::path::extension(filename).endswith(extension);
});
}
bool FrontendInputs::verifyInputs(DiagnosticEngine &diags, bool treatAsSIL,
bool isREPLRequested,
bool isNoneRequested) const {
if (isREPLRequested) {
if (hasInputs()) {
diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files);
return true;
}
} else if (treatAsSIL) {
if (isWholeModule()) {
if (inputCount() != 1) {
diags.diagnose(SourceLoc(), diag::error_mode_requires_one_input_file);
return true;
}
} else {
assertMustNotBeMoreThanOnePrimaryInput();
// If we have the SIL as our primary input, we can waive the one file
// requirement as long as all the other inputs are SIBs.
if (!areAllNonPrimariesSIB()) {
diags.diagnose(SourceLoc(),
diag::error_mode_requires_one_sil_multi_sib);
return true;
}
}
} else if (!isNoneRequested && !hasInputs()) {
diags.diagnose(SourceLoc(), diag::error_mode_requires_an_input_file);
return true;
}
return false;
}
bool FrontendInputs::areAllNonPrimariesSIB() const {
for (const InputFile &input : getAllFiles()) {
if (input.isPrimary())
continue;
if (!llvm::sys::path::extension(input.file()).endswith(SIB_EXTENSION)) {
return false;
}
}
return true;
}
bool FrontendOptions::needsProperModuleName(ActionType action) {
switch (action) {
case ActionType::NoneAction: