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

Chris Lattner sabre at nondot.org
Thu Jul 9 10:25:12 PDT 2009


Author: lattner
Date: Thu Jul  9 12:25:12 2009
New Revision: 75148

URL: http://llvm.org/viewvc/llvm-project?rev=75148&view=rev
Log:
add llvm-mc support for parsing the .lcomm directive, patch by Kevin Enderby!

Added:
    llvm/trunk/test/MC/AsmParser/directive_lcomm.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=75148&r1=75147&r2=75148&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Thu Jul  9 12:25:12 2009
@@ -115,14 +115,15 @@
     virtual void EmitSymbolAttribute(MCSymbol *Symbol,
                                      SymbolAttr Attribute) = 0;
 
-    /// EmitCommonSymbol - Emit a common symbol of @param Size with the @param
-    /// Pow2Alignment if non-zero.
+    /// EmitCommonSymbol - Emit a common or local common symbol of @param Size
+    /// with the @param Pow2Alignment if non-zero.
     ///
     /// @param Symbol - The common symbol to emit.
     /// @param Size - The size of the common symbol.
     /// @param Pow2Alignment - The alignment of the common symbol if non-zero.
+    /// @param IsLocal - If true, then the symbol is to be a local common
     virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
-                                  unsigned Pow2Alignment) = 0;
+                                  unsigned Pow2Alignment, bool IsLocal) = 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=75148&r1=75147&r2=75148&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Jul  9 12:25:12 2009
@@ -42,7 +42,7 @@
     virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
 
     virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
-                                  unsigned Pow2Alignment);
+                                  unsigned Pow2Alignment, bool IsLocal);
 
     virtual void EmitBytes(const char *Data, unsigned Length);
 
@@ -146,8 +146,11 @@
 }
 
 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
-                                     unsigned Pow2Alignment) {
-  OS << ".comm";
+                                     unsigned Pow2Alignment, bool IsLocal) {
+  if (IsLocal)
+    OS << ".lcomm";
+  else
+    OS << ".comm";
   OS << ' ' << Symbol->getName() << ',' << Size;
   if (Pow2Alignment != 0)
     OS << ',' << Pow2Alignment;

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

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_lcomm.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_lcomm.s Thu Jul  9 12:25:12 2009
@@ -0,0 +1,10 @@
+# RUN: llvm-mc %s | FileCheck %s
+
+# CHECK: TEST0:
+# CHECK: .lcomm a,7,4
+# CHECK: .lcomm b,8
+# CHECK: .lcomm c,0
+TEST0:  
+        .lcomm a, 8-1, 4
+        .lcomm b,8
+        .lcomm  c,  0

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

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Thu Jul  9 12:25:12 2009
@@ -521,7 +521,9 @@
       return ParseDirectiveSymbolAttribute(MCStreamer::WeakReference);
 
     if (!strcmp(IDVal, ".comm"))
-      return ParseDirectiveComm();
+      return ParseDirectiveComm(/*IsLocal=*/false);
+    if (!strcmp(IDVal, ".lcomm"))
+      return ParseDirectiveComm(/*IsLocal=*/true);
 
     Warning(IDLoc, "ignoring directive for now");
     EatToEndOfStatement();
@@ -901,8 +903,8 @@
 }
 
 /// ParseDirectiveComm
-///  ::= .comm identifier , size_expression [ , align_expression ]
-bool AsmParser::ParseDirectiveComm() {
+///  ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ]
+bool AsmParser::ParseDirectiveComm(bool IsLocal) {
   if (Lexer.isNot(asmtok::Identifier))
     return TokError("expected identifier in directive");
   
@@ -930,28 +932,29 @@
   }
   
   if (Lexer.isNot(asmtok::EndOfStatement))
-    return TokError("unexpected token in '.comm' directive");
+    return TokError("unexpected token in '.comm' or '.lcomm' directive");
   
   Lexer.Lex();
 
-  // NOTE: a size of zero should create a undefined symbol
+  // NOTE: a size of zero for a .comm should create a undefined symbol
+  // but a size of .lcomm creates a bss symbol of size zero.
   if (Size < 0)
-    return Error(SizeLoc, "invalid '.comm' size, can't be less than zero");
+    return Error(SizeLoc, "invalid '.comm' or '.lcomm' directive size, can't "
+                 "be less than zero");
 
   // NOTE: The alignment in the directive is a power of 2 value, the assember
   // may internally end up wanting an alignment in bytes.
   // FIXME: Diagnose overflow.
   if (Pow2Alignment < 0)
-    return Error(Pow2AlignmentLoc, "invalid '.comm' alignment, can't be less "
-                 "than zero");
+    return Error(Pow2AlignmentLoc, "invalid '.comm' or '.lcomm' directive "
+                 "alignment, can't be less than zero");
 
   // TODO: Symbol must be undefined or it is a error to re-defined the symbol
   if (Sym->getSection() || Ctx.GetSymbolValue(Sym))
     return Error(IDLoc, "invalid symbol redefinition");
 
-  // TODO: Symbol to be made into a common with this Size and Pow2Alignment
-
-  Out.EmitCommonSymbol(Sym, Size, Pow2Alignment);
+  // Create the Symbol as a common or local common with Size and Pow2Alignment
+  Out.EmitCommonSymbol(Sym, Size, Pow2Alignment, IsLocal);
 
   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=75148&r1=75147&r2=75148&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Thu Jul  9 12:25:12 2009
@@ -110,7 +110,7 @@
   /// accepts a single symbol (which should be a label or an external).
   bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
 
-  bool ParseDirectiveComm(); // ".comm"
+  bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
   
 };
 





More information about the llvm-commits mailing list