aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp82
1 files changed, 60 insertions, 22 deletions
diff --git a/contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp
index 05f23e143341..0c255ef02d2a 100644
--- a/contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ b/contrib/llvm-project/llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -90,15 +90,40 @@ public:
return false;
}
- bool parseSectionFlags(StringRef FlagStr, bool &Passive) {
- SmallVector<StringRef, 2> Flags;
- // If there are no flags, keep Flags empty
- FlagStr.split(Flags, ",", -1, false);
- for (auto &Flag : Flags) {
- if (Flag == "passive")
+ bool parseSectionFlags(StringRef FlagStr, bool &Passive, bool &Group) {
+ for (char C : FlagStr) {
+ switch (C) {
+ case 'p':
Passive = true;
- else
- return error("Expected section flags, instead got: ", Lexer->getTok());
+ break;
+ case 'G':
+ Group = true;
+ break;
+ default:
+ return Parser->Error(getTok().getLoc(),
+ StringRef("Unexepcted section flag: ") + FlagStr);
+ }
+ }
+ return false;
+ }
+
+ bool parseGroup(StringRef &GroupName) {
+ if (Lexer->isNot(AsmToken::Comma))
+ return TokError("expected group name");
+ Lex();
+ if (Lexer->is(AsmToken::Integer)) {
+ GroupName = getTok().getString();
+ Lex();
+ } else if (Parser->parseIdentifier(GroupName)) {
+ return TokError("invalid group name");
+ }
+ if (Lexer->is(AsmToken::Comma)) {
+ Lex();
+ StringRef Linkage;
+ if (Parser->parseIdentifier(Linkage))
+ return TokError("invalid linkage");
+ if (Linkage != "comdat")
+ return TokError("Linkage must be 'comdat'");
}
return false;
}
@@ -116,6 +141,8 @@ public:
auto Kind = StringSwitch<Optional<SectionKind>>(Name)
.StartsWith(".data", SectionKind::getData())
+ .StartsWith(".tdata", SectionKind::getThreadData())
+ .StartsWith(".tbss", SectionKind::getThreadBSS())
.StartsWith(".rodata", SectionKind::getReadOnly())
.StartsWith(".text", SectionKind::getText())
.StartsWith(".custom_section", SectionKind::getMetadata())
@@ -128,27 +155,34 @@ public:
if (!Kind.hasValue())
return Parser->Error(Lexer->getLoc(), "unknown section kind: " + Name);
- MCSectionWasm *Section = getContext().getWasmSection(Name, Kind.getValue());
// Update section flags if present in this .section directive
bool Passive = false;
- if (parseSectionFlags(getTok().getStringContents(), Passive))
+ bool Group = false;
+ if (parseSectionFlags(getTok().getStringContents(), Passive, Group))
return true;
- if (Passive) {
- if (!Section->isWasmData())
- return Parser->Error(getTok().getLoc(),
- "Only data sections can be passive");
- Section->setPassive();
- }
-
Lex();
- if (expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") ||
- expect(AsmToken::EndOfStatement, "eol"))
+ if (expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@"))
+ return true;
+
+ StringRef GroupName;
+ if (Group && parseGroup(GroupName))
+ return true;
+
+ if (expect(AsmToken::EndOfStatement, "eol"))
return true;
- auto WS = getContext().getWasmSection(Name, Kind.getValue());
+ // TODO: Parse UniqueID
+ MCSectionWasm *WS = getContext().getWasmSection(
+ Name, Kind.getValue(), GroupName, MCContext::GenericSectionID);
+ if (Passive) {
+ if (!WS->isWasmData())
+ return Parser->Error(getTok().getLoc(),
+ "Only data sections can be passive");
+ WS->setPassive();
+ }
getStreamer().SwitchSection(WS);
return false;
}
@@ -187,9 +221,13 @@ public:
Lexer->is(AsmToken::Identifier)))
return error("Expected label,@type declaration, got: ", Lexer->getTok());
auto TypeName = Lexer->getTok().getString();
- if (TypeName == "function")
+ if (TypeName == "function") {
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
- else if (TypeName == "global")
+ auto *Current =
+ cast<MCSectionWasm>(getStreamer().getCurrentSection().first);
+ if (Current->getGroup())
+ WasmSym->setComdat(true);
+ } else if (TypeName == "global")
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
else if (TypeName == "object")
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_DATA);