summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorOliver Stannard <oliver.stannard@arm.com>2015-11-17 09:58:07 +0000
committerOliver Stannard <oliver.stannard@arm.com>2015-11-17 09:58:07 +0000
commit07b43d39a8ef5be442210c5ca21c780c19db0683 (patch)
tree759e1f5a6e8d11c14ad3886424dff632cf7fcf85 /llvm/lib/MC
parent3e0588d033189941222cf9aa37810b61d9893d68 (diff)
downloadbcm5719-llvm-07b43d39a8ef5be442210c5ca21c780c19db0683.tar.gz
bcm5719-llvm-07b43d39a8ef5be442210c5ca21c780c19db0683.zip
[Assembler] Allow non-fatal errors after parsing
This adds reportError to MCContext, which can be used as an alternative to reportFatalError when the assembler wants to try to continue processing the rest of the file after the error is reported, so that all of the errors ina file can be reported. It records the fact that an error was encountered, so we can avoid emitting an object file if any errors occurred. This patch doesn't add any uses of this function (a later patch will convert most uses of reportFatalError to use it), but there is a small functional change: we use the SourceManager to print the error message, even if we have a null SMLoc. This means that we get a SourceManager-style message, with the file and line information shown as <unknown>, rather than the "LLVM ERROR" style used by report_fatal_error. llvm-svn: 253327
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/MCContext.cpp22
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp2
2 files changed, 18 insertions, 6 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 93c7aaf36ee..383540a7a8f 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -42,7 +42,7 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false),
GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
AllowTemporaryLabels(true), DwarfCompileUnitID(0),
- AutoReset(DoAutoReset) {
+ AutoReset(DoAutoReset), HadError(false) {
std::error_code EC = llvm::sys::fs::current_path(CompilationDir);
if (EC)
@@ -102,6 +102,8 @@ void MCContext::reset() {
DwarfLocSeen = false;
GenDwarfForAssembly = false;
GenDwarfFileNumber = 0;
+
+ HadError = false;
}
//===----------------------------------------------------------------------===//
@@ -475,14 +477,24 @@ void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
[&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
}
-void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const {
- // If we have a source manager and a location, use it. Otherwise just
- // use the generic report_fatal_error().
- if (!SrcMgr || Loc == SMLoc())
+//===----------------------------------------------------------------------===//
+// Error Reporting
+//===----------------------------------------------------------------------===//
+
+void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
+ HadError = true;
+
+ // If we have a source manager use it. Otherwise just use the generic
+ // report_fatal_error().
+ if (!SrcMgr)
report_fatal_error(Msg, false);
// Use the source manager to print the message.
SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
+}
+
+void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
+ reportError(Loc, Msg);
// If we reached here, we are failing ungracefully. Run the interrupt handlers
// to make sure any special cleanups get done, in particular that we remove
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index dd0e6bde9d8..8e8be8e52f6 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -703,7 +703,7 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
if (!HadError && !NoFinalize)
Out.Finish();
- return HadError;
+ return HadError || getContext().hadError();
}
void AsmParser::checkForValidSection() {
OpenPOWER on IntegriCloud