diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-06-28 20:29:16 +0000 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-06-28 20:29:16 +0000 |
commit | 597ba1800869e6db6819014ce5e843a6a709bb45 (patch) | |
tree | 5c47bdfcebfcd81c75288dffe0bbbd80b312b4ef /llvm/lib/MC/MCParser/WasmAsmParser.cpp | |
parent | 30e5cf1d8f3ae419d9786595558707b1f230d081 (diff) | |
download | bcm5719-llvm-597ba1800869e6db6819014ce5e843a6a709bb45.tar.gz bcm5719-llvm-597ba1800869e6db6819014ce5e843a6a709bb45.zip |
[WebAssembly] Assembler: Improve section parsing.
Reviewers: sbc100
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63947
llvm-svn: 364681
Diffstat (limited to 'llvm/lib/MC/MCParser/WasmAsmParser.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/WasmAsmParser.cpp | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp index 3000a2315d3..141e7fc36f9 100644 --- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -114,13 +114,17 @@ public: 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); + auto Kind = StringSwitch<Optional<SectionKind>>(Name) + .StartsWith(".data", SectionKind::getData()) + .StartsWith(".rodata", SectionKind::getReadOnly()) + .StartsWith(".text", SectionKind::getText()) + .StartsWith(".custom_section", SectionKind::getMetadata()) + .StartsWith(".bss", SectionKind::getBSS()) + .Default(Optional<SectionKind>()); + 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; @@ -139,28 +143,9 @@ public: if (expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") || expect(AsmToken::EndOfStatement, "eol")) return true; - struct SectionType { - const char *Name; - SectionKind Kind; - }; - static SectionType SectionTypes[] = { - {".text", SectionKind::getText()}, - {".rodata", SectionKind::getReadOnly()}, - {".data", SectionKind::getData()}, - {".custom_section", SectionKind::getMetadata()}, - // TODO: add more types. - }; - for (size_t I = 0; I < sizeof(SectionTypes) / sizeof(SectionType); I++) { - if (Name.startswith(SectionTypes[I].Name)) { - auto WS = getContext().getWasmSection(Name, SectionTypes[I].Kind); - getStreamer().SwitchSection(WS); - return false; - } - } - // Not found, just ignore this section. - // For code in a text section WebAssemblyAsmParser automatically adds - // one section per function, so they're optional to be specified with - // this directive. + + auto WS = getContext().getWasmSection(Name, Kind.getValue()); + getStreamer().SwitchSection(WS); return false; } |