Added llvm-mc support for parsing the .desc directive.
authorKevin Enderby <enderby@apple.com>
Tue, 14 Jul 2009 18:17:10 +0000 (18:17 +0000)
committerKevin Enderby <enderby@apple.com>
Tue, 14 Jul 2009 18:17:10 +0000 (18:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75645 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCStreamer.h
lib/MC/MCAsmStreamer.cpp
test/MC/AsmParser/directive_desc.s [new file with mode: 0644]
tools/llvm-mc/AsmParser.cpp
tools/llvm-mc/AsmParser.h

index 8ceb7723f93a85bf0bec0df81a833e815a8624c5..a418a0f0b0ea5da5837813f50ca02f44ac818e1e 100644 (file)
@@ -120,6 +120,12 @@ namespace llvm {
     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.
     ///
index b8e71ce1f6b05d1d437e95745a960703e5c23895..b3460080d73313d1556a81fdd98a8a005f51260b 100644 (file)
@@ -45,6 +45,8 @@ namespace {
 
     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 @@ void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
   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)
diff --git a/test/MC/AsmParser/directive_desc.s b/test/MC/AsmParser/directive_desc.s
new file mode 100644 (file)
index 0000000..80acc26
--- /dev/null
@@ -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
index c105801632830b6d78105e4def794061ccf7da93..d94b7b3270b0fe19dab3113a94623ef39d83fced 100644 (file)
@@ -526,6 +526,8 @@ bool AsmParser::ParseStatement() {
       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 @@ bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
   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) {
index da546732a716655ff72f90cd1033b7050ff1f061..b4f5e2d428a920ea127d57be17e6696ca22b41f9 100644 (file)
@@ -109,6 +109,7 @@ private:
   /// 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"