[llvm-commits] [llvm] r74487 - in /llvm/trunk: test/MC/AsmParser/directive_symbol_attrs.s tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h
Daniel Dunbar
daniel at zuster.org
Mon Jun 29 17:33:19 PDT 2009
Author: ddunbar
Date: Mon Jun 29 19:33:19 2009
New Revision: 74487
URL: http://llvm.org/viewvc/llvm-project?rev=74487&view=rev
Log:
llvm-mc: Parse symbol attribute directives.
Added:
llvm/trunk/test/MC/AsmParser/directive_symbol_attrs.s
Modified:
llvm/trunk/tools/llvm-mc/AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.h
Added: llvm/trunk/test/MC/AsmParser/directive_symbol_attrs.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_symbol_attrs.s?rev=74487&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_symbol_attrs.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_symbol_attrs.s Mon Jun 29 19:33:19 2009
@@ -0,0 +1,7 @@
+# RUN: llvm-mc %s > %t
+
+# RUN: grep -A 3 TEST0 %t > %t2
+# RUN: grep ".globl a" %t2 | count 1
+# RUN: grep ".globl b" %t2 | count 1
+TEST0:
+ .globl a, b
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=74487&r1=74486&r2=74487&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Mon Jun 29 19:33:19 2009
@@ -456,6 +456,32 @@
if (!strcmp(IDVal, ".space"))
return ParseDirectiveSpace();
+ // Symbol attribute directives
+ if (!strcmp(IDVal, ".globl") || !strcmp(IDVal, ".global"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::Global);
+ if (!strcmp(IDVal, ".hidden"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::Hidden);
+ if (!strcmp(IDVal, ".indirect_symbol"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::IndirectSymbol);
+ if (!strcmp(IDVal, ".internal"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::Internal);
+ if (!strcmp(IDVal, ".lazy_reference"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::LazyReference);
+ if (!strcmp(IDVal, ".no_dead_strip"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::NoDeadStrip);
+ if (!strcmp(IDVal, ".private_extern"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::PrivateExtern);
+ if (!strcmp(IDVal, ".protected"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::Protected);
+ if (!strcmp(IDVal, ".reference"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::Reference);
+ if (!strcmp(IDVal, ".weak"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::Weak);
+ if (!strcmp(IDVal, ".weak_definition"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::WeakDefinition);
+ if (!strcmp(IDVal, ".weak_reference"))
+ return ParseDirectiveSymbolAttribute(MCStreamer::WeakReference);
+
Lexer.PrintMessage(IDLoc, "warning: ignoring directive for now");
EatToEndOfStatement();
return false;
@@ -802,3 +828,32 @@
return false;
}
+/// ParseDirectiveSymbolAttribute
+/// ::= { ".globl", ".weak", ... } [ identifier ( , identifier )* ]
+bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
+ if (Lexer.isNot(asmtok::EndOfStatement)) {
+ for (;;) {
+ if (Lexer.isNot(asmtok::Identifier))
+ return TokError("expected identifier in directive");
+
+ MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
+ Lexer.Lex();
+
+ // If this is use of an undefined symbol then mark it external.
+ if (!Sym->getSection() && !Ctx.GetSymbolValue(Sym))
+ Sym->setExternal(true);
+
+ Out.EmitSymbolAttribute(Sym, Attr);
+
+ if (Lexer.is(asmtok::EndOfStatement))
+ break;
+
+ if (Lexer.isNot(asmtok::Comma))
+ return TokError("unexpected token in directive");
+ Lexer.Lex();
+ }
+ }
+
+ Lexer.Lex();
+ 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=74487&r1=74486&r2=74487&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Mon Jun 29 19:33:19 2009
@@ -15,6 +15,7 @@
#define ASMPARSER_H
#include "AsmLexer.h"
+#include "llvm/MC/MCStreamer.h"
namespace llvm {
class AsmExpr;
@@ -81,6 +82,10 @@
bool ParseDirectiveOrg(); // ".org"
// ".align{,32}", ".p2align{,w,l}"
bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
+
+ /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
+ /// accepts a single symbol (which should be a label or an external).
+ bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
};
More information about the llvm-commits
mailing list