diff options
author | Sam Clegg <sbc@chromium.org> | 2018-05-22 20:20:25 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-05-22 20:20:25 +0000 |
commit | 45b88895e71fe7201c9d0c73a2edb27ee76425af (patch) | |
tree | 613a30fb4f5c8f278b4990846ec5de900ce345bf /lld/Common | |
parent | 3a12af1eb9752de83b99a32ead3b6a7b07200040 (diff) |
Code cleanup in preparation for adding LTO for wasm. NFC.
- Move some common code into Common/rrorHandler.cpp and
Common/Strings.h.
- Don't use `fatal` when incompatible bitcode files are
encountered.
- Rename NameRef variable to just Name
See D47162
Differential Revision: https://reviews.llvm.org/D47206
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; +} |