summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorWouter van Oortmerssen <aardappel@gmail.com>2019-06-28 16:51:06 +0000
committerWouter van Oortmerssen <aardappel@gmail.com>2019-06-28 16:51:06 +0000
commit633d222d30b0d8923009b85f63aa209524fd8ffd (patch)
treeb9ac77ddf6cca0586b54464d8dc53e704cc76d79 /llvm/lib
parent3b4f086df4a02c6eda60477302cec00772fdcfb4 (diff)
downloadbcm5719-llvm-633d222d30b0d8923009b85f63aa209524fd8ffd.tar.gz
bcm5719-llvm-633d222d30b0d8923009b85f63aa209524fd8ffd.zip
[WebAssembly] Added visibility and ident directives to WasmAsmParser.
Summary: These are output by clang -S, so can now be roundtripped thru clang. (partially) fixes: https://bugs.llvm.org/show_bug.cgi?id=34544 Reviewers: dschuff Subscribers: sbc100, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63901 llvm-svn: 364658
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/MCParser/WasmAsmParser.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
index 1054b871052..3000a2315d3 100644
--- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -56,6 +56,15 @@ public:
addDirectiveHandler<&WasmAsmParser::parseSectionDirective>(".section");
addDirectiveHandler<&WasmAsmParser::parseDirectiveSize>(".size");
addDirectiveHandler<&WasmAsmParser::parseDirectiveType>(".type");
+ addDirectiveHandler<&WasmAsmParser::ParseDirectiveIdent>(".ident");
+ addDirectiveHandler<
+ &WasmAsmParser::ParseDirectiveSymbolAttribute>(".weak");
+ addDirectiveHandler<
+ &WasmAsmParser::ParseDirectiveSymbolAttribute>(".local");
+ addDirectiveHandler<
+ &WasmAsmParser::ParseDirectiveSymbolAttribute>(".internal");
+ addDirectiveHandler<
+ &WasmAsmParser::ParseDirectiveSymbolAttribute>(".hidden");
}
bool error(const StringRef &Msg, const AsmToken &Tok) {
@@ -198,6 +207,51 @@ public:
Lex();
return expect(AsmToken::EndOfStatement, "EOL");
}
+
+ // FIXME: Shared with ELF.
+ /// ParseDirectiveIdent
+ /// ::= .ident string
+ bool ParseDirectiveIdent(StringRef, SMLoc) {
+ if (getLexer().isNot(AsmToken::String))
+ return TokError("unexpected token in '.ident' directive");
+ StringRef Data = getTok().getIdentifier();
+ Lex();
+ if (getLexer().isNot(AsmToken::EndOfStatement))
+ return TokError("unexpected token in '.ident' directive");
+ Lex();
+ getStreamer().EmitIdent(Data);
+ return false;
+ }
+
+ // FIXME: Shared with ELF.
+ /// ParseDirectiveSymbolAttribute
+ /// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ]
+ bool ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
+ MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
+ .Case(".weak", MCSA_Weak)
+ .Case(".local", MCSA_Local)
+ .Case(".hidden", MCSA_Hidden)
+ .Case(".internal", MCSA_Internal)
+ .Case(".protected", MCSA_Protected)
+ .Default(MCSA_Invalid);
+ assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
+ if (getLexer().isNot(AsmToken::EndOfStatement)) {
+ while (true) {
+ StringRef Name;
+ if (getParser().parseIdentifier(Name))
+ return TokError("expected identifier in directive");
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
+ getStreamer().EmitSymbolAttribute(Sym, Attr);
+ if (getLexer().is(AsmToken::EndOfStatement))
+ break;
+ if (getLexer().isNot(AsmToken::Comma))
+ return TokError("unexpected token in directive");
+ Lex();
+ }
+ }
+ Lex();
+ return false;
+ }
};
} // end anonymous namespace
OpenPOWER on IntegriCloud