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

Kevin Enderby enderby at apple.com
Tue Jul 14 11:17:12 PDT 2009


Author: enderby
Date: Tue Jul 14 13:17:10 2009
New Revision: 75645

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

Added:
    llvm/trunk/test/MC/AsmParser/directive_desc.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=75645&r1=75644&r2=75645&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Jul 14 13:17:10 2009
@@ -120,6 +120,12 @@
     virtual void EmitSymbolAttribute(MCSymbol *Symbol,
                                      SymbolAttr Attribute) = 0;
 
+    /// EmitSymbolDesc - Set the @param DescValue for the @param Symbol.
+    ///
+    /// @param Symbol - The symbol to have its n_desc field set.
+    /// @param DescValue - The value to set into the n_desc field.
+    virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
+
     /// EmitCommonSymbol - Emit a common or local common symbol of @param Size
     /// with the @param Pow2Alignment if non-zero.
     ///

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

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Jul 14 13:17:10 2009
@@ -45,6 +45,8 @@
 
     virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
 
+    virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
+
     virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
                                   unsigned Pow2Alignment, bool IsLocal);
 
@@ -166,6 +168,10 @@
   OS << ' ' << Symbol->getName() << '\n';
 }
 
+void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
+  OS << ".desc" << ' ' << Symbol->getName() << ',' << DescValue << '\n';
+}
+
 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
                                      unsigned Pow2Alignment, bool IsLocal) {
   if (IsLocal)

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

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_desc.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_desc.s Tue Jul 14 13:17:10 2009
@@ -0,0 +1,8 @@
+# RUN: llvm-mc %s | FileCheck %s
+
+# CHECK: TEST0:
+# CHECK: .desc foo,16
+# CHECK: .desc bar,4
+TEST0:  
+	.desc foo,0x10
+	.desc     bar, 1 +3

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

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jul 14 13:17:10 2009
@@ -526,6 +526,8 @@
       return ParseDirectiveComm(/*IsLocal=*/true);
     if (!strcmp(IDVal, ".zerofill"))
       return ParseDirectiveDarwinZerofill();
+    if (!strcmp(IDVal, ".desc"))
+      return ParseDirectiveDarwinSymbolDesc();
 
     if (!strcmp(IDVal, ".subsections_via_symbols"))
       return ParseDirectiveDarwinSubsectionsViaSymbols();
@@ -909,6 +911,37 @@
   return false;  
 }
 
+/// ParseDirectiveDarwinSymbolDesc
+///  ::= .desc identifier , expression
+bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
+  if (Lexer.isNot(asmtok::Identifier))
+    return TokError("expected identifier in directive");
+  
+  // handle the identifier as the key symbol.
+  SMLoc IDLoc = Lexer.getLoc();
+  MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
+  Lexer.Lex();
+
+  if (Lexer.isNot(asmtok::Comma))
+    return TokError("unexpected token in '.desc' directive");
+  Lexer.Lex();
+
+  SMLoc DescLoc = Lexer.getLoc();
+  int64_t DescValue;
+  if (ParseAbsoluteExpression(DescValue))
+    return true;
+
+  if (Lexer.isNot(asmtok::EndOfStatement))
+    return TokError("unexpected token in '.desc' directive");
+  
+  Lexer.Lex();
+
+  // Set the n_desc field of this Symbol to this DescValue
+  Out.EmitSymbolDesc(Sym, DescValue);
+
+  return false;
+}
+
 /// ParseDirectiveComm
 ///  ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ]
 bool AsmParser::ParseDirectiveComm(bool IsLocal) {

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

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jul 14 13:17:10 2009
@@ -109,6 +109,7 @@
   /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
   /// accepts a single symbol (which should be a label or an external).
   bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
+  bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
 
   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
   bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"





More information about the llvm-commits mailing list