@@ -42,10 +42,10 @@ void anchorForGetMainExecutable() {}
42
42
43
43
using namespace llvm ::MachO;
44
44
45
- static bool validateModule (llvm::StringRef data, bool Verbose) {
46
- swift::serialization::ExtendedValidationInfo extendedInfo;
47
- swift::serialization::ValidationInfo info =
48
- swift::serialization::validateSerializedAST (data, &extendedInfo);
45
+ static bool validateModule (llvm::StringRef data, bool Verbose,
46
+ swift::serialization::ValidationInfo &info,
47
+ swift::serialization::ExtendedValidationInfo &extendedInfo) {
48
+ info = swift::serialization::validateSerializedAST (data, &extendedInfo);
49
49
if (info.status != swift::serialization::Status::Valid)
50
50
return false ;
51
51
@@ -175,9 +175,6 @@ int main(int argc, char **argv) {
175
175
llvm::cl::Positional, llvm::cl::desc (" compiled_swift_file1.o ..." ),
176
176
llvm::cl::OneOrMore);
177
177
178
- llvm::cl::opt<std::string> SDK (
179
- " sdk" , llvm::cl::desc (" path to the SDK to build against" ));
180
-
181
178
llvm::cl::opt<bool > DumpModule (
182
179
" dump-module" , llvm::cl::desc (
183
180
" Dump the imported module after checking it imports just fine" ));
@@ -194,40 +191,33 @@ int main(int argc, char **argv) {
194
191
llvm::cl::opt<std::string> DumpTypeFromMangled (
195
192
" type-from-mangled" , llvm::cl::desc (" dump type from mangled names list" ));
196
193
197
- // FIXME: we should infer this from the module.
198
- llvm::cl::opt<std::string> TargetTriple (
199
- " target-triple" , llvm::cl::desc (" specify target triple" ));
200
-
201
194
llvm::cl::ParseCommandLineOptions (argc, argv);
202
195
// Unregister our options so they don't interfere with the command line
203
196
// parsing in CodeGen/BackendUtil.cpp.
204
197
ModuleCachePath.removeArgument ();
205
198
DumpModule.removeArgument ();
206
199
DumpTypeFromMangled.removeArgument ();
207
- SDK.removeArgument ();
208
200
InputNames.removeArgument ();
209
- TargetTriple.removeArgument ();
210
201
211
202
// Fetch the serialized module bitstreams from the Mach-O files and
212
203
// register them with the module loader.
213
204
llvm::SmallVector<std::pair<char *, uint64_t >, 8 > Modules;
214
205
if (!collectASTModules (InputNames, Modules))
215
206
return 1 ;
216
207
208
+ if (Modules.empty ())
209
+ return 0 ;
210
+
211
+ swift::serialization::ValidationInfo info;
212
+ swift::serialization::ExtendedValidationInfo extendedInfo;
217
213
for (auto &Module : Modules) {
218
- if (!validateModule (StringRef (Module.first , Module.second ), Verbose)) {
214
+ if (!validateModule (StringRef (Module.first , Module.second ), Verbose, info,
215
+ extendedInfo)) {
219
216
llvm::errs () << " Malformed module!\n " ;
220
217
return 1 ;
221
218
}
222
219
}
223
220
224
- // If no SDK was specified via -sdk, check environment variable SDKROOT.
225
- if (SDK.getNumOccurrences () == 0 ) {
226
- const char *SDKROOT = getenv (" SDKROOT" );
227
- if (SDKROOT)
228
- SDK = SDKROOT;
229
- }
230
-
231
221
// Create a Swift compiler.
232
222
llvm::SmallVector<std::string, 4 > modules;
233
223
swift::CompilerInstance CI;
@@ -237,13 +227,9 @@ int main(int argc, char **argv) {
237
227
llvm::sys::fs::getMainExecutable (argv[0 ],
238
228
reinterpret_cast <void *>(&anchorForGetMainExecutable)));
239
229
240
- Invocation.setSDKPath (SDK);
241
-
242
- // FIXME: we should infer this from the module.
243
- if (!TargetTriple.empty ())
244
- Invocation.setTargetTriple (TargetTriple);
245
- else
246
- Invocation.setTargetTriple (llvm::sys::getDefaultTargetTriple ());
230
+ // Infer SDK and Target triple from the module.
231
+ Invocation.setSDKPath (extendedInfo.getSDKPath ());
232
+ Invocation.setTargetTriple (info.targetTriple );
247
233
248
234
Invocation.setModuleName (" lldbtest" );
249
235
Invocation.getClangImporterOptions ().ModuleCachePath = ModuleCachePath;
0 commit comments