|
25 | 25 | #include "llvm/CodeGen/MachineModuleInfo.h"
|
26 | 26 | #include "llvm/CodeGen/TargetPassConfig.h"
|
27 | 27 | #include "llvm/IR/DataLayout.h"
|
| 28 | +#include "llvm/IR/DiagnosticInfo.h" |
| 29 | +#include "llvm/IR/DiagnosticPrinter.h" |
28 | 30 | #include "llvm/IR/IRPrintingPasses.h"
|
29 | 31 | #include "llvm/IR/LLVMContext.h"
|
30 | 32 | #include "llvm/IR/LegacyPassManager.h"
|
@@ -111,6 +113,11 @@ static cl::opt<bool> DiscardValueNames(
|
111 | 113 | cl::desc("Discard names from Value (other than GlobalValue)."),
|
112 | 114 | cl::init(false), cl::Hidden);
|
113 | 115 |
|
| 116 | +static cl::opt<bool> ExitOnError( |
| 117 | + "exit-on-error", |
| 118 | + cl::desc("Exit as soon as an error is encountered."), |
| 119 | + cl::init(false), cl::Hidden); |
| 120 | + |
114 | 121 | static int compileModule(char **, LLVMContext &);
|
115 | 122 |
|
116 | 123 | static std::unique_ptr<tool_output_file>
|
@@ -181,6 +188,17 @@ GetOutputStream(const char *TargetName, Triple::OSType OS,
|
181 | 188 | return FDOut;
|
182 | 189 | }
|
183 | 190 |
|
| 191 | +static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context) { |
| 192 | + bool *HasError = static_cast<bool *>(Context); |
| 193 | + if (DI.getSeverity() == DS_Error) |
| 194 | + *HasError = true; |
| 195 | + |
| 196 | + DiagnosticPrinterRawOStream DP(errs()); |
| 197 | + errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; |
| 198 | + DI.print(DP); |
| 199 | + errs() << "\n"; |
| 200 | +} |
| 201 | + |
184 | 202 | // main - Entry point for the llc compiler.
|
185 | 203 | //
|
186 | 204 | int main(int argc, char **argv) {
|
@@ -215,6 +233,11 @@ int main(int argc, char **argv) {
|
215 | 233 |
|
216 | 234 | Context.setDiscardValueNames(DiscardValueNames);
|
217 | 235 |
|
| 236 | + // Set a diagnostic handler that doesn't exit on the first error |
| 237 | + bool HasError = false; |
| 238 | + if (!ExitOnError) |
| 239 | + Context.setDiagnosticHandler(DiagnosticHandler, &HasError); |
| 240 | + |
218 | 241 | // Compile the module TimeCompilations times to give better compile time
|
219 | 242 | // metrics.
|
220 | 243 | for (unsigned I = TimeCompilations; I; --I)
|
@@ -441,6 +464,12 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
441 | 464 |
|
442 | 465 | PM.run(*M);
|
443 | 466 |
|
| 467 | + if (!ExitOnError) { |
| 468 | + auto HasError = *static_cast<bool *>(Context.getDiagnosticContext()); |
| 469 | + if (HasError) |
| 470 | + return 1; |
| 471 | + } |
| 472 | + |
444 | 473 | // Compare the two outputs and make sure they're the same
|
445 | 474 | if (CompileTwice) {
|
446 | 475 | if (Buffer.size() != CompileTwiceBuffer.size() ||
|
|
0 commit comments