summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mc/AsmParser.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2010-01-21 00:19:58 +0000
committerSean Callanan <scallanan@apple.com>2010-01-21 00:19:58 +0000
commit7a77eae2f3d4d2f0ff0ea4b817c24823f4a8b5c6 (patch)
tree797075ea41bbe8b991b2f72a0e9597c96e76ae94 /llvm/tools/llvm-mc/AsmParser.cpp
parent879cc735fc6707aa5b6191158d8808d84fba3a8d (diff)
downloadbcm5719-llvm-7a77eae2f3d4d2f0ff0ea4b817c24823f4a8b5c6.tar.gz
bcm5719-llvm-7a77eae2f3d4d2f0ff0ea4b817c24823f4a8b5c6.zip
Moved handling of inclusion from the AsmLexer to
the AsmParser, breaking AsmLexer's dependence on SourceMgr. llvm-svn: 94054
Diffstat (limited to 'llvm/tools/llvm-mc/AsmParser.cpp')
-rw-r--r--llvm/tools/llvm-mc/AsmParser.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp
index 0e0c1a4de7a..068e506be26 100644
--- a/llvm/tools/llvm-mc/AsmParser.cpp
+++ b/llvm/tools/llvm-mc/AsmParser.cpp
@@ -40,8 +40,10 @@ typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy;
AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
const MCAsmInfo &_MAI)
- : Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM), TargetParser(0),
- SectionUniquingMap(0) {
+ : Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM), TargetParser(0),
+ CurBuffer(0), SectionUniquingMap(0) {
+ Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
+
// Debugging directives.
AddDirectiveHandler(".file", &AsmParser::ParseDirectiveFile);
AddDirectiveHandler(".line", &AsmParser::ParseDirectiveLine);
@@ -104,14 +106,38 @@ void AsmParser::PrintMessage(SMLoc Loc, const std::string &Msg,
const char *Type) const {
SrcMgr.PrintMessage(Loc, Msg, Type);
}
-
+
+bool AsmParser::EnterIncludeFile(const std::string &Filename) {
+ int NewBuf = SrcMgr.AddIncludeFile(Filename, Lexer.getLoc());
+ if (NewBuf == -1)
+ return true;
+
+ CurBuffer = NewBuf;
+
+ Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
+
+ return false;
+}
+
const AsmToken &AsmParser::Lex() {
- const AsmToken &tok = Lexer.Lex();
+ const AsmToken *tok = &Lexer.Lex();
- if (tok.is(AsmToken::Error))
+ if (tok->is(AsmToken::Eof)) {
+ // If this is the end of an included file, pop the parent file off the
+ // include stack.
+ SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer);
+ if (ParentIncludeLoc != SMLoc()) {
+ CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
+ Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer),
+ ParentIncludeLoc.getPointer());
+ tok = &Lexer.Lex();
+ }
+ }
+
+ if (tok->is(AsmToken::Error))
PrintMessage(Lexer.getErrLoc(), Lexer.getErr(), "error");
- return tok;
+ return *tok;
}
bool AsmParser::Run() {
@@ -1522,7 +1548,7 @@ bool AsmParser::ParseDirectiveInclude() {
// Attempt to switch the lexer to the included file before consuming the end
// of statement to avoid losing it when we switch.
- if (Lexer.EnterIncludeFile(Filename)) {
+ if (EnterIncludeFile(Filename)) {
PrintMessage(IncludeLoc,
"Could not find include file '" + Filename + "'",
"error");
OpenPOWER on IntegriCloud