summaryrefslogtreecommitdiff
path: root/tools/llvm-mc/AsmParser.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-30 00:33:19 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-30 00:33:19 +0000
commitd7b267bd908ee1a1792a6a917c036e764fc3ace0 (patch)
treebffeb3ad2677bfc0651dc023a2fc2e685d17d996 /tools/llvm-mc/AsmParser.cpp
parente25b845b437cdee395d22c9e2f292fc2dec9521d (diff)
downloadllvm-d7b267bd908ee1a1792a6a917c036e764fc3ace0.tar.gz
llvm-d7b267bd908ee1a1792a6a917c036e764fc3ace0.tar.bz2
llvm-d7b267bd908ee1a1792a6a917c036e764fc3ace0.tar.xz
llvm-mc: Parse symbol attribute directives.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74487 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/AsmParser.cpp')
-rw-r--r--tools/llvm-mc/AsmParser.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index 29222d4c0f..9a71139873 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/tools/llvm-mc/AsmParser.cpp
@@ -456,6 +456,32 @@ bool AsmParser::ParseStatement() {
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 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
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;
+}