1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

Removes redundant llvm::, add comments and simplify a return type of a function.

No functional change intended.

llvm-svn: 312673
This commit is contained in:
Rui Ueyama 2017-09-06 22:05:32 +00:00
parent 98e3c40489
commit db8c4e1c9e

View File

@ -40,31 +40,31 @@ enum {
#include "Options.inc"
#undef PREFIX
static const llvm::opt::OptTable::Info InfoTable[] = {
static const opt::OptTable::Info InfoTable[] = {
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
{X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
#include "Options.inc"
#undef OPTION
};
class LibOptTable : public llvm::opt::OptTable {
class LibOptTable : public opt::OptTable {
public:
LibOptTable() : OptTable(InfoTable, true) {}
};
}
static std::string getOutputPath(llvm::opt::InputArgList *Args,
const llvm::NewArchiveMember &FirstMember) {
static std::string getOutputPath(opt::InputArgList *Args,
const NewArchiveMember &FirstMember) {
if (auto *Arg = Args->getLastArg(OPT_out))
return Arg->getValue();
SmallString<128> Val = StringRef(FirstMember.Buf->getBufferIdentifier());
llvm::sys::path::replace_extension(Val, ".lib");
sys::path::replace_extension(Val, ".lib");
return Val.str();
}
static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args,
StringSaver &Saver) {
std::vector<StringRef> Ret;
// Add current directory as first item of the search path.
@ -87,28 +87,29 @@ static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
return Ret;
}
static Optional<std::string> findInputFile(StringRef File,
ArrayRef<StringRef> Paths) {
for (auto Dir : Paths) {
static std::string findInputFile(StringRef File, ArrayRef<StringRef> Paths) {
for (StringRef Dir : Paths) {
SmallString<128> Path = Dir;
sys::path::append(Path, File);
if (sys::fs::exists(Path))
return Path.str().str();
}
return Optional<std::string>();
return "";
}
int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
BumpPtrAllocator Alloc;
StringSaver Saver(Alloc);
// Parse command line arguments.
SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
ArgsArr = NewArgs;
LibOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
llvm::opt::InputArgList Args =
opt::InputArgList Args =
Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount);
if (MissingCount) {
llvm::errs() << "missing arg value for \""
@ -120,32 +121,33 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
if (!Args.hasArgNoClaim(OPT_INPUT)) {
// No input files. To match lib.exe, silently do nothing.
// If no input files, silently do nothing to match lib.exe.
if (!Args.hasArgNoClaim(OPT_INPUT))
return 0;
}
std::vector<StringRef> SearchPaths = getSearchPaths(&Args, Saver);
std::vector<llvm::NewArchiveMember> Members;
// Create a NewArchiveMember for each input file.
std::vector<NewArchiveMember> Members;
for (auto *Arg : Args.filtered(OPT_INPUT)) {
Optional<std::string> Path = findInputFile(Arg->getValue(), SearchPaths);
if (!Path.hasValue()) {
std::string Path = findInputFile(Arg->getValue(), SearchPaths);
if (Path.empty()) {
llvm::errs() << Arg->getValue() << ": no such file or directory\n";
return 1;
}
Expected<NewArchiveMember> MOrErr =
NewArchiveMember::getFile(Saver.save(*Path), /*Deterministic=*/true);
NewArchiveMember::getFile(Saver.save(Path), /*Deterministic=*/true);
if (!MOrErr) {
handleAllErrors(MOrErr.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
handleAllErrors(MOrErr.takeError(), [&](const ErrorInfoBase &EIB) {
llvm::errs() << Arg->getValue() << ": " << EIB.message() << "\n";
});
return 1;
}
llvm::file_magic Magic = llvm::identify_magic(MOrErr->Buf->getBuffer());
if (Magic != llvm::file_magic::coff_object &&
Magic != llvm::file_magic::bitcode &&
Magic != llvm::file_magic::windows_resource) {
file_magic Magic = identify_magic(MOrErr->Buf->getBuffer());
if (Magic != file_magic::coff_object && Magic != file_magic::bitcode &&
Magic != file_magic::windows_resource) {
llvm::errs() << Arg->getValue()
<< ": not a COFF object, bitcode or resource file\n";
return 1;
@ -153,11 +155,12 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
Members.emplace_back(std::move(*MOrErr));
}
// Create an archive file.
std::string OutputPath = getOutputPath(&Args, Members[0]);
std::error_code EC =
llvm::writeArchive(OutputPath, Members,
/*WriteSymtab=*/true, object::Archive::K_GNU,
/*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin));
writeArchive(OutputPath, Members,
/*WriteSymtab=*/true, object::Archive::K_GNU,
/*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin));
if (EC) {
llvm::errs() << OutputPath << ": " << EC.message() << "\n";