Add AsmParser support for darwin tbss directive.
authorEric Christopher <echristo@apple.com>
Fri, 14 May 2010 01:50:28 +0000 (01:50 +0000)
committerEric Christopher <echristo@apple.com>
Fri, 14 May 2010 01:50:28 +0000 (01:50 +0000)
Nothing uses this yet.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103757 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/AsmParser.h
include/llvm/MC/MCStreamer.h
lib/MC/MCAsmStreamer.cpp
lib/MC/MCMachOStreamer.cpp
lib/MC/MCNullStreamer.cpp
lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/directive_tbss.s [new file with mode: 0644]

index 7a78906733afa1659344f4e5f1aaa887a018830d..e668e6474e86556339781853393bd9dd95b3450e 100644 (file)
@@ -136,6 +136,7 @@ private:
 
   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
   bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
+  bool ParseDirectiveDarwinTBSS(); // Darwin specific ".tbss"
 
   // Darwin specific ".subsections_via_symbols"
   bool ParseDirectiveDarwinSubsectionsViaSymbols();
index 9e9f68a8daab44cb1af8009882533ddde45e901c..400f4c027db0ea205ed19a461a4e6cf2b12c1e22 100644 (file)
@@ -188,6 +188,14 @@ namespace llvm {
     virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
                               unsigned Size = 0,unsigned ByteAlignment = 0) = 0;
 
+    /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
+    ///
+    /// @param Symbol - The thread local common symbol to emit.
+    /// @param Size - The size of the symbol.
+    /// @param ByteAlignment - The alignment of the thread local common symbol
+    /// if non-zero.  This must be a power of 2 on some targets.
+    virtual void EmitTBSSSymbol(MCSymbol *Symbol, uint64_t Size,
+                                unsigned ByteAlignment = 0) = 0;
     /// @}
     /// @name Generating Data
     /// @{
index 6acc90af8a5101ad2c8df255efd0b0ff03336ecd..62735ad3f3a9a4f3f89bc9697c5d6610fc5db5ad 100644 (file)
@@ -126,6 +126,9 @@ public:
   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
                             unsigned Size = 0, unsigned ByteAlignment = 0);
 
+  virtual void EmitTBSSSymbol (MCSymbol *Symbol, uint64_t Size,
+                               unsigned ByteAlignment = 0);
+                               
   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
 
   virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
@@ -360,6 +363,21 @@ void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
   EmitEOL();
 }
 
+// .tbss sym$tlv$init, size, align
+void MCAsmStreamer::EmitTBSSSymbol(MCSymbol *Symbol, uint64_t Size,
+                                   unsigned ByteAlignment) {
+  assert(Symbol != NULL && "Symbol shouldn't be NULL!");
+  OS << ".tbss ";
+  
+  // This is a mach-o specific directive and the name requires some mangling.
+  OS << *Symbol << "$tlv$init, " << Size;
+  
+  // Output align if we have it.
+  if (ByteAlignment != 0) OS << ", " << Log2_32(ByteAlignment);
+  
+  EmitEOL();
+}
+
 static inline char toOctal(int X) { return (X&7)+'0'; }
 
 static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
index 62abf745ba7a9b5fa05d63d1c849359afb288015..b27f151f4341b0be6443b3bae9e449314530c591 100644 (file)
@@ -126,6 +126,8 @@ public:
   }
   virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
                             unsigned Size = 0, unsigned ByteAlignment = 0);
+  virtual void EmitTBSSSymbol(MCSymbol *Symbol, uint64_t Size,
+                              unsigned ByteAlignment = 0);
   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
   virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
   virtual void EmitGPRel32Value(const MCExpr *Value) {
@@ -337,6 +339,11 @@ void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
     SectData.setAlignment(ByteAlignment);
 }
 
+void MCMachOStreamer::EmitTBSSSymbol(MCSymbol *Symbol, uint64_t Size,
+                                     unsigned ByteAlignment) {
+  assert(false && "Implement me!");
+}
+
 void MCMachOStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
   getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
 }
index 8bde2d9b06c8f4443cd981310f7e1ac52d108d34..c206bb34517778e05846dc2e3700eeca9c9f5720 100644 (file)
@@ -55,7 +55,8 @@ namespace {
 
     virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
                               unsigned Size = 0, unsigned ByteAlignment = 0) {}
-
+    virtual void EmitTBSSSymbol(MCSymbol *Symbol, uint64_t Size,
+                                unsigned ByteAlignment) {}
     virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
 
     virtual void EmitValue(const MCExpr *Value, unsigned Size,
index fe2164cfd88f9fd6912f437511891486f4994462..18977de8adb9e035126a64f7fbb1f5dea1d6a9a4 100644 (file)
@@ -703,6 +703,8 @@ bool AsmParser::ParseStatement() {
       return ParseDirectiveDarwinSymbolDesc();
     if (IDVal == ".lsym")
       return ParseDirectiveDarwinLsym();
+    if (IDVal == ".tbss")
+      return ParseDirectiveDarwinTBSS();
 
     if (IDVal == ".subsections_via_symbols")
       return ParseDirectiveDarwinSubsectionsViaSymbols();
@@ -1427,6 +1429,61 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
   return false;
 }
 
+/// ParseDirectiveDarwinTBSS
+///  ::= .tbss identifier, size, align
+bool AsmParser::ParseDirectiveDarwinTBSS() {
+  SMLoc IDLoc = Lexer.getLoc();
+  StringRef Name;
+  if (ParseIdentifier(Name))
+    return TokError("expected identifier in directive");
+  
+  // Demangle the name output.  The trailing characters are guaranteed to be
+  // $tlv$init so just strip that off.
+  StringRef DemName = Name.substr(0, Name.size() - strlen("$tlv$init"));
+  
+  // Handle the identifier as the key symbol.
+  MCSymbol *Sym = CreateSymbol(DemName);
+
+  if (Lexer.isNot(AsmToken::Comma))
+    return TokError("unexpected token in directive");
+  Lex();
+
+  int64_t Size;
+  SMLoc SizeLoc = Lexer.getLoc();
+  if (ParseAbsoluteExpression(Size))
+    return true;
+
+  int64_t Pow2Alignment = 0;
+  SMLoc Pow2AlignmentLoc;
+  if (Lexer.is(AsmToken::Comma)) {
+    Lex();
+    Pow2AlignmentLoc = Lexer.getLoc();
+    if (ParseAbsoluteExpression(Pow2Alignment))
+      return true;
+  }
+  
+  if (Lexer.isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.tbss' directive");
+  
+  Lex();
+
+  if (Size < 0)
+    return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than"
+                 "zero");
+
+  // FIXME: Diagnose overflow.
+  if (Pow2Alignment < 0)
+    return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less"
+                 "than zero");
+
+  if (!Sym->isUndefined())
+    return Error(IDLoc, "invalid symbol redefinition");
+  
+  Out.EmitTBSSSymbol(Sym, Size, Pow2Alignment ? 1 << Pow2Alignment : 0);
+  
+  return false;
+}
+
 /// ParseDirectiveDarwinSubsectionsViaSymbols
 ///  ::= .subsections_via_symbols
 bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() {
diff --git a/test/MC/AsmParser/directive_tbss.s b/test/MC/AsmParser/directive_tbss.s
new file mode 100644 (file)
index 0000000..01ba17b
--- /dev/null
@@ -0,0 +1,7 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+# CHECK: .tbss _a$tlv$init, 4
+# CHECK: .tbss _b$tlv$init, 4, 3
+
+.tbss _a$tlv$init, 4
+.tbss _b$tlv$init, 4, 3