summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCParser/WasmAsmParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/MC/MCParser/WasmAsmParser.cpp')
-rw-r--r--llvm/lib/MC/MCParser/WasmAsmParser.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
index 17d86aa0d64..a8a48d1cd69 100644
--- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -81,13 +81,53 @@ 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")
+ Passive = true;
+ else
+ return error("Expected section flags, instead got: ", Lexer->getTok());
+ }
+ return false;
+ }
+
bool parseSectionDirective(StringRef, SMLoc) {
StringRef Name;
if (Parser->parseIdentifier(Name))
return TokError("expected identifier in directive");
- // FIXME: currently requiring this very fixed format.
- if (expect(AsmToken::Comma, ",") || expect(AsmToken::String, "string") ||
- expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") ||
+
+ if (expect(AsmToken::Comma, ","))
+ return true;
+
+ if (Lexer->isNot(AsmToken::String))
+ return error("expected string in directive, instead got: ", Lexer->getTok());
+
+ SectionKind Kind = StringSwitch<SectionKind>(Name)
+ .StartsWith(".data", SectionKind::getData())
+ .StartsWith(".rodata", SectionKind::getReadOnly())
+ .StartsWith(".text", SectionKind::getText())
+ .StartsWith(".custom_section", SectionKind::getMetadata());
+
+ MCSectionWasm* Section = getContext().getWasmSection(Name, Kind);
+
+ // Update section flags if present in this .section directive
+ bool Passive = false;
+ if (parseSectionFlags(getTok().getStringContents(), Passive))
+ 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"))
return true;
// This is done automatically by the assembler for text sections currently,
OpenPOWER on IntegriCloud