diff options
Diffstat (limited to 'lld/Common')
-rw-r--r-- | lld/Common/ErrorHandler.cpp | 16 | ||||
-rw-r--r-- | lld/Common/Strings.cpp | 9 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp index 18affce4d5a..6dacc2c850b 100644 --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -12,7 +12,8 @@ #include "lld/Common/Threads.h" #include "llvm/ADT/Twine.h" -#include "llvm/Support/Error.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/raw_ostream.h" #include <mutex> @@ -59,6 +60,19 @@ void lld::exitLld(int Val) { _exit(Val); } +void lld::diagnosticHandler(const DiagnosticInfo &DI) { + SmallString<128> S; + raw_svector_ostream OS(S); + DiagnosticPrinterRawOStream DP(OS); + DI.print(DP); + warn(S); +} + +void lld::checkError(Error E) { + handleAllErrors(std::move(E), + [&](ErrorInfoBase &EIB) { error(EIB.message()); }); +} + void ErrorHandler::print(StringRef S, raw_ostream::Colors C) { *ErrorOS << LogName << ": "; if (ColorDiagnostics) { diff --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp index 1fac65b88ae..36f4f77d847 100644 --- a/lld/Common/Strings.cpp +++ b/lld/Common/Strings.cpp @@ -98,3 +98,12 @@ bool lld::isValidCIdentifier(StringRef S) { std::all_of(S.begin() + 1, S.end(), [](char C) { return C == '_' || isAlnum(C); }); } + +// Write the contents of the a buffer to a file +void lld::saveBuffer(StringRef Buffer, const Twine &Path) { + std::error_code EC; + raw_fd_ostream OS(Path.str(), EC, sys::fs::OpenFlags::F_None); + if (EC) + error("cannot create " + Path + ": " + EC.message()); + OS << Buffer; +} |