aboutsummaryrefslogtreecommitdiffstats
path: root/lib/AsmParser
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-07-02 23:08:13 +0000
committerChris Lattner <sabre@nondot.org>2009-07-02 23:08:13 +0000
commiteeb4a84ac8d91fb1d5a7c484a1c7047409faee30 (patch)
treea74754636cc687794c2d224169dec37702cc34be /lib/AsmParser
parent92bcb426c3e4503c99324afd4ed0a73521711a56 (diff)
downloadexternal_llvm-eeb4a84ac8d91fb1d5a7c484a1c7047409faee30.zip
external_llvm-eeb4a84ac8d91fb1d5a7c484a1c7047409faee30.tar.gz
external_llvm-eeb4a84ac8d91fb1d5a7c484a1c7047409faee30.tar.bz2
switch the .ll parser to use SourceMgr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r--lib/AsmParser/LLLexer.cpp23
-rw-r--r--lib/AsmParser/LLLexer.h10
-rw-r--r--lib/AsmParser/LLParser.cpp8
-rw-r--r--lib/AsmParser/LLParser.h4
-rw-r--r--lib/AsmParser/Parser.cpp21
5 files changed, 28 insertions, 38 deletions
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp
index 090e614..741c538 100644
--- a/lib/AsmParser/LLLexer.cpp
+++ b/lib/AsmParser/LLLexer.cpp
@@ -24,24 +24,7 @@
using namespace llvm;
bool LLLexer::Error(LocTy ErrorLoc, const std::string &Msg) const {
- // Scan backward to find the start of the line.
- const char *LineStart = ErrorLoc;
- while (LineStart != CurBuf->getBufferStart() &&
- LineStart[-1] != '\n' && LineStart[-1] != '\r')
- --LineStart;
- // Get the end of the line.
- const char *LineEnd = ErrorLoc;
- while (LineEnd != CurBuf->getBufferEnd() &&
- LineEnd[0] != '\n' && LineEnd[0] != '\r')
- ++LineEnd;
-
- unsigned LineNo = 1;
- for (const char *FP = CurBuf->getBufferStart(); FP != ErrorLoc; ++FP)
- if (*FP == '\n') ++LineNo;
-
- ErrorInfo = SMDiagnostic(CurBuf->getBufferIdentifier(),
- LineNo, ErrorLoc-LineStart, Msg,
- std::string(LineStart, LineEnd));
+ ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
return true;
}
@@ -197,8 +180,8 @@ static const char *isLabelTail(const char *CurPtr) {
// Lexer definition.
//===----------------------------------------------------------------------===//
-LLLexer::LLLexer(MemoryBuffer *StartBuf, SMDiagnostic &Err)
- : CurBuf(StartBuf), ErrorInfo(Err), APFloatVal(0.0) {
+LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err)
+ : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), APFloatVal(0.0) {
CurPtr = CurBuf->getBufferStart();
}
diff --git a/lib/AsmParser/LLLexer.h b/lib/AsmParser/LLLexer.h
index 49a63a1..b5e58f1 100644
--- a/lib/AsmParser/LLLexer.h
+++ b/lib/AsmParser/LLLexer.h
@@ -17,6 +17,7 @@
#include "LLToken.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/Support/SourceMgr.h"
#include <string>
namespace llvm {
@@ -28,6 +29,7 @@ namespace llvm {
const char *CurPtr;
MemoryBuffer *CurBuf;
SMDiagnostic &ErrorInfo;
+ SourceMgr &SM;
// Information about the current token.
const char *TokStart;
@@ -40,15 +42,15 @@ namespace llvm {
std::string TheError;
public:
- explicit LLLexer(MemoryBuffer *StartBuf, SMDiagnostic &);
+ explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &);
~LLLexer() {}
lltok::Kind Lex() {
return CurKind = LexToken();
}
- typedef const char* LocTy;
- LocTy getLoc() const { return TokStart; }
+ typedef SMLoc LocTy;
+ LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
lltok::Kind getKind() const { return CurKind; }
const std::string getStrVal() const { return StrVal; }
const Type *getTyVal() const { return TyVal; }
@@ -58,7 +60,7 @@ namespace llvm {
bool Error(LocTy L, const std::string &Msg) const;
- bool Error(const std::string &Msg) const { return Error(CurPtr, Msg); }
+ bool Error(const std::string &Msg) const { return Error(getLoc(), Msg); }
std::string getFilename() const;
private:
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index d5dbb52..3966ab3 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -131,7 +131,7 @@ bool LLParser::ParseTopLevelEntities() {
unsigned Linkage, Visibility;
if (ParseOptionalLinkage(Linkage) ||
ParseOptionalVisibility(Visibility) ||
- ParseGlobal("", 0, Linkage, true, Visibility))
+ ParseGlobal("", SMLoc(), Linkage, true, Visibility))
return true;
break;
}
@@ -140,7 +140,7 @@ bool LLParser::ParseTopLevelEntities() {
case lltok::kw_protected: { // OptionalVisibility
unsigned Visibility;
if (ParseOptionalVisibility(Visibility) ||
- ParseGlobal("", 0, 0, false, Visibility))
+ ParseGlobal("", SMLoc(), 0, false, Visibility))
return true;
break;
}
@@ -149,7 +149,7 @@ bool LLParser::ParseTopLevelEntities() {
case lltok::kw_addrspace: // OptionalAddrSpace
case lltok::kw_constant: // GlobalType
case lltok::kw_global: // GlobalType
- if (ParseGlobal("", 0, 0, false, 0)) return true;
+ if (ParseGlobal("", SMLoc(), 0, false, 0)) return true;
break;
}
}
@@ -3162,7 +3162,7 @@ bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc) {
PATypeHolder Ty(Type::VoidTy);
Value *Size = 0;
- LocTy SizeLoc = 0;
+ LocTy SizeLoc;
unsigned Alignment = 0;
if (ParseType(Ty)) return true;
diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h
index fdb2147..6659620 100644
--- a/lib/AsmParser/LLParser.h
+++ b/lib/AsmParser/LLParser.h
@@ -73,8 +73,8 @@ namespace llvm {
std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
std::vector<GlobalValue*> NumberedVals;
public:
- LLParser(MemoryBuffer *F, SMDiagnostic &Err, Module *m) :
- Context(m->getContext()), Lex(F, Err), M(m) {}
+ LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
+ Context(m->getContext()), Lex(F, SM, Err), M(m) {}
bool Run();
LLVMContext& getContext() { return Context; }
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index 17aae39..d66c13d 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -24,33 +24,38 @@ using namespace llvm;
Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
LLVMContext &Context) {
std::string ErrorStr;
- OwningPtr<MemoryBuffer>
- F(MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr));
+ MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
if (F == 0) {
Err = SMDiagnostic("", -1, -1,
"Could not open input file '" + Filename + "'", "");
return 0;
}
+ SourceMgr SM;
+ SM.AddNewSourceBuffer(F, SMLoc());
+
OwningPtr<Module> M(new Module(Filename, Context));
- if (LLParser(F.get(), Err, M.get()).Run())
+ if (LLParser(F, SM, Err, M.get()).Run())
return 0;
return M.take();
}
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
SMDiagnostic &Err, LLVMContext &Context) {
- OwningPtr<MemoryBuffer>
- F(MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
- "<string>"));
+ MemoryBuffer *F =
+ MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
+ "<string>");
+ SourceMgr SM;
+ SM.AddNewSourceBuffer(F, SMLoc());
+
// If we are parsing into an existing module, do it.
if (M)
- return LLParser(F.get(), Err, M).Run() ? 0 : M;
+ return LLParser(F, SM, Err, M).Run() ? 0 : M;
// Otherwise create a new module.
OwningPtr<Module> M2(new Module("<string>", Context));
- if (LLParser(F.get(), Err, M2.get()).Run())
+ if (LLParser(F, SM, Err, M2.get()).Run())
return 0;
return M2.take();
}