Add support for parsing .size directives for ELF.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 17 Jul 2010 03:09:18 +0000 (03:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 17 Jul 2010 03:09:18 +0000 (03:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108606 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/ELFAsmParser.cpp

index 7a54dd39aa479720fbb654303b3faec97212ce19..f87031860e629fa59f174d2e620c25fd3faf87ad 100644 (file)
@@ -31,6 +31,8 @@ public:
                                  &ELFAsmParser::ParseSectionDirectiveData));
     Parser.AddDirectiveHandler(this, ".text", MCAsmParser::DirectiveHandler(
                                  &ELFAsmParser::ParseSectionDirectiveText));
+    Parser.AddDirectiveHandler(this, ".size", MCAsmParser::DirectiveHandler(
+                                 &ELFAsmParser::ParseSizeDirective));
   }
 
   bool ParseSectionDirectiveData(StringRef, SMLoc) {
@@ -43,6 +45,7 @@ public:
                               MCSectionELF::SHF_EXECINSTR |
                               MCSectionELF::SHF_ALLOC, SectionKind::getText());
   }
+  bool ParseSizeDirective(StringRef, SMLoc);
 };
 
 }
@@ -59,6 +62,27 @@ bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
   return false;
 }
 
+bool ELFAsmParser::ParseSizeDirective(StringRef, SMLoc) {
+  StringRef Name;
+  if (getParser().ParseIdentifier(Name))
+    return TokError("expected identifier in directive");
+  MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);;
+
+  if (getLexer().isNot(AsmToken::Comma))
+    return TokError("unexpected token in directive");
+  Lex();
+
+  const MCExpr *Expr;
+  if (getParser().ParseExpression(Expr))
+    return true;
+
+  if (getLexer().isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in directive");
+
+  getStreamer().EmitELFSize(Sym, Expr);
+  return false;
+}
+
 namespace llvm {
 
 MCAsmParserExtension *createELFAsmParser() {