[llvm-commits] [llvm] r75711 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp test/MC/AsmParser/directive_include.s tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h

Kevin Enderby enderby at apple.com
Tue Jul 14 16:21:56 PDT 2009


Author: enderby
Date: Tue Jul 14 18:21:55 2009
New Revision: 75711

URL: http://llvm.org/viewvc/llvm-project?rev=75711&view=rev
Log:
Added llvm-mc support for parsing the .include directive.

Added:
    llvm/trunk/test/MC/AsmParser/directive_include.s
Modified:
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.h

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=75711&r1=75710&r2=75711&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Jul 14 18:21:55 2009
@@ -160,6 +160,12 @@
     /// @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;
+
     /// @}
     /// @name Generating Data
     /// @{

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=75711&r1=75710&r2=75711&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Jul 14 18:21:55 2009
@@ -57,6 +57,8 @@
 
     virtual void AbortAssembly(const char *AbortReason = NULL);
 
+    virtual void SwitchInputAssemblyFile(const char *FileName);
+
     virtual void EmitBytes(const char *Data, unsigned Length);
 
     virtual void EmitValue(const MCValue &Value, unsigned Size);
@@ -137,6 +139,10 @@
   
 }
 
+void MCAsmStreamer::SwitchInputAssemblyFile(const char *FileName) {
+  OS << ".include" << ' ' << FileName << '\n';
+}
+
 void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
                                    bool MakeAbsolute) {
   assert(!Symbol->getSection() && "Cannot assign to a label!");

Added: llvm/trunk/test/MC/AsmParser/directive_include.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_include.s?rev=75711&view=auto

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_include.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_include.s Tue Jul 14 18:21:55 2009
@@ -0,0 +1,8 @@
+# RUN: llvm-mc %s | FileCheck %s
+
+# 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"

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=75711&r1=75710&r2=75711&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jul 14 18:21:55 2009
@@ -535,6 +535,8 @@
       return ParseDirectiveDarwinSubsectionsViaSymbols();
     if (!strcmp(IDVal, ".abort"))
       return ParseDirectiveAbort();
+    if (!strcmp(IDVal, ".include"))
+      return ParseDirectiveInclude();
 
     Warning(IDLoc, "ignoring directive for now");
     EatToEndOfStatement();
@@ -1158,3 +1160,25 @@
 
   return false;
 }
+
+/// ParseDirectiveInclude
+///  ::= .include "filename"
+bool AsmParser::ParseDirectiveInclude() {
+  const char *Str;
+
+  if (Lexer.isNot(asmtok::String))
+    return TokError("expected string in '.include' directive");
+  
+  Str = Lexer.getCurStrVal();
+
+  Lexer.Lex();
+
+  if (Lexer.isNot(asmtok::EndOfStatement))
+    return TokError("unexpected token in '.include' directive");
+  
+  Lexer.Lex();
+
+  Out.SwitchInputAssemblyFile(Str);
+
+  return false;
+}

Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=75711&r1=75710&r2=75711&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jul 14 18:21:55 2009
@@ -119,6 +119,7 @@
   bool ParseDirectiveDarwinSubsectionsViaSymbols();
 
   bool ParseDirectiveAbort(); // ".abort"
+  bool ParseDirectiveInclude(); // ".include"
 };
 
 } // end namespace llvm





More information about the llvm-commits mailing list