MC/AsmParser: Move .tbss and .zerofill parsing to Darwin specific parser.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 12 Jul 2010 19:37:35 +0000 (19:37 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 12 Jul 2010 19:37:35 +0000 (19:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108180 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/AsmParser.h
lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/directive_zerofill.s
test/MC/AsmParser/exprs.s

index 43cb596a6686737a7d7e93abbb2b5f28b4434e6b..f504caa39fc0ce3c2ebe9d98f938b8e761e6e483 100644 (file)
@@ -139,8 +139,6 @@ private:
   bool ParseDirectiveELFType(); // ELF specific ".type"
 
   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
-  bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
-  bool ParseDirectiveDarwinTBSS(); // Darwin specific ".tbss"
 
   bool ParseDirectiveAbort(); // ".abort"
   bool ParseDirectiveInclude(); // ".include"
index b9139fe5af6dc62439b0a3e52de6ab31e80c1b4b..0aeff0f0d1af42b9b86e8d098b4edf50017227b2 100644 (file)
@@ -83,6 +83,12 @@ public:
     Parser.AddDirectiveHandler(this, ".secure_log_reset",
                                MCAsmParser::DirectiveHandler(
                              &DarwinAsmParser::ParseDirectiveSecureLogReset));
+    Parser.AddDirectiveHandler(this, ".tbss",
+                               MCAsmParser::DirectiveHandler(
+                                 &DarwinAsmParser::ParseDirectiveTBSS));
+    Parser.AddDirectiveHandler(this, ".zerofill",
+                               MCAsmParser::DirectiveHandler(
+                                 &DarwinAsmParser::ParseDirectiveZerofill));
   }
 
   bool ParseDirectiveDesc(StringRef, SMLoc);
@@ -91,6 +97,8 @@ public:
   bool ParseDirectiveSecureLogReset(StringRef, SMLoc);
   bool ParseDirectiveSecureLogUnique(StringRef, SMLoc);
   bool ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
+  bool ParseDirectiveTBSS(StringRef, SMLoc);
+  bool ParseDirectiveZerofill(StringRef, SMLoc);
 };
 
 }
@@ -838,10 +846,6 @@ bool AsmParser::ParseStatement() {
       return ParseDirectiveComm(/*IsLocal=*/false);
     if (IDVal == ".lcomm")
       return ParseDirectiveComm(/*IsLocal=*/true);
-    if (IDVal == ".zerofill")
-      return ParseDirectiveDarwinZerofill();
-    if (IDVal == ".tbss")
-      return ParseDirectiveDarwinTBSS();
 
     if (IDVal == ".abort")
       return ParseDirectiveAbort();
@@ -1532,12 +1536,12 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
   return false;
 }
 
-/// ParseDirectiveDarwinZerofill
+/// ParseDirectiveZerofill
 ///  ::= .zerofill segname , sectname [, identifier , size_expression [
 ///      , align_expression ]]
-bool AsmParser::ParseDirectiveDarwinZerofill() {
+bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
   StringRef Segment;
-  if (ParseIdentifier(Segment))
+  if (getParser().ParseIdentifier(Segment))
     return TokError("expected segment name after '.zerofill' directive");
 
   if (getLexer().isNot(AsmToken::Comma))
@@ -1545,7 +1549,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
   Lex();
 
   StringRef Section;
-  if (ParseIdentifier(Section))
+  if (getParser().ParseIdentifier(Section))
     return TokError("expected section name after comma in '.zerofill' "
                     "directive");
 
@@ -1553,9 +1557,9 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
   // the section but with no symbol.
   if (getLexer().is(AsmToken::EndOfStatement)) {
     // Create the zerofill section but no symbol
-    getStreamer().EmitZerofill(Ctx.getMachOSection(Segment, Section,
-                                         MCSectionMachO::S_ZEROFILL, 0,
-                                         SectionKind::getBSS()));
+    getStreamer().EmitZerofill(getContext().getMachOSection(
+                                 Segment, Section, MCSectionMachO::S_ZEROFILL,
+                                 0, SectionKind::getBSS()));
     return false;
   }
 
@@ -1565,11 +1569,11 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
 
   SMLoc IDLoc = getLexer().getLoc();
   StringRef IDStr;
-  if (ParseIdentifier(IDStr))
+  if (getParser().ParseIdentifier(IDStr))
     return TokError("expected identifier in directive");
   
   // handle the identifier as the key symbol.
-  MCSymbol *Sym = CreateSymbol(IDStr);
+  MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr);
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
@@ -1577,7 +1581,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
 
   int64_t Size;
   SMLoc SizeLoc = getLexer().getLoc();
-  if (ParseAbsoluteExpression(Size))
+  if (getParser().ParseAbsoluteExpression(Size))
     return true;
 
   int64_t Pow2Alignment = 0;
@@ -1585,7 +1589,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
   if (getLexer().is(AsmToken::Comma)) {
     Lex();
     Pow2AlignmentLoc = getLexer().getLoc();
-    if (ParseAbsoluteExpression(Pow2Alignment))
+    if (getParser().ParseAbsoluteExpression(Pow2Alignment))
       return true;
   }
   
@@ -1611,24 +1615,24 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
   // Create the zerofill Symbol with Size and Pow2Alignment
   //
   // FIXME: Arch specific.
-  getStreamer().EmitZerofill(Ctx.getMachOSection(Segment, Section,
-                                       MCSectionMachO::S_ZEROFILL, 0,
-                                       SectionKind::getBSS()),
-                   Sym, Size, 1 << Pow2Alignment);
+  getStreamer().EmitZerofill(getContext().getMachOSection(
+                               Segment, Section, MCSectionMachO::S_ZEROFILL,
+                               0, SectionKind::getBSS()),
+                             Sym, Size, 1 << Pow2Alignment);
 
   return false;
 }
 
-/// ParseDirectiveDarwinTBSS
+/// ParseDirectiveTBSS
 ///  ::= .tbss identifier, size, align
-bool AsmParser::ParseDirectiveDarwinTBSS() {
+bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) {
   SMLoc IDLoc = getLexer().getLoc();
   StringRef Name;
-  if (ParseIdentifier(Name))
+  if (getParser().ParseIdentifier(Name))
     return TokError("expected identifier in directive");
     
   // Handle the identifier as the key symbol.
-  MCSymbol *Sym = CreateSymbol(Name);
+  MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
@@ -1636,7 +1640,7 @@ bool AsmParser::ParseDirectiveDarwinTBSS() {
 
   int64_t Size;
   SMLoc SizeLoc = getLexer().getLoc();
-  if (ParseAbsoluteExpression(Size))
+  if (getParser().ParseAbsoluteExpression(Size))
     return true;
 
   int64_t Pow2Alignment = 0;
@@ -1644,7 +1648,7 @@ bool AsmParser::ParseDirectiveDarwinTBSS() {
   if (getLexer().is(AsmToken::Comma)) {
     Lex();
     Pow2AlignmentLoc = getLexer().getLoc();
-    if (ParseAbsoluteExpression(Pow2Alignment))
+    if (getParser().ParseAbsoluteExpression(Pow2Alignment))
       return true;
   }
   
@@ -1665,7 +1669,7 @@ bool AsmParser::ParseDirectiveDarwinTBSS() {
   if (!Sym->isUndefined())
     return Error(IDLoc, "invalid symbol redefinition");
   
-  getStreamer().EmitTBSSSymbol(Ctx.getMachOSection(
+  getStreamer().EmitTBSSSymbol(getContext().getMachOSection(
                                  "__DATA", "__thread_bss",
                                  MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
                                  0, SectionKind::getThreadBSS()),
index 207b8a97991f7728a1c9c7f0b7c4130e6e10ab22..bd6e485a707091b0e8d85312cde40f334b65c058 100644 (file)
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+# RUN: llvm-mc -triple i386-apple-darwin9 %s | FileCheck %s
 
 # CHECK: TEST0:
 # CHECK: .zerofill __FOO,__bar,x,1
index d9a248cd94ffe93c2b0868bfd77dc4aee728c60c..350360ce684e551a2d57ff5f5b0d5a5df9911c49 100644 (file)
@@ -70,5 +70,3 @@ L0:
 L1:
         jmp A
         .long . - L1
-
-        .zerofill __DATA,_bss,A,0