[llvm-commits] [llvm] r74058 - in /llvm/trunk/tools/llvm-mc: AsmParser.cpp AsmParser.h

Chris Lattner sabre at nondot.org
Tue Jun 23 21:43:34 PDT 2009


Author: lattner
Date: Tue Jun 23 23:43:34 2009
New Revision: 74058

URL: http://llvm.org/viewvc/llvm-project?rev=74058&view=rev
Log:
add support for parsing and emitting .section directives.  We can now parse 
things like:
.section __TEXT,__cstring,cstring_literals



Modified:
    llvm/trunk/tools/llvm-mc/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.h

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

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jun 23 23:43:34 2009
@@ -196,6 +196,10 @@
   
   // Otherwise, we have a normal instruction or directive.  
   if (IDVal[0] == '.') {
+    if (!strcmp(IDVal, ".section"))
+      return ParseDirectiveSection();
+    
+    
     Lexer.PrintMessage(IDLoc, "warning: ignoring directive for now");
     EatToEndOfStatement();
     return false;
@@ -207,7 +211,7 @@
     return true;
   
   if (Lexer.isNot(asmtok::EndOfStatement))
-    return TokError("unexpected token in operand list");
+    return TokError("unexpected token in argument list");
 
   // Eat the end of statement marker.
   Lexer.Lex();
@@ -219,3 +223,32 @@
   // Skip to end of line for now.
   return false;
 }
+
+/// ParseDirectiveSection:
+///   ::= .section identifier
+bool AsmParser::ParseDirectiveSection() {
+  if (Lexer.isNot(asmtok::Identifier))
+    return TokError("expected identifier after '.section' directive");
+  
+  std::string Section = Lexer.getCurStrVal();
+  Lexer.Lex();
+  
+  // Accept a comma separated list of modifiers.
+  while (Lexer.is(asmtok::Comma)) {
+    Lexer.Lex();
+    
+    if (Lexer.isNot(asmtok::Identifier))
+      return TokError("expected identifier in '.section' directive");
+    Section += ',';
+    Section += Lexer.getCurStrVal();
+    Lexer.Lex();
+  }
+  
+  if (Lexer.isNot(asmtok::EndOfStatement))
+    return TokError("unexpected token in '.section' directive");
+  Lexer.Lex();
+
+  Out.SwitchSection(Ctx.GetSection(Section.c_str()));
+  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=74058&r1=74057&r2=74058&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jun 23 23:43:34 2009
@@ -52,6 +52,10 @@
   bool ParseX86InstOperands(MCInst &Inst);
   bool ParseX86Operand(X86Operand &Op);
   bool ParseX86MemOperand(X86Operand &Op);
+  
+  // Directive Parsing.
+  bool ParseDirectiveSection();
+  
 };
 
 } // end namespace llvm





More information about the llvm-commits mailing list