ModuleInterface: refactor out a utility to extract compiler flags from a module interface file. NFC

This commit is contained in:
Xi Ge
2021-05-02 22:41:39 -07:00
parent 57a893bdb3
commit 3d6662f382
5 changed files with 18 additions and 12 deletions

View File

@@ -30,6 +30,7 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/CommandLine.h"
#include <system_error>
using namespace swift;
@@ -947,6 +948,18 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
}
}
bool swift::extractCompilerFlagsFromInterface(StringRef buffer,
llvm::StringSaver &ArgSaver,
SmallVectorImpl<const char *> &SubArgs) {
SmallVector<StringRef, 1> FlagMatches;
auto FlagRe = llvm::Regex("^// swift-module-flags:(.*)$", llvm::Regex::Newline);
if (!FlagRe.match(buffer, &FlagMatches))
return true;
assert(FlagMatches.size() == 2);
llvm::cl::TokenizeGNUCommandLine(FlagMatches[1], ArgSaver, SubArgs);
return false;
}
bool SerializedModuleLoaderBase::canImportModule(
ImportPath::Element mID, llvm::VersionTuple version, bool underlyingVersion) {
// Look on disk.