#include "llvm/Support/Format.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <string>
static std::string ToolName;
-static bool error(Twine Message) {
+static void error(const Twine &Message, StringRef File) {
HadError = true;
- errs() << ToolName << ": " << Message << ".\n";
- errs().flush();
- return true;
+ WithColor::error(errs(), ToolName) << "'" << File << "': " << Message << "\n";
}
// This version of error() prints the archive name and member name, for example:
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
StringRef ArchitectureName = StringRef()) {
HadError = true;
- errs() << ToolName << ": " << FileName;
+ WithColor::error(errs(), ToolName) << "'" << FileName << "'";
Expected<StringRef> NameOrErr = C.getName();
// TODO: if we have a error getting the name then it would be nice to print
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
- errs() << " " << Buf << "\n";
+ errs() << ": " << Buf << "\n";
}
// This version of error() prints the file name and which architecture slice it // is from, for example: "foo.o (for architecture i386)" after the ToolName
static void error(llvm::Error E, StringRef FileName,
StringRef ArchitectureName = StringRef()) {
HadError = true;
- errs() << ToolName << ": " << FileName;
+ WithColor::error(errs(), ToolName) << "'" << FileName << "'";
if (!ArchitectureName.empty())
errs() << " (for architecture " << ArchitectureName << ") ";
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
- errs() << " " << Buf << "\n";
+ errs() << ": " << Buf << "\n";
}
/// Get the length of the string that represents @p num in Radix including the
if (none_of(ArchFlags, [&](const std::string &Name) {
return Name == T.getArchName();
})) {
- error(Filename + ": No architecture specified");
+ error("no architecture specified", Filename);
return false;
}
return true;
error(std::move(Err), UA->getFileName());
} else {
consumeError(AOrErr.takeError());
- error("Mach-O universal file: " + file + " for architecture " +
- StringRef(I->getArchFlagName()) +
- " is not a Mach-O file or an archive file");
+ error("mach-o universal file for architecture " +
+ StringRef(I->getArchFlagName()) +
+ " is not a mach-o file or an archive file",
+ file);
}
}
}
if (!ArchFound) {
- errs() << ToolName << ": file: " << file
- << " does not contain architecture" << ArchFlags[i] << ".\n";
+ error("file does not contain architecture " + ArchFlags[i], file);
return;
}
}
error(std::move(Err), UA->getFileName());
} else {
consumeError(AOrErr.takeError());
- error("Mach-O universal file: " + file + " for architecture " +
- StringRef(I->getArchFlagName()) +
- " is not a Mach-O file or an archive file");
+ error("mach-o universal file for architecture " +
+ StringRef(I->getArchFlagName()) +
+ " is not a mach-o file or an archive file",
+ file);
}
return;
}
error(std::move(Err), UA->getFileName());
} else {
consumeError(AOrErr.takeError());
- error("Mach-O universal file: " + file + " for architecture " +
- StringRef(I->getArchFlagName()) +
- " is not a Mach-O file or an archive file");
+ error("mach-o universal file for architecture " +
+ StringRef(I->getArchFlagName()) +
+ " is not a mach-o file or an archive file",
+ file);
}
}
} else if (ObjectFile *o = dyn_cast<ObjectFile>(&Bin)) {
outs() << "\n";
}
} else {
- errs() << ToolName << ": " << file << ": "
- << "Unrecognized file type.\n";
+ error("unsupported file type", file);
}
// System V adds an extra newline at the end of each file.
if (OutputFormat == sysv)