bool CoreDriver::parse(llvm::ArrayRef<const char *> args, CoreLinkingContext &ctx, raw_ostream &diagnostics) { // Parse command line options using CoreOptions.td CoreOptTable table; unsigned missingIndex; unsigned missingCount; llvm::opt::InputArgList parsedArgs = table.ParseArgs(args.slice(1), missingIndex, missingCount); if (missingCount) { diagnostics << "error: missing arg value for '" << parsedArgs.getArgString(missingIndex) << "' expected " << missingCount << " argument(s).\n"; return false; } // Set default options ctx.setOutputPath("-"); ctx.setDeadStripping(false); ctx.setGlobalsAreDeadStripRoots(false); ctx.setPrintRemainingUndefines(false); ctx.setAllowRemainingUndefines(true); ctx.setSearchArchivesToOverrideTentativeDefinitions(false); // Process all the arguments and create input files. for (auto inputArg : parsedArgs) { switch (inputArg->getOption().getID()) { case OPT_mllvm: ctx.appendLLVMOption(inputArg->getValue()); break; case OPT_entry: ctx.setEntrySymbolName(inputArg->getValue()); break; case OPT_output: ctx.setOutputPath(inputArg->getValue()); break; case OPT_dead_strip: ctx.setDeadStripping(true); break; case OPT_keep_globals: ctx.setGlobalsAreDeadStripRoots(true); break; case OPT_undefines_are_errors: ctx.setPrintRemainingUndefines(true); ctx.setAllowRemainingUndefines(false); break; case OPT_commons_search_archives: ctx.setSearchArchivesToOverrideTentativeDefinitions(true); break; case OPT_add_pass: ctx.addPassNamed(inputArg->getValue()); break; case OPT_INPUT: { std::vector<std::unique_ptr<File>> files = loadFile(ctx, inputArg->getValue(), false); for (std::unique_ptr<File> &file : files) ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file))); break; } default: break; } } if (ctx.getNodes().empty()) { diagnostics << "No input files\n"; return false; } // Validate the combination of options used. return ctx.validate(diagnostics); }