- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- try {
- cl::ParseCommandLineOptions(argc, argv, " llvm extractor\n");
- sys::PrintStackTraceOnErrorSignal();
-
- std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
- if (M.get() == 0) {
- cerr << argv[0] << ": bytecode didn't read correctly.\n";
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ LLVMContext &Context = getGlobalContext();
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
+
+ // Use lazy loading, since we only care about selected global values.
+ SMDiagnostic Err;
+ std::auto_ptr<Module> M;
+ M.reset(getLazyIRFileModule(InputFilename, Err, Context));
+
+ if (M.get() == 0) {
+ Err.print(argv[0], errs());
+ return 1;
+ }
+
+ // Use SetVector to avoid duplicates.
+ SetVector<GlobalValue *> GVs;
+
+ // Figure out which globals we should extract.
+ for (size_t i = 0, e = ExtractGlobals.size(); i != e; ++i) {
+ GlobalValue *GV = M->getNamedGlobal(ExtractGlobals[i]);
+ if (!GV) {
+ errs() << argv[0] << ": program doesn't contain global named '"
+ << ExtractGlobals[i] << "'!\n";