mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #13233 from davidungar/PR2-5
Preparatory, simple changes to ease reviewing of the next PR.
This commit is contained in:
@@ -306,7 +306,7 @@ public:
|
||||
/// sil-opt, sil-func-extractor, sil-llvm-gen, and sil-nm.
|
||||
/// Return value includes the buffer so caller can keep it alive.
|
||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
|
||||
setUpInputForSILTool(StringRef InputFilename, StringRef ModuleNameArg,
|
||||
setUpInputForSILTool(StringRef inputFilename, StringRef moduleNameArg,
|
||||
bool alwaysSetModuleToMain,
|
||||
serialization::ExtendedValidationInfo &extendedInfo);
|
||||
bool hasSerializedAST() {
|
||||
|
||||
@@ -514,8 +514,8 @@ public:
|
||||
/// -dump-scope-maps.
|
||||
SmallVector<std::pair<unsigned, unsigned>, 2> DumpScopeMapLocations;
|
||||
|
||||
/// Indicates whether the RequestedAction will immediately run code.
|
||||
bool actionIsImmediate() const;
|
||||
/// Indicates whether the action will immediately run code.
|
||||
static bool isActionImmediate(ActionType);
|
||||
|
||||
/// Return a hash code of any components from these options that should
|
||||
/// contribute to a Swift Bridging PCH hash.
|
||||
|
||||
@@ -771,6 +771,40 @@ std::string FrontendArgsToOptionsConverter::determineBaseNameOfOutput() const {
|
||||
return llvm::sys::path::stem(nameToStem).str();
|
||||
}
|
||||
|
||||
ArrayRef<std::string>
|
||||
FrontendArgsToOptionsConverter::getOutputFilenamesFromCommandLineOrFilelist() {
|
||||
if (cachedOutputFilenamesFromCommandLineOrFilelist) {
|
||||
return *cachedOutputFilenamesFromCommandLineOrFilelist;
|
||||
}
|
||||
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) {
|
||||
assert(!Args.hasArg(options::OPT_o) &&
|
||||
"don't use -o with -output-filelist");
|
||||
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
|
||||
readOutputFileList(A->getValue()));
|
||||
} else {
|
||||
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
|
||||
Args.getAllArgValues(options::OPT_o));
|
||||
}
|
||||
return *cachedOutputFilenamesFromCommandLineOrFilelist;
|
||||
}
|
||||
|
||||
/// Try to read an output file list file.
|
||||
std::vector<std::string> FrontendArgsToOptionsConverter::readOutputFileList(
|
||||
const StringRef filelistPath) const {
|
||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
|
||||
llvm::MemoryBuffer::getFile(filelistPath);
|
||||
if (!buffer) {
|
||||
Diags.diagnose(SourceLoc(), diag::cannot_open_file, filelistPath,
|
||||
buffer.getError().message());
|
||||
}
|
||||
std::vector<std::string> outputFiles;
|
||||
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
|
||||
outputFiles.push_back(line.str());
|
||||
}
|
||||
return outputFiles;
|
||||
}
|
||||
|
||||
void FrontendArgsToOptionsConverter::determineSupplementaryOutputFilenames() {
|
||||
using namespace options;
|
||||
auto determineOutputFilename =
|
||||
@@ -884,40 +918,6 @@ void FrontendArgsToOptionsConverter::computeLLVMArgs() {
|
||||
}
|
||||
}
|
||||
|
||||
ArrayRef<std::string>
|
||||
FrontendArgsToOptionsConverter::getOutputFilenamesFromCommandLineOrFilelist() {
|
||||
if (cachedOutputFilenamesFromCommandLineOrFilelist) {
|
||||
return *cachedOutputFilenamesFromCommandLineOrFilelist;
|
||||
}
|
||||
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) {
|
||||
assert(!Args.hasArg(options::OPT_o) &&
|
||||
"don't use -o with -output-filelist");
|
||||
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
|
||||
readOutputFileList(A->getValue()));
|
||||
} else {
|
||||
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
|
||||
Args.getAllArgValues(options::OPT_o));
|
||||
}
|
||||
return *cachedOutputFilenamesFromCommandLineOrFilelist;
|
||||
}
|
||||
|
||||
/// Try to read an output file list file.
|
||||
std::vector<std::string> FrontendArgsToOptionsConverter::readOutputFileList(
|
||||
const StringRef filelistPath) const {
|
||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
|
||||
llvm::MemoryBuffer::getFile(filelistPath);
|
||||
if (!buffer) {
|
||||
Diags.diagnose(SourceLoc(), diag::cannot_open_file, filelistPath,
|
||||
buffer.getError().message());
|
||||
}
|
||||
std::vector<std::string> outputFiles;
|
||||
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
|
||||
outputFiles.push_back(line.str());
|
||||
}
|
||||
return outputFiles;
|
||||
}
|
||||
|
||||
static bool ParseFrontendArgs(FrontendOptions &opts, ArgList &args,
|
||||
DiagnosticEngine &diags) {
|
||||
return FrontendArgsToOptionsConverter(diags, args, opts).convert();
|
||||
|
||||
@@ -111,31 +111,33 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
SourceMgr, Diagnostics));
|
||||
|
||||
if (Invocation.getFrontendOptions().EnableSourceImport) {
|
||||
bool immediate = Invocation.getFrontendOptions().actionIsImmediate();
|
||||
bool immediate = FrontendOptions::isActionImmediate(
|
||||
Invocation.getFrontendOptions().RequestedAction);
|
||||
bool enableResilience = Invocation.getFrontendOptions().EnableResilience;
|
||||
Context->addModuleLoader(SourceLoader::create(*Context,
|
||||
!immediate,
|
||||
enableResilience,
|
||||
DepTracker));
|
||||
}
|
||||
|
||||
{
|
||||
auto SML = SerializedModuleLoader::create(*Context, DepTracker);
|
||||
this->SML = SML.get();
|
||||
Context->addModuleLoader(std::move(SML));
|
||||
|
||||
}
|
||||
{
|
||||
// Wire up the Clang importer. If the user has specified an SDK, use it.
|
||||
// Otherwise, we just keep it around as our interface to Clang's ABI
|
||||
// knowledge.
|
||||
auto clangImporter =
|
||||
ClangImporter::create(*Context, Invocation.getClangImporterOptions(),
|
||||
Invocation.getPCHHash(),
|
||||
DepTracker);
|
||||
Invocation.getPCHHash(), DepTracker);
|
||||
if (!clangImporter) {
|
||||
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
|
||||
return true;
|
||||
}
|
||||
|
||||
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
|
||||
}
|
||||
|
||||
assert(Lexer::isIdentifier(Invocation.getModuleName()));
|
||||
|
||||
@@ -390,11 +392,11 @@ void CompilerInstance::getImplicitlyImportedModules(
|
||||
|
||||
void CompilerInstance::createREPLFile(
|
||||
const ImplicitImports &implicitImports) const {
|
||||
auto *SingleInputFile = new (*Context) SourceFile(
|
||||
auto *singleInputFile = new (*Context) SourceFile(
|
||||
*MainModule, Invocation.getSourceFileKind(), None, implicitImports.kind,
|
||||
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile);
|
||||
MainModule->addFile(*SingleInputFile);
|
||||
addAdditionalInitialImportsTo(SingleInputFile, implicitImports);
|
||||
MainModule->addFile(*singleInputFile);
|
||||
addAdditionalInitialImportsTo(singleInputFile, implicitImports);
|
||||
}
|
||||
|
||||
std::unique_ptr<DelayedParsingCallbacks>
|
||||
@@ -534,7 +536,7 @@ OptionSet<TypeCheckingFlags> CompilerInstance::computeTypeCheckingOptions() {
|
||||
if (options.DebugTimeFunctionBodies) {
|
||||
TypeCheckOptions |= TypeCheckingFlags::DebugTimeFunctionBodies;
|
||||
}
|
||||
if (options.actionIsImmediate()) {
|
||||
if (FrontendOptions::isActionImmediate(options.RequestedAction)) {
|
||||
TypeCheckOptions |= TypeCheckingFlags::ForImmediateMode;
|
||||
}
|
||||
if (options.DebugTimeExpressionTypeChecking) {
|
||||
@@ -627,8 +629,8 @@ void CompilerInstance::parseAndTypeCheckMainFile(
|
||||
static void
|
||||
forEachSourceFileIn(ModuleDecl *module,
|
||||
llvm::function_ref<void(SourceFile &)> fn) {
|
||||
for (auto File : module->getFiles()) {
|
||||
if (auto SF = dyn_cast<SourceFile>(File))
|
||||
for (auto file : module->getFiles()) {
|
||||
if (auto SF = dyn_cast<SourceFile>(file))
|
||||
fn(*SF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ bool FrontendOptions::needsProperModuleName(ActionType action) {
|
||||
llvm_unreachable("Unknown ActionType");
|
||||
}
|
||||
|
||||
bool FrontendOptions::actionIsImmediate() const {
|
||||
switch (RequestedAction) {
|
||||
bool FrontendOptions::isActionImmediate(ActionType action) {
|
||||
switch (action) {
|
||||
case ActionType::NoneAction:
|
||||
case ActionType::Parse:
|
||||
case ActionType::Typecheck:
|
||||
|
||||
Reference in New Issue
Block a user