[llvm-commits] [llvm] r74734 - in /llvm/trunk: include/llvm/Assembly/Parser.h lib/AsmParser/LLLexer.cpp lib/AsmParser/LLLexer.h lib/AsmParser/LLParser.h lib/AsmParser/Parser.cpp tools/bugpoint/BugDriver.cpp tools/llvm-as/llvm-as.cpp

Chris Lattner sabre at nondot.org
Thu Jul 2 15:46:19 PDT 2009


Author: lattner
Date: Thu Jul  2 17:46:18 2009
New Revision: 74734

URL: http://llvm.org/viewvc/llvm-project?rev=74734&view=rev
Log:
switch the .ll parser into SMDiagnostic.



Modified:
    llvm/trunk/include/llvm/Assembly/Parser.h
    llvm/trunk/lib/AsmParser/LLLexer.cpp
    llvm/trunk/lib/AsmParser/LLLexer.h
    llvm/trunk/lib/AsmParser/LLParser.h
    llvm/trunk/lib/AsmParser/Parser.cpp
    llvm/trunk/tools/bugpoint/BugDriver.cpp
    llvm/trunk/tools/llvm-as/llvm-as.cpp

Modified: llvm/trunk/include/llvm/Assembly/Parser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Assembly/Parser.h?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Assembly/Parser.h (original)
+++ llvm/trunk/include/llvm/Assembly/Parser.h Thu Jul  2 17:46:18 2009
@@ -19,7 +19,7 @@
 namespace llvm {
 
 class Module;
-class ParseError;
+class SMDiagnostic;
 class raw_ostream;
 class LLVMContext;
 
@@ -31,8 +31,8 @@
 /// @brief Parse LLVM Assembly from a file
 Module *ParseAssemblyFile(
   const std::string &Filename, ///< The name of the file to parse
-  ParseError &Error,           ///< If not null, an object to return errors in.
-  LLVMContext& Context         ///< Context in which to allocate globals info.
+  SMDiagnostic &Error,         ///< Error result info.
+  LLVMContext &Context         ///< Context in which to allocate globals info.
 );
 
 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
@@ -44,61 +44,10 @@
 Module *ParseAssemblyString(
   const char *AsmString, ///< The string containing assembly
   Module *M,             ///< A module to add the assembly too.
-  ParseError &Error,     ///< If not null, an object to return errors in.
-  LLVMContext& Context
+  SMDiagnostic &Error,   ///< Error result info.
+  LLVMContext &Context
 );
 
-//===------------------------------------------------------------------------===
-//                              Helper Classes
-//===------------------------------------------------------------------------===
-
-/// An instance of this class can be passed to ParseAssemblyFile or 
-/// ParseAssemblyString functions in order to capture error information from
-/// the parser.  It provides a standard way to print out the error message
-/// including the file name and line number where the error occurred.
-/// @brief An LLVM Assembly Parsing Error Object
-class ParseError {
-public:
-  ParseError() : Filename("unknown"), Message("none"), LineNo(0), ColumnNo(0) {}
-  ParseError(const ParseError &E);
-
-  void setFilename(const std::string &F) { Filename = F; }
-  
-  inline const std::string &getRawMessage() const {   // Just the raw message.
-    return Message;
-  }
-
-  inline const std::string &getFilename() const {
-    return Filename;
-  }
-
-  void setError(const std::string &message, int lineNo = -1, int ColNo = -1,
-                const std::string &FileContents = "") {
-    Message = message;
-    LineNo = lineNo; ColumnNo = ColNo;
-    LineContents = FileContents;
-  }
-
-  // getErrorLocation - Return the line and column number of the error in the
-  // input source file.  The source filename can be derived from the
-  // ParserOptions in effect.  If positional information is not applicable,
-  // these will return a value of -1.
-  //
-  inline void getErrorLocation(int &Line, int &Column) const {
-    Line = LineNo; Column = ColumnNo;
-  }
-  
-  void PrintError(const char *ProgName, raw_ostream &S);
-
-private :
-  std::string Filename;
-  std::string Message;
-  int LineNo, ColumnNo;                               // -1 if not relevant
-  std::string LineContents;
-
-  void operator=(const ParseError &E); // DO NOT IMPLEMENT
-};
-
 } // End llvm namespace
 
 #endif

Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.cpp Thu Jul  2 17:46:18 2009
@@ -16,6 +16,7 @@
 #include "llvm/Instruction.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Assembly/Parser.h"
 #include <cstdlib>
@@ -38,8 +39,9 @@
   for (const char *FP = CurBuf->getBufferStart(); FP != ErrorLoc; ++FP)
     if (*FP == '\n') ++LineNo;
 
-  std::string LineContents(LineStart, LineEnd);
-  ErrorInfo.setError(Msg, LineNo, ErrorLoc-LineStart, LineContents);
+  ErrorInfo = SMDiagnostic(CurBuf->getBufferIdentifier(),
+                           LineNo, ErrorLoc-LineStart, Msg,
+                           std::string(LineStart, LineEnd));
   return true;
 }
 
@@ -195,7 +197,7 @@
 // Lexer definition.
 //===----------------------------------------------------------------------===//
 
-LLLexer::LLLexer(MemoryBuffer *StartBuf, ParseError &Err)
+LLLexer::LLLexer(MemoryBuffer *StartBuf, SMDiagnostic &Err)
   : CurBuf(StartBuf), ErrorInfo(Err), APFloatVal(0.0) {
   CurPtr = CurBuf->getBufferStart();
 }

Modified: llvm/trunk/lib/AsmParser/LLLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.h?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.h (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.h Thu Jul  2 17:46:18 2009
@@ -22,12 +22,12 @@
 namespace llvm {
   class MemoryBuffer;
   class Type;
-  class ParseError;
+  class SMDiagnostic;
 
   class LLLexer {
     const char *CurPtr;
     MemoryBuffer *CurBuf;
-    ParseError &ErrorInfo;
+    SMDiagnostic &ErrorInfo;
 
     // Information about the current token.
     const char *TokStart;
@@ -40,7 +40,7 @@
 
     std::string TheError;
   public:
-    explicit LLLexer(MemoryBuffer *StartBuf, ParseError &);
+    explicit LLLexer(MemoryBuffer *StartBuf, SMDiagnostic &);
     ~LLLexer() {}
 
     lltok::Kind Lex() {

Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Thu Jul  2 17:46:18 2009
@@ -73,7 +73,7 @@
     std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
     std::vector<GlobalValue*> NumberedVals;
   public:
-    LLParser(MemoryBuffer *F, ParseError &Err, Module *m) : 
+    LLParser(MemoryBuffer *F, SMDiagnostic &Err, Module *m) : 
       Context(m->getContext()), Lex(F, Err), M(m) {}
     bool Run();
 

Modified: llvm/trunk/lib/AsmParser/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/Parser.cpp?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/Parser.cpp (original)
+++ llvm/trunk/lib/AsmParser/Parser.cpp Thu Jul  2 17:46:18 2009
@@ -15,20 +15,20 @@
 #include "LLParser.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstring>
 using namespace llvm;
 
-Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err,
-                                LLVMContext& Context) {
-  Err.setFilename(Filename);
-
+Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
+                                LLVMContext &Context) {
   std::string ErrorStr;
   OwningPtr<MemoryBuffer>
     F(MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr));
   if (F == 0) {
-    Err.setError("Could not open input file '" + Filename + "'");
+    Err = SMDiagnostic("", -1, -1,
+                       "Could not open input file '" + Filename + "'", "");
     return 0;
   }
 
@@ -39,9 +39,7 @@
 }
 
 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
-                                  ParseError &Err, LLVMContext& Context) {
-  Err.setFilename("<string>");
-
+                                  SMDiagnostic &Err, LLVMContext &Context) {
   OwningPtr<MemoryBuffer>
     F(MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
                                  "<string>"));
@@ -56,33 +54,3 @@
     return 0;
   return M2.take();
 }
-
-
-//===------------------------------------------------------------------------===
-//                              ParseError Class
-//===------------------------------------------------------------------------===
-
-void ParseError::PrintError(const char *ProgName, raw_ostream &S) {
-  errs() << ProgName << ": ";
-  if (Filename == "-")
-    errs() << "<stdin>";
-  else
-    errs() << Filename;
-
-  if (LineNo != -1) {
-    errs() << ':' << LineNo;
-    if (ColumnNo != -1)
-      errs() << ':' << (ColumnNo+1);
-  }
-
-  errs() << ": " << Message << '\n';
-
-  if (LineNo != -1 && ColumnNo != -1) {
-    errs() << LineContents << '\n';
-
-    // Print out spaces/tabs before the caret.
-    for (unsigned i = 0; i != unsigned(ColumnNo); ++i)
-      errs() << (LineContents[i] == '\t' ? '\t' : ' ');
-    errs() << "^\n";
-  }
-}

Modified: llvm/trunk/tools/bugpoint/BugDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.cpp?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/BugDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/BugDriver.cpp Thu Jul  2 17:46:18 2009
@@ -23,6 +23,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 #include <iostream>
 #include <memory>
@@ -82,9 +83,9 @@
   if (Buffer.get())
     Result = ParseBitcodeFile(Buffer.get(), Ctxt);
   
-  ParseError Err;
+  SMDiagnostic Err;
   if (!Result && !(Result = ParseAssemblyFile(Filename, Err, Ctxt))) {
-    Err.PrintError("bugpoint", errs()); 
+    Err.Print("bugpoint", errs()); 
     Result = 0;
   }
   

Modified: llvm/trunk/tools/llvm-as/llvm-as.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-as/llvm-as.cpp?rev=74734&r1=74733&r2=74734&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
+++ llvm/trunk/tools/llvm-as/llvm-as.cpp Thu Jul  2 17:46:18 2009
@@ -23,6 +23,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/raw_ostream.h"
@@ -64,10 +65,10 @@
   std::ostream *Out = 0;
   try {
     // Parse the file now...
-    ParseError Err;
+    SMDiagnostic Err;
     std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context));
     if (M.get() == 0) {
-      Err.PrintError(argv[0], errs());
+      Err.Print(argv[0], errs());
       return 1;
     }
 





More information about the llvm-commits mailing list