switch the .ll parser into SMDiagnostic.




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74734 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp
index b3f7cdb..090e614 100644
--- a/lib/AsmParser/LLLexer.cpp
+++ b/lib/AsmParser/LLLexer.cpp
@@ -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();
 }
diff --git a/lib/AsmParser/LLLexer.h b/lib/AsmParser/LLLexer.h
index 995aa4e..49a63a1 100644
--- a/lib/AsmParser/LLLexer.h
+++ b/lib/AsmParser/LLLexer.h
@@ -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() {
diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h
index 6691f60..fdb2147 100644
--- a/lib/AsmParser/LLParser.h
+++ b/lib/AsmParser/LLParser.h
@@ -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();
 
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index 82d6f8f..17aae39 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -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";
-  }
-}