[llvm-commits] [llvm] r94041 - in /llvm/trunk: include/llvm/MC/MCAsmLexer.h tools/llvm-mc/AsmLexer.cpp tools/llvm-mc/AsmParser.cpp

Sean Callanan scallanan at apple.com
Wed Jan 20 14:18:24 PST 2010


Author: spyffe
Date: Wed Jan 20 16:18:24 2010
New Revision: 94041

URL: http://llvm.org/viewvc/llvm-project?rev=94041&view=rev
Log:
Modified MCAsmLexer to return error information upward
rather than printing it locally, reducing its dependence
on SourceMgr.

Modified:
    llvm/trunk/include/llvm/MC/MCAsmLexer.h
    llvm/trunk/tools/llvm-mc/AsmLexer.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.cpp

Modified: llvm/trunk/include/llvm/MC/MCAsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLexer.h?rev=94041&r1=94040&r2=94041&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLexer.h Wed Jan 20 16:18:24 2010
@@ -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 @@
 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 @@
   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 @@
   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(); }

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=94041&r1=94040&r2=94041&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Wed Jan 20 16:18:24 2010
@@ -44,7 +44,8 @@
 /// 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));
 }
 

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=94041&r1=94040&r2=94041&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Wed Jan 20 16:18:24 2010
@@ -101,7 +101,12 @@
 }
 
 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() {





More information about the llvm-commits mailing list