diff options
| author | Heejin Ahn <aheejin@gmail.com> | 2018-11-14 02:46:21 +0000 |
|---|---|---|
| committer | Heejin Ahn <aheejin@gmail.com> | 2018-11-14 02:46:21 +0000 |
| commit | da419bdb5e3e167ea90c6923660059f35fa17d67 (patch) | |
| tree | 0264ae56ecdddf59399c2b355e1dee8eeffafb63 /llvm/tools/yaml2obj/yaml2wasm.cpp | |
| parent | 6a3c279d1cdcd4205a233952b4bacd5941cd355e (diff) | |
| download | bcm5719-llvm-da419bdb5e3e167ea90c6923660059f35fa17d67.tar.gz bcm5719-llvm-da419bdb5e3e167ea90c6923660059f35fa17d67.zip | |
[WebAssembly] Add support for the event section
Summary:
This adds support for the 'event section' specified in the exception
handling proposal. (This was named 'exception section' first, but later
renamed to 'event section' to take possibilities of other kinds of
events into consideration. But currently we only store exception info in
this section.)
The event section is added between the global section and the export
section. This is for ease of validation per request of the V8 team.
This patch:
- Creates the event symbol type, which is a weak symbol
- Makes 'throw' instruction take the event symbol '__cpp_exception'
- Adds relocation support for events
- Adds WasmObjectWriter / WasmObjectFile (Reader) support
- Adds obj2yaml / yaml2obj support
- Adds '.eventtype' printing support
Reviewers: dschuff, sbc100, aardappel
Subscribers: jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D54096
llvm-svn: 346825
Diffstat (limited to 'llvm/tools/yaml2obj/yaml2wasm.cpp')
| -rw-r--r-- | llvm/tools/yaml2obj/yaml2wasm.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp index 2b1e256f8f6..4a9269d96a1 100644 --- a/llvm/tools/yaml2obj/yaml2wasm.cpp +++ b/llvm/tools/yaml2obj/yaml2wasm.cpp @@ -37,6 +37,7 @@ private: int writeSectionContent(raw_ostream &OS, WasmYAML::TableSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::MemorySection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::GlobalSection &Section); + int writeSectionContent(raw_ostream &OS, WasmYAML::EventSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::ExportSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::StartSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::ElemSection &Section); @@ -49,6 +50,7 @@ private: WasmYAML::Object &Obj; uint32_t NumImportedFunctions = 0; uint32_t NumImportedGlobals = 0; + uint32_t NumImportedEvents = 0; }; static int writeUint64(raw_ostream &OS, uint64_t Value) { @@ -152,6 +154,7 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, switch (Info.Kind) { case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_GLOBAL: + case wasm::WASM_SYMBOL_TYPE_EVENT: encodeULEB128(Info.ElementIndex, SubSection.GetStream()); if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) writeStringRef(Info.Name, SubSection.GetStream()); @@ -292,6 +295,11 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, writeUint8(OS, Import.GlobalImport.Mutable); NumImportedGlobals++; break; + case wasm::WASM_EXTERNAL_EVENT: + writeUint32(OS, Import.EventImport.Attribute); + writeUint32(OS, Import.EventImport.SigIndex); + NumImportedGlobals++; + break; case wasm::WASM_EXTERNAL_MEMORY: writeLimits(Import.Memory, OS); break; @@ -370,6 +378,22 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, } int WasmWriter::writeSectionContent(raw_ostream &OS, + WasmYAML::EventSection &Section) { + encodeULEB128(Section.Events.size(), OS); + uint32_t ExpectedIndex = NumImportedEvents; + for (auto &Event : Section.Events) { + if (Event.Index != ExpectedIndex) { + errs() << "Unexpected event index: " << Event.Index << "\n"; + return 1; + } + ++ExpectedIndex; + encodeULEB128(Event.Attribute, OS); + encodeULEB128(Event.SigIndex, OS); + } + return 0; +} + +int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::ElemSection &Section) { encodeULEB128(Section.Segments.size(), OS); for (auto &Segment : Section.Segments) { @@ -474,17 +498,7 @@ int WasmWriter::writeWasm(raw_ostream &OS) { writeUint32(OS, Obj.Header.Version); // Write each section - uint32_t LastType = 0; for (const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) { - uint32_t Type = Sec->Type; - if (Type != wasm::WASM_SEC_CUSTOM) { - if (Type < LastType) { - errs() << "Out of order section type: " << Type << "\n"; - return 1; - } - LastType = Type; - } - encodeULEB128(Sec->Type, OS); std::string OutString; raw_string_ostream StringStream(OutString); @@ -509,6 +523,9 @@ int WasmWriter::writeWasm(raw_ostream &OS) { } else if (auto S = dyn_cast<WasmYAML::GlobalSection>(Sec.get())) { if (auto Err = writeSectionContent(StringStream, *S)) return Err; + } else if (auto S = dyn_cast<WasmYAML::EventSection>(Sec.get())) { + if (auto Err = writeSectionContent(StringStream, *S)) + return Err; } else if (auto S = dyn_cast<WasmYAML::ExportSection>(Sec.get())) { if (auto Err = writeSectionContent(StringStream, *S)) return Err; |

