diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-03-04 17:18:04 +0000 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-03-04 17:18:04 +0000 |
commit | f3feb6adb919770f7ad4888ecb3a5c15076e5bf6 (patch) | |
tree | 07d7f20e8baa412aabf78b4aaa5503b6d8007fc9 /llvm/lib/MC/MCParser/WasmAsmParser.cpp | |
parent | de11105d2ece076e9d8dcfb01286643e81af8922 (diff) | |
download | bcm5719-llvm-f3feb6adb919770f7ad4888ecb3a5c15076e5bf6.tar.gz bcm5719-llvm-f3feb6adb919770f7ad4888ecb3a5c15076e5bf6.zip |
[WebAssembly] Add support for data sections in the assembler.
Summary:
This is quite minimal so far, introduce them with .section,
fill them with .int8 or .asciz, end with .size
Reviewers: dschuff, sbc100, aheejin
Subscribers: jgravelle-google, sunfish, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58660
llvm-svn: 355321
Diffstat (limited to 'llvm/lib/MC/MCParser/WasmAsmParser.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/WasmAsmParser.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp index a8a48d1cd69..197e9052566 100644 --- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -130,11 +130,27 @@ public: if (expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") || expect(AsmToken::EndOfStatement, "eol")) return true; - // This is done automatically by the assembler for text sections currently, - // so we don't need to emit that here. This is what it would do (and may - // be needed later for other section types): - // auto WS = getContext().getWasmSection(Name, SectionKind::getText()); - // getStreamer().SwitchSection(WS); + struct SectionType { + const char *Name; + SectionKind Kind; + }; + static SectionType SectionTypes[] = { + { ".text", SectionKind::getText() }, + { ".rodata", SectionKind::getReadOnly() }, + { ".data", SectionKind::getData() }, + // 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. return false; } @@ -153,9 +169,8 @@ public: if (expect(AsmToken::EndOfStatement, "eol")) return true; // This is done automatically by the assembler for functions currently, - // so we don't need to emit that here. This is what it would do: - (void)Sym; - // getStreamer().emitELFSize(Sym, Expr); + // so this is only currently needed for data sections: + getStreamer().emitELFSize(Sym, Expr); return false; } |