[llvm-commits] [llvm] r75896 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp test/MC/AsmParser/directive_include.s tools/llvm-mc/AsmLexer.cpp tools/llvm-mc/AsmLexer.h tools/llvm-mc/AsmParser.cpp
Chris Lattner
sabre at nondot.org
Wed Jul 15 23:14:55 PDT 2009
Author: lattner
Date: Thu Jul 16 01:14:39 2009
New Revision: 75896
URL: http://llvm.org/viewvc/llvm-project?rev=75896&view=rev
Log:
implement .include in the lexer/parser instead of passing it into the streamer.
Modified:
llvm/trunk/include/llvm/MC/MCStreamer.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/test/MC/AsmParser/directive_include.s
llvm/trunk/tools/llvm-mc/AsmLexer.cpp
llvm/trunk/tools/llvm-mc/AsmLexer.h
llvm/trunk/tools/llvm-mc/AsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=75896&r1=75895&r2=75896&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Thu Jul 16 01:14:39 2009
@@ -160,12 +160,6 @@
/// @param AbortReason - The reason assembly is terminated, if non-NULL.
virtual void AbortAssembly(const char *AbortReason) = 0;
- /// SwitchInputAssemblyFile - Assemble the contents of the specified file in
- /// @param FileName at this point in the assembly.
- ///
- /// @param FileName - The file to assemble at this point
- virtual void SwitchInputAssemblyFile(const char *FileName) = 0;
-
/// DumpSymbolsandMacros - Dump to the specified file in @param FileName all
/// symbols and macros at this point in the assembly.
///
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=75896&r1=75895&r2=75896&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Jul 16 01:14:39 2009
@@ -57,8 +57,6 @@
virtual void AbortAssembly(const char *AbortReason = NULL);
- virtual void SwitchInputAssemblyFile(const char *FileName);
-
virtual void DumpSymbolsandMacros(const char *FileName);
virtual void LoadSymbolsandMacros(const char *FileName);
@@ -143,10 +141,6 @@
}
-void MCAsmStreamer::SwitchInputAssemblyFile(const char *FileName) {
- OS << ".include" << ' ' << FileName << '\n';
-}
-
void MCAsmStreamer::DumpSymbolsandMacros(const char *FileName) {
OS << ".dump" << ' ' << FileName << '\n';
}
Modified: llvm/trunk/test/MC/AsmParser/directive_include.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_include.s?rev=75896&r1=75895&r2=75896&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_include.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_include.s Thu Jul 16 01:14:39 2009
@@ -1,8 +1,9 @@
-# RUN: llvm-mc %s | FileCheck %s
+# RUN: llvm-mc %s -I %p | FileCheck %s
+# CHECK: TESTA:
# CHECK: TEST0:
-# CHECK: .include "some/include/file"
-# CHECK: .include "mary had a little lamb"
-TEST0:
- .include "some/include/file"
- .include "mary had a little lamb"
+# CHECK: .set a, 0
+# CHECK: TESTB:
+TESTA:
+ .include "directive_set.s"
+TESTB:
Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=75896&r1=75895&r2=75896&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Thu Jul 16 01:14:39 2009
@@ -54,6 +54,21 @@
return asmtok::Error;
}
+/// EnterIncludeFile - Enter the specified file. This prints an error and
+/// returns true on failure.
+bool AsmLexer::EnterIncludeFile(const std::string &Filename) {
+ int NewBuf = SrcMgr.AddIncludeFile(Filename, SMLoc::getFromPointer(CurPtr));
+ if (NewBuf == -1)
+ return true;
+
+ // Save the line number and lex buffer of the includer.
+ CurBuffer = NewBuf;
+ CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
+ CurPtr = CurBuf->getBufferStart();
+ return false;
+}
+
+
int AsmLexer::getNextChar() {
char CurChar = *CurPtr++;
switch (CurChar) {
@@ -72,6 +87,10 @@
CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc);
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
CurPtr = ParentIncludeLoc.getPointer();
+
+ // Reset the token start pointer to the start of the new file.
+ TokStart = CurPtr;
+
return getNextChar();
}
Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=75896&r1=75895&r2=75896&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Thu Jul 16 01:14:39 2009
@@ -97,6 +97,9 @@
SMLoc getLoc() const;
+ /// EnterIncludeFile - Enter the specified file. This returns true on failure.
+ bool EnterIncludeFile(const std::string &Filename);
+
void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
private:
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=75896&r1=75895&r2=75896&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Thu Jul 16 01:14:39 2009
@@ -1168,21 +1168,27 @@
/// ParseDirectiveInclude
/// ::= .include "filename"
bool AsmParser::ParseDirectiveInclude() {
- const char *Str;
-
if (Lexer.isNot(asmtok::String))
return TokError("expected string in '.include' directive");
- Str = Lexer.getCurStrVal();
-
+ std::string Filename = Lexer.getCurStrVal();
+ SMLoc IncludeLoc = Lexer.getLoc();
Lexer.Lex();
if (Lexer.isNot(asmtok::EndOfStatement))
return TokError("unexpected token in '.include' directive");
- Lexer.Lex();
-
- Out.SwitchInputAssemblyFile(Str);
+ // Strip the quotes.
+ Filename = Filename.substr(1, Filename.size()-2);
+
+ // 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)) {
+ Lexer.PrintMessage(IncludeLoc,
+ "Could not find include file '" + Filename + "'",
+ "error");
+ return true;
+ }
return false;
}
More information about the llvm-commits
mailing list