bool CoreDriver::link(llvm::ArrayRef<const char *> args, raw_ostream &diagnostics) { CoreLinkingContext ctx; // Register possible input file parsers. ctx.registry().addSupportYamlFiles(); ctx.registry().addKindTable(Reference::KindNamespace::testing, Reference::KindArch::all, coreKindStrings); if (!parse(args, ctx)) return false; return Driver::link(ctx); }
bool CoreDriver::link(int argc, const char *argv[], raw_ostream &diagnostics) { CoreLinkingContext ctx; if (!parse(argc, argv, ctx)) return false; // Register possible input file parsers. ctx.registry().addSupportNativeObjects(); ctx.registry().addSupportYamlFiles(); ctx.registry().addKindTable(Reference::KindNamespace::testing, Reference::KindArch::all, coreKindStrings); return Driver::link(ctx); }
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); }
bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx, raw_ostream &diagnostics) { // Parse command line options using CoreOptions.td std::unique_ptr<llvm::opt::InputArgList> parsedArgs; CoreOptTable table; unsigned missingIndex; unsigned missingCount; parsedArgs.reset( table.ParseArgs(&argv[1], &argv[argc], missingIndex, missingCount)); if (missingCount) { diagnostics << "error: missing arg value for '" << parsedArgs->getArgString(missingIndex) << "' expected " << missingCount << " argument(s).\n"; return false; } std::unique_ptr<InputGraph> inputGraph(new InputGraph()); // 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 Elements 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: inputGraph->addInputElement(std::unique_ptr<InputElement>( new COREFileNode(ctx, inputArg->getValue()))); break; default: break; } } if (!inputGraph->size()) { diagnostics << "No input files\n"; return false; } ctx.setInputGraph(std::move(inputGraph)); // Validate the combination of options used. return ctx.validate(diagnostics); }