|
22 | 22 | #include "swift/Basic/STLExtras.h" |
23 | 23 | #include "swift/Basic/SourceManager.h" |
24 | 24 | #include "swift/Basic/Version.h" |
| 25 | +#include "swift/Option/Options.h" |
25 | 26 |
|
| 27 | +#include "llvm/Option/OptTable.h" |
| 28 | +#include "llvm/Option/ArgList.h" |
26 | 29 | #include "llvm/ADT/SmallString.h" |
27 | 30 | #include "llvm/ADT/StringSet.h" |
28 | 31 | #include "llvm/Support/Debug.h" |
@@ -970,6 +973,33 @@ bool swift::extractCompilerFlagsFromInterface(StringRef buffer, |
970 | 973 | return true; |
971 | 974 | assert(FlagMatches.size() == 2); |
972 | 975 | llvm::cl::TokenizeGNUCommandLine(FlagMatches[1], ArgSaver, SubArgs); |
| 976 | + SmallVector<StringRef, 1> IgnFlagMatches; |
| 977 | + // Cherry-pick supported options from the ignorable list. |
| 978 | + auto IgnFlagRe = llvm::Regex("^// swift-module-flags-ignorable:(.*)$", |
| 979 | + llvm::Regex::Newline); |
| 980 | + // It's OK the interface doesn't have the ignorable list, we just ignore them |
| 981 | + // all. |
| 982 | + if (!IgnFlagRe.match(buffer, &IgnFlagMatches)) |
| 983 | + return false; |
| 984 | + SmallVector<const char *, 8> IgnSubArgs; |
| 985 | + llvm::cl::TokenizeGNUCommandLine(IgnFlagMatches[1], ArgSaver, IgnSubArgs); |
| 986 | + std::unique_ptr<llvm::opt::OptTable> table = swift::createSwiftOptTable(); |
| 987 | + unsigned missingArgIdx = 0; |
| 988 | + unsigned missingArgCount = 0; |
| 989 | + auto parsedIgns = table->ParseArgs(IgnSubArgs, missingArgIdx, missingArgCount); |
| 990 | + for (auto parse: parsedIgns) { |
| 991 | + // Check if the option is a frontend option. This will filter out unknown |
| 992 | + // options and input-like options. |
| 993 | + if (!parse->getOption().hasFlag(options::FrontendOption)) |
| 994 | + continue; |
| 995 | + // Push the supported option and its value to the list. |
| 996 | + // We shouldn't need to worry about cases like -tbd-install_name=Foo because |
| 997 | + // the parsing function should have droped alias options already. |
| 998 | + SubArgs.push_back(ArgSaver.save(parse->getSpelling()).data()); |
| 999 | + for (auto value: parse->getValues()) |
| 1000 | + SubArgs.push_back(value); |
| 1001 | + } |
| 1002 | + |
973 | 1003 | return false; |
974 | 1004 | } |
975 | 1005 |
|
|
0 commit comments