summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2010-01-20 22:18:24 +0000
committerSean Callanan <scallanan@apple.com>2010-01-20 22:18:24 +0000
commit70855e42e64df4defc6657a624aeb3db48aac578 (patch)
tree78d868650658647a0742428c5c4904981ed83ba8
parent97c5a140c29a05c2b4403fd706689f6bce6c109a (diff)
downloadbcm5719-llvm-70855e42e64df4defc6657a624aeb3db48aac578.tar.gz
bcm5719-llvm-70855e42e64df4defc6657a624aeb3db48aac578.zip
Modified MCAsmLexer to return error information upward
rather than printing it locally, reducing its dependence on SourceMgr. llvm-svn: 94041
-rw-r--r--llvm/include/llvm/MC/MCAsmLexer.h23
-rw-r--r--llvm/tools/llvm-mc/AsmLexer.cpp3
-rw-r--r--llvm/tools/llvm-mc/AsmParser.cpp7
3 files changed, 29 insertions, 4 deletions
diff --git a/llvm/include/llvm/MC/MCAsmLexer.h b/llvm/include/llvm/MC/MCAsmLexer.h
index e9a6e3fda4a..bec6ede4ae2 100644
--- a/llvm/include/llvm/MC/MCAsmLexer.h
+++ b/llvm/include/llvm/MC/MCAsmLexer.h
@@ -12,11 +12,11 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/System/DataTypes.h"
+#include "llvm/Support/SMLoc.h"
namespace llvm {
class MCAsmLexer;
class MCInst;
-class SMLoc;
class Target;
/// AsmToken - Target independent representation for an assembler token.
@@ -103,6 +103,10 @@ public:
class MCAsmLexer {
/// The current token, stored in the base class for faster access.
AsmToken CurTok;
+
+ /// The location and description of the current error
+ SMLoc ErrLoc;
+ std::string Err;
MCAsmLexer(const MCAsmLexer &); // DO NOT IMPLEMENT
void operator=(const MCAsmLexer &); // DO NOT IMPLEMENT
@@ -110,7 +114,12 @@ protected: // Can only create subclasses.
MCAsmLexer();
virtual AsmToken LexToken() = 0;
-
+
+ void SetError(const SMLoc &errLoc, const std::string &err) {
+ ErrLoc = errLoc;
+ Err = err;
+ }
+
public:
virtual ~MCAsmLexer();
@@ -126,6 +135,16 @@ public:
const AsmToken &getTok() {
return CurTok;
}
+
+ /// getErrLoc - Get the current error location
+ const SMLoc &getErrLoc() {
+ return ErrLoc;
+ }
+
+ /// getErr - Get the current error string
+ const std::string &getErr() {
+ return Err;
+ }
/// getKind - Get the kind of current token.
AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
diff --git a/llvm/tools/llvm-mc/AsmLexer.cpp b/llvm/tools/llvm-mc/AsmLexer.cpp
index ba0d247d46c..758fac4cd2b 100644
--- a/llvm/tools/llvm-mc/AsmLexer.cpp
+++ b/llvm/tools/llvm-mc/AsmLexer.cpp
@@ -44,7 +44,8 @@ void AsmLexer::PrintMessage(SMLoc Loc, const std::string &Msg,
/// ReturnError - Set the error to the specified string at the specified
/// location. This is defined to always return AsmToken::Error.
AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
- PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
+ SetError(SMLoc::getFromPointer(Loc), Msg);
+
return AsmToken(AsmToken::Error, StringRef(Loc, 0));
}
diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp
index ab37eb83830..eb77e8d395b 100644
--- a/llvm/tools/llvm-mc/AsmParser.cpp
+++ b/llvm/tools/llvm-mc/AsmParser.cpp
@@ -101,7 +101,12 @@ bool AsmParser::TokError(const char *Msg) {
}
const AsmToken &AsmParser::Lex() {
- return Lexer.Lex();
+ const AsmToken &tok = Lexer.Lex();
+
+ if (tok.is(AsmToken::Error))
+ Lexer.PrintMessage(Lexer.getErrLoc(), Lexer.getErr(), "error");
+
+ return tok;
}
bool AsmParser::Run() {
OpenPOWER on IntegriCloud