@@ -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" ));
@@ -188,54 +185,39 @@ int main(int argc, char **argv) {
188
185
llvm::cl::opt<std::string> ModuleCachePath (
189
186
" module-cache-path" , llvm::cl::desc (" Clang module cache path" ));
190
187
191
- llvm::cl::list<std::string> ImportPaths (
192
- " I" , llvm::cl::desc (" add a directory to the import search path" ));
193
-
194
- llvm::cl::list<std::string> FrameworkPaths (
195
- " F" , llvm::cl::desc (" add a directory to the framework search path" ));
196
-
197
188
llvm::cl::opt<std::string> DumpDeclFromMangled (
198
189
" decl-from-mangled" , llvm::cl::desc (" dump decl from mangled names list" ));
199
190
200
191
llvm::cl::opt<std::string> DumpTypeFromMangled (
201
192
" type-from-mangled" , llvm::cl::desc (" dump type from mangled names list" ));
202
193
203
- // FIXME: we should infer this from the module.
204
- llvm::cl::opt<std::string> TargetTriple (
205
- " target-triple" , llvm::cl::desc (" specify target triple" ));
206
-
207
194
llvm::cl::ParseCommandLineOptions (argc, argv);
208
195
// Unregister our options so they don't interfere with the command line
209
196
// parsing in CodeGen/BackendUtil.cpp.
210
- FrameworkPaths.removeArgument ();
211
- ImportPaths.removeArgument ();
212
197
ModuleCachePath.removeArgument ();
213
198
DumpModule.removeArgument ();
214
199
DumpTypeFromMangled.removeArgument ();
215
- SDK.removeArgument ();
216
200
InputNames.removeArgument ();
217
- TargetTriple.removeArgument ();
218
201
219
202
// Fetch the serialized module bitstreams from the Mach-O files and
220
203
// register them with the module loader.
221
204
llvm::SmallVector<std::pair<char *, uint64_t >, 8 > Modules;
222
205
if (!collectASTModules (InputNames, Modules))
223
206
return 1 ;
224
207
208
+ if (Modules.empty ())
209
+ return 0 ;
210
+
211
+ swift::serialization::ValidationInfo info;
212
+ swift::serialization::ExtendedValidationInfo extendedInfo;
225
213
for (auto &Module : Modules) {
226
- if (!validateModule (StringRef (Module.first , Module.second ), Verbose)) {
214
+ if (!validateModule (StringRef (Module.first , Module.second ), Verbose, info,
215
+ extendedInfo)) {
227
216
llvm::errs () << " Malformed module!\n " ;
228
217
return 1 ;
229
218
}
230
219
}
231
220
232
- // If no SDK was specified via -sdk, check environment variable SDKROOT.
233
- if (SDK.getNumOccurrences () == 0 ) {
234
- const char *SDKROOT = getenv (" SDKROOT" );
235
- if (SDKROOT)
236
- SDK = SDKROOT;
237
- }
238
-
239
221
// Create a Swift compiler.
240
222
llvm::SmallVector<std::string, 4 > modules;
241
223
swift::CompilerInstance CI;
@@ -245,22 +227,12 @@ int main(int argc, char **argv) {
245
227
llvm::sys::fs::getMainExecutable (argv[0 ],
246
228
reinterpret_cast <void *>(&anchorForGetMainExecutable)));
247
229
248
- Invocation.setSDKPath (SDK);
249
-
250
- // FIXME: we should infer this from the module.
251
- if (!TargetTriple.empty ())
252
- Invocation.setTargetTriple (TargetTriple);
253
- else
254
- Invocation.setTargetTriple (llvm::sys::getDefaultTargetTriple ());
230
+ // Infer SDK and Target triple from the module.
231
+ Invocation.setSDKPath (extendedInfo.getSDKPath ());
232
+ Invocation.setTargetTriple (info.targetTriple );
255
233
256
234
Invocation.setModuleName (" lldbtest" );
257
235
Invocation.getClangImporterOptions ().ModuleCachePath = ModuleCachePath;
258
- Invocation.setImportSearchPaths (ImportPaths);
259
- std::vector<swift::SearchPathOptions::FrameworkSearchPath> FramePaths;
260
- for (const auto &path : FrameworkPaths) {
261
- FramePaths.push_back ({path, /* isSystem=*/ false });
262
- }
263
- Invocation.setFrameworkSearchPaths (FramePaths);
264
236
265
237
if (CI.setup (Invocation))
266
238
return 1 ;
0 commit comments